Class 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  
    • 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 of override will override the same properties of orig.
      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 List of 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 given Configuration 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)
      Runs runnable against all the anchors in the configuration pointed to by opts.
      static java.lang.String serializeProperties​(java.util.Map map)
      Turn a set of properties into a comma-separated string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • Configurations

        public Configurations()
    • 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 of override will override the same properties of orig.
      • 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 List of all the fully-qualified anchors specified in the properties location listed in opts. If no properties location is listed in opts, this returns whatever the product derivations can find in their default configurations. If the properties location specified in opts 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 mutate opts.
        Since:
        1.1.0
      • populateConfiguration

        public static void populateConfiguration​(Configuration conf,
                                                 Options opts)
        Set the given Configuration instance from the command line options provided. All property names of the given configuration are recognized; additionally, if a properties or p 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. If configurationName 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)
        Runs runnable against all the anchors in the configuration pointed to by opts. Each invocation gets a fresh clone of opts with the properties option set appropriately.
        Since:
        1.1.0