Class Uberspect
- java.lang.Object
-
- org.apache.commons.jexl3.internal.introspection.Uberspect
-
- All Implemented Interfaces:
JexlUberspect
public class Uberspect extends java.lang.Object implements JexlUberspect
Implements Uberspect to provide the default introspective functionality of JEXL.This is the class to derive to customize introspection.
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Uberspect.ArithmeticUberspect
The concrete uberspect Arithmetic class.-
Nested classes/interfaces inherited from interface org.apache.commons.jexl3.introspection.JexlUberspect
JexlUberspect.JexlResolver, JexlUberspect.PropertyResolver, JexlUberspect.ResolverStrategy
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ref.Reference<java.lang.ClassLoader>
loader
The class loader reference; used to recreate the introspector when necessary.protected org.apache.commons.logging.Log
logger
The logger to use for all warnings and errors.private java.util.Map<java.lang.Class<? extends JexlArithmetic>,java.util.Set<JexlOperator>>
operatorMap
The map from arithmetic classes to overloaded operator sets.private JexlPermissions
permissions
The permissions.private java.lang.ref.Reference<Introspector>
ref
The soft reference to the introspector currently in use.private JexlUberspect.ResolverStrategy
strategy
The resolver strategy.static java.lang.Object
TRY_FAILED
Publicly exposed special failure object returned by tryInvoke.private java.util.concurrent.atomic.AtomicInteger
version
The introspector version.-
Fields inherited from interface org.apache.commons.jexl3.introspection.JexlUberspect
JEXL_STRATEGY, MAP, MAP_STRATEGY, POJO
-
-
Constructor Summary
Constructors Constructor Description Uberspect(org.apache.commons.logging.Log runtimeLogger, JexlUberspect.ResolverStrategy sty)
Creates a new Uberspect.Uberspect(org.apache.commons.logging.Log runtimeLogger, JexlUberspect.ResolverStrategy sty, JexlPermissions perms)
Creates a new Uberspect.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Introspector
base()
Gets the current introspector base.JexlArithmetic.Uberspect
getArithmetic(JexlArithmetic arithmetic)
Gets an arithmetic operator resolver for a given arithmetic instance.java.lang.Class<?>
getClassByName(java.lang.String className)
Gets a class by name through this introspector class loader.java.lang.ClassLoader
getClassLoader()
Gets the current class loader.JexlMethod
getConstructor(java.lang.Object ctorHandle, java.lang.Object... args)
Returns a class constructor.java.lang.reflect.Field
getField(java.lang.Class<?> c, java.lang.String key)
Gets the field named bykey
for the classc
.java.lang.String[]
getFieldNames(java.lang.Class<?> c)
Gets the accessible field names known for a given class.java.util.Iterator<?>
getIterator(java.lang.Object obj)
Gets an iterator from an object.java.lang.reflect.Method
getMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Object[] params)
Gets the method defined byname
andparams
for the Classc
.java.lang.reflect.Method
getMethod(java.lang.Class<?> c, MethodKey key)
Gets the method defined bykey
and for the Classc
.JexlMethod
getMethod(java.lang.Object obj, java.lang.String method, java.lang.Object... args)
Returns a JexlMethod.java.lang.String[]
getMethodNames(java.lang.Class<?> c)
Gets the accessible methods names known for a given class.java.lang.reflect.Method[]
getMethods(java.lang.Class<?> c, java.lang.String methodName)
Gets all the methods with a given name from this map.JexlPropertyGet
getPropertyGet(java.lang.Object obj, java.lang.Object identifier)
Property getter.JexlPropertyGet
getPropertyGet(java.util.List<JexlUberspect.PropertyResolver> resolvers, java.lang.Object obj, java.lang.Object identifier)
Property getter.JexlPropertySet
getPropertySet(java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)
Property setter.JexlPropertySet
getPropertySet(java.util.List<JexlUberspect.PropertyResolver> resolvers, java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)
Property setter.java.util.List<JexlUberspect.PropertyResolver>
getResolvers(JexlOperator op, java.lang.Object obj)
Applies this uberspect property resolver strategy.int
getVersion()
Gets this uberspect version.void
setClassLoader(java.lang.ClassLoader nloader)
Sets the class loader to use.
-
-
-
Field Detail
-
TRY_FAILED
public static final java.lang.Object TRY_FAILED
Publicly exposed special failure object returned by tryInvoke.
-
logger
protected final org.apache.commons.logging.Log logger
The logger to use for all warnings and errors.
-
strategy
private final JexlUberspect.ResolverStrategy strategy
The resolver strategy.
-
permissions
private final JexlPermissions permissions
The permissions.
-
version
private final java.util.concurrent.atomic.AtomicInteger version
The introspector version.
-
ref
private volatile java.lang.ref.Reference<Introspector> ref
The soft reference to the introspector currently in use.
-
loader
private volatile java.lang.ref.Reference<java.lang.ClassLoader> loader
The class loader reference; used to recreate the introspector when necessary.
-
operatorMap
private final java.util.Map<java.lang.Class<? extends JexlArithmetic>,java.util.Set<JexlOperator>> operatorMap
The map from arithmetic classes to overloaded operator sets.This map keeps track of which operator methods are overloaded per JexlArithmetic classes allowing a fail fast test during interpretation by avoiding seeking a method when there is none.
-
-
Constructor Detail
-
Uberspect
public Uberspect(org.apache.commons.logging.Log runtimeLogger, JexlUberspect.ResolverStrategy sty)
Creates a new Uberspect.- Parameters:
runtimeLogger
- the logger used for all logging needssty
- the resolver strategy
-
Uberspect
public Uberspect(org.apache.commons.logging.Log runtimeLogger, JexlUberspect.ResolverStrategy sty, JexlPermissions perms)
Creates a new Uberspect.- Parameters:
runtimeLogger
- the logger used for all logging needssty
- the resolver strategyperms
- the introspector permissions
-
-
Method Detail
-
base
protected final Introspector base()
Gets the current introspector base.If the reference has been collected, this method will recreate the underlying introspector.
- Returns:
- the introspector
-
getArithmetic
public JexlArithmetic.Uberspect getArithmetic(JexlArithmetic arithmetic)
Description copied from interface:JexlUberspect
Gets an arithmetic operator resolver for a given arithmetic instance.- Specified by:
getArithmetic
in interfaceJexlUberspect
- Parameters:
arithmetic
- the arithmetic instance- Returns:
- the arithmetic uberspect or null if no operator method were overridden
-
getClassByName
public final java.lang.Class<?> getClassByName(java.lang.String className)
Gets a class by name through this introspector class loader.- Specified by:
getClassByName
in interfaceJexlUberspect
- Parameters:
className
- the class name- Returns:
- the class instance or null if it could not be found
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:JexlUberspect
Gets the current class loader.- Specified by:
getClassLoader
in interfaceJexlUberspect
- Returns:
- the class loader
-
getConstructor
public JexlMethod getConstructor(java.lang.Object ctorHandle, java.lang.Object... args)
Description copied from interface:JexlUberspect
Returns a class constructor.- Specified by:
getConstructor
in interfaceJexlUberspect
- Parameters:
ctorHandle
- a class or class nameargs
- constructor arguments- Returns:
- a
JexlMethod
-
getField
public final java.lang.reflect.Field getField(java.lang.Class<?> c, java.lang.String key)
Gets the field named bykey
for the classc
.- Parameters:
c
- Class in which the field search is taking placekey
- Name of the field being searched for- Returns:
- a
Field
or null if it does not exist or is not accessible
-
getFieldNames
public final java.lang.String[] getFieldNames(java.lang.Class<?> c)
Gets the accessible field names known for a given class.- Parameters:
c
- the class- Returns:
- the class field names
-
getIterator
public java.util.Iterator<?> getIterator(java.lang.Object obj)
Description copied from interface:JexlUberspect
Gets an iterator from an object.- Specified by:
getIterator
in interfaceJexlUberspect
- Parameters:
obj
- to get the iterator from- Returns:
- an iterator over obj or null
-
getMethod
public final java.lang.reflect.Method getMethod(java.lang.Class<?> c, MethodKey key)
Gets the method defined bykey
and for the Classc
.- Parameters:
c
- Class in which the method search is taking placekey
- MethodKey of the method being searched for- Returns:
- a
Method
or null if no unambiguous method could be found through introspection.
-
getMethod
public final java.lang.reflect.Method getMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Object[] params)
Gets the method defined byname
andparams
for the Classc
.- Parameters:
c
- Class in which the method search is taking placename
- Name of the method being searched forparams
- An array of Objects (not Classes) that describe the parameters- Returns:
- a
Method
or null if no unambiguous method could be found through introspection.
-
getMethod
public JexlMethod getMethod(java.lang.Object obj, java.lang.String method, java.lang.Object... args)
Description copied from interface:JexlUberspect
Returns a JexlMethod.- Specified by:
getMethod
in interfaceJexlUberspect
- Parameters:
obj
- the objectmethod
- the method nameargs
- method arguments- Returns:
- a
JexlMethod
-
getMethodNames
public final java.lang.String[] getMethodNames(java.lang.Class<?> c)
Gets the accessible methods names known for a given class.- Parameters:
c
- the class- Returns:
- the class method names
-
getMethods
public final java.lang.reflect.Method[] getMethods(java.lang.Class<?> c, java.lang.String methodName)
Gets all the methods with a given name from this map.- Parameters:
c
- the classmethodName
- the seeked methods name- Returns:
- the array of methods
-
getPropertyGet
public JexlPropertyGet getPropertyGet(java.util.List<JexlUberspect.PropertyResolver> resolvers, java.lang.Object obj, java.lang.Object identifier)
Description copied from interface:JexlUberspect
Property getter.Seeks a JexlPropertyGet apropos to an expression like
Seebar.woogie
.JexlUberspect.ResolverStrategy.apply(JexlOperator, java.lang.Object)
- Specified by:
getPropertyGet
in interfaceJexlUberspect
- Parameters:
resolvers
- the list of property resolvers to tryobj
- the object to get the property fromidentifier
- property name- Returns:
- a
JexlPropertyGet
or null
-
getPropertyGet
public JexlPropertyGet getPropertyGet(java.lang.Object obj, java.lang.Object identifier)
Description copied from interface:JexlUberspect
Property getter.returns a JelPropertySet apropos to an expression like
bar.woogie
.- Specified by:
getPropertyGet
in interfaceJexlUberspect
- Parameters:
obj
- the object to get the property fromidentifier
- property name- Returns:
- a
JexlPropertyGet
or null
-
getPropertySet
public JexlPropertySet getPropertySet(java.util.List<JexlUberspect.PropertyResolver> resolvers, java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)
Description copied from interface:JexlUberspect
Property setter.Seeks a JelPropertySet apropos to an expression like
Seefoo.bar = "geir"
.JexlUberspect.ResolverStrategy.apply(JexlOperator, java.lang.Object)
- Specified by:
getPropertySet
in interfaceJexlUberspect
- Parameters:
resolvers
- the list of property resolvers to try,obj
- the object to get the property fromidentifier
- property namearg
- value to set- Returns:
- a
JexlPropertySet
or null
-
getPropertySet
public JexlPropertySet getPropertySet(java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)
Description copied from interface:JexlUberspect
Property setter.Seeks a JelPropertySet apropos to an expression like
foo.bar = "geir"
.- Specified by:
getPropertySet
in interfaceJexlUberspect
- Parameters:
obj
- the object to get the property from.identifier
- property namearg
- value to set- Returns:
- a
JexlPropertySet
or null
-
getResolvers
public java.util.List<JexlUberspect.PropertyResolver> getResolvers(JexlOperator op, java.lang.Object obj)
Description copied from interface:JexlUberspect
Applies this uberspect property resolver strategy.- Specified by:
getResolvers
in interfaceJexlUberspect
- Parameters:
op
- the operatorobj
- the object- Returns:
- the applied strategy resolver list
-
getVersion
public int getVersion()
Description copied from interface:JexlUberspect
Gets this uberspect version.- Specified by:
getVersion
in interfaceJexlUberspect
- Returns:
- the class loader modification count
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader nloader)
Description copied from interface:JexlUberspect
Sets the class loader to use.This increments the version.
- Specified by:
setClassLoader
in interfaceJexlUberspect
- Parameters:
nloader
- the class loader
-
-