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/interfaces inherited from interface org.apache.commons.jexl3.introspection.JexlUberspect
JexlUberspect.ClassConstantResolver, JexlUberspect.ClassNameResolver, JexlUberspect.ConstantResolverFactory, JexlUberspect.JexlResolver, JexlUberspect.PropertyResolver, JexlUberspect.ResolverStrategy
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ref.Reference<java.lang.ClassLoader>loaderThe class loader reference; used to recreate the introspector when necessary.protected org.apache.commons.logging.LogloggerThe logger to use for all warnings and errors.private java.util.Map<java.lang.Class<? extends JexlArithmetic>,java.util.Set<JexlOperator>>operatorMapThe map from arithmetic classes to overloaded operator sets.private JexlPermissionspermissionsThe permissions.private java.lang.ref.Reference<Introspector>refThe soft reference to the introspector currently in use.private JexlUberspect.ResolverStrategystrategyThe resolver strategy.static java.lang.ObjectTRY_FAILEDPublicly exposed special failure object returned by tryInvoke.private java.util.concurrent.atomic.AtomicIntegerversionThe 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 Introspectorbase()Gets the current introspector base.JexlArithmetic.UberspectgetArithmetic(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.ClassLoadergetClassLoader()Gets the current class loader.JexlMethodgetConstructor(java.lang.Object ctorHandle, java.lang.Object... args)Returns a class constructor.java.lang.reflect.FieldgetField(java.lang.Class<?> c, java.lang.String key)Gets the field named bykeyfor 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.MethodgetMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Object[] params)Gets the method defined bynameandparamsfor the Classc.java.lang.reflect.MethodgetMethod(java.lang.Class<?> c, MethodKey key)Gets the method defined bykeyand for the Classc.JexlMethodgetMethod(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.OperatorgetOperator(JexlArithmetic arithmetic)Gets an arithmetic operator executor for a given arithmetic instance.(package private) java.util.Set<JexlOperator>getOverloads(JexlArithmetic arithmetic)Computes which operators have an overload implemented in the arithmetic.JexlPropertyGetgetPropertyGet(java.lang.Object obj, java.lang.Object identifier)Property getter.JexlPropertyGetgetPropertyGet(java.util.List<JexlUberspect.PropertyResolver> resolvers, java.lang.Object obj, java.lang.Object identifier)Property getter.JexlPropertySetgetPropertySet(java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)Property setter.JexlPropertySetgetPropertySet(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.intgetVersion()Gets this uberspect version.voidsetClassLoader(java.lang.ClassLoader loader)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
-
getOverloads
java.util.Set<JexlOperator> getOverloads(JexlArithmetic arithmetic)
Computes which operators have an overload implemented in the arithmetic.This is used to speed up resolution and avoid introspection when possible.
- Parameters:
arithmetic- the arithmetic instance- Returns:
- the set of overloaded operators
-
getArithmetic
public JexlArithmetic.Uberspect getArithmetic(JexlArithmetic arithmetic)
Description copied from interface:JexlUberspectGets an arithmetic operator resolver for a given arithmetic instance.- Specified by:
getArithmeticin interfaceJexlUberspect- Parameters:
arithmetic- the arithmetic instance- Returns:
- the arithmetic uberspect or null if no operator method were overridden
- See Also:
JexlUberspect.getOperator(JexlArithmetic)
-
getOperator
public Operator getOperator(JexlArithmetic arithmetic)
Description copied from interface:JexlUberspectGets an arithmetic operator executor for a given arithmetic instance.- Specified by:
getOperatorin interfaceJexlUberspect- Parameters:
arithmetic- the arithmetic instance- Returns:
- an operator uberspect instance
-
getClassByName
public final java.lang.Class<?> getClassByName(java.lang.String className)
Gets a class by name through this introspector class loader.- Specified by:
getClassByNamein 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:JexlUberspectGets the current class loader.- Specified by:
getClassLoaderin interfaceJexlUberspect- Returns:
- the class loader
-
getConstructor
public JexlMethod getConstructor(java.lang.Object ctorHandle, java.lang.Object... args)
Description copied from interface:JexlUberspectReturns a class constructor.- Specified by:
getConstructorin 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 bykeyfor the classc.- Parameters:
c- Class in which the field search is taking placekey- Name of the field being searched for- Returns:
- a
Fieldor 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:JexlUberspectGets an iterator from an object.- Specified by:
getIteratorin 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 bykeyand for the Classc.- Parameters:
c- Class in which the method search is taking placekey- MethodKey of the method being searched for- Returns:
- a
Methodor 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 bynameandparamsfor 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
Methodor 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:JexlUberspectReturns a JexlMethod.- Specified by:
getMethodin 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:JexlUberspectProperty getter.Seeks a JexlPropertyGet apropos to an expression like
Seebar.woogie.JexlUberspect.ResolverStrategy.apply(JexlOperator, Object)- Specified by:
getPropertyGetin interfaceJexlUberspect- Parameters:
resolvers- the list of property resolvers to tryobj- the object to get the property fromidentifier- property name- Returns:
- a
JexlPropertyGetor null
-
getPropertyGet
public JexlPropertyGet getPropertyGet(java.lang.Object obj, java.lang.Object identifier)
Description copied from interface:JexlUberspectProperty getter.returns a JelPropertySet apropos to an expression like
bar.woogie.- Specified by:
getPropertyGetin interfaceJexlUberspect- Parameters:
obj- the object to get the property fromidentifier- property name- Returns:
- a
JexlPropertyGetor 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:JexlUberspectProperty setter.Seeks a JelPropertySet apropos to an expression like
Seefoo.bar = "geir".JexlUberspect.ResolverStrategy.apply(JexlOperator, Object)- Specified by:
getPropertySetin 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
JexlPropertySetor null
-
getPropertySet
public JexlPropertySet getPropertySet(java.lang.Object obj, java.lang.Object identifier, java.lang.Object arg)
Description copied from interface:JexlUberspectProperty setter.Seeks a JelPropertySet apropos to an expression like
foo.bar = "geir".- Specified by:
getPropertySetin interfaceJexlUberspect- Parameters:
obj- the object to get the property from.identifier- property namearg- value to set- Returns:
- a
JexlPropertySetor null
-
getResolvers
public java.util.List<JexlUberspect.PropertyResolver> getResolvers(JexlOperator op, java.lang.Object obj)
Description copied from interface:JexlUberspectApplies this uberspect property resolver strategy.- Specified by:
getResolversin interfaceJexlUberspect- Parameters:
op- the operatorobj- the object- Returns:
- the applied strategy resolver list
-
getVersion
public int getVersion()
Description copied from interface:JexlUberspectGets this uberspect version.- Specified by:
getVersionin interfaceJexlUberspect- Returns:
- the class loader modification count
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader loader)
Description copied from interface:JexlUberspectSets the class loader to use.This increments the version.
- Specified by:
setClassLoaderin interfaceJexlUberspect- Parameters:
loader- the class loader
-
-