com.gentics.api.lib.resolving
Class PropertyResolver

java.lang.Object
  extended by com.gentics.api.lib.resolving.PropertyResolver
All Implemented Interfaces:
Resolvable
Direct Known Subclasses:
PropertySetter

public class PropertyResolver
extends Object
implements Resolvable

Instances of class PropertyResolver can resolve properties by paths based on a single Resolvable object. The resolving process is done iteratively for each part of the property path as long as each property is a Resolvable itself.
Example: Let the base object be a Resolvable representing a User. A call to resolve(String) with "organisation.name" would first call Resolvable.get(String) with "organisation" on the base object. If and only if the return value is again a Resolvable (representing the organisation of the user) the resolving process would continue by calling Resolvable.get(String) with "name" on the organisation object. The return value of this call would be the final value, since "name" is the last part of the property path.

The resolving process is also capable of resolving multivalue properties:
Let's expand the example above in the following way: The base object again is the user, and the call to resolve(String) is done with "organisation.employees.email". Resolving of "organisation" gives a single Resolvable representing the user's organisation. The property "employees" shall be a Collection of Resolvables representing all users of the organisation. The resolving process would now continue by iterating over the Collection and get the property "email" for each Resolvable. So the final return value would be a Collection of all email addresses of all users of the base user's organisation.

The PropertyResolver has also static variants of the resolve methods that get another base object to start resolving. If one of those methods is used, the default base object is ignored and the given startObject is used instead.


Nested Class Summary
static class PropertyResolver.PropertyPathEntry
          Inner class to return property path entries
 
Field Summary
protected  Resolvable m_startObject
           
 
Constructor Summary
PropertyResolver(Resolvable startObject)
          create an instance of a PropertyResolver based on the given Resolvable
 
Method Summary
 boolean canResolve()
          Determine whether this resolver (the base object) can resolve right now or not
 Object get(String key)
          Get a property from the base object.
 Object getProperty(String key)
          Get a property from the start object.
static Object resolve(Resolvable startObject, String propertyPath)
          Resolve the given property path to a value (which also might be a Collection of values) or null, starting with the given startObject
static Object resolve(Resolvable startObject, String propertyPath, boolean failIfUnresolvablePath)
          Resolve the given property path to a value (which also might be a Collection of values) or null, starting with the given startObject.
 Object resolve(String propertyPath)
          Resolve the given property path to a value (which also might be a Collection of values) or null.
 Object resolve(String propertyPath, boolean failIfUnresolvablePath)
          Resolve the given property path to a value (which also might be a Collection of values) or null.
static List resolvePath(Resolvable startObject, String propertyPath)
          Resolve the given propertypath into a list of instances of PropertyResolver.PropertyPathEntry, starting with the given Resolvable
protected static List resolvePath(Resolvable startObject, String propertyPath, boolean failIfUnresolvablePath, Class implementingClass, boolean cleanResolvableStack, Stack resolvableStack)
          Resolve the given path into a list of objects.
 List resolvePath(String propertyPath)
          Resolve the given propertypath into a list of instances of PropertyResolver.PropertyPathEntry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_startObject

protected Resolvable m_startObject
Constructor Detail

PropertyResolver

public PropertyResolver(Resolvable startObject)
create an instance of a PropertyResolver based on the given Resolvable

Parameters:
startObject - base resolvable object
Method Detail

resolve

public Object resolve(String propertyPath)
               throws UnknownPropertyException
Resolve the given property path to a value (which also might be a Collection of values) or null.

Parameters:
propertyPath - property path
Returns:
the value of the property
Throws:
UnknownPropertyException

resolve

public static Object resolve(Resolvable startObject,
                             String propertyPath)
                      throws UnknownPropertyException
Resolve the given property path to a value (which also might be a Collection of values) or null, starting with the given startObject

Parameters:
startObject - start object
propertyPath - property path
Returns:
the value of the property
Throws:
UnknownPropertyException

resolvePath

public List resolvePath(String propertyPath)
                 throws UnknownPropertyException
Resolve the given propertypath into a list of instances of PropertyResolver.PropertyPathEntry.

Parameters:
propertyPath - property path to resolve
Returns:
list of PropertyPathEntries
Throws:
UnknownPropertyException

resolvePath

public static List resolvePath(Resolvable startObject,
                               String propertyPath)
                        throws UnknownPropertyException
Resolve the given propertypath into a list of instances of PropertyResolver.PropertyPathEntry, starting with the given Resolvable

Parameters:
startObject - resolvable to start resolving
propertyPath - property path to resolve
Returns:
list of PropertyPathEntries
Throws:
UnknownPropertyException

resolvePath

protected static List resolvePath(Resolvable startObject,
                                  String propertyPath,
                                  boolean failIfUnresolvablePath,
                                  Class implementingClass,
                                  boolean cleanResolvableStack,
                                  Stack resolvableStack)
                           throws UnknownPropertyException
Resolve the given path into a list of objects. The list will always contain the last part of the resolved objects and all other that implement the given class. Important implementation notice: When the flag cleanResolvableStack is set to false, an (empty) resolvableStack must be passed to this method and the caller must afterwards clean the resolvable stack by calling ResolverContextHandler.pop(Object) for all objects that were put onto this stack (in the order they are popped() from this stack).

Parameters:
startObject - start object
propertyPath - property path to resolve
failIfUnresolvablePath - true when the process shall fail if one part of the path could not be resolved
implementingClass - interface or class all returned objects have to implement, null for only returning the last object
cleanResolvableStack - flag to mark whether the resolvable context shall be cleaned
resolvableStack - stack for resolvable objects
Returns:
list of objects resolved from the path. the last object in the list is always the last part in the path
Throws:
UnknownPropertyException, - and logs a warning
UnknownPropertyException

resolve

public Object resolve(String propertyPath,
                      boolean failIfUnresolvablePath)
               throws UnknownPropertyException
Resolve the given property path to a value (which also might be a Collection of values) or null.

Parameters:
propertyPath - property path
failIfUnresolvablePath - true when the resolving shall fail with an UnknownPropertyException, when a part of the property path (not the last) could not be resolved. otherwise, the method would just return null in such a case
Returns:
the value of the property
Throws:
UnknownPropertyException

resolve

public static Object resolve(Resolvable startObject,
                             String propertyPath,
                             boolean failIfUnresolvablePath)
                      throws UnknownPropertyException
Resolve the given property path to a value (which also might be a Collection of values) or null, starting with the given startObject.

Parameters:
startObject - start object
propertyPath - property path
failIfUnresolvablePath - true when the resolving shall fail with an UnknownPropertyException, when a part of the property path (not the last) could not be resolved. otherwise, the method would just return null in such a case
Returns:
the value of the property
Throws:
UnknownPropertyException

get

public Object get(String key)
Get a property from the base object.

Specified by:
get in interface Resolvable
Parameters:
key - property key
Returns:
property of the start object

canResolve

public boolean canResolve()
Determine whether this resolver (the base object) can resolve right now or not

Specified by:
canResolve in interface Resolvable
Returns:
true when resolving is possible, false if not

getProperty

public Object getProperty(String key)
Get a property from the start object.

Specified by:
getProperty in interface Resolvable
Parameters:
key - property key
Returns:
property from the start object


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.