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.
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
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.
|
getConfiguration, getDefaultDocumentation, getName, getType, setDocumentation, setName
public NamedValuePropertyImpl(Configuration configuration, java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method getter, java.lang.reflect.Method namesGetter)
configuration
- Configuration to which this Property belongsname
- Parameter namec
- Parameter typegetter
- A method on type c with a String argument that returns the named property valuenamesGetter
- A zero-argument method on type c that returns a String array with names of the property valuespublic NamedValuePropertyImpl(Configuration configuration, java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method mapGetter)
configuration
- Configuration to which this Property belongsname
- Parameter namec
- Parameter typemapGetter
- A zero-argument method on type c that returns a Mappublic static NamedValueProperty getNamedValueProperty(Configuration configuration, java.lang.String name, java.lang.Class<?> type)
configuration
- Configuration to which this Property belongsname
- Parameter nametype
- Parameter typepublic void setModifiers(java.lang.reflect.Method setter, java.lang.reflect.Method remover)
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 Stringremover
- A method that removes a value by name; arg types {String}public java.lang.Object getValue(java.lang.String name) throws StructuralException
getValue
in interface NamedValueProperty
name
- Name of a value of this propertyStructuralException
- if the value can't be retrievedNamedValueProperty.getValue(java.lang.String)
public java.util.List<java.lang.String> getValueNames()
getValueNames
in interface NamedValueProperty
NamedValueProperty.getValueNames()
public boolean isNamedAutomatically()
isNamedAutomatically
in interface NamedValueProperty
NamedValueProperty.isNamedAutomatically()
public void removeValue(java.lang.String name) throws StructuralException
NamedValueProperty
removeValue
in interface NamedValueProperty
name
- Name of value to removeStructuralException
- if isFixedCardinality()NamedValueProperty.removeValue(java.lang.String)
public void setValue(java.lang.String name, java.lang.Object value) throws StructuralException
NamedValueProperty
setValue
in interface NamedValueProperty
name
- Name of the valuevalue
- New value of the valueStructuralException
- if !isMutablepublic void setValue(java.lang.Object value) throws StructuralException
NamedValueProperty
setValue
in interface NamedValueProperty
value
- New value of the value, from which the Property can automaticall
determine the nameStructuralException
- if !isNamedAutomatically() or !isMutablepublic boolean isFixedCardinality()
isFixedCardinality
in interface Property
Property.isFixedCardinality()
public boolean isMutable()
isMutable
in interface Property
isMutable
in class AbstractProperty
AbstractProperty.isMutable()
public java.lang.String getDocumentation()
getDocumentation
in interface Property
getDocumentation
in class AbstractProperty
Property.getDocumentation()