org.apache.openjpa.lib.conf
Class Value

java.lang.Object
  extended by org.apache.openjpa.lib.conf.Value
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
BooleanValue, DoubleValue, FileValue, IntValue, ObjectValue, StringListValue, StringValue

public abstract class Value
extends Object
implements Cloneable

A configuration value.

Author:
Marc Prud'hommeaux, Pinaki Poddar (added dynamic Value support)

Constructor Summary
Value()
          Default constructor.
Value(String prop)
          Constructor.
 
Method Summary
 void addListener(ValueListener listener)
          Listener for value changes.
 String alias(String str)
          Alias the given setting.
protected  String alias(String str, String[] aliases, boolean nullNotFound)
          Alias the given setting.
protected  void assertChangeable()
          Asserts if this receiver can be changed.
 Object clone()
           
 boolean equals(Object other)
          Use original value instead of current value because they are one and the same for non-dynamic Values and ensures that modifying dynamic Values do not impact equality or hashCode contract.
 String[] getAliases()
          Aliases for the value in the form key1, value1, key2, value2, ...
 String getDefault()
          The default value for the property as a string.
 String getInstantiatingGetter()
          The name of the getter method for the instantiated value of this property(as opposed to the string value)
protected abstract  String getInternalString()
          Return the internal string form of this value.
 List<ValueListener> getListeners()
          Gets unmodifable list of listeners for value changes.
 String getLoadKey()
          The key under which this value was loaded, or null.
 String getOriginalValue()
          Gets the original value.
 String getProperty()
          The property name that will be used when setting or getting this value in a Map.
 Class getScope()
          A class defining the scope in which this value is defined.
 String getString()
          Return a stringified version of this value.
abstract  Class getValueType()
          Returns the type of the property that this Value represents.
 int hashCode()
          Use original value instead of current value because they are one and the same for non-dynamic Values and ensures that modifying dynamic Values do not impact equality or hashCode contract.
 boolean isAliasListComprehensive()
          Whether or not the alias list defines all possible settings for this value.
 boolean isDynamic()
          Affirms if this receiver can be mutated even when the configuration it belongs to has been frozen.
 void removeListener(ValueListener listener)
           
 void setAlias(String key, String value)
          Replaces an existing alias, or adds the given alias to the front of the alias list if it does not already exist.
protected  String[] setAlias(String key, String value, String[] aliases)
          Set an alias into a current alias list, returning the new list.
 void setAliases(String[] aliases)
          Aliases for the value in the form key1, value1, key2, value2, ...
 void setAliasListComprehensive(boolean aliasListIsComprehensive)
          Whether or not the alias list defines all possible settings for this value.
 void setDefault(String def)
          The default value for the propert as a string.
 void setDynamic(boolean flag)
          Sets if this receiver can be mutated even when the configuration it belongs to has been frozen.
 void setInstantiatingGetter(String getter)
          The name of the getter method for the instantiated value of this property(as opposed to the string value).
protected abstract  void setInternalObject(Object obj)
          Set this value from an object.
protected abstract  void setInternalString(String str)
          Set this value from the given string.
 void setLoadKey(String loadKey)
          The key under which this value was loaded, or null.
 void setObject(Object obj)
          Set this value as an object.
 void setProperty(String prop)
          The property name that will be used when setting or getting this value in a Map.
 void setScope(Class cls)
          A class defining the scope in which this value is defined.
 void setString(String val)
          Set this value from the given string.
 String unalias(String str)
          Unalias the given setting.
protected  String unalias(String str, String[] aliases, boolean nullNotFound)
          Unalias the given setting.
 void valueChanged()
          Subclasses should call this method when their internal value changes.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Value

public Value()
Default constructor.


Value

public Value(String prop)
Constructor. Supply the property name.

See Also:
setProperty(java.lang.String)
Method Detail

getProperty

public String getProperty()
The property name that will be used when setting or getting this value in a Map.


setProperty

public void setProperty(String prop)
The property name that will be used when setting or getting this value in a Map.


getLoadKey

public String getLoadKey()
The key under which this value was loaded, or null.


setLoadKey

public void setLoadKey(String loadKey)
The key under which this value was loaded, or null.


getAliases

public String[] getAliases()
Aliases for the value in the form key1, value1, key2, value2, ... All alias values must be in string form.


setAliases

public void setAliases(String[] aliases)
Aliases for the value in the form key1, value1, key2, value2, ... All alias values must be in string form.

To avoid potential side-effects, this method copies the array passed in.


setAlias

public void setAlias(String key,
                     String value)
Replaces an existing alias, or adds the given alias to the front of the alias list if it does not already exist. All alias values must be in string form.


setAlias

protected String[] setAlias(String key,
                            String value,
                            String[] aliases)
Set an alias into a current alias list, returning the new list.


isAliasListComprehensive

public boolean isAliasListComprehensive()
Whether or not the alias list defines all possible settings for this value. If so, an error will be generated when attempting to invoke any method on this value with an unknown option.


setAliasListComprehensive

public void setAliasListComprehensive(boolean aliasListIsComprehensive)
Whether or not the alias list defines all possible settings for this value. If so, an error will be generated when attempting to invoke any method on this value with an unknown option.


alias

public String alias(String str)
Alias the given setting.


alias

protected String alias(String str,
                       String[] aliases,
                       boolean nullNotFound)
Alias the given setting.


unalias

public String unalias(String str)
Unalias the given setting.


unalias

protected String unalias(String str,
                         String[] aliases,
                         boolean nullNotFound)
Unalias the given setting.


getDefault

public String getDefault()
The default value for the property as a string.


setDefault

public void setDefault(String def)
The default value for the propert as a string.


getInstantiatingGetter

public String getInstantiatingGetter()
The name of the getter method for the instantiated value of this property(as opposed to the string value)


setInstantiatingGetter

public void setInstantiatingGetter(String getter)
The name of the getter method for the instantiated value of this property(as opposed to the string value). If the string starts with this., then the getter will be looked up on the value instance itself. Otherwise, the getter will be looked up on the configuration instance.


getScope

public Class getScope()
A class defining the scope in which this value is defined. This will be used by the configuration framework to look up metadata about the value.


setScope

public void setScope(Class cls)
A class defining the scope in which this value is defined. This will be used by the configuration framework to look up metadata about the value.


getString

public String getString()
Return a stringified version of this value. If the current value has a short alias key, the alias key is returned.


setString

public void setString(String val)
Set this value from the given string. If the given string is null or empty and a default is defined, the default is used. If the given string(or default) is an alias key, it will be converted to the corresponding value internally.
If this Value is being set to a non-default value for the first time (as designated by originalString being null), then the value is remembered as original. This original value is used for equality and hashCode computation if this Value is dynamic.


setObject

public void setObject(Object obj)
Set this value as an object.
If this Value is being set to a non-default value for the first time (as designated by originalString being null), then the value is remembered as original. This original value is used for equality and hashCode computation if this Value is dynamic.


getOriginalValue

public String getOriginalValue()
Gets the original value. Original value denotes the Stringified form of this Value, from which it has been set, if ever. If this Value has never been set to a non-default value, then returns the default value, which itself can be null.

Since:
1.1.0

getValueType

public abstract Class getValueType()
Returns the type of the property that this Value represents.


getInternalString

protected abstract String getInternalString()
Return the internal string form of this value.


setInternalString

protected abstract void setInternalString(String str)
Set this value from the given string.


setInternalObject

protected abstract void setInternalObject(Object obj)
Set this value from an object.


getListeners

public List<ValueListener> getListeners()
Gets unmodifable list of listeners for value changes.


addListener

public void addListener(ValueListener listener)
Listener for value changes.


removeListener

public void removeListener(ValueListener listener)

valueChanged

public void valueChanged()
Subclasses should call this method when their internal value changes.


assertChangeable

protected void assertChangeable()
Asserts if this receiver can be changed. Subclasses must invoke this method before changing its internal state. This receiver can not be changed if all of the following is true
  • this receiver is not dynamic
  • ValueListener attached to this receiver is a Configuration
  • Configuration is read-only


  • setDynamic

    public void setDynamic(boolean flag)
    Sets if this receiver can be mutated even when the configuration it belongs to has been frozen.

    Since:
    1.1.0

    isDynamic

    public boolean isDynamic()
    Affirms if this receiver can be mutated even when the configuration it belongs to has been frozen.

    Since:
    1.1.0

    hashCode

    public int hashCode()
    Use original value instead of current value because they are one and the same for non-dynamic Values and ensures that modifying dynamic Values do not impact equality or hashCode contract.

    Overrides:
    hashCode in class Object

    equals

    public boolean equals(Object other)
    Use original value instead of current value because they are one and the same for non-dynamic Values and ensures that modifying dynamic Values do not impact equality or hashCode contract.

    Overrides:
    equals in class Object

    clone

    public Object clone()
    Overrides:
    clone in class Object


    Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.