org.apache.openjpa.lib.conf
Class ConfigurationImpl

java.lang.Object
  extended by org.apache.openjpa.lib.conf.ConfigurationImpl
All Implemented Interfaces:
BeanInfo, Externalizable, Serializable, Cloneable, Configuration, ValueListener, Closeable
Direct Known Subclasses:
OpenJPAConfigurationImpl

public class ConfigurationImpl
extends Object
implements Configuration, Externalizable, ValueListener

Default implementation of the Configuration interface. Subclasses can choose to obtain configuration information from JNDI, Properties, a Bean-builder, etc. This class provides base configuration functionality, including serialization, the equals and hashCode contracts, and default property loading. Property descriptors for Value instances are constructed from the Localizer for the package of the configuration class. The following localized strings will be used for describing a value, where name is the last token of the value's property string:

Author:
Abe White
See Also:
Serialized Form

Field Summary
 StringValue id
           
 ObjectValue logFactoryPlugin
           
 
Fields inherited from interface org.apache.openjpa.lib.conf.Configuration
ATTRIBUTE_ALLOWED_VALUES, ATTRIBUTE_CATEGORY, ATTRIBUTE_INTERFACE, ATTRIBUTE_ORDER, ATTRIBUTE_TYPE, ATTRIBUTE_XML
 
Fields inherited from interface java.beans.BeanInfo
ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32
 
Constructor Summary
ConfigurationImpl()
          Default constructor.
ConfigurationImpl(boolean loadGlobals)
          Constructor.
 
Method Summary
 BooleanValue addBoolean(String property)
          Add the given value to the set of configuration properties.
 DoubleValue addDouble(String property)
          Add the given value to the set of configuration properties.
 FileValue addFile(String property)
          Add the given value to the set of configuration properties.
 IntValue addInt(String property)
          Add the given value to the set of configuration properties.
 ObjectValue addObject(String property)
          Add the given value to the set of configuration properties.
 PluginValue addPlugin(String property, boolean singleton)
          Add the given value to the set of configuration properties.
 PluginListValue addPluginList(String property)
          Add the given value to the set of configuration properties.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a listener for any property changes.
 StringValue addString(String property)
          Add the given value to the set of configuration properties.
 StringListValue addStringList(String property)
          Add the given value to the set of configuration properties.
 Value addValue(Value val)
          Add the given value to the set of configuration properties.
 void assertNotReadOnly()
          Checks if the configuration is read only and if so throws an exception, otherwise returns silently.
 Object clone()
          Uses toProperties(boolean) and fromProperties(java.util.Map) to clone configuration.
 void close()
          Closes all closeable values and plugins.
 boolean equals(Object other)
          Performs an equality check based on the properties returned from toProperties(boolean).
 void fromProperties(Map map)
          Set this Configuration via the given map.
 BeanInfo[] getAdditionalBeanInfo()
           
 BeanDescriptor getBeanDescriptor()
           
 Log getConfigurationLog()
          Returns the logging channel openjpa.Runtime by default.
 int getDefaultEventIndex()
           
 int getDefaultPropertyIndex()
           
 Value[] getDynamicValues()
          Gets the values that can be modified dynamically i.e.
 EventSetDescriptor[] getEventSetDescriptors()
           
 Image getIcon(int kind)
           
 String getId()
          An environment-specific identifier for this configuration.
 String getLog()
          Log plugin setting.
 Log getLog(String category)
          Return the log for the given category.
 LogFactory getLogFactory()
          The log factory.
 MethodDescriptor[] getMethodDescriptors()
           
 String getProductName()
          Return the product name.
 String getPropertiesResource()
          Return the resource that was set via auto-configuration methods setProperties(java.lang.String) or setPropertiesFile(java.io.File), or null if none.
 PropertyDescriptor[] getPropertyDescriptors()
           
 Value getValue(String property)
          Return the Value for the given property, or null if none.
 Value[] getValues()
          Return the set of all Values.
 int hashCode()
          Computes hash code based on the properties returned from toProperties(boolean).
 void instantiateAll()
          Call the instantiating get methods for all values.
 boolean isDynamic(String property)
          Affirms if the given property can be modified dynamically i.e.
protected  boolean isInvalidProperty(String propName)
          Returns true if the specified property name should raise a warning if it is not found in the list of known properties.
 boolean isReadOnly()
          Return true if this configuration is immutable.
 boolean loadGlobals()
          Automatically load global values from the system's ProductDerivations, and from System properties.
 void modifyDynamic(String property, Object newValue)
          Modifies a dynamic property of this receiver even when frozen.
protected  void preClose()
          Invoked by final method close() after invoking the ProductDerivation.beforeConfigurationClose(org.apache.openjpa.lib.conf.Configuration) callbacks but before performing internal close operations.
 void readExternal(ObjectInput in)
          Implementation of the Externalizable interface to read from the properties written by writeExternal(java.io.ObjectOutput).
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a listener for any property changes.
 boolean removeValue(Value val)
          Remove the given value from the set of configuration properties.
 void setId(String id)
          An environment-specific identifier for this configuration.
 void setLog(String log)
          Log plugin setting.
 void setLogFactory(LogFactory logFactory)
          The log factory.
 void setProductName(String name)
          Set the product name.
 void setProperties(String resourceName)
          This method loads the named resource as a properties file.
 void setPropertiesFile(File file)
          This method loads the named file as a properties file.
 void setReadOnly(boolean readOnly)
          Lock down the configuration's state.
 Map toProperties(boolean storeDefaults)
          A properties representation of this Configuration.
static String toXMLName(String propName)
          Convert propName to a lowercase-with-hyphens-style string.
 void valueChanged(Value val)
          Callback used by Value objects to notify listener of change.
 void writeExternal(ObjectOutput out)
          Implementation of the Externalizable interface to write the properties returned by toProperties(boolean).
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logFactoryPlugin

public ObjectValue logFactoryPlugin

id

public StringValue id
Constructor Detail

ConfigurationImpl

public ConfigurationImpl()
Default constructor. Attempts to load default properties through system's configured ProductDerivations.


ConfigurationImpl

public ConfigurationImpl(boolean loadGlobals)
Constructor.

Parameters:
loadGlobals - whether to attempt to load the global properties
Method Detail

loadGlobals

public boolean loadGlobals()
Automatically load global values from the system's ProductDerivations, and from System properties.


getProductName

public String getProductName()
Description copied from interface: Configuration
Return the product name. Defaults to openjpa.

Specified by:
getProductName in interface Configuration

setProductName

public void setProductName(String name)
Description copied from interface: Configuration
Set the product name.

Specified by:
setProductName in interface Configuration

getLogFactory

public LogFactory getLogFactory()
Description copied from interface: Configuration
The log factory. If no log factory has been set explicitly, this method will create one.

Specified by:
getLogFactory in interface Configuration

setLogFactory

public void setLogFactory(LogFactory logFactory)
Description copied from interface: Configuration
The log factory.

Specified by:
setLogFactory in interface Configuration

getLog

public String getLog()
Description copied from interface: Configuration
Log plugin setting.

Specified by:
getLog in interface Configuration

setLog

public void setLog(String log)
Description copied from interface: Configuration
Log plugin setting.

Specified by:
setLog in interface Configuration

getLog

public Log getLog(String category)
Description copied from interface: Configuration
Return the log for the given category.

Specified by:
getLog in interface Configuration
See Also:
Configuration.getLogFactory()

getId

public String getId()
Description copied from interface: Configuration
An environment-specific identifier for this configuration. This might correspond to a JPA persistence-unit name, or to some other more-unique value available in the current environment.

Specified by:
getId in interface Configuration

setId

public void setId(String id)
Description copied from interface: Configuration
An environment-specific identifier for this configuration. This might correspond to a JPA persistence-unit name, or to some other more-unique value available in the current environment.

Specified by:
setId in interface Configuration

getConfigurationLog

public Log getConfigurationLog()
Returns the logging channel openjpa.Runtime by default.

Specified by:
getConfigurationLog in interface Configuration

getValues

public Value[] getValues()
Description copied from interface: Configuration
Return the set of all Values.

Specified by:
getValues in interface Configuration

getValue

public Value getValue(String property)
Description copied from interface: Configuration
Return the Value for the given property, or null if none.

Specified by:
getValue in interface Configuration

setReadOnly

public void setReadOnly(boolean readOnly)
Description copied from interface: Configuration
Lock down the configuration's state. Attempting to set state on a read-only configuration results in an exception.

Specified by:
setReadOnly in interface Configuration

instantiateAll

public void instantiateAll()
Description copied from interface: Configuration
Call the instantiating get methods for all values. Up-front instantiation allows one to avoid the synchronization necessary with lazy instantiation.

Specified by:
instantiateAll in interface Configuration

isReadOnly

public boolean isReadOnly()
Description copied from interface: Configuration
Return true if this configuration is immutable.

Specified by:
isReadOnly in interface Configuration

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: Configuration
Adds a listener for any property changes. The property events fired will not include the old value.

Specified by:
addPropertyChangeListener in interface Configuration
Parameters:
listener - the listener to receive notification of property changes

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: Configuration
Removes a listener for any property changes.

Specified by:
removePropertyChangeListener in interface Configuration
Parameters:
listener - the listener to remove

valueChanged

public void valueChanged(Value val)
Description copied from interface: ValueListener
Callback used by Value objects to notify listener of change.

Specified by:
valueChanged in interface ValueListener

close

public final void close()
Closes all closeable values and plugins.

Specified by:
close in interface Configuration
Specified by:
close in interface Closeable

preClose

protected void preClose()
Invoked by final method close() after invoking the ProductDerivation.beforeConfigurationClose(org.apache.openjpa.lib.conf.Configuration) callbacks but before performing internal close operations.

Since:
0.9.7

getAdditionalBeanInfo

public BeanInfo[] getAdditionalBeanInfo()
Specified by:
getAdditionalBeanInfo in interface BeanInfo

getBeanDescriptor

public BeanDescriptor getBeanDescriptor()
Specified by:
getBeanDescriptor in interface BeanInfo

getDefaultEventIndex

public int getDefaultEventIndex()
Specified by:
getDefaultEventIndex in interface BeanInfo

getDefaultPropertyIndex

public int getDefaultPropertyIndex()
Specified by:
getDefaultPropertyIndex in interface BeanInfo

getEventSetDescriptors

public EventSetDescriptor[] getEventSetDescriptors()
Specified by:
getEventSetDescriptors in interface BeanInfo

getIcon

public Image getIcon(int kind)
Specified by:
getIcon in interface BeanInfo

getMethodDescriptors

public MethodDescriptor[] getMethodDescriptors()
Specified by:
getMethodDescriptors in interface BeanInfo

getPropertyDescriptors

public PropertyDescriptor[] getPropertyDescriptors()
Specified by:
getPropertyDescriptors in interface BeanInfo

toProperties

public Map toProperties(boolean storeDefaults)
Description copied from interface: Configuration
A properties representation of this Configuration. Note that changes made to this properties object will not be automatically reflected in this Configuration object.

Specified by:
toProperties in interface Configuration
Parameters:
storeDefaults - if true, then properties will be written out even if they match the default value for a property

fromProperties

public void fromProperties(Map map)
Description copied from interface: Configuration
Set this Configuration via the given map. Any keys missing from the given map will not be set. Note that changes made to this map will not be automatically reflected in this Configuration object. IMPORTANT: If the map contains instantiated objects(rather than string values), only the string representation of those objects are considered in this configuration's equals and hashCode methods. If the object's property has no string form(such as an ObjectValue), the object is not part of the equality and hashing calculations.

Specified by:
fromProperties in interface Configuration

isInvalidProperty

protected boolean isInvalidProperty(String propName)
Returns true if the specified property name should raise a warning if it is not found in the list of known properties.


setProperties

public void setProperties(String resourceName)
                   throws IOException
This method loads the named resource as a properties file. It is useful for auto-configuration tools so users can specify a properties value with the name of a resource.

Throws:
IOException

setPropertiesFile

public void setPropertiesFile(File file)
                       throws IOException
This method loads the named file as a properties file. It is useful for auto-configuration tools so users can specify a propertiesFile value with the name of a file.

Throws:
IOException

getPropertiesResource

public String getPropertiesResource()
Return the resource that was set via auto-configuration methods setProperties(java.lang.String) or setPropertiesFile(java.io.File), or null if none.


assertNotReadOnly

public void assertNotReadOnly()
Checks if the configuration is read only and if so throws an exception, otherwise returns silently. Implementations should call this method before setting any state.


equals

public boolean equals(Object other)
Performs an equality check based on the properties returned from toProperties(boolean).

Overrides:
equals in class Object

hashCode

public int hashCode()
Computes hash code based on the properties returned from toProperties(boolean).

Overrides:
hashCode in class Object

toXMLName

public static String toXMLName(String propName)
Convert propName to a lowercase-with-hyphens-style string. This algorithm is only designed for mixes of uppercase and lowercase letters and lone digits. A more sophisticated conversion should probably be handled by a proper parser generator or regular expressions.


readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Implementation of the Externalizable interface to read from the properties written by writeExternal(java.io.ObjectOutput).

Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Implementation of the Externalizable interface to write the properties returned by toProperties(boolean).

Specified by:
writeExternal in interface Externalizable
Throws:
IOException

clone

public Object clone()
Uses toProperties(boolean) and fromProperties(java.util.Map) to clone configuration.

Specified by:
clone in interface Configuration
Overrides:
clone in class Object

removeValue

public boolean removeValue(Value val)
Description copied from interface: Configuration
Remove the given value from the set of configuration properties.

Specified by:
removeValue in interface Configuration

addValue

public Value addValue(Value val)
Description copied from interface: Configuration
Add the given value to the set of configuration properties. This method replaces any existing value under the same property.

Specified by:
addValue in interface Configuration

addString

public StringValue addString(String property)
Add the given value to the set of configuration properties.


addFile

public FileValue addFile(String property)
Add the given value to the set of configuration properties.


addInt

public IntValue addInt(String property)
Add the given value to the set of configuration properties.


addDouble

public DoubleValue addDouble(String property)
Add the given value to the set of configuration properties.


addBoolean

public BooleanValue addBoolean(String property)
Add the given value to the set of configuration properties.


addStringList

public StringListValue addStringList(String property)
Add the given value to the set of configuration properties.


addObject

public ObjectValue addObject(String property)
Add the given value to the set of configuration properties.


addPlugin

public PluginValue addPlugin(String property,
                             boolean singleton)
Add the given value to the set of configuration properties.


addPluginList

public PluginListValue addPluginList(String property)
Add the given value to the set of configuration properties.


modifyDynamic

public void modifyDynamic(String property,
                          Object newValue)
Description copied from interface: Configuration
Modifies a dynamic property of this receiver even when frozen.

Specified by:
modifyDynamic in interface Configuration

isDynamic

public boolean isDynamic(String property)
Description copied from interface: Configuration
Affirms if the given property can be modified dynamically i.e. even after the receiver is frozen.

Specified by:
isDynamic in interface Configuration

getDynamicValues

public Value[] getDynamicValues()
Description copied from interface: Configuration
Gets the values that can be modified dynamically i.e. even after the receiver is frozen.

Specified by:
getDynamicValues in interface Configuration


Copyright © 2006-2007 Apache Software Foundation. All Rights Reserved.