org.jets3t.service
Class Jets3tProperties

java.lang.Object
  extended by org.jets3t.service.Jets3tProperties
All Implemented Interfaces:
java.io.Serializable

public class Jets3tProperties
extends java.lang.Object
implements java.io.Serializable

Utility class to load and store JetS3t-specific properties.

Properties are initially loaded via getInstance methods from a named properties file, which must be available at the root of the classpath, or from an input stream. In either case the properties are cached according to a name, such that subsequent calls to get a properties instance with the same name will return the same properties object.

For more information about JetS3t properties please see: JetS3t Configuration

See Also:
Serialized Form

Field Summary
static java.lang.String JETS3T_PROPERTIES_ID
           
 
Constructor Summary
Jets3tProperties()
           
 
Method Summary
 void clearAllProperties()
          Clears (removes) all the property names and values used internally by this object.
 void clearProperty(java.lang.String propertyName)
          Removes a property name and value.
 boolean containsKey(java.lang.String propertyName)
           
 boolean getBoolProperty(java.lang.String propertyName, boolean defaultValue)
           
static Jets3tProperties getInstance(java.io.InputStream inputStream, java.lang.String propertiesIdentifer)
          Return a properties instance based on properties read from an input stream, and stores the properties object in a cache referenced by the propertiesIdentifier.
static Jets3tProperties getInstance(java.lang.String propertiesFileName)
          Return a properties instance based on properties read from a properties file, and stores the properties object in a cache referenced by the properties file name.
 int getIntProperty(java.lang.String propertyName, int defaultValue)
           
 long getLongProperty(java.lang.String propertyName, long defaultValue)
           
 java.util.Properties getProperties()
           
 java.lang.String getStringProperty(java.lang.String propertyName, java.lang.String defaultValue)
           
 boolean isLoaded()
           
 void loadAndReplaceProperties(java.io.InputStream inputStream, java.lang.String propertiesSource)
          Reads properties from an InputStream and stores them in this class's properties object.
 void loadAndReplaceProperties(Jets3tProperties properties, java.lang.String propertiesSource)
          Merges properties from another JetS3tProperties object into this instance.
 void loadAndReplaceProperties(java.util.Properties newProperties, java.lang.String propertiesSource)
          Merges properties from another Properties object into this instance.
 void setProperty(java.lang.String propertyName, java.lang.String propertyValue)
          Sets or removes a property value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JETS3T_PROPERTIES_ID

public static final java.lang.String JETS3T_PROPERTIES_ID
See Also:
Constant Field Values
Constructor Detail

Jets3tProperties

public Jets3tProperties()
Method Detail

getInstance

public static Jets3tProperties getInstance(java.io.InputStream inputStream,
                                           java.lang.String propertiesIdentifer)
                                    throws java.io.IOException
Return a properties instance based on properties read from an input stream, and stores the properties object in a cache referenced by the propertiesIdentifier.

Parameters:
inputStream - an input stream containing property name/value pairs in a format that can be read by Properties.load(InputStream).
propertiesIdentifer - the name under which the properties are cached
Returns:
a properties object initialised with property values from the input stream
Throws:
java.io.IOException

getInstance

public static Jets3tProperties getInstance(java.lang.String propertiesFileName)
Return a properties instance based on properties read from a properties file, and stores the properties object in a cache referenced by the properties file name.

Parameters:
propertiesFileName - the name of a properties file that exists in the root of the classpath, such that it can be loaded with the code getClass().getResourceAsStream("/" + propertiesFileName);.
Returns:
a properties object initialised with property values from the properties file

setProperty

public void setProperty(java.lang.String propertyName,
                        java.lang.String propertyValue)
Sets or removes a property value.

Parameters:
propertyName - the name of the property to set or remove.
propertyValue - a new value for the property. If this value is null, the named property will be removed.

clearProperty

public void clearProperty(java.lang.String propertyName)
Removes a property name and value.

Parameters:
propertyName - the name of the property to remove.

clearAllProperties

public void clearAllProperties()
Clears (removes) all the property names and values used internally by this object. Use this method in combination with loadAndReplaceProperties(Properties, String) to directly manage the properties encapsulated in this class.


loadAndReplaceProperties

public void loadAndReplaceProperties(java.io.InputStream inputStream,
                                     java.lang.String propertiesSource)
                              throws java.io.IOException
Reads properties from an InputStream and stores them in this class's properties object. If a new property already exists, the property value is replaced.

Parameters:
inputStream - an input stream containing property name/value pairs in a format that can be read by Properties.load(InputStream).
propertiesSource - a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.
Throws:
java.io.IOException

loadAndReplaceProperties

public void loadAndReplaceProperties(Jets3tProperties properties,
                                     java.lang.String propertiesSource)
Merges properties from another JetS3tProperties object into this instance. If a new property already exists, the property value is replaced.

Parameters:
properties - the object containing properties that will be merged into this set of properties.
propertiesSource - a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.

loadAndReplaceProperties

public void loadAndReplaceProperties(java.util.Properties newProperties,
                                     java.lang.String propertiesSource)
Merges properties from another Properties object into this instance. If a new property already exists, the property value is replaced.

Parameters:
newProperties - the object containing properties that will be merged into this set of properties.
propertiesSource - a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.

getProperties

public java.util.Properties getProperties()
Returns:
a properties object containing all this object's properties, but cloned so changes to the returned properties object are not reflected in this object.

getStringProperty

public java.lang.String getStringProperty(java.lang.String propertyName,
                                          java.lang.String defaultValue)
Parameters:
propertyName -
defaultValue -
Returns:
the named Property value as a string if the property is set, otherwise returns the default value.

getLongProperty

public long getLongProperty(java.lang.String propertyName,
                            long defaultValue)
                     throws java.lang.NumberFormatException
Parameters:
propertyName -
defaultValue -
Returns:
the named Property value as a long if the property is set, otherwise returns the default value.
Throws:
java.lang.NumberFormatException

getIntProperty

public int getIntProperty(java.lang.String propertyName,
                          int defaultValue)
                   throws java.lang.NumberFormatException
Parameters:
propertyName -
defaultValue -
Returns:
the named Property value as an int if the property is set, otherwise returns the default value.
Throws:
java.lang.NumberFormatException

getBoolProperty

public boolean getBoolProperty(java.lang.String propertyName,
                               boolean defaultValue)
                        throws java.lang.IllegalArgumentException
Parameters:
propertyName -
defaultValue -
Returns:
the named Property value as a boolean if the property is set, otherwise returns the default value.
Throws:
java.lang.IllegalArgumentException

containsKey

public boolean containsKey(java.lang.String propertyName)
Parameters:
propertyName - the property name to check for.
Returns:
true if the property exists, false otherwise.

isLoaded

public boolean isLoaded()
Returns:
true if this properties object was successfully loaded from an input stream or a named properties file, false otherwise.