public class PropertyAccess extends Object
Constructor and Description |
---|
PropertyAccess(Object target,
String propertyName)
Constructs a reflection access to a property of an object.
|
PropertyAccess(Object target,
String propertyName,
List<String> prefixList,
List<String> suffixList)
Constructs a reflection access to a property of an object.
|
Modifier and Type | Method and Description |
---|---|
Class<?> |
getFirstGenericTypeArgument()
Gets the class of the first generic argument of the property.
|
List<String> |
getPrefixList()
Returns the list of all possible prefixes for field names.
|
Object |
getProperty()
Returns the value of the property.
|
Type |
getPropertyGenericType()
Returns the generic type of the property.
|
Class<?> |
getPropertyType()
Returns the class of the property.
|
List<String> |
getSuffixList()
Returns the list of all possible suffixes for field and method names.
|
boolean |
isPropertyAccessible() |
void |
setProperty(Object value)
Sets the property on the target object to a given value.
|
void |
setPropertyStrict(Object value)
Sets the property on the target object to a given value.
|
public PropertyAccess(Object target, String propertyName) throws SourceTransformerException
target
- the target object, not null.propertyName
- the name of the property, not null.SourceTransformerException
- if reflection access to fields
or methods fails.NullPointerException
- if target or propertyName are null.public PropertyAccess(Object target, String propertyName, List<String> prefixList, List<String> suffixList) throws SourceTransformerException
target
- the target object, not null.propertyName
- the name of the property, not null.prefixList
- List of all possible prefixes for field names.
I.e. if the property name is "name",
"prefix" + "name" is also tried as field name
if "prefix" is contained in this list.suffixList
- List of all possible suffixes for field and method
names. I.e. if the property name is "name",
"name" + "suffix" is also tried as field name and base method name
if "suffix" is contained in this list.SourceTransformerException
- if reflection access to fields
or methods fails.NullPointerException
- if target or propertyName are null.public void setProperty(Object value) throws SourceTransformerException
value
- the value to set the property to.SourceTransformerException
- if the property cannot be set.
Common reasons for such an exception are that the property
does not exist at all, or is not writeable, or value has the
wrong class.public void setPropertyStrict(Object value) throws SourceTransformerException
value
- the value to set the property to.SourceTransformerException
- if the property cannot be set.
Common reasons for such an exception are that the property
does not exist at all, or is not writeable, or value has the
wrong class.public Object getProperty() throws SourceTransformerException
SourceTransformerException
- if the property is not readable.
A common reason for this is that no public field and no getter
exists with the given name.public boolean isPropertyAccessible()
public Class<?> getPropertyType()
public Type getPropertyGenericType()
public Class<?> getFirstGenericTypeArgument()
public List<String> getPrefixList()
public List<String> getSuffixList()
Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.