util
Class PropertyContainer

java.lang.Object
  extended by util.PropertyContainer
All Implemented Interfaces:
Cloneable, Initializable, PropertyBearing
Direct Known Subclasses:
AbstractAnalyser, AbstractCommandRenderer, AbstractConversion, AbstractDataCollector, AbstractDataSink, AbstractDisplayable, AbstractDriver, AbstractErrorFinalizer, AbstractFit, AbstractLogger, AbstractMerit, AbstractParameter, AbstractParameterCluster, AbstractPinholeShift, AbstractScheduler, AbstractShelter, AbstractSql, AbstractTarget, AbstractTargetProvider, AbstractTransferProxy, AdapterUnit, AmplifierCrosstalk, Annulus, AsciiCatalog, AstroKernel, AuxiliaryPointing, AuxiliaryUnit, CentralProjection, CrosstalkDark, DarkOverlapTiler, DarkTiler, DigitizedSkySurveyImage, Donut, E2VGeometry, ElementHelper, ExpressionCalculator, FitsCheck, FitsConvert, FlatFinder, FocusSpindleFit, GenericSql, GuiderData, GuiderMode, GuiderParameters, GuiderParametersAltAz, GuiderParametersRaDe, GuidingStatistic, HeaderUpdate, HighestTarget, Icat, ImageAmoeba, ImageCache, JWheel.DummyAxes, LightCurveSimulator, LogParser, Mailer, MirrorCenter, MomentsFocusser, Overscan, PIDControl, PointingModel, PrepareDark, PropertySyslog, ReductionMaster, RmiPropertyContainer, RobotChoreography, SensorSql, SensorTest, SextractorRead, ShapeListener, SightInfo, Simbad, SimulateFits, StarAmoeba, StarCatalog, StaticSql, StellaGuider, TargetConsistency, TargetHelper, TelescopeAxis, TelescopeHelper, TypeHelper, UserDrivenFitting, UserProperty, VizierStar, Waltz, WcsFit, WcsMatch, WcsProjection, WifsipMaster.WifsipGeometry

public class PropertyContainer
extends Object
implements PropertyBearing, Initializable, Cloneable

An implementation of the PropertyBearing interface. Provides a protected constructor with a single Map object. All of the interface methods are implemented with a Map object.

As of version 1.1, this class already uses the Syslog object for logging rather than the old Message class.

As of version 2.0, this class does not store String values but rather objects of the appropriate type. String values are permitted, though, and are converted (either using number parsing or construction with a single-string constructor) on first retrieval. As of version 2.1, characters are supported as primitive types. As of version 3.0, the special key PropertyBearing.KEY_URLRESOURCES may point to a comma-separated list of url-resources. If present, a URLClassLoader is constructed from the urls specified, and resources can be queried using getResource(java.lang.String) and getResourceAsStream(java.lang.String).

A note on serializing property containers: The generic class does not implement the Serializable interface, though many daughters might need this behaviour. If you only make a daughter class serializable, the (de)serializing process acts on the default (=empty) contructor of PropertyContainer thus The properties in the info map are empty! Think of writing a customized #writeObject and #readObject method instead.

See Also:
PropertySyslog

Nested Class Summary
static class PropertyContainer.URLResource
          A test class for url-class loaders.
 
Field Summary
private  List<String> bundlenames
          The list of bundle names.
private  Map<String,ResourceBundle> bundles
          A mapping of resource bundle names to resource bundle objects.
private static boolean DEFURLUSECONFIG
          Default, not search the current directory for resources.
private static boolean DEFURLUSECURRENT
          Default, not search the current directory for resources.
private static boolean DEFURLUSEHOME
          Default, not search user's home directory for resources.
private  Map<String,Object> info
          The properties of this object.
static String KEY_LISTSEPARATOR
          The key for list separators.
static String KEY_LOCALECOUNTRY
          The key to the locale country.
static String KEY_LOCALELANGUAGE
          The key to the locale language.
static String KEY_MAPKEYVALUECHAR
          The key for map key-value separator.
static String KEY_MAPSEPARATOR
          The key for list separators.
static String KEY_NOINITONCREATE
          If true, new instances are not initalized during creation.
static String KEY_RESOURCEBUNDLES
          The key listing resource bundles.
private  Set<URL> localurl
          A private set of URLS if the PropertyBearing.KEY_URLRESOURCES is defined.
private static ClassLoader locate
          An url-class loader constructed for all property containers.
private  Locale region
          The locale used for this property container.
private static Set<URL> urlset
          A set of URLs for the class loader, for all property containers.
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected PropertyContainer()
          Default constructor.
  PropertyContainer(Map<String,String> props)
          Constructs a new property container.
 
Method Summary
static Map<String,String> augment(Map<String,String> def, Map<String,String> tokens)
          Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental map.
static Map<String,String> augment(Map<String,String> def, String tokens)
          Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental string.
static Map<String,String> augment(Map<String,String> def, String tokens, String delim, String key)
          Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental string.
private  void checkProperties()
          We check the mapping found in our properties against any defined public static fields starting with KEY_.
 Object clone()
          Clones this property container.
static Object createFrom(Map<String,String> prop)
          Constructs a new property container from a given mapping.
static
<T> T
createFrom(Map<String,String> prop, Class<T> to)
          If the PropertyBearing.KEY_CLASS is not set in the properties, the name of the argumental class is put into the mapping before a new object is created using the mian method.
static Object createFrom(String classkey, Map<String,String> prop)
          Constructs a new property container from a given mapping.
private static Object createWith(Constructor<?> create, Object with)
          Create an object with a constructor and a single argument.
 boolean defaultBoolean(String key, boolean def)
          Tests if the given key is present in the properties of this container.
 boolean defaultChar(String key, char def)
          Tests if the given key is present in the properties of this container.
 boolean defaultDouble(String key, double def)
          Tests if the given key is present in the properties of this container.
 boolean defaultFloat(String key, float def)
          Tests if the given key is present in the properties of this container.
 boolean defaultInt(String key, int def)
          Tests if the given key is present in the properties of this container.
 boolean defaultLong(String key, long def)
          Tests if the given key is present in the properties of this container.
 boolean defaultObject(String key, Class def, String defstring)
          Tests if the given key is present in the properties of this container.
 boolean defaultObject(String key, Object def)
          Tests if the given key is present in the properties of this container.
 Map<String,Object> defaultProperties(Map<String,String> defaults)
          Sets default mappings for this object.
 boolean defaultProperty(String key, String def)
          Tests if the given key is present as a map to a string in this container.
 boolean getAsBoolean(String key)
          Returns the property mapped to the given key as a primitive boolean.
 char getAsChar(String key)
          Returns the property mapped to the given key as a primitive char.
 double getAsDouble(String key)
          Returns the property mapped to the given key as a primitive double.
<T extends Enum<T>>
List<T>
getAsEnums(String key, Class<T> cls)
           
 float getAsFloat(String key)
          Returns the property mapped to the given key as a primitive float.
 int getAsInt(String key)
          Returns the property mapped to the given key as a primitive int.
 List<String> getAsList(String key)
          Returns a comma-separated string as a list of Strings.
 long getAsLong(String key)
          Returns the property mapped to the given key as a primitive long.
 Map<String,String> getAsMap(String key)
          Returns a colon-equals devided string as a mapping of string keys to string values.
protected  Map<String,String> getAsMap(String key, String delim, String col)
          Returns a colon-equals devided string as a mapping of string keys to string values.
 Object getAsObject(String key)
          Returns the direct mapping of the key.
<T> T
getAsObject(String key, Class<T> oftype)
          Returns the direct mapping of the key.
private static Object getInstance(Class<?> cls, String init)
          Tries to instantiate a new instance of a class using a single-string constructor.
static ClassLoader getLocalClassLoader()
          Returns the local class loader.
 Object getLocalized(String key)
          Scans all known resource bundles for the specified key.
 Object getLocalized(String key, String bundlename)
          Loades a localized resource from a resource bundle.
 String getLocalizedString(String key)
          Scans all known resource bundles for the specified key.
 String getLocalizedString(String key, String bundlename)
          Gets a localized string version from a resource.
 Map<String,Object> getProperties()
          Returns the entire properties of this object as a map.
static Map<String,String> getPropertiesToKey(PropertyBearing p, String key)
          Retrieves properties to the stated key, or null, if the key is not linked.
 Map<String,String> getPropertiesToKey(String key)
          Scans my properties for the resource.
 String getProperty(String key)
          Returns a special property of this property container.
 URL getResource(String value)
          Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES.
 InputStream getResourceAsStream(String key)
          Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES.
 URL getResourceFromKey(String key)
          Locates a resource from a propty in this property container.
 Enumeration getResources(String key)
          Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES.
 boolean has(String key)
          Tests if this property container contains a certain property.
 void init()
          Loads URL-resources, if there are any.
protected  boolean isNew(String oldval, String newval)
          Returns true, if either, but not both strings are null or if they are different.
static Object keyCreate(PropertyBearing p, String key)
          Creates an object from a key name in a property container.
protected  Object keyCreate(String key)
          Creates an object from a property key name.
private  ResourceBundle loadBundle(String name)
          Loads a resource bundle using a locale defined with the two KEY_LOCALELANGUAGE and KEY_LOCALECOUNTRY keys.
private  Set<URL> loadResource()
          This method parses through the URL's provided in PropertyBearing.KEY_URLRESOURCES.
 Object parseObject(String key, Class forclass)
          Parses a property.
 double reload()
          Does a reload of myself, if I'm reloadable.
 double reload(Reloadable self)
          Use my properties, see if I can establish the state of the resource my properties were constructed from, and if their state has changed, reload them and call with each key found in the newly loaded properties the rescanned method of the reloadable object.
 Object removeProperty(String key)
          Removes the property of the given name.
protected  double rescanned(String key, String old, String newval)
          We provide this abstract method for subclasses that want to be Reloadable instances, but do not implement this interface itself.
private static Constructor<?> scanFor(Constructor[] all, Class[] params)
          Scans and returns the constructr with the given argument map.
 Object setObject(String key, Object val)
          Sets a special property to an object rather then a string.
protected  void setProperties(Map<String,Object> prop)
          Needed for daughter classes that have to set the properites directly.
 String setProperty(String key, String val)
          Sets a special property of this property container.
 Map<String,String> stringProperties()
          Retruns a mapping where all objects are replaced by their string representations.
 String toString()
          A string description, returning the string description of the properties of this container.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_NOINITONCREATE

public static final String KEY_NOINITONCREATE
If true, new instances are not initalized during creation.

See Also:
Constant Field Values

KEY_LOCALELANGUAGE

public static final String KEY_LOCALELANGUAGE
The key to the locale language. If undefined, the default is used.

See Also:
Constant Field Values

KEY_LOCALECOUNTRY

public static final String KEY_LOCALECOUNTRY
The key to the locale country. If undefined, the default is used.

See Also:
Constant Field Values

KEY_RESOURCEBUNDLES

public static final String KEY_RESOURCEBUNDLES
The key listing resource bundles.

See Also:
Constant Field Values

KEY_LISTSEPARATOR

public static final String KEY_LISTSEPARATOR
The key for list separators.

See Also:
Constant Field Values

KEY_MAPSEPARATOR

public static final String KEY_MAPSEPARATOR
The key for list separators.

See Also:
Constant Field Values

KEY_MAPKEYVALUECHAR

public static final String KEY_MAPKEYVALUECHAR
The key for map key-value separator.

See Also:
Constant Field Values

DEFURLUSEHOME

private static final boolean DEFURLUSEHOME
Default, not search user's home directory for resources.

See Also:
Constant Field Values

DEFURLUSECURRENT

private static final boolean DEFURLUSECURRENT
Default, not search the current directory for resources.

See Also:
Constant Field Values

DEFURLUSECONFIG

private static final boolean DEFURLUSECONFIG
Default, not search the current directory for resources.

See Also:
Constant Field Values

urlset

private static Set<URL> urlset
A set of URLs for the class loader, for all property containers.


locate

private static ClassLoader locate
An url-class loader constructed for all property containers.


info

private Map<String,Object> info
The properties of this object.


region

private Locale region
The locale used for this property container.


localurl

private Set<URL> localurl
A private set of URLS if the PropertyBearing.KEY_URLRESOURCES is defined.


bundlenames

private List<String> bundlenames
The list of bundle names. Initialized on first unspecific search.


bundles

private Map<String,ResourceBundle> bundles
A mapping of resource bundle names to resource bundle objects.

Constructor Detail

PropertyContainer

protected PropertyContainer()
Default constructor. Calls PropertyContainer(Map) with a null-argument.


PropertyContainer

public PropertyContainer(Map<String,String> props)
Constructs a new property container. If the argument is null an empty Properties object is created as this object's properties. If the special PropertyBearing.KEY_URLRESOURCES is present in the properties, a new URLClassLoader is constructed using the tokenized value of the key as URL-addresses. If no such value is set, the default class loader is used, which allows access to resources in the classpath.

Method Detail

augment

public static final Map<String,String> augment(Map<String,String> def,
                                               String tokens)
Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental string. The formatting must follow the StringTools#propertize(String) syntax.

Parameters:
tokens - key=value pairs, separated by a colon.

augment

public static final Map<String,String> augment(Map<String,String> def,
                                               String tokens,
                                               String delim,
                                               String key)
Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental string. The formatting must follow the StringTools#propertize(String) syntax.

Parameters:
tokens - key=value pairs, separated by a colon.

augment

public static final Map<String,String> augment(Map<String,String> def,
                                               Map<String,String> tokens)
Augments or overrides parts of a mapping which may be a default mapping gained by the non-static method #getDefaultProperties by key-value pairs given in the argumental map. This method returns the new mapping and thus can be used in constructors, unlike Map.putAll(java.util.Map) that returns void.


init

public void init()
Loads URL-resources, if there are any.

Specified by:
init in interface Initializable

checkProperties

private void checkProperties()
We check the mapping found in our properties against any defined public static fields starting with KEY_.


clone

public Object clone()
Clones this property container. The info map is cloned via the hash-maps clone method, i. e. the values and keys are not cloned themselves.
Note this method is annotated to suppress warnings, otherwise the generics cannot be cloned without issuing of a warning.

Overrides:
clone in class Object

getProperties

public Map<String,Object> getProperties()
Returns the entire properties of this object as a map. The implementation returns a concrete Properties object.

Specified by:
getProperties in interface PropertyBearing

stringProperties

public Map<String,String> stringProperties()
Retruns a mapping where all objects are replaced by their string representations. This can be used to store the properties in a file. Objects in my properties that implement Patterned are converted via Patterned.toPattern(), objects that implement a method like this are also converted likewise. The toString() method is only used as a last resort.

Specified by:
stringProperties in interface PropertyBearing

defaultProperties

public Map<String,Object> defaultProperties(Map<String,String> defaults)
Sets default mappings for this object. If the argumental map is non-null, all currently unknown mappings are put into the properties of this container as strings. All known mappings are removed from the default mapping.

Specified by:
defaultProperties in interface PropertyBearing
Parameters:
defaults - Default mappings of keys to objects.

reload

public double reload()
Does a reload of myself, if I'm reloadable. This is part of the implementation of the Reloadable interface.


reload

public double reload(Reloadable self)
Use my properties, see if I can establish the state of the resource my properties were constructed from, and if their state has changed, reload them and call with each key found in the newly loaded properties the rescanned method of the reloadable object. We compile an average of the rescanning process, which is then returned onto the caller.


rescanned

protected double rescanned(String key,
                           String old,
                           String newval)
We provide this abstract method for subclasses that want to be Reloadable instances, but do not implement this interface itself. Subclasses should always call this method before rescanning on their own. We throw an illegal arguement exception if the PropertyBearing.KEY_CLASS property has changed, but one on a change of


isNew

protected boolean isNew(String oldval,
                        String newval)
Returns true, if either, but not both strings are null or if they are different.


getProperty

public String getProperty(String key)
Returns a special property of this property container. If the object mapped to this key is not a string, it's toString method is evoked. The string returned is always trimmed. If the specified key is not found, null is returned.

Specified by:
getProperty in interface PropertyBearing
Parameters:
key - The key for the Properties object.
Returns:
The value of the getProperty() call to this objects's Properties object.

parseObject

public Object parseObject(String key,
                          Class forclass)
Parses a property. If the key points to a string instance, we use a single-string constructor of the given class to instantiate an object using the property string. If instantiation is successful, the mapping of the key is replaced to a mapping to this new object. If unsuccessful, the key is deleted.

Specified by:
parseObject in interface PropertyBearing

setProperty

public String setProperty(String key,
                          String val)
Sets a special property of this property container.

Specified by:
setProperty in interface PropertyBearing
Parameters:
key - The key for this Property.
value - The value of this Property.

removeProperty

public Object removeProperty(String key)
Removes the property of the given name. Returns the last setting.

Specified by:
removeProperty in interface PropertyBearing

setObject

public Object setObject(String key,
                        Object val)
Sets a special property to an object rather then a string. Used mainly for updating containers of primitive data types. Does nothing if the supplied value is null.

Specified by:
setObject in interface PropertyBearing

has

public boolean has(String key)
Tests if this property container contains a certain property. Returns the result of the Hashtable method containsKey.

Specified by:
has in interface PropertyBearing

getAsObject

public Object getAsObject(String key)
Returns the direct mapping of the key. This might return a null key. This method is best used after first ensuring that a default mapping to an object of the appropraite class exists, see defaultObject(java.lang.String, java.lang.Object).

Specified by:
getAsObject in interface PropertyBearing

getAsObject

public <T> T getAsObject(String key,
                         Class<T> oftype)
Returns the direct mapping of the key. This might return a null key. This method is best used after first ensuring that a default mapping to an object of the appropraite class exists, see defaultObject(java.lang.String, java.lang.Object).

Specified by:
getAsObject in interface PropertyBearing

getAsEnums

public <T extends Enum<T>> List<T> getAsEnums(String key,
                                              Class<T> cls)

getAsList

public List<String> getAsList(String key)
Returns a comma-separated string as a list of Strings. If the key is not present, we return null.

Specified by:
getAsList in interface PropertyBearing
Returns:
null if no such property exists.

getAsMap

public Map<String,String> getAsMap(String key)
Returns a colon-equals devided string as a mapping of string keys to string values. If the key is not present, we return null.

Specified by:
getAsMap in interface PropertyBearing
Returns:
null if no such property exists.

getAsMap

protected Map<String,String> getAsMap(String key,
                                      String delim,
                                      String col)
Returns a colon-equals devided string as a mapping of string keys to string values. If the key is not present, we return null.


getAsBoolean

public boolean getAsBoolean(String key)
Returns the property mapped to the given key as a primitive boolean. The mapped value is trimmed prior to parsing.

Specified by:
getAsBoolean in interface PropertyBearing

getAsInt

public int getAsInt(String key)
Returns the property mapped to the given key as a primitive int. The mapped value is trimmed prior to parsing.

Specified by:
getAsInt in interface PropertyBearing
Returns:
Zero on failure.

getAsChar

public char getAsChar(String key)
Returns the property mapped to the given key as a primitive char. If the mapped value is a string, only the first character in it is returned and stored.

Specified by:
getAsChar in interface PropertyBearing
Returns:
0 on failure.

getAsLong

public long getAsLong(String key)
Returns the property mapped to the given key as a primitive long. The mapped value is trimmed prior to parsing.

Specified by:
getAsLong in interface PropertyBearing
Returns:
Zero on failure.

getAsDouble

public double getAsDouble(String key)
Returns the property mapped to the given key as a primitive double. The mapped value is trimmed prior to parsing.

Specified by:
getAsDouble in interface PropertyBearing
Returns:
NaN on failure.

getAsFloat

public float getAsFloat(String key)
Returns the property mapped to the given key as a primitive float. The mapped value is trimmed prior to parsing.

Specified by:
getAsFloat in interface PropertyBearing
Returns:
NaN on failure.

defaultProperty

public boolean defaultProperty(String key,
                               String def)
Tests if the given key is present as a map to a string in this container. If not, the default value is mapped to the key, replacing any former mappings of key not pointing to a string object.

Specified by:
defaultProperty in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped at method call.

defaultInt

public boolean defaultInt(String key,
                          int def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into an integer via the Integer.parseInt method. If this conversation fails or if the key is not present in the container, the default value is stored.

Specified by:
defaultInt in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to an int.

defaultChar

public boolean defaultChar(String key,
                           char def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into an integer via the Integer.parseInt method. If this conversation fails or if the key is not present in the container, the default value is stored.

Specified by:
defaultChar in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to an int.

defaultDouble

public boolean defaultDouble(String key,
                             double def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into a double via the Double.parseDouble method. If this conversation fails or if the key is not present in the container, the default value is stored.

Specified by:
defaultDouble in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to a double.

defaultLong

public boolean defaultLong(String key,
                           long def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into a long via the Long.parseLong method. If this conversation fails or if the key is not present in the container, the default value is stored.

Specified by:
defaultLong in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to a long.

defaultFloat

public boolean defaultFloat(String key,
                            float def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into a float via the Float.parseFloat method. If this conversation fails or if the key is not present in the container, the default value is stored.

Specified by:
defaultFloat in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to a float.

defaultBoolean

public boolean defaultBoolean(String key,
                              boolean def)
Tests if the given key is present in the properties of this container. If it is not, the default value is stored as a string representation.

Specified by:
defaultBoolean in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the given key was already mapped to a boolean.

defaultObject

public boolean defaultObject(String key,
                             Object def)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into a new instance of the def object class using the mapped string as the constructor argument. If the construction fails for any reason, the default representation is converted into a string with it's toString method and stored as a property.

Specified by:
defaultObject in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
Returns:
True if the key was mapped to a correct constructor string.

defaultObject

public boolean defaultObject(String key,
                             Class def,
                             String defstring)
Tests if the given key is present in the properties of this container. If it is, the mapping is converted into a new instance of the def object class using the mapped string as the constructor argument. If the construction fails for any reason, the default string representation is stored as a property.

Specified by:
defaultObject in interface PropertyBearing
Parameters:
key - The properties key to test for a present mapping.
def - The default value of the key. Set if not present.
defstring - The default constructor string.
Returns:
True if the key was mapped to a correct constructor string.

getResource

public URL getResource(String value)
Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES. As for the general contract for resource-finding, first the main class loader tries to locate the resource and only if it failes, the URL's are searched.

Specified by:
getResource in interface PropertyBearing

getResourceFromKey

public URL getResourceFromKey(String key)
Locates a resource from a propty in this property container. The value handed over is a key which is looked up for its match. If this is non-null, we retrieve the resource via getResource(java.lang.String).


getLocalClassLoader

public static ClassLoader getLocalClassLoader()
Returns the local class loader.


getResources

public Enumeration getResources(String key)
                         throws IOException
Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES. As for the general contract for resource-finding, first the main class loader tries to locate the resource and only if it failes, the URL's are searched.

Specified by:
getResources in interface PropertyBearing
Throws:
IOException

getResourceAsStream

public InputStream getResourceAsStream(String key)
Locates a resource using either the default class loader or the URLClassLoader defined with PropertyBearing.KEY_URLRESOURCES. As for the general contract for resource-finding, first the main class loader tries to locate the resource and only if it failes, the URL's are searched.

Specified by:
getResourceAsStream in interface PropertyBearing

getLocalized

public Object getLocalized(String key,
                           String bundlename)
Loades a localized resource from a resource bundle. The resource bundle is loaded only if queried.


getLocalizedString

public String getLocalizedString(String key,
                                 String bundlename)
Gets a localized string version from a resource.


getLocalized

public Object getLocalized(String key)
Scans all known resource bundles for the specified key. The first non-null match is returned, scanning direction is implied by the KEY_RESOURCEBUNDLES order. As a last resort, the properties of the property container are queried.

Specified by:
getLocalized in interface PropertyBearing

getLocalizedString

public String getLocalizedString(String key)
Scans all known resource bundles for the specified key. The first non-null match is returned as a string, scanning direction is implied by the KEY_RESOURCEBUNDLES order. As a last resort, the properties of the property container are queried.


toString

public String toString()
A string description, returning the string description of the properties of this container.

Overrides:
toString in class Object

getPropertiesToKey

public Map<String,String> getPropertiesToKey(String key)
Scans my properties for the resource. If the key is not found in my properties or if the resource this key points at cannot be found, we return null. If the resource is found, we return PropertyLoader.load(URL), which currently returns a map with at least three keys, even if the reource is empty.


getPropertiesToKey

public static Map<String,String> getPropertiesToKey(PropertyBearing p,
                                                    String key)
Retrieves properties to the stated key, or null, if the key is not linked. If the key is linked, but the resource cannot be found, a warning is issued.

Parameters:
p - A property bearing instance, mostly myself.
key - the key to scan for.

createFrom

public static final <T> T createFrom(Map<String,String> prop,
                                     Class<T> to)
If the PropertyBearing.KEY_CLASS is not set in the properties, the name of the argumental class is put into the mapping before a new object is created using the mian method. This object is then cast to the class reference type.

This means, if the class key is present, the argument class can also be a superclass/interface of the desired object. If the key is missing, the class must be instantiable.


keyCreate

protected Object keyCreate(String key)
Creates an object from a property key name. The composed properties are scanned for an entry of the given key. If this entry exist, we try to locate the resource. If this resource could be located, we construct a property container out of that. This property container should contain a class entry, which is then used to create the final Object.


keyCreate

public static final Object keyCreate(PropertyBearing p,
                                     String key)
Creates an object from a key name in a property container.


createFrom

public static final Object createFrom(Map<String,String> prop)
Constructs a new property container from a given mapping. The PropertyBearing.KEY_CLASS key must at least be present. If the object constructed implements the Initializable field, the init method is called unless a KEY_NOINITONCREATE property is present and points to true.

Parameters:
prop - A mapping, most likely a properties object.
Returns:
A new instance of a property container or null if construction fails.

createFrom

public static final Object createFrom(String classkey,
                                      Map<String,String> prop)
Constructs a new property container from a given mapping. The key given for the class name must at least be present. If the object constructed implements the Initializable field, the init method is called unless a KEY_NOINITONCREATE property is present and points to true.

Parameters:
prop - A mapping, most likely a properties object.
Returns:
A new instance of a property container or null if construction fails.

scanFor

private static Constructor<?> scanFor(Constructor[] all,
                                      Class[] params)
Scans and returns the constructr with the given argument map.


createWith

private static final Object createWith(Constructor<?> create,
                                       Object with)
                                throws InvocationTargetException,
                                       InstantiationException,
                                       IllegalAccessException
Create an object with a constructor and a single argument.

Throws:
InvocationTargetException
InstantiationException
IllegalAccessException

setProperties

protected void setProperties(Map<String,Object> prop)
Needed for daughter classes that have to set the properites directly. This method is used for custom serialization.


loadResource

private Set<URL> loadResource()
This method parses through the URL's provided in PropertyBearing.KEY_URLRESOURCES. Each valid URL found is added to a local set. If this class defines new URLs, as checked against the #urls set, the class-loader is reconstructed to reflect the new class loader.

Returns:
The set of local URLs for caching.

loadBundle

private ResourceBundle loadBundle(String name)
Loads a resource bundle using a locale defined with the two KEY_LOCALELANGUAGE and KEY_LOCALECOUNTRY keys. Additionally, the PropertyBearing.KEY_URLRESOURCES are used for locating the named resource bundle.


getInstance

private static final Object getInstance(Class<?> cls,
                                        String init)
Tries to instantiate a new instance of a class using a single-string constructor.