Package org.apache.openjpa.lib.conf
Class Configurations
- java.lang.Object
-
- org.apache.openjpa.lib.conf.Configurations
-
public class Configurations extends 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 String
CONFIG_RESOURCE_ANCHOR
static String
CONFIG_RESOURCE_PATH
-
Constructor Summary
Constructors Constructor Description Configurations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
combinePlugins(String orig, 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(Object obj, Configuration conf, String properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(Object obj, Configuration conf, String properties, String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(Object obj, Configuration conf, Properties properties)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static void
configureInstance(Object obj, Configuration conf, Properties properties, String configurationName)
Configures the given object with the given properties by matching the properties string to the object's setter methods.static boolean
containsProperty(String partialKey, Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.static boolean
containsProperty(Value value, Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.static String
getClassName(String plugin)
Return the class name from the given plugin string, or null if none.static List<String>
getFullyQualifiedAnchorsInPropertiesLocation(Options opts)
Return a Listof all the fully-qualified anchors specified in the properties location listed in opts
.static String
getPlugin(String clsName, String props)
Combine the given class name and properties into a plugin string.static String
getProperties(String plugin)
Return the properties part of the given plugin string, or null if none.static Object
getProperty(String partialKey, Map m)
Get the property under the given partial key, prefixed with any possible configuration prefix.static Object
lookup(String name, String userKey, Log log)
Looks up the given name in JNDI.static Object
newInstance(String clsName, ClassLoader loader)
Create the instance with the given class name, using the given class loader.static Object
newInstance(String clsName, Configuration conf, String props, ClassLoader loader)
Create and configure an instance with the given class name and properties as a String.static Object
newInstance(String clsName, Configuration conf, Properties props, ClassLoader loader)
Create and configure an instance with the given class name and properties.static Map<String,String>
parseConfigResource(String props)
static Options
parseProperties(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 Object
removeProperty(String partialKey, Map props)
Remove the property under the given partial key, prefixed with any possible configuration prefix.static void
removeProperty(String partialKey, Map<?,?> remaining, Map<?,?> props)
static boolean
runAgainstAllAnchors(Options opts, Configurations.Runnable runnable)
Runsrunnable
against all the anchors in the configuration pointed to byopts
.static String
serializeProperties(Map map)
Turn a set of properties into a comma-separated string.
-
-
-
Field Detail
-
CONFIG_RESOURCE_PATH
public static final String CONFIG_RESOURCE_PATH
- See Also:
- Constant Field Values
-
CONFIG_RESOURCE_ANCHOR
public static final String CONFIG_RESOURCE_ANCHOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getClassName
public static String getClassName(String plugin)
Return the class name from the given plugin string, or null if none.
-
getProperties
public static String getProperties(String plugin)
Return the properties part of the given plugin string, or null if none.
-
getPlugin
public static String getPlugin(String clsName, String props)
Combine the given class name and properties into a plugin string.
-
combinePlugins
public static String combinePlugins(String orig, 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 Object newInstance(String clsName, 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 Object newInstance(String clsName, Configuration conf, String props, ClassLoader loader)
Create and configure an instance with the given class name and properties as a String.
-
newInstance
public static Object newInstance(String clsName, Configuration conf, Properties props, ClassLoader loader)
Create and configure an instance with the given class name and properties.
-
getFullyQualifiedAnchorsInPropertiesLocation
public static List<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.
-
configureInstance
public static void configureInstance(Object obj, Configuration conf, 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:
RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(Object obj, Configuration conf, String properties, 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:
RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(Object obj, Configuration conf, 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:
RuntimeException
- on configuration error
-
configureInstance
public static void configureInstance(Object obj, Configuration conf, Properties properties, 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:
RuntimeException
- on configuration error
-
serializeProperties
public static String serializeProperties(Map map)
Turn a set of properties into a comma-separated string.
-
parseProperties
public static Options parseProperties(String properties)
Parse a set of properties from a comma-separated string.
-
lookup
public static Object lookup(String name, 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, Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.
-
containsProperty
public static boolean containsProperty(String partialKey, Map props)
Test whether the map contains the given partial key, prefixed with any possible configuration prefix.
-
getProperty
public static Object getProperty(String partialKey, Map m)
Get the property under the given partial key, prefixed with any possible configuration prefix.
-
removeProperty
public static Object removeProperty(String partialKey, Map props)
Remove the property under the given partial key, prefixed with any possible configuration prefix.
-
removeProperty
public static void removeProperty(String partialKey, Map<?,?> remaining, 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
-
-