Class FieldBasedObjectInterpolator
- java.lang.Object
-
- org.codehaus.plexus.interpolation.object.FieldBasedObjectInterpolator
-
- All Implemented Interfaces:
ObjectInterpolator
public class FieldBasedObjectInterpolator extends java.lang.Object implements ObjectInterpolator
Reflectively traverses an object graph and uses anInterpolator
instance to resolve any String fields in the graph.NOTE: This code is based on a reimplementation of ModelInterpolator in maven-project 2.1.0-M1, which became a performance bottleneck when the interpolation process became a hotspot.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FieldBasedObjectInterpolator.InterpolateObjectAction
private static class
FieldBasedObjectInterpolator.InterpolationTarget
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>
blacklistedFieldNames
private java.util.Set<java.lang.String>
blacklistedPackagePrefixes
static java.util.Set<java.lang.String>
DEFAULT_BLACKLISTED_FIELD_NAMES
static java.util.Set<java.lang.String>
DEFAULT_BLACKLISTED_PACKAGE_PREFIXES
private static java.util.Map<java.lang.Class,java.lang.Boolean>
fieldIsPrimitiveByClass
private static java.util.Map<java.lang.Class,java.lang.reflect.Field[]>
fieldsByClass
private java.util.List<ObjectInterpolationWarning>
warnings
-
Constructor Summary
Constructors Constructor Description FieldBasedObjectInterpolator()
Use the default settings for blacklisted fields and packages, where fields named 'parent' and classes in packages starting with 'java' will not be interpolated.FieldBasedObjectInterpolator(java.util.Set<java.lang.String> blacklistedFieldNames, java.util.Set<java.lang.String> blacklistedPackagePrefixes)
Use the given black-lists to limit the interpolation of fields and classes (by package).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearCaches()
Clear out the Reflection caches kept for the most expensive operations encountered: field lookup and primitive queries for fields.java.util.List<ObjectInterpolationWarning>
getWarnings()
Retrieve theList
of warnings (ObjectInterpolationWarning
instances) generated during the last interpolation execution.boolean
hasWarnings()
Returns true if the last interpolation execution generated warnings.void
interpolate(java.lang.Object target, BasicInterpolator interpolator)
Using reflective field access and mutation, traverse the object graph from the given starting point and interpolate any Strings found in that graph using the givenInterpolator
.void
interpolate(java.lang.Object target, BasicInterpolator interpolator, RecursionInterceptor recursionInterceptor)
Using reflective field access and mutation, traverse the object graph from the given starting point and interpolate any Strings found in that graph using the givenInterpolator
.
-
-
-
Field Detail
-
DEFAULT_BLACKLISTED_FIELD_NAMES
public static final java.util.Set<java.lang.String> DEFAULT_BLACKLISTED_FIELD_NAMES
-
DEFAULT_BLACKLISTED_PACKAGE_PREFIXES
public static final java.util.Set<java.lang.String> DEFAULT_BLACKLISTED_PACKAGE_PREFIXES
-
fieldsByClass
private static final java.util.Map<java.lang.Class,java.lang.reflect.Field[]> fieldsByClass
-
fieldIsPrimitiveByClass
private static final java.util.Map<java.lang.Class,java.lang.Boolean> fieldIsPrimitiveByClass
-
blacklistedFieldNames
private java.util.Set<java.lang.String> blacklistedFieldNames
-
blacklistedPackagePrefixes
private java.util.Set<java.lang.String> blacklistedPackagePrefixes
-
warnings
private java.util.List<ObjectInterpolationWarning> warnings
-
-
Constructor Detail
-
FieldBasedObjectInterpolator
public FieldBasedObjectInterpolator()
Use the default settings for blacklisted fields and packages, where fields named 'parent' and classes in packages starting with 'java' will not be interpolated.
-
FieldBasedObjectInterpolator
public FieldBasedObjectInterpolator(java.util.Set<java.lang.String> blacklistedFieldNames, java.util.Set<java.lang.String> blacklistedPackagePrefixes)
Use the given black-lists to limit the interpolation of fields and classes (by package).- Parameters:
blacklistedFieldNames
- The list of field names to ignoreblacklistedPackagePrefixes
- The list of package prefixes whose classes should be ignored
-
-
Method Detail
-
clearCaches
public static void clearCaches()
Clear out the Reflection caches kept for the most expensive operations encountered: field lookup and primitive queries for fields. These caches are static since they apply at the class level, not the instance level.
-
hasWarnings
public boolean hasWarnings()
Returns true if the last interpolation execution generated warnings.- Specified by:
hasWarnings
in interfaceObjectInterpolator
- Returns:
- true/false.
-
getWarnings
public java.util.List<ObjectInterpolationWarning> getWarnings()
Retrieve theList
of warnings (ObjectInterpolationWarning
instances) generated during the last interpolation execution.- Specified by:
getWarnings
in interfaceObjectInterpolator
- Returns:
- The list of warnings.
-
interpolate
public void interpolate(java.lang.Object target, BasicInterpolator interpolator) throws InterpolationException
Using reflective field access and mutation, traverse the object graph from the given starting point and interpolate any Strings found in that graph using the givenInterpolator
. Limits to this process can be managed using the black lists configured in the constructor.- Specified by:
interpolate
in interfaceObjectInterpolator
- Parameters:
target
- The starting point of the object graph to traverseinterpolator
- TheInterpolator
used to resolve any Strings encountered during traversal. NOTE: UsesSimpleRecursionInterceptor
.- Throws:
InterpolationException
- in case of an error.
-
interpolate
public void interpolate(java.lang.Object target, BasicInterpolator interpolator, RecursionInterceptor recursionInterceptor) throws InterpolationException
Using reflective field access and mutation, traverse the object graph from the given starting point and interpolate any Strings found in that graph using the givenInterpolator
. Limits to this process can be managed using the black lists configured in the constructor.- Specified by:
interpolate
in interfaceObjectInterpolator
- Parameters:
target
- The starting point of the object graph to traverseinterpolator
- TheInterpolator
used to resolve any Strings encountered during traversal.recursionInterceptor
- TheRecursionInterceptor
used to detect cyclical expressions in the graph- Throws:
InterpolationException
- in case of an error.
-
-