ca.nengo.config.impl
Class NamedValuePropertyImpl

java.lang.Object
  extended by ca.nengo.config.impl.AbstractProperty
      extended by ca.nengo.config.impl.NamedValuePropertyImpl
All Implemented Interfaces:
NamedValueProperty, Property

public class NamedValuePropertyImpl
extends AbstractProperty
implements NamedValueProperty

Default implementation of NamedValueProperty. This implementation uses reflection to call methods on an underlying configurable object in order to get and set multiple property values.

Use of this class is analogous to ListPropertyImpl. See ListPropertyImpl docs for more information.

Author:
Bryan Tripp

Constructor Summary
NamedValuePropertyImpl(Configuration configuration, java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method mapGetter)
           
NamedValuePropertyImpl(Configuration configuration, java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method getter, java.lang.reflect.Method namesGetter)
           
 
Method Summary
 java.lang.String getDocumentation()
           
static NamedValueProperty getNamedValueProperty(Configuration configuration, java.lang.String name, java.lang.Class<?> type)
           
 java.lang.Object getValue(java.lang.String name)
           
 java.util.List<java.lang.String> getValueNames()
           
 boolean isFixedCardinality()
           
 boolean isMutable()
           
 boolean isNamedAutomatically()
           
 void removeValue(java.lang.String name)
          Removes a value by name
 void setModifiers(java.lang.reflect.Method setter, java.lang.reflect.Method remover)
          Sets optional methods used to make the property mutable.
 void setValue(java.lang.Object value)
          Sets an automatically-named value
 void setValue(java.lang.String name, java.lang.Object value)
          Sets a value by name.
 
Methods inherited from class ca.nengo.config.impl.AbstractProperty
getConfiguration, getDefaultDocumentation, getName, getType, setDocumentation, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ca.nengo.config.Property
getName, getType, setName
 

Constructor Detail

NamedValuePropertyImpl

public NamedValuePropertyImpl(Configuration configuration,
                              java.lang.String name,
                              java.lang.Class<?> c,
                              java.lang.reflect.Method getter,
                              java.lang.reflect.Method namesGetter)
Parameters:
configuration - Configuration to which this Property belongs
name - Parameter name
c - Parameter type
getter - A method on type c with a String argument that returns the named property value
namesGetter - A zero-argument method on type c that returns a String array with names of the property values

NamedValuePropertyImpl

public NamedValuePropertyImpl(Configuration configuration,
                              java.lang.String name,
                              java.lang.Class<?> c,
                              java.lang.reflect.Method mapGetter)
Parameters:
configuration - Configuration to which this Property belongs
name - Parameter name
c - Parameter type
mapGetter - A zero-argument method on type c that returns a Map containing values of the property
Method Detail

getNamedValueProperty

public static NamedValueProperty getNamedValueProperty(Configuration configuration,
                                                       java.lang.String name,
                                                       java.lang.Class<?> type)
Parameters:
configuration - Configuration to which this Property belongs
name - Parameter name
type - Parameter type
Returns:
Property or null if the necessary methods don't exist on the underlying class

setModifiers

public void setModifiers(java.lang.reflect.Method setter,
                         java.lang.reflect.Method remover)
Sets optional methods used to make the property mutable.

Parameters:
setter - A setter method with arg types {String, Object}; {Object} is also OK if the getType() has a zero-arg method getName() which returns a String
remover - A method that removes a value by name; arg types {String}

getValue

public java.lang.Object getValue(java.lang.String name)
                          throws StructuralException
Specified by:
getValue in interface NamedValueProperty
Parameters:
name - Name of a value of this property
Returns:
The value
Throws:
StructuralException
See Also:
NamedValueProperty.getValue(java.lang.String)

getValueNames

public java.util.List<java.lang.String> getValueNames()
Specified by:
getValueNames in interface NamedValueProperty
Returns:
Names of all values
See Also:
NamedValueProperty.getValueNames()

isNamedAutomatically

public boolean isNamedAutomatically()
Specified by:
isNamedAutomatically in interface NamedValueProperty
Returns:
True if values are named automatically, in which case the setter setValue(Object) can be used; otherwise value names must be provided by the caller via setValue(String, Object)
See Also:
NamedValueProperty.isNamedAutomatically()

removeValue

public void removeValue(java.lang.String name)
                 throws StructuralException
Description copied from interface: NamedValueProperty
Removes a value by name

Specified by:
removeValue in interface NamedValueProperty
Parameters:
name - Name of value to remove
Throws:
StructuralException - if isFixedCardinality()
See Also:
NamedValueProperty.removeValue(java.lang.String)

setValue

public void setValue(java.lang.String name,
                     java.lang.Object value)
              throws StructuralException
Description copied from interface: NamedValueProperty
Sets a value by name.

Specified by:
setValue in interface NamedValueProperty
Parameters:
name - Name of the value
value - New value of the value
Throws:
StructuralException - if !isMutable

setValue

public void setValue(java.lang.Object value)
              throws StructuralException
Description copied from interface: NamedValueProperty
Sets an automatically-named value

Specified by:
setValue in interface NamedValueProperty
Parameters:
value - New value of the value, from which the Property can automaticall determine the name
Throws:
StructuralException - if !isNamedAutomatically() or !isMutable

isFixedCardinality

public boolean isFixedCardinality()
Specified by:
isFixedCardinality in interface Property
Returns:
True if the property has a fixed number of values
See Also:
Property.isFixedCardinality()

isMutable

public boolean isMutable()
Specified by:
isMutable in interface Property
Overrides:
isMutable in class AbstractProperty
Returns:
True if values can be changed after construction of the Configurable
See Also:
AbstractProperty.isMutable()

getDocumentation

public java.lang.String getDocumentation()
Specified by:
getDocumentation in interface Property
Overrides:
getDocumentation in class AbstractProperty
Returns:
Text describing the property semantics (plain text or HTML)
See Also:
Property.getDocumentation()