org.apache.commons.ognl
Class ObjectPropertyAccessor

java.lang.Object
  extended by org.apache.commons.ognl.ObjectPropertyAccessor
All Implemented Interfaces:
PropertyAccessor
Direct Known Subclasses:
ArrayPropertyAccessor, EnumerationPropertyAccessor, IteratorPropertyAccessor, ListPropertyAccessor, SetPropertyAccessor

public class ObjectPropertyAccessor
extends Object
implements PropertyAccessor

Implementation of PropertyAccessor that uses reflection on the target object's class to find a field or a pair of set/get methods with the given property name.

Author:
Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)

Constructor Summary
ObjectPropertyAccessor()
           
 
Method Summary
 Object getPossibleProperty(Map<String,Object> context, Object target, String name)
          Returns OgnlRuntime.NotFound if the property does not exist.
 Object getProperty(Map<String,Object> context, Object target, Object oname)
          Extracts and returns the property of the given name from the given target object.
 Class<?> getPropertyClass(OgnlContext context, Object target, Object index)
           
 String getSourceAccessor(OgnlContext context, Object target, Object index)
          Returns a java string representing the textual method that should be called to access a particular element.
 String getSourceSetter(OgnlContext context, Object target, Object index)
          Returns a java string representing the textual method that should be called to set a particular element.
 boolean hasGetProperty(Map<String,Object> context, Object target, Object oname)
           
 boolean hasGetProperty(OgnlContext context, Object target, Object oname)
           
 boolean hasSetProperty(Map<String,Object> context, Object target, Object oname)
           
 boolean hasSetProperty(OgnlContext context, Object target, Object oname)
           
 Object setPossibleProperty(Map<String,Object> context, Object target, String name, Object value)
          Returns OgnlRuntime.NotFound if the property does not exist.
 void setProperty(Map<String,Object> context, Object target, Object oname, Object value)
          Sets the value of the property of the given name in the given target object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPropertyAccessor

public ObjectPropertyAccessor()
Method Detail

getPossibleProperty

public Object getPossibleProperty(Map<String,Object> context,
                                  Object target,
                                  String name)
                           throws OgnlException
Returns OgnlRuntime.NotFound if the property does not exist.

Throws:
OgnlException

setPossibleProperty

public Object setPossibleProperty(Map<String,Object> context,
                                  Object target,
                                  String name,
                                  Object value)
                           throws OgnlException
Returns OgnlRuntime.NotFound if the property does not exist.

Throws:
OgnlException

hasGetProperty

public boolean hasGetProperty(OgnlContext context,
                              Object target,
                              Object oname)
                       throws OgnlException
Throws:
OgnlException

hasGetProperty

public boolean hasGetProperty(Map<String,Object> context,
                              Object target,
                              Object oname)
                       throws OgnlException
Throws:
OgnlException

hasSetProperty

public boolean hasSetProperty(OgnlContext context,
                              Object target,
                              Object oname)
                       throws OgnlException
Throws:
OgnlException

hasSetProperty

public boolean hasSetProperty(Map<String,Object> context,
                              Object target,
                              Object oname)
                       throws OgnlException
Throws:
OgnlException

getProperty

public Object getProperty(Map<String,Object> context,
                          Object target,
                          Object oname)
                   throws OgnlException
Description copied from interface: PropertyAccessor
Extracts and returns the property of the given name from the given target object.

Specified by:
getProperty in interface PropertyAccessor
Parameters:
context - The current execution context.
target - the object to get the property from
oname - the name of the property to get.
Returns:
the current value of the given property in the given object
Throws:
OgnlException - if there is an error locating the property in the given object

setProperty

public void setProperty(Map<String,Object> context,
                        Object target,
                        Object oname,
                        Object value)
                 throws OgnlException
Description copied from interface: PropertyAccessor
Sets the value of the property of the given name in the given target object.

Specified by:
setProperty in interface PropertyAccessor
Parameters:
context - The current execution context.
target - the object to set the property in
oname - the name of the property to set
value - the new value for the property.
Throws:
OgnlException - if there is an error setting the property in the given object

getPropertyClass

public Class<?> getPropertyClass(OgnlContext context,
                                 Object target,
                                 Object index)

getSourceAccessor

public String getSourceAccessor(OgnlContext context,
                                Object target,
                                Object index)
Description copied from interface: PropertyAccessor
Returns a java string representing the textual method that should be called to access a particular element. (ie "get")

Specified by:
getSourceAccessor in interface PropertyAccessor
Parameters:
context - The current execution context.
target - The current object target on the expression tree being evaluated.
index - The index object that will be placed inside the string to access the value.
Returns:
The source accessor method to call.

getSourceSetter

public String getSourceSetter(OgnlContext context,
                              Object target,
                              Object index)
Description copied from interface: PropertyAccessor
Returns a java string representing the textual method that should be called to set a particular element. (ie "set")

Specified by:
getSourceSetter in interface PropertyAccessor
Parameters:
context - The current execution context.
target - The current object target on the expression tree being evaluated.
index - The index object that will be placed inside the string to set the value.
Returns:
The source setter method to call.


Copyright © 1997-2013 The Apache Software Foundation. All Rights Reserved.