org.activemath.abstractcontent
Class SubconfImpl.Util

java.lang.Object
  extended by org.activemath.abstractcontent.SubconfImpl.Util
Enclosing class:
SubconfImpl

public static class SubconfImpl.Util
extends Object


Constructor Summary
SubconfImpl.Util()
           
 
Method Summary
static Object createConfiguredObjectWithConfig(Subconfiguration config)
          Finds the class and constructor with a subconfiguration, invokes it, and returns it.
static void dumpSubconfigurationToErr(Subconfiguration c)
           
static Set getChildrenNames(Map props, String prefix)
          Creates a Set of the possible property-names after the given prefix.
static URL getClassOrigin(Class c)
          Returns the URL of the class-file or jar-file that loaded the indicated class.
static SubconfImpl.PathResolver makeAbsFilePathResolver()
          Returns an PathResolver meant to handle property-values that are absolute path names.
static SubconfImpl.PathResolver makeBasedPathResolver(URL baseURL)
          Provides a resolver that uses relative URL resolutions of the URL class.
static SubconfImpl.PathResolver makeBaseFileWithinPathResolver(File baseFile)
          Path resolver uses the same strategy as ActiveMath's Manager and makes "/" the base-path.
static Map makeMap(Subconfiguration conf)
          A simplistic Map implementation just providing the Map.get(java.lang.Object) method backed by an Subconfiguration.getProperty(java.lang.String).
static Iterator makeMergedIterator(Iterator firstIt, Map firstMap, Iterator secondIt)
          An Iterator implementation iterating first over the first iterator then following with the iterator of the second iterator whose keys are not in the first.
static SubconfImpl.PathResolver makeNullPathResolver()
          Provides a SubconfImpl.PathResolver which throws IllegalStateException at every-call.
static Map makeUnprefixedMap(Map source, String prefix)
          Implements Map.get(java.lang.Object) adding the prefix (and a "period") to each key.
static Iterator makeUnprefixingIterator(Iterator it, String prefix)
          Implements an Iterator that changes the String returned by the given iterator to either exclude them (if it does not start with the prefix) or provide the string with the prefix removed.
static String prepend(String prefix, String name)
          Prepends the prefix to the name taking care of possible null values (in which case the "." is avoided and a "" is appended.
static boolean runningOnWindows()
           
static File slashSeparatedToLocalAbsolute(String slashSep)
          Returns a file object given a /-separated path supposed to be absolute.
static File slashSeparatedToLocalRelative(File base, String slashSep)
          Converts the given string denoting a slash-separated path into a File relative to a base-file.
static File slashSeparatedToLocalWithin(File base, String slashSep)
          Converts the given string denoting a slash-separated path into a File relative to a base-file.
static File urlToFile(URL url)
          Converts the result of URL.getFile() into a File object with machine dependent file separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubconfImpl.Util

public SubconfImpl.Util()
Method Detail

prepend

public static String prepend(String prefix,
                             String name)
Prepends the prefix to the name taking care of possible null values (in which case the "." is avoided and a "" is appended. This method is the central place meant to obey the "child"-notion in a set of properties.

Parameters:
prefix - the string to be made before the name, followed by a "." if not-null
name - the name
Returns:
the prepended value

dumpSubconfigurationToErr

public static void dumpSubconfigurationToErr(Subconfiguration c)

makeNullPathResolver

public static SubconfImpl.PathResolver makeNullPathResolver()
Provides a SubconfImpl.PathResolver which throws IllegalStateException at every-call. Subconfiguration objects created with such a path-resolver will throw this exception at every-call to Subconfiguration.getPath(java.lang.String).


makeBasedPathResolver

public static SubconfImpl.PathResolver makeBasedPathResolver(URL baseURL)
Provides a resolver that uses relative URL resolutions of the URL class.


makeBaseFileWithinPathResolver

public static SubconfImpl.PathResolver makeBaseFileWithinPathResolver(File baseFile)
Path resolver uses the same strategy as ActiveMath's Manager and makes "/" the base-path.


makeAbsFilePathResolver

public static SubconfImpl.PathResolver makeAbsFilePathResolver()
Returns an PathResolver meant to handle property-values that are absolute path names.


getChildrenNames

public static Set getChildrenNames(Map props,
                                   String prefix)
Creates a Set of the possible property-names after the given prefix. For example, if "a.b.c", "a.b.d" and "a.d.d" are property-names in prop, a call to this method with prefix being "a" would return the set made of "b" and "d".

Parameters:
props - a map supposed to have String objects as keys
prefix - the prefix which, appended with "." will be used to check property-names

makeMap

public static Map makeMap(Subconfiguration conf)
A simplistic Map implementation just providing the Map.get(java.lang.Object) method backed by an Subconfiguration.getProperty(java.lang.String). Note that the method Map.get(java.lang.Object) can only accept String objects.


makeMergedIterator

public static Iterator makeMergedIterator(Iterator firstIt,
                                          Map firstMap,
                                          Iterator secondIt)
An Iterator implementation iterating first over the first iterator then following with the iterator of the second iterator whose keys are not in the first.

TODO: this inner anonymous class should be a subclasseable class.


makeUnprefixingIterator

public static Iterator makeUnprefixingIterator(Iterator it,
                                               String prefix)
Implements an Iterator that changes the String returned by the given iterator to either exclude them (if it does not start with the prefix) or provide the string with the prefix removed.

TODO: this inner anonymous class should be a subclasseable class.


makeUnprefixedMap

public static Map makeUnprefixedMap(Map source,
                                    String prefix)
Implements Map.get(java.lang.Object) adding the prefix (and a "period") to each key.


getClassOrigin

public static URL getClassOrigin(Class c)
Returns the URL of the class-file or jar-file that loaded the indicated class.

Parameters:
c - The class to be searched for

urlToFile

public static File urlToFile(URL url)
Converts the result of URL.getFile() into a File object with machine dependent file separator.

This operation is the converse of the File.toURL() operation, it allows, however other protocols to co-exist.

See Also:
which is used here to convert to a file.

slashSeparatedToLocalRelative

public static File slashSeparatedToLocalRelative(File base,
                                                 String slashSep)
Converts the given string denoting a slash-separated path into a File relative to a base-file.

Note that this method does neither ensure that the file exists nor that the slashSet does not go outside of the base directory.

Leading slashes are forgotten.

Parameters:
base - the file-name from where to start the walk
slashSep - the string to decode

runningOnWindows

public static boolean runningOnWindows()

slashSeparatedToLocalAbsolute

public static File slashSeparatedToLocalAbsolute(String slashSep)
Returns a file object given a /-separated path supposed to be absolute. Considers that this string is expected to start with / if on Unix systems or a disk name if on Windows systems (like D:). Note that this implies that Windows users have to type their paths in a non-traditional fashion (like C:/

Throws:
IllegalArgumentException - if the path does not start with one of the results of File.listRoots().
IllegalStateException - if File.getCanonicalPath() fails for some reason.

slashSeparatedToLocalWithin

public static File slashSeparatedToLocalWithin(File base,
                                               String slashSep)
Converts the given string denoting a slash-separated path into a File relative to a base-file.

This method ensures that the indicated path is within the indicated base comparing the File.getParentFile() which may be resource-expensive.

Leading slashes are forgotten.


createConfiguredObjectWithConfig

public static Object createConfiguredObjectWithConfig(Subconfiguration config)
                                               throws InvocationTargetException
Finds the class and constructor with a subconfiguration, invokes it, and returns it.

Parameters:
config - the configuration object of which the class property should be the class-name of the object to be instantiated.
Returns:
the configured object
Throws:
IllegalStateException - in case instiation does not work.
InvocationTargetException