Package org.apache.openjpa.lib.conf
Class Configurations
- java.lang.Object
-
- org.apache.openjpa.lib.conf.Configurations
-
public class Configurations extends java.lang.Object
Utility methods dealing with configuration.- Author:
- Abe White
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Configurations.Runnable
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONFIG_RESOURCE_ANCHOR
static java.lang.String
CONFIG_RESOURCE_PATH
-
Constructor Summary
Constructors Constructor Description Configurations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
combinePlugins(java.lang.String orig, java.lang.String override)
Return a plugin string that combines the properties of the given plugin strings, where properties ofoverride
will override the same properties oforig
.static void
configureInstance(java.lang.Object obj, Configuration conf, java.lang.String properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(java.lang.Object obj, Configuration conf, java.lang.String properties, java.lang.String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(java.lang.Object obj, Configuration conf, java.util.Properties properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(java.lang.Object obj, Configuration conf, java.util.Properties properties, java.lang.String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static boolean
containsProperty(java.lang.String partialKey, java.util.Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.static boolean
containsProperty(Value value, java.util.Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.static java.lang.String
getClassName(java.lang.String plugin)
Return the class name from the given plugin string, or null if none.static java.util.List<java.lang.String>
getFullyQualifiedAnchorsInPropertiesLocation(Options opts)
Return a Listof all the fully-qualified anchors specified in the properties location listed in opts
.static java.lang.String
getPlugin(java.lang.String clsName, java.lang.String props)
Combine the given class name and properties into a plugin string.static java.lang.String
getProperties(java.lang.String plugin)
Return the properties part of the given plugin string, or null if none.static java.lang.Object
getProperty(java.lang.String partialKey, java.util.Map m)
Get the property under the given partial key, prefixed with any possible configuration prefix.static java.lang.Object
lookup(java.lang.String name, java.lang.String userKey, Log log)
Looks up the given name in JNDI.static java.lang.Object
newInstance(java.lang.String clsName, java.lang.ClassLoader loader)
Create the instance with the given class name, using the given class loader.static java.lang.Object
newInstance(java.lang.String clsName, Configuration conf, java.lang.String props, java.lang.ClassLoader loader)
Create and configure an instance with the given class name and properties as a String.static java.lang.Object
newInstance(java.lang.String clsName, Configuration conf, java.util.Properties props, java.lang.ClassLoader loader)
Create and configure an instance with the given class name and properties.static java.util.Map<java.lang.String,java.lang.String>
parseConfigResource(java.lang.String props)
static Options
parseProperties(java.lang.String properties)
Parse a set of properties from a comma-separated string.static void
populateConfiguration(Configuration conf, Options opts)
Set the givenConfiguration
instance from the command line options provided.static java.lang.Object
removeProperty(java.lang.String partialKey, java.util.Map props)
Remove the property under the given partial key, prefixed with any possible configuration prefix.static void
removeProperty(java.lang.String partialKey, java.util.Map<?,?> remaining, java.util.Map<?,?> props)
static boolean
runAgainstAllAnchors(Options opts, Configurations.Runnable runnable)
Runsrunnable
against all the anchors in the configuration pointed to byopts
.static java.lang.String
serializeProperties(java.util.Map map)
Turn a set of properties into a comma-separated string.
-
-
-
Field Detail
-
CONFIG_RESOURCE_PATH
public static final java.lang.String CONFIG_RESOURCE_PATH
- See Also:
- Constant Field Values
-
CONFIG_RESOURCE_ANCHOR
public static final java.lang.String CONFIG_RESOURCE_ANCHOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getClassName
public static java.lang.String getClassName(java.lang.String plugin)
Return the class name from the given plugin string, or null if none.
-
getProperties
public static java.lang.String getProperties(java.lang.String plugin)
Return the properties part of the given plugin string, or null if none.
-
getPlugin
public static java.lang.String getPlugin(java.lang.String clsName, java.lang.String props)
Combine the given class name and properties into a plugin string.
-
combinePlugins
public static java.lang.String combinePlugins(java.lang.String orig, java.lang.String override)
Return a plugin string that combines the properties of the given plugin strings, where properties ofoverride
will override the same properties oforig
.
-
newInstance
public static java.lang.Object newInstance(java.lang.String clsName, java.lang.ClassLoader loader)
Create the instance with the given class name, using the given class loader. No configuration of the instance is performed by this method.
-
newInstance
public static java.lang.Object newInstance(java.lang.String clsName, Configuration conf, java.lang.String props, java.lang.ClassLoader loader)
Create and configure an instance with the given class name and properties as a String.
-
newInstance
public static java.lang.Object newInstance(java.lang.String clsName, Configuration conf, java.util.Properties props, java.lang.ClassLoader loader)
Create and configure an instance with the given class name and properties.
-
getFullyQualifiedAnchorsInPropertiesLocation
public static java.util.List<java.lang.String> getFullyQualifiedAnchorsInPropertiesLocation(Options opts)
Return a Listof all the fully-qualified anchors specified in the properties location listed in opts
. If no properties location is listed inopts
, this returns whatever the product derivations can find in their default configurations. If the properties location specified inopts
already contains an anchor spec, this returns that anchor. Note that in this fully-qualified-input case, the logic involving product derivations and resource parsing is short-circuited, so this method should not be used as a means to test that a particular anchor is defined in a given location by invoking with a fully-qualified anchor. This does not mutateopts
.- Since:
- 1.1.0
-
populateConfiguration
public static void populateConfiguration(Configuration conf, Options opts)
Set the givenConfiguration
instance from the command line options provided. All property names of the given configuration are recognized; additionally, if aproperties
orp
argument exists, the resource it points to will be loaded and set into the given configuration instance. It can point to either a file or a resource name.
-
parseConfigResource
public static java.util.Map<java.lang.String,java.lang.String> parseConfigResource(java.lang.String props)
-
configureInstance
public static void configureInstance(java.lang.Object obj, Configuration conf, java.lang.String properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods. The properties string should be in the form "prop1=val1, prop2=val2 ...". Does not validate that setter methods exist for the properties.- Throws:
java.lang.RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(java.lang.Object obj, Configuration conf, java.lang.String properties, java.lang.String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods. The properties string should be in the form "prop1=val1, prop2=val2 ...". Validates that setter methods exist for the properties.- Throws:
java.lang.RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(java.lang.Object obj, Configuration conf, java.util.Properties properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods. Does not validate that setter methods exist for the properties.- Throws:
java.lang.RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(java.lang.Object obj, Configuration conf, java.util.Properties properties, java.lang.String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods. IfconfigurationName
is non-null
, validates that setter methods exist for the properties.- Throws:
java.lang.RuntimeException
- on configuration error
-
serializeProperties
public static java.lang.String serializeProperties(java.util.Map map)
Turn a set of properties into a comma-separated string.
-
parseProperties
public static Options parseProperties(java.lang.String properties)
Parse a set of properties from a comma-separated string.
-
lookup
public static java.lang.Object lookup(java.lang.String name, java.lang.String userKey, Log log)
Looks up the given name in JNDI. If the name is null, null is returned.
-
containsProperty
public static boolean containsProperty(Value value, java.util.Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.
-
containsProperty
public static boolean containsProperty(java.lang.String partialKey, java.util.Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.
-
getProperty
public static java.lang.Object getProperty(java.lang.String partialKey, java.util.Map m)
Get the property under the given partial key, prefixed with any possible configuration prefix.
-
removeProperty
public static java.lang.Object removeProperty(java.lang.String partialKey, java.util.Map props)
Remove the property under the given partial key, prefixed with any possible configuration prefix.
-
removeProperty
public static void removeProperty(java.lang.String partialKey, java.util.Map<?,?> remaining, java.util.Map<?,?> props)
-
runAgainstAllAnchors
public static boolean runAgainstAllAnchors(Options opts, Configurations.Runnable runnable)
Runsrunnable
against all the anchors in the configuration pointed to byopts
. Each invocation gets a fresh clone ofopts
with theproperties
option set appropriately.- Since:
- 1.1.0
-
-