javax.media.jai
Class PropertySourceImpl

java.lang.Object
  extended byjavax.media.jai.PropertySourceImpl
All Implemented Interfaces:
PropertySource, Serializable
Direct Known Subclasses:
WritablePropertySourceImpl

public class PropertySourceImpl
extends Object
implements PropertySource, Serializable

A utility implementation of the PropertySource interface. Properties are managed by three internal structures: one which maps property names to values, a second which maps property names to PropertySources, and a third which tracks which entries in the name-value mapping derived their respective values from a PropertySource in the name-PropertySource mapping. The case of property names is retained for subsequent retrieval but is ignored when the names are used as keys.

Since:
JAI 1.1
See Also:
CaselessStringKey, PropertySource, WritablePropertySource, WritablePropertySourceImpl, Serialized Form

Field Summary
protected  Set cachedPropertyNames
          CaselessStringKeys corresponding to the keys of entries in properties which derived their respective values from a PropertySource in propertySources.
protected  Map properties
          Mapping of CaselessStringKeys to values.
protected  Map propertySources
          Mapping of CaselessStringKeys to PropertySources.
 
Constructor Summary
protected PropertySourceImpl()
          Constructs a PropertySourceImpl instance with no properties set.
  PropertySourceImpl(Map propertyMap, PropertySource propertySource)
          Constructs a PropertySourceImpl instance which will derive properties from one or both of the supplied parameters.
 
Method Summary
 Map getProperties()
          Copies into a Map all properties currently available via this PropertySource.
 Object getProperty(String propertyName)
          Returns the value of a property.
 Class getPropertyClass(String propertyName)
          Returns the class expected to be returned by a request for the property with the specified name.
 String[] getPropertyNames()
          Returns an array of Strings recognized as names by this property source.
 String[] getPropertyNames(String prefix)
          Returns an array of Strings recognized as names by this property source that begin with the supplied prefix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected transient Map properties
Mapping of CaselessStringKeys to values. If this object is serialized, only those entries of which the value is serializable will be retained.


propertySources

protected transient Map propertySources
Mapping of CaselessStringKeys to PropertySources. If this object is serialized, only those entries of which the value is serializable will be retained.


cachedPropertyNames

protected Set cachedPropertyNames
CaselessStringKeys corresponding to the keys of entries in properties which derived their respective values from a PropertySource in propertySources.

Constructor Detail

PropertySourceImpl

protected PropertySourceImpl()
Constructs a PropertySourceImpl instance with no properties set.


PropertySourceImpl

public PropertySourceImpl(Map propertyMap,
                          PropertySource propertySource)
Constructs a PropertySourceImpl instance which will derive properties from one or both of the supplied parameters. The propertyMap and propertySource parameters will be used to initialize the name-value and name-PropertySource mappings, respectively. Entries in the propertyMap object will be assumed to be properties if the key is a String or a CaselessStringKey. The propertySource object will be queried for the names of properties that it emits but requests for associated values will not be made at this time so as to to defer any calculation that such requests might provoke. The case of property names will be retained but will be ignored insofar as the name is used as a key to the property value.

Parameters:
propertyMap - A Map from which to copy properties which have keys which are either Strings or CaselessStringKeys.
propertySource - A PropertySource from which to derive properties.
Throws:
IllegalArgumentException - if propertyMap and propertySource are both null and this constructor is not being invoked from within a subclass constructor. When invoked from a subclass constructor both parameters may be null.
Method Detail

getPropertyNames

public String[] getPropertyNames()
Returns an array of Strings recognized as names by this property source. The case of the property names is retained. If no properties are available, null will be returned.

Specified by:
getPropertyNames in interface PropertySource
Returns:
an array of Strings giving the valid property names or null.

getPropertyNames

public String[] getPropertyNames(String prefix)
Returns an array of Strings recognized as names by this property source that begin with the supplied prefix. If no property names match, null will be returned. The comparison is done in a case-independent manner.

Specified by:
getPropertyNames in interface PropertySource
Returns:
an array of Strings giving the valid property names.
Throws:
IllegalArgumentException - if prefix is null.

getPropertyClass

public Class getPropertyClass(String propertyName)
Returns the class expected to be returned by a request for the property with the specified name. If this information is unavailable, null will be returned. This method queries only the name-value mapping so as to avoid requesting a property value from a PropertySource to which the name might refer via the name-PropertySource mapping. If it is known from getPropertyNames() that the property is emitted by this PropertySource but this method returns null, then getProperty() will have to be invoked and the Class obtained from the property value itself.

Specified by:
getPropertyClass in interface PropertySource
Parameters:
propertyName - the name of the property, as a String.
Returns:
The Class expected to be returneded by a request for the value of this property or null.
Throws:
IllegalArgumentException - if propertyName is null.

getProperty

public Object getProperty(String propertyName)
Returns the value of a property. If the property name is not recognized, java.awt.Image.UndefinedProperty will be returned.

If the requested name is found in the name-value mapping, the corresponding value will be returned. Otherwise the name-PropertySource mapping will be queried and the value will be derived from the found PropertySource, if any. If the value is derived from a PropertySource, a record will be kept of this and this property will be referred to as a "cached property".

Specified by:
getProperty in interface PropertySource
Parameters:
propertyName - the name of the property, as a String.
Returns:
the value of the property, as an Object, or the value java.awt.Image.UndefinedProperty.
Throws:
IllegalArgumentException - if propertyName is null.

getProperties

public Map getProperties()
Copies into a Map all properties currently available via this PropertySource. All property values are copied by reference rather than by being cloned. The keys in the Map will be Strings with the original property name case intact. Property values derived from the name-value mapping will take precedence. The names of properties whose values are derived via the name-PropertySource mapping will be recorded as "cached properties".

Returns:
A Map of all properties or null if none are defined.