ma.glasnost.orika.property
Class PropertyResolver

java.lang.Object
  extended by ma.glasnost.orika.property.PropertyResolver
All Implemented Interfaces:
PropertyResolverStrategy
Direct Known Subclasses:
IntrospectorPropertyResolver

public abstract class PropertyResolver
extends Object
implements PropertyResolverStrategy

PropertyResolver defines the core functionality for resolving properties; specific PropertyResolverStrategy implementations should extend from this class, implementing the 'collectProperties' method.

Author:
matt.deboer@gmail.com

Field Summary
static String ELEMENT_PROPERT_PREFIX
          The prefix used to begin a nested element property
static String ELEMENT_PROPERT_SUFFIX
          The suffix used to complete a nested element property
 
Constructor Summary
PropertyResolver(boolean includePublicFields)
          Creates a new PropertyResolver instance
 
Method Summary
protected  String capitalize(String string)
          Convert the first character of the provided string to uppercase.
protected abstract  void collectProperties(Class<?> type, Type<?> referenceType, Map<String,Property> properties)
          Collects all properties for the specified type.
protected  void collectPublicFieldProperties(Type<?> referenceType, Map<String,Property> properties)
          Add public non-static fields as properties
 Property getElementProperty(Type type, String p)
           
 Property getElementProperty(Type type, String p, Property owner)
           
 Property getIndividualElementProperty(Type type, String p, Property owner)
           
 NestedProperty getNestedProperty(Type type, String p)
          Resolves a nested property for the provided type, based on the specified property expression (a sequence property names qualified by '.').
protected  NestedProperty getNestedProperty(Type type, String p, Property owner)
           
 Map<String,Property> getProperties(Type theType)
          Collects and returns the (mappable) properties for the given type.
 Property getProperty(Property owner, String expr)
          Resolves a property for the specified type; nested and dynamically defined properties should be handled automatically.
 Property getProperty(Type type, String expr)
          Resolves a property for the specified type; nested and dynamically defined properties should be handled automatically.
protected  Property getProperty(Type type, String expr, boolean isNestedLookup, Property owner)
          Resolves the specified property expression
protected  boolean hasTypeParameters(Class<?> type)
          Tests whether the specified class has type parameters either on itself or on it's super-class or declared interfaces
protected  boolean isElementPropertyExpression(String expression)
          Determines whether the provided string is a valid element property expression
protected  boolean isIndividualElementExpression(String expression)
          Determines whether the provided string is a valid element property expression
protected  boolean isInlinePropertyExpression(String expression)
          Determines whether the provided string is a valid in-line property expression
protected  boolean isNestedPropertyExpression(String expression)
          Determines whether the provided string is a valid nested property expression
protected  Property processProperty(String propertyName, Class<?> propertyType, Method readMethod, Method writeMethod, Class<?> owningType, Type<?> referenceType, Map<String,Property> properties)
          Processes a property, adding it to the map of properties for the owning type being processed
 Property resolveInlineProperty(Type type, String expr)
          Resolves in-line properties, which are defined with the following format:
"name{getterName|setterName|type=typeName}".

Setter name can be omitted, as well as type name; if getter name is omitted, then setter name must be preceded by '|', like so:
"name{|setterName|type=typeName}", or like "name{|setterName}".
 Type<?> resolvePropertyType(Method readMethod, Class<?> rawType, Class<?> owningType, Type<?> referenceType)
          Resolves the type of a property from the provided input factors.
protected  String[] splitElementProperty(String propertyName)
           
protected  String[] splitNestedProperty(String propertyName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ELEMENT_PROPERT_PREFIX

public static final String ELEMENT_PROPERT_PREFIX
The prefix used to begin a nested element property

See Also:
Constant Field Values

ELEMENT_PROPERT_SUFFIX

public static final String ELEMENT_PROPERT_SUFFIX
The suffix used to complete a nested element property

See Also:
Constant Field Values
Constructor Detail

PropertyResolver

public PropertyResolver(boolean includePublicFields)
Creates a new PropertyResolver instance

Parameters:
includePublicFields - whether public fields should be included as properties
Method Detail

getProperties

public Map<String,Property> getProperties(Type theType)
Description copied from interface: PropertyResolverStrategy
Collects and returns the (mappable) properties for the given type. Such properties are not required to have both getter and setter, as in some cases, they will participate in one-way mappings.

Specified by:
getProperties in interface PropertyResolverStrategy
Parameters:
theType - the type for which to resolve properties
Returns:
a Map keyed by property names, with corresponding Property instances as values

capitalize

protected String capitalize(String string)
Convert the first character of the provided string to uppercase.

Parameters:
string -
Returns:
the String with the first character converter to uppercase.

processProperty

protected Property processProperty(String propertyName,
                                   Class<?> propertyType,
                                   Method readMethod,
                                   Method writeMethod,
                                   Class<?> owningType,
                                   Type<?> referenceType,
                                   Map<String,Property> properties)
Processes a property, adding it to the map of properties for the owning type being processed

Parameters:
propertyName - the name of the property
propertyType - the Class of the property
readMethod - the read method for the property
writeMethod - the write method for the property
owningType - the owning type for which the properties are being resolved
referenceType - a reference type to be used for resolving generic parameters
properties -

hasTypeParameters

protected boolean hasTypeParameters(Class<?> type)
Tests whether the specified class has type parameters either on itself or on it's super-class or declared interfaces

Parameters:
type -
Returns:

resolvePropertyType

public Type<?> resolvePropertyType(Method readMethod,
                                   Class<?> rawType,
                                   Class<?> owningType,
                                   Type<?> referenceType)
Resolves the type of a property from the provided input factors.

Parameters:
readMethod -
rawType -
owningType -
referenceType -
Returns:
the resolved Type of the property

collectPublicFieldProperties

protected void collectPublicFieldProperties(Type<?> referenceType,
                                            Map<String,Property> properties)
Add public non-static fields as properties

Parameters:
referenceType - the type for which to collect public field properties
properties - the collected properties for this type

isNestedPropertyExpression

protected boolean isNestedPropertyExpression(String expression)
Determines whether the provided string is a valid nested property expression

Parameters:
expression - the expression to evaluate
Returns:
true of the expression represents a nested property

isElementPropertyExpression

protected boolean isElementPropertyExpression(String expression)
Determines whether the provided string is a valid element property expression

Parameters:
expression - the expression to evaluate
Returns:
true if the expression represents an element property

isIndividualElementExpression

protected boolean isIndividualElementExpression(String expression)
Determines whether the provided string is a valid element property expression

Parameters:
expression - the expression to evaluate
Returns:
true if the expression represents an element property

splitNestedProperty

protected String[] splitNestedProperty(String propertyName)
Parameters:
propertyName -
Returns:

splitElementProperty

protected String[] splitElementProperty(String propertyName)
Parameters:
propertyName -
Returns:

getNestedProperty

public NestedProperty getNestedProperty(Type type,
                                        String p)
Description copied from interface: PropertyResolverStrategy
Resolves a nested property for the provided type, based on the specified property expression (a sequence property names qualified by '.').

Specified by:
getNestedProperty in interface PropertyResolverStrategy
Returns:
the NestedProperty instance defined by the provided expression

getNestedProperty

protected NestedProperty getNestedProperty(Type type,
                                           String p,
                                           Property owner)
Parameters:
type -
p -
owner -
Returns:

getElementProperty

public Property getElementProperty(Type type,
                                   String p)
Parameters:
type -
p -
Returns:

getElementProperty

public Property getElementProperty(Type type,
                                   String p,
                                   Property owner)
Parameters:
type -
p -
Returns:
the Property represented by the specified element property expression

getIndividualElementProperty

public Property getIndividualElementProperty(Type type,
                                             String p,
                                             Property owner)
Parameters:
type -
p -
Returns:
the Property represented by the specified element property expression

getProperty

public Property getProperty(Type type,
                            String expr)
Description copied from interface: PropertyResolverStrategy
Resolves a property for the specified type; nested and dynamically defined properties should be handled automatically.

Specified by:
getProperty in interface PropertyResolverStrategy
Returns:
the property (of any format)

getProperty

public Property getProperty(Property owner,
                            String expr)
Description copied from interface: PropertyResolverStrategy
Resolves a property for the specified type; nested and dynamically defined properties should be handled automatically.

Specified by:
getProperty in interface PropertyResolverStrategy
Returns:
the property (of any format)

getProperty

protected Property getProperty(Type type,
                               String expr,
                               boolean isNestedLookup,
                               Property owner)
                        throws MappingException
Resolves the specified property expression

Parameters:
type - the property's owning type
expr - the property expression to resolve
properties - the known properties for the type
Returns:
the resolved Property
Throws:
MappingException - if the expression cannot be resolved to a property for the type

isInlinePropertyExpression

protected boolean isInlinePropertyExpression(String expression)
Determines whether the provided string is a valid in-line property expression

Parameters:
expression - the expression to evaluate
Returns:
true if the expression represents an in-line property

resolveInlineProperty

public Property resolveInlineProperty(Type type,
                                      String expr)
Resolves in-line properties, which are defined with the following format:
"name{getterName|setterName|type=typeName}".

Setter name can be omitted, as well as type name; if getter name is omitted, then setter name must be preceded by '|', like so:
"name{|setterName|type=typeName}", or like "name{|setterName}".

At least one of getter or setter must be provided.
Getter or setter 'names' can optionally be the java source of the method call including static arguments, like so:
"name{getTheName(\"someString\")|setTheName(\"someString\", %s)}"
If the setter is defined in this way, it should contain the string '%s' which represents the value being set.

Parameters:
type -
expr -
Returns:
an in-line Property as defined by the provided expression

collectProperties

protected abstract void collectProperties(Class<?> type,
                                          Type<?> referenceType,
                                          Map<String,Property> properties)
Collects all properties for the specified type.

Parameters:
type - the type for which to collect properties
referenceType - the reference type for use in resolving generic parameters as needed
properties - the properties collected for the current type


Copyright © 2013 Glasnost. All Rights Reserved.