Package org.apache.openjpa.lib.conf
Class ConfigurationImpl
- java.lang.Object
 - 
- 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 theConfigurationinterface. Subclasses can choose to obtain configuration information from JNDI, Properties, a Bean-builder, etc. This class provides base configuration functionality, including serialization, theequalsandhashCodecontracts, and default property loading. Property descriptors forValueinstances are constructed from theLocalizerfor 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:- name-name: The name that will be displayed for the option in a user interface; required.
 - name-desc: A brief description of the option; required.
 - name-type: The type or category name for this option; required.
 - name-expert: True if this is an expert option, false otherwise; defaults to false.
 - name-values: Set of expected or common values, excluding alias keys; optional.
 - name-interface: The class name of an interface whose discoverable implementations should be included in the set of expected or common values; optional.
 - name-cat: The hierarchical category for the property name, separated by ".".
 - name-displayorder: The order in which the property should be displayer.
 
- Author:
 - Abe White
 - See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description StringValueidObjectValuelogFactoryPlugin- 
Fields inherited from interface java.beans.BeanInfo
ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32 
- 
Fields inherited from interface org.apache.openjpa.lib.conf.Configuration
ATTRIBUTE_ALLOWED_VALUES, ATTRIBUTE_CATEGORY, ATTRIBUTE_INTERFACE, ATTRIBUTE_ORDER, ATTRIBUTE_TYPE, ATTRIBUTE_XML, INIT_STATE_FREEZING, INIT_STATE_FROZEN, INIT_STATE_LIQUID 
 - 
 
- 
Constructor Summary
Constructors Constructor Description ConfigurationImpl()Default constructor.ConfigurationImpl(boolean loadGlobals)Constructor. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleanValueaddBoolean(String property)Add the given value to the set of configuration properties.DoubleValueaddDouble(String property)Add the given value to the set of configuration properties.FileValueaddFile(String property)Add the given value to the set of configuration properties.IntValueaddInt(String property)Add the given value to the set of configuration properties.ObjectValueaddObject(String property)Add the given value to the set of configuration properties.PluginValueaddPlugin(String property, boolean singleton)Add the given value to the set of configuration properties.PluginListValueaddPluginList(String property)Add the given value to the set of configuration properties.voidaddPropertyChangeListener(PropertyChangeListener listener)Adds a listener for any property changes.StringValueaddString(String property)Add the given value to the set of configuration properties.StringListValueaddStringList(String property)Add the given value to the set of configuration properties.<T extends Value>
TaddValue(T val)Add the given value to the set of configuration properties.Objectclone()UsestoProperties(boolean)andfromProperties(java.util.Map)to clone configuration.voidclose()Closes all closeable values and plugins.booleanequals(Object other)Performs an equality check based on equality of values.voidfromProperties(Map map)Set this Configuration via the given map.BeanInfo[]getAdditionalBeanInfo()BeanDescriptorgetBeanDescriptor()LoggetConfigurationLog()Returns the logging channelopenjpa.Runtimeby default.intgetDefaultEventIndex()intgetDefaultPropertyIndex()EventSetDescriptor[]getEventSetDescriptors()ImagegetIcon(int kind)StringgetId()An environment-specific identifier for this configuration.StringgetLog()Log plugin setting.LoggetLog(String category)Return the log for the given category.LogFactorygetLogFactory()The log factory.MethodDescriptor[]getMethodDescriptors()StringgetProductName()Return the product name.StringgetPropertiesResource()Return the resource that was set via auto-configuration methodssetProperties(java.lang.String)orsetPropertiesFile(java.io.File), or null if none.PropertyDescriptor[]getPropertyDescriptors()Set<String>getPropertyKeys()Gets all known property keys.List<String>getPropertyKeys(String propertyName)Get the set of all known property keys, including any equivalent keys, appropriately prefixed.ClassLoadergetUserClassLoader()Gets a class loader that can be additionally used to load custom plugin values.ValuegetValue(String property)Gets the registered Value for the given propertyName.Value[]getValues()Return the set of allValues.inthashCode()Computes hash code based on the hashCodes of the values.voidinstantiateAll()Call the instantiating get methods for all values.booleanisDeferResourceLoading()protected booleanisInvalidProperty(String propName)Returns true if the specified property name should raise a warning if it is not found in the list of known properties.booleanisReadOnly()Return true if this configuration is immutable.booleanloadGlobals()Automatically load global values from the system'sProductDerivations, and from System properties.protected voidpreClose()Invoked by final methodclose()after invoking theProductDerivation.beforeConfigurationClose(org.apache.openjpa.lib.conf.Configuration)callbacks but before performing internal close operations.voidreadExternal(ObjectInput in)Implementation of theExternalizableinterface to read from the properties written bywriteExternal(java.io.ObjectOutput).voidremovePropertyChangeListener(PropertyChangeListener listener)Removes a listener for any property changes.booleanremoveValue(Value val)Remove the given value from the set of configuration properties.voidsetDeferResourceLoading(boolean deferResourceLoading)voidsetId(String id)An environment-specific identifier for this configuration.voidsetLog(String log)Log plugin setting.voidsetLogFactory(LogFactory logFactory)The log factory.voidsetProductName(String name)Set the product name.voidsetProperties(String resourceName)This method loads the named resource as a properties file.voidsetPropertiesFile(File file)This method loads the named file as a properties file.voidsetReadOnly(int newState)Lock down the configuration's state.voidsetUserClassLoader(ClassLoader cl)Sets an additional classloader to load custom plugin values.MaptoProperties(boolean storeDefaults)An internal method to retrieve properties, to support 2 public methods, getAllProperties() and toProperties(boolean).static StringtoXMLName(String propName)ConvertpropNameto a lowercase-with-hyphens-style string.voidvalueChanged(Value val)Callback used byValueobjects to notify listener of change.voidwriteExternal(ObjectOutput out)Implementation of theExternalizableinterface to write the properties returned bytoProperties(boolean). 
 - 
 
- 
- 
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 configuredProductDerivations. 
- 
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'sProductDerivations, and from System properties. 
- 
getProductName
public String getProductName()
Description copied from interface:ConfigurationReturn the product name. Defaults toopenjpa.- Specified by:
 getProductNamein interfaceConfiguration
 
- 
setProductName
public void setProductName(String name)
Description copied from interface:ConfigurationSet the product name.- Specified by:
 setProductNamein interfaceConfiguration
 
- 
getLogFactory
public LogFactory getLogFactory()
Description copied from interface:ConfigurationThe log factory. If no log factory has been set explicitly, this method will create one.- Specified by:
 getLogFactoryin interfaceConfiguration
 
- 
setLogFactory
public void setLogFactory(LogFactory logFactory)
Description copied from interface:ConfigurationThe log factory.- Specified by:
 setLogFactoryin interfaceConfiguration
 
- 
getLog
public String getLog()
Description copied from interface:ConfigurationLog plugin setting.- Specified by:
 getLogin interfaceConfiguration
 
- 
setLog
public void setLog(String log)
Description copied from interface:ConfigurationLog plugin setting.- Specified by:
 setLogin interfaceConfiguration
 
- 
getLog
public Log getLog(String category)
Description copied from interface:ConfigurationReturn the log for the given category.- Specified by:
 getLogin interfaceConfiguration- See Also:
 Configuration.getLogFactory()
 
- 
getId
public String getId()
Description copied from interface:ConfigurationAn 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:
 getIdin interfaceConfiguration
 
- 
setId
public void setId(String id)
Description copied from interface:ConfigurationAn 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:
 setIdin interfaceConfiguration
 
- 
getConfigurationLog
public Log getConfigurationLog()
Returns the logging channelopenjpa.Runtimeby default.- Specified by:
 getConfigurationLogin interfaceConfiguration
 
- 
getValues
public Value[] getValues()
Description copied from interface:ConfigurationReturn the set of allValues.- Specified by:
 getValuesin interfaceConfiguration
 
- 
getValue
public Value getValue(String property)
Gets the registered Value for the given propertyName.- Specified by:
 getValuein interfaceConfiguration- Parameters:
 property- can be either fully-qualified name or the simple name with which the value has been registered. A value may have multiple equivalent names and this method searches with all equivalent names.
 
- 
setReadOnly
public void setReadOnly(int newState)
Description copied from interface:ConfigurationLock down the configuration's state. Attempting to set state on a read-only configuration results in an exception.- Specified by:
 setReadOnlyin interfaceConfiguration
 
- 
isDeferResourceLoading
public boolean isDeferResourceLoading()
 
- 
setDeferResourceLoading
public void setDeferResourceLoading(boolean deferResourceLoading)
 
- 
instantiateAll
public void instantiateAll()
Description copied from interface:ConfigurationCall the instantiating get methods for all values. Up-front instantiation allows one to avoid the synchronization necessary with lazy instantiation.- Specified by:
 instantiateAllin interfaceConfiguration
 
- 
isReadOnly
public boolean isReadOnly()
Description copied from interface:ConfigurationReturn true if this configuration is immutable.- Specified by:
 isReadOnlyin interfaceConfiguration
 
- 
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface:ConfigurationAdds a listener for any property changes. The property events fired will not include the old value.- Specified by:
 addPropertyChangeListenerin interfaceConfiguration- Parameters:
 listener- the listener to receive notification of property changes
 
- 
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface:ConfigurationRemoves a listener for any property changes.- Specified by:
 removePropertyChangeListenerin interfaceConfiguration- Parameters:
 listener- the listener to remove
 
- 
valueChanged
public void valueChanged(Value val)
Description copied from interface:ValueListenerCallback used byValueobjects to notify listener of change.- Specified by:
 valueChangedin interfaceValueListener
 
- 
close
public final void close()
Closes all closeable values and plugins.- Specified by:
 closein interfaceCloseable- Specified by:
 closein interfaceConfiguration
 
- 
preClose
protected void preClose()
Invoked by final methodclose()after invoking theProductDerivation.beforeConfigurationClose(org.apache.openjpa.lib.conf.Configuration)callbacks but before performing internal close operations.- Since:
 - 0.9.7
 
 
- 
getAdditionalBeanInfo
public BeanInfo[] getAdditionalBeanInfo()
- Specified by:
 getAdditionalBeanInfoin interfaceBeanInfo
 
- 
getBeanDescriptor
public BeanDescriptor getBeanDescriptor()
- Specified by:
 getBeanDescriptorin interfaceBeanInfo
 
- 
getDefaultEventIndex
public int getDefaultEventIndex()
- Specified by:
 getDefaultEventIndexin interfaceBeanInfo
 
- 
getDefaultPropertyIndex
public int getDefaultPropertyIndex()
- Specified by:
 getDefaultPropertyIndexin interfaceBeanInfo
 
- 
getEventSetDescriptors
public EventSetDescriptor[] getEventSetDescriptors()
- Specified by:
 getEventSetDescriptorsin interfaceBeanInfo
 
- 
getMethodDescriptors
public MethodDescriptor[] getMethodDescriptors()
- Specified by:
 getMethodDescriptorsin interfaceBeanInfo
 
- 
getPropertyDescriptors
public PropertyDescriptor[] getPropertyDescriptors()
- Specified by:
 getPropertyDescriptorsin interfaceBeanInfo
 
- 
toProperties
public Map toProperties(boolean storeDefaults)
An internal method to retrieve properties, to support 2 public methods, getAllProperties() and toProperties(boolean).- Specified by:
 toPropertiesin interfaceConfiguration- Parameters:
 storeDefaults- whether or not to retrieve a property if its value is the default value.
 
- 
fromProperties
public void fromProperties(Map map)
Description copied from interface:ConfigurationSet 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'sequalsandhashCodemethods. If the object's property has no string form(such as anObjectValue), the object is not part of the equality and hashing calculations.- Specified by:
 fromPropertiesin interfaceConfiguration
 
- 
getPropertyKeys
public List<String> getPropertyKeys(String propertyName)
Description copied from interface:ConfigurationGet the set of all known property keys, including any equivalent keys, appropriately prefixed.- Specified by:
 getPropertyKeysin interfaceConfiguration- Parameters:
 propertyName- the name of the property for which the keys are to be retrieved.
 
- 
getPropertyKeys
public Set<String> getPropertyKeys()
Gets all known property keys. The keys are harvested from the property names (including the equivalent names) of the registered values. A key may be prefixed if the corresponding property name was without a prefix.- Specified by:
 getPropertyKeysin interfaceConfiguration- See Also:
 The Values that are are filtered out.
 
- 
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 apropertiesvalue 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 apropertiesFilevalue with the name of a file.- Throws:
 IOException
 
- 
getPropertiesResource
public String getPropertiesResource()
Return the resource that was set via auto-configuration methodssetProperties(java.lang.String)orsetPropertiesFile(java.io.File), or null if none. 
- 
equals
public boolean equals(Object other)
 
- 
hashCode
public int hashCode()
 
- 
toXMLName
public static String toXMLName(String propName)
ConvertpropNameto 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 theExternalizableinterface to read from the properties written bywriteExternal(java.io.ObjectOutput).- Specified by:
 readExternalin interfaceExternalizable- Throws:
 IOExceptionClassNotFoundException
 
- 
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
Implementation of theExternalizableinterface to write the properties returned bytoProperties(boolean).- Specified by:
 writeExternalin interfaceExternalizable- Throws:
 IOException
 
- 
clone
public Object clone()
UsestoProperties(boolean)andfromProperties(java.util.Map)to clone configuration.- Specified by:
 clonein interfaceConfiguration- Overrides:
 clonein classObject
 
- 
removeValue
public boolean removeValue(Value val)
Description copied from interface:ConfigurationRemove the given value from the set of configuration properties.- Specified by:
 removeValuein interfaceConfiguration
 
- 
addValue
public <T extends Value> T addValue(T val)
Description copied from interface:ConfigurationAdd the given value to the set of configuration properties. This method replaces any existing value under the same property.- Specified by:
 addValuein interfaceConfiguration
 
- 
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. 
- 
getUserClassLoader
public ClassLoader getUserClassLoader()
Description copied from interface:ConfigurationGets a class loader that can be additionally used to load custom plugin values.- Specified by:
 getUserClassLoaderin interfaceConfiguration- Returns:
 - an additional classloader for loading custom plugins. Can be null.
 - See Also:
 Configurations.newInstance(String, ClassLoader)
 
- 
setUserClassLoader
public void setUserClassLoader(ClassLoader cl)
Description copied from interface:ConfigurationSets an additional classloader to load custom plugin values. In OSGi environment, we internally set the bundle class loader as the user class loader.- Specified by:
 setUserClassLoaderin interfaceConfiguration- Parameters:
 cl- a class loader to load custom plugin values
 
 - 
 
 -