ma.glasnost.orika.property
Class RegexPropertyResolver

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

public class RegexPropertyResolver
extends IntrospectorPropertyResolver

RegexPropertyResolver uses regular expressions to find properties based on patterns configured for locating the read and write methods.

The patterns provided should produce a match where group(1) returns the name of the property.
Note that the name will automatically be un-capitalized, so you need not worry about defining your regular expression to handle this.

Only no-argument getter methods returning a type are considered for a read method match, and only single-argument methods are considered for a write method match; the write method need not have a void return type.

The type of the setter method must be a sub-type (or matching type) of the getter method's type; if the getter method is a strict sub-type, then the type of the setter method will define the type of the property.

Example


"read([\w]+)Property" would match a method named 'readMySpecialProperty', and define the name of the corresponding property as 'MySpecial', which will be automatically un-capitalized to 'mySpecial'.

Author:
matt.deboer@gmail.com

Field Summary
 
Fields inherited from class ma.glasnost.orika.property.PropertyResolver
ELEMENT_PROPERT_PREFIX, ELEMENT_PROPERT_SUFFIX
 
Constructor Summary
RegexPropertyResolver(String readMethodRegex, String writeMethodRegex, boolean includeJavaBeans, boolean includePublicFields)
           
 
Method Summary
protected  void collectProperties(Class<?> type, Type<?> referenceType, Map<String,Property> properties)
          Collects all properties for the specified type.
protected  String uncapitalize(String string)
          Converts the first character of a String to lowercase
 
Methods inherited from class ma.glasnost.orika.property.PropertyResolver
capitalize, collectPublicFieldProperties, getElementProperty, getElementProperty, getIndividualElementProperty, getNestedProperty, getNestedProperty, getProperties, getProperty, getProperty, getProperty, hasTypeParameters, isElementPropertyExpression, isIndividualElementExpression, isInlinePropertyExpression, isNestedPropertyExpression, processProperty, resolveInlineProperty, resolvePropertyType, splitElementProperty, splitNestedProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexPropertyResolver

public RegexPropertyResolver(String readMethodRegex,
                             String writeMethodRegex,
                             boolean includeJavaBeans,
                             boolean includePublicFields)
Parameters:
readMethodRegex -
writeMethodRegex -
includeJavaBeans -
includePublicFields -
Method Detail

uncapitalize

protected String uncapitalize(String string)
Converts the first character of a String to lowercase

Parameters:
string -
Returns:
the original String with the first character converted to lowercase

collectProperties

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

Overrides:
collectProperties in class IntrospectorPropertyResolver
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.