Package org.apache.openjpa.lib.conf
Class ConfigurationImpl
- java.lang.Object
-
- org.apache.openjpa.lib.conf.ConfigurationImpl
-
- All Implemented Interfaces:
java.beans.BeanInfo
,java.io.Externalizable
,java.io.Serializable
,java.lang.Cloneable
,Configuration
,ValueListener
,Closeable
- Direct Known Subclasses:
OpenJPAConfigurationImpl
public class ConfigurationImpl extends java.lang.Object implements Configuration, java.io.Externalizable, ValueListener
Default implementation of theConfiguration
interface. Subclasses can choose to obtain configuration information from JNDI, Properties, a Bean-builder, etc. This class provides base configuration functionality, including serialization, theequals
andhashCode
contracts, and default property loading. Property descriptors forValue
instances are constructed from theLocalizer
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:- 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 StringValue
id
ObjectValue
logFactoryPlugin
-
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 BooleanValue
addBoolean(java.lang.String property)
Add the given value to the set of configuration properties.DoubleValue
addDouble(java.lang.String property)
Add the given value to the set of configuration properties.FileValue
addFile(java.lang.String property)
Add the given value to the set of configuration properties.IntValue
addInt(java.lang.String property)
Add the given value to the set of configuration properties.ObjectValue
addObject(java.lang.String property)
Add the given value to the set of configuration properties.PluginValue
addPlugin(java.lang.String property, boolean singleton)
Add the given value to the set of configuration properties.PluginListValue
addPluginList(java.lang.String property)
Add the given value to the set of configuration properties.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener for any property changes.StringValue
addString(java.lang.String property)
Add the given value to the set of configuration properties.StringListValue
addStringList(java.lang.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.java.lang.Object
clone()
UsestoProperties(boolean)
andfromProperties(java.util.Map)
to clone configuration.void
close()
Closes all closeable values and plugins.boolean
equals(java.lang.Object other)
Performs an equality check based on equality of values.void
fromProperties(java.util.Map map)
Set this Configuration via the given map.java.beans.BeanInfo[]
getAdditionalBeanInfo()
java.beans.BeanDescriptor
getBeanDescriptor()
Log
getConfigurationLog()
Returns the logging channelopenjpa.Runtime
by default.int
getDefaultEventIndex()
int
getDefaultPropertyIndex()
java.beans.EventSetDescriptor[]
getEventSetDescriptors()
java.awt.Image
getIcon(int kind)
java.lang.String
getId()
An environment-specific identifier for this configuration.java.lang.String
getLog()
Log plugin setting.Log
getLog(java.lang.String category)
Return the log for the given category.LogFactory
getLogFactory()
The log factory.java.beans.MethodDescriptor[]
getMethodDescriptors()
java.lang.String
getProductName()
Return the product name.java.lang.String
getPropertiesResource()
Return the resource that was set via auto-configuration methodssetProperties(java.lang.String)
orsetPropertiesFile(java.io.File)
, or null if none.java.beans.PropertyDescriptor[]
getPropertyDescriptors()
java.util.Set<java.lang.String>
getPropertyKeys()
Gets all known property keys.java.util.List<java.lang.String>
getPropertyKeys(java.lang.String propertyName)
Get the set of all known property keys, including any equivalent keys, appropriately prefixed.java.lang.ClassLoader
getUserClassLoader()
Gets a class loader that can be additionally used to load custom plugin values.Value
getValue(java.lang.String property)
Gets the registered Value for the given propertyName.Value[]
getValues()
Return the set of allValue
s.int
hashCode()
Computes hash code based on the hashCodes of the values.void
instantiateAll()
Call the instantiating get methods for all values.boolean
isDeferResourceLoading()
protected boolean
isInvalidProperty(java.lang.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'sProductDerivation
s, and from System properties.protected void
preClose()
Invoked by final methodclose()
after invoking theProductDerivation.beforeConfigurationClose(org.apache.openjpa.lib.conf.Configuration)
callbacks but before performing internal close operations.void
readExternal(java.io.ObjectInput in)
Implementation of theExternalizable
interface to read from the properties written bywriteExternal(java.io.ObjectOutput)
.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a listener for any property changes.boolean
removeValue(Value val)
Remove the given value from the set of configuration properties.void
setDeferResourceLoading(boolean deferResourceLoading)
void
setId(java.lang.String id)
An environment-specific identifier for this configuration.void
setLog(java.lang.String log)
Log plugin setting.void
setLogFactory(LogFactory logFactory)
The log factory.void
setProductName(java.lang.String name)
Set the product name.void
setProperties(java.lang.String resourceName)
This method loads the named resource as a properties file.void
setPropertiesFile(java.io.File file)
This method loads the named file as a properties file.void
setReadOnly(int newState)
Lock down the configuration's state.void
setUserClassLoader(java.lang.ClassLoader cl)
Sets an additional classloader to load custom plugin values.java.util.Map
toProperties(boolean storeDefaults)
An internal method to retrieve properties, to support 2 public methods, getAllProperties() and toProperties(boolean).static java.lang.String
toXMLName(java.lang.String propName)
ConvertpropName
to a lowercase-with-hyphens-style string.void
valueChanged(Value val)
Callback used byValue
objects to notify listener of change.void
writeExternal(java.io.ObjectOutput out)
Implementation of theExternalizable
interface 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 configuredProductDerivation
s.
-
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'sProductDerivation
s, and from System properties.
-
getProductName
public java.lang.String getProductName()
Description copied from interface:Configuration
Return the product name. Defaults toopenjpa
.- Specified by:
getProductName
in interfaceConfiguration
-
setProductName
public void setProductName(java.lang.String name)
Description copied from interface:Configuration
Set the product name.- Specified by:
setProductName
in interfaceConfiguration
-
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 interfaceConfiguration
-
setLogFactory
public void setLogFactory(LogFactory logFactory)
Description copied from interface:Configuration
The log factory.- Specified by:
setLogFactory
in interfaceConfiguration
-
getLog
public java.lang.String getLog()
Description copied from interface:Configuration
Log plugin setting.- Specified by:
getLog
in interfaceConfiguration
-
setLog
public void setLog(java.lang.String log)
Description copied from interface:Configuration
Log plugin setting.- Specified by:
setLog
in interfaceConfiguration
-
getLog
public Log getLog(java.lang.String category)
Description copied from interface:Configuration
Return the log for the given category.- Specified by:
getLog
in interfaceConfiguration
- See Also:
Configuration.getLogFactory()
-
getId
public java.lang.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 interfaceConfiguration
-
setId
public void setId(java.lang.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 interfaceConfiguration
-
getConfigurationLog
public Log getConfigurationLog()
Returns the logging channelopenjpa.Runtime
by default.- Specified by:
getConfigurationLog
in interfaceConfiguration
-
getValues
public Value[] getValues()
Description copied from interface:Configuration
Return the set of allValue
s.- Specified by:
getValues
in interfaceConfiguration
-
getValue
public Value getValue(java.lang.String property)
Gets the registered Value for the given propertyName.- Specified by:
getValue
in 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:Configuration
Lock down the configuration's state. Attempting to set state on a read-only configuration results in an exception.- Specified by:
setReadOnly
in interfaceConfiguration
-
isDeferResourceLoading
public boolean isDeferResourceLoading()
-
setDeferResourceLoading
public void setDeferResourceLoading(boolean deferResourceLoading)
-
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 interfaceConfiguration
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:Configuration
Return true if this configuration is immutable.- Specified by:
isReadOnly
in interfaceConfiguration
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.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 interfaceConfiguration
- Parameters:
listener
- the listener to receive notification of property changes
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from interface:Configuration
Removes a listener for any property changes.- Specified by:
removePropertyChangeListener
in interfaceConfiguration
- Parameters:
listener
- the listener to remove
-
valueChanged
public void valueChanged(Value val)
Description copied from interface:ValueListener
Callback used byValue
objects to notify listener of change.- Specified by:
valueChanged
in interfaceValueListener
-
close
public final void close()
Closes all closeable values and plugins.- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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 java.beans.BeanInfo[] getAdditionalBeanInfo()
- Specified by:
getAdditionalBeanInfo
in interfacejava.beans.BeanInfo
-
getBeanDescriptor
public java.beans.BeanDescriptor getBeanDescriptor()
- Specified by:
getBeanDescriptor
in interfacejava.beans.BeanInfo
-
getDefaultEventIndex
public int getDefaultEventIndex()
- Specified by:
getDefaultEventIndex
in interfacejava.beans.BeanInfo
-
getDefaultPropertyIndex
public int getDefaultPropertyIndex()
- Specified by:
getDefaultPropertyIndex
in interfacejava.beans.BeanInfo
-
getEventSetDescriptors
public java.beans.EventSetDescriptor[] getEventSetDescriptors()
- Specified by:
getEventSetDescriptors
in interfacejava.beans.BeanInfo
-
getIcon
public java.awt.Image getIcon(int kind)
- Specified by:
getIcon
in interfacejava.beans.BeanInfo
-
getMethodDescriptors
public java.beans.MethodDescriptor[] getMethodDescriptors()
- Specified by:
getMethodDescriptors
in interfacejava.beans.BeanInfo
-
getPropertyDescriptors
public java.beans.PropertyDescriptor[] getPropertyDescriptors()
- Specified by:
getPropertyDescriptors
in interfacejava.beans.BeanInfo
-
toProperties
public java.util.Map toProperties(boolean storeDefaults)
An internal method to retrieve properties, to support 2 public methods, getAllProperties() and toProperties(boolean).- Specified by:
toProperties
in interfaceConfiguration
- Parameters:
storeDefaults
- whether or not to retrieve a property if its value is the default value.
-
fromProperties
public void fromProperties(java.util.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'sequals
andhashCode
methods. 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:
fromProperties
in interfaceConfiguration
-
getPropertyKeys
public java.util.List<java.lang.String> getPropertyKeys(java.lang.String propertyName)
Description copied from interface:Configuration
Get the set of all known property keys, including any equivalent keys, appropriately prefixed.- Specified by:
getPropertyKeys
in interfaceConfiguration
- Parameters:
propertyName
- the name of the property for which the keys are to be retrieved.
-
getPropertyKeys
public java.util.Set<java.lang.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:
getPropertyKeys
in interfaceConfiguration
- See Also:
The Values that are are filtered out.
-
isInvalidProperty
protected boolean isInvalidProperty(java.lang.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(java.lang.String resourceName) throws java.io.IOException
This method loads the named resource as a properties file. It is useful for auto-configuration tools so users can specify aproperties
value with the name of a resource.- Throws:
java.io.IOException
-
setPropertiesFile
public void setPropertiesFile(java.io.File file) throws java.io.IOException
This method loads the named file as a properties file. It is useful for auto-configuration tools so users can specify apropertiesFile
value with the name of a file.- Throws:
java.io.IOException
-
getPropertiesResource
public java.lang.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(java.lang.Object other)
Performs an equality check based on equality of values.Equality
of Values varies if the Value isdynamic
.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Computes hash code based on the hashCodes of the values.HashCode
of a Value varies if the Value isdynamic
.- Overrides:
hashCode
in classjava.lang.Object
-
toXMLName
public static java.lang.String toXMLName(java.lang.String propName)
ConvertpropName
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(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
Implementation of theExternalizable
interface to read from the properties written bywriteExternal(java.io.ObjectOutput)
.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
Implementation of theExternalizable
interface to write the properties returned bytoProperties(boolean)
.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
clone
public java.lang.Object clone()
UsestoProperties(boolean)
andfromProperties(java.util.Map)
to clone configuration.- Specified by:
clone
in interfaceConfiguration
- Overrides:
clone
in classjava.lang.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 interfaceConfiguration
-
addValue
public <T extends Value> T addValue(T 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 interfaceConfiguration
-
addString
public StringValue addString(java.lang.String property)
Add the given value to the set of configuration properties.
-
addFile
public FileValue addFile(java.lang.String property)
Add the given value to the set of configuration properties.
-
addInt
public IntValue addInt(java.lang.String property)
Add the given value to the set of configuration properties.
-
addDouble
public DoubleValue addDouble(java.lang.String property)
Add the given value to the set of configuration properties.
-
addBoolean
public BooleanValue addBoolean(java.lang.String property)
Add the given value to the set of configuration properties.
-
addStringList
public StringListValue addStringList(java.lang.String property)
Add the given value to the set of configuration properties.
-
addObject
public ObjectValue addObject(java.lang.String property)
Add the given value to the set of configuration properties.
-
addPlugin
public PluginValue addPlugin(java.lang.String property, boolean singleton)
Add the given value to the set of configuration properties.
-
addPluginList
public PluginListValue addPluginList(java.lang.String property)
Add the given value to the set of configuration properties.
-
getUserClassLoader
public java.lang.ClassLoader getUserClassLoader()
Description copied from interface:Configuration
Gets a class loader that can be additionally used to load custom plugin values.- Specified by:
getUserClassLoader
in interfaceConfiguration
- Returns:
- an additional classloader for loading custom plugins. Can be null.
- See Also:
Configurations.newInstance(String, ClassLoader)
-
setUserClassLoader
public void setUserClassLoader(java.lang.ClassLoader cl)
Description copied from interface:Configuration
Sets 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:
setUserClassLoader
in interfaceConfiguration
- Parameters:
cl
- a class loader to load custom plugin values
-
-