All Packages Class Hierarchy This Package Previous Next Index
Class org.webmacro.util.PropertyOperator
java.lang.Object
|
+----org.webmacro.util.PropertyOperator
- public final class PropertyOperator
- extends Object
This class knows how to extract properties from objects efficiently.
A simple property "Bar" can be accessed in a sub-object "Foo" (and
in one case, sub-object "Baz") using any of the following method
signatures, listed in the order that they will be tried:
- Foo.Bar
- Foo.getBar() / Foo.setBar(object)
- Foo.getBar("Baz") / Foo.setBar("Baz", object)
- Foo.get("Bar") / Foo.put("Bar",object)
The PropertyOperator is capable of extracting an iterator from an object
if in any of the following conditions are true, listed in the order that
they will be tried:
- The object itself is an array
- The object itself is an Iterator
- The object itself is an Enumeration
- The object has an "Iterator iterator()" method
- The object has an "Enumeration elements()" method
You can specify a long list of property names, and the above methods
will be recursively applied. For example, if your list were
Order,Customer,Fred,Name,Last the PropertyOperator might be
able to access it as:
Order.getCustomer("Fred").getName().Last
-
getIterator(Object)
- Evaluate the supplied object and work out a way to return it
as an iterator.
-
getProperty(Object, Object[])
- Attempt to retrieve a property using the rules of property
introspection described above.
-
setProperty(Object, Object[], Object)
- Given a property description name, attempt to set the property
value to the supplied object.
getProperty
public static final Object getProperty(Object context,
Object names[]) throws PropertyException, SecurityException, InvalidContextException
- Attempt to retrieve a property using the rules of property
introspection described above.
- Parameters:
- context - outermost container which is introspected
- names - property names, one per array entry
- Returns:
- the property described by the names, inside the instance
- Throws: PropertyException
- the property we'd like to look at
- Throws: SecurityExeption
- you are not permitted to try
- Throws: InvalidContextException
- one of the names is a PropertyReference which could not be evaluated against the supplied context
setProperty
public static final boolean setProperty(Object context,
Object names[],
Object value) throws PropertyException, SecurityException, InvalidContextException
- Given a property description name, attempt to set the property
value to the supplied object.
- Parameters:
- context - An object containing a property
- names - The string names of that property
- value - the new value the property is to be set to
- Throws: PropertyException
- not possible to set the property
- Throws: SecurityException
- you are not permitted to try
- Throws: InvalidContextException
- a PropertyReference in the argument names could not be resolved against the supplied context
getIterator
public static final Iterator getIterator(Object instance) throws PropertyException
- Evaluate the supplied object and work out a way to return it
as an iterator.
- Parameters:
- context - an object believed to represent a list
- Returns:
- an Iterator that iterates through that list
- Throws: PropertyException
- could not extract iterator from instance
All Packages Class Hierarchy This Package Previous Next Index