com.gridsystems.utils
Class FileProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by com.gridsystems.utils.FileProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
Direct Known Subclasses:
SecureFileProperties

public class FileProperties
extends java.util.Properties

This class implements a Properties object linked to a File object. Changes in the file will be automatically updated, and changes in the object will produce changes in the file.

Version:
1.0
Author:
Rodrigo Ruiz
See Also:
Serialized Form

Field Summary
protected  java.io.File f
          The source file for the property data.
protected  java.lang.String header
          The header to set when writing the file.
protected  long lastModified
          The last known modification time of the file.
protected  java.util.concurrent.atomic.AtomicInteger lockWrite
          A flag indicating if a setProperty should invoke commit.
static java.lang.Boolean synchronize
          This value controls the access synchronised to the security files.
protected  long ts
          Last update time.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
FileProperties(java.io.File f)
          Create a file linked Properties object.
FileProperties(java.io.File f, java.util.Properties defaults)
          Creates a file linked Properties object, with the specified default values.
 
Method Summary
 void commit()
          Propagates changes in memory to the file associated with this object.
 boolean getBoolProperty(java.lang.String key)
          Gets a property as a boolean value.
 int getIntProperty(java.lang.String key)
          Gets a property as an int value.
 int getIntProperty(java.lang.String key, int defaultValue)
          Generic property access method for integer properties.
 long getLongProperty(java.lang.String key)
          Gets a property as a long value.
 long getLongProperty(java.lang.String key, long def)
          Gets a property as a long value.
 java.lang.String getProperty(java.lang.String key)
          Searches for the property with the specified key in this property list.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Searches for the property with the specified key in this property list.
 void lockWrites()
          It locks commits.
 java.util.Enumeration<?> propertyNames()
          Returns an enumeration of all the keys in this property list, including the keys in the default property list.
 void setFile(java.io.File f)
          Sets the file associated to this instance.
 void setHeader(java.lang.String header)
          Sets the text of the header that will be written to the file.
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Calls the hashtable method put.
protected  void sync()
          If associated file is older than current version, updates the properties from the file.
 void unlockWrites()
          It unlocks commits and commits the last changes.
 
Methods inherited from class java.util.Properties
list, list, load, load, loadFromXML, save, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

synchronize

public static java.lang.Boolean synchronize
This value controls the access synchronised to the security files.


f

protected java.io.File f
The source file for the property data.


lastModified

protected long lastModified
The last known modification time of the file.


ts

protected long ts
Last update time.


header

protected java.lang.String header
The header to set when writing the file.


lockWrite

protected java.util.concurrent.atomic.AtomicInteger lockWrite
A flag indicating if a setProperty should invoke commit.

Constructor Detail

FileProperties

public FileProperties(java.io.File f,
                      java.util.Properties defaults)
Creates a file linked Properties object, with the specified default values.

Parameters:
f - The file to link to
defaults - The default values

FileProperties

public FileProperties(java.io.File f)
Create a file linked Properties object.

Parameters:
f - The file to link to
Method Detail

setHeader

public void setHeader(java.lang.String header)
Sets the text of the header that will be written to the file.

Parameters:
header - The header text to use

setFile

public void setFile(java.io.File f)
Sets the file associated to this instance.

Parameters:
f - The file

lockWrites

public void lockWrites()
It locks commits. Used when you make multiple setProperties.


unlockWrites

public void unlockWrites()
It unlocks commits and commits the last changes.


getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.

Overrides:
getProperty in class java.util.Properties
Parameters:
key - the key.
defaultValue - a default value.
Returns:
the value in this property list with the specified key value.

getProperty

public java.lang.String getProperty(java.lang.String key)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

Overrides:
getProperty in class java.util.Properties
Parameters:
key - the property key.
Returns:
the value in this property list with the specified key value.

getIntProperty

public int getIntProperty(java.lang.String key,
                          int defaultValue)
Generic property access method for integer properties.

Parameters:
key - The name of the property
defaultValue - The default value to return in case of error
Returns:
the integer value of the property

getIntProperty

public int getIntProperty(java.lang.String key)
Gets a property as an int value.

Parameters:
key - The property key
Returns:
The property value as an int

getBoolProperty

public boolean getBoolProperty(java.lang.String key)
Gets a property as a boolean value.

Parameters:
key - The key of the property
Returns:
the boolean value of the property

getLongProperty

public long getLongProperty(java.lang.String key)
Gets a property as a long value.

Parameters:
key - The key of the property
Returns:
the long value of the property

getLongProperty

public long getLongProperty(java.lang.String key,
                            long def)
Gets a property as a long value.

Parameters:
key - The key of the property
def - The default value in case of error
Returns:
The long value of the property

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Calls the hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values.

Overrides:
setProperty in class java.util.Properties
Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value

propertyNames

public java.util.Enumeration<?> propertyNames()
Returns an enumeration of all the keys in this property list, including the keys in the default property list.

Overrides:
propertyNames in class java.util.Properties
Returns:
an enumeration of all the keys in this property list, including the keys in the default property list.
See Also:
Enumeration

sync

protected void sync()
If associated file is older than current version, updates the properties from the file.

If the file does not exists, the current values are cleared.


commit

public void commit()
Propagates changes in memory to the file associated with this object.



Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.