org.xwiki.velocity.introspection
Class ChainingUberspector

java.lang.Object
  extended by org.apache.velocity.util.introspection.UberspectImpl
      extended by org.xwiki.velocity.introspection.AbstractChainableUberspector
          extended by org.xwiki.velocity.introspection.ChainingUberspector
All Implemented Interfaces:
org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.introspection.UberspectLoggable, org.apache.velocity.util.RuntimeServicesAware, ChainableUberspector

public class ChainingUberspector
extends AbstractChainableUberspector
implements org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.RuntimeServicesAware, org.apache.velocity.util.introspection.UberspectLoggable

Since the current version of the Velocity engine (1.5) does not allow more than one uberspector, this class is a workaround. It manually constructs a chain of uberspectors, loading the classes in the order defined in the "runtime.introspector.uberspect.chainClasses" property, and after that simply forwarding all calls to the top of the chain. Note that the calls will be made from the rightmost class to the leftmost one. Along the chain, each uberspectors can forward the call to the rest of the chain, build its own result, and/or process in any way the resulting value. This allows uberspectors to enhance the list of returned methods, block out methods returned by other uberspectors, or take various actions on the returned method (for example add or remove parameters before searching the method, log executed method names, or catch exceptions when executing those methods).

This is not actually part of the chain, but is more of a handle that allows the calls intended for only one uberspector to reach the chain. It duplicates some of the code from the velocity runtime initialization code, hoping that a future version of the engine will support chaining natively.

The chain is defined using the configuration parameter runtime.introspector.uberspect.chainClasses. This property should contain a list of canonical class names. Any wrong entry in the list will be ignored. If this property is not defined or contains only wrong classnames, then by default a SecureUberspector is used as the only entry in the chain. The first (leftmost) uberspector does not have to be chainable (as it will not need to forward calls). If a uberspector in the middle of the chain is not chainable, then it will break the chain at that point (all previos uberspectors will be discarded from the chain).

Since:
1.5M1
Version:
$Id: 652381ae363685f63e7817bfb1a45da7564e77f5 $
See Also:
ChainableUberspector

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.velocity.util.introspection.UberspectImpl
org.apache.velocity.util.introspection.UberspectImpl.VelGetterImpl, org.apache.velocity.util.introspection.UberspectImpl.VelMethodImpl, org.apache.velocity.util.introspection.UberspectImpl.VelSetterImpl
 
Field Summary
static String UBERSPECT_CHAIN_CLASSNAMES
          The key of the parameter that allows defining the list of chained uberspectors.
 
Fields inherited from class org.xwiki.velocity.introspection.AbstractChainableUberspector
inner
 
Fields inherited from class org.apache.velocity.util.introspection.UberspectImpl
introspector, log
 
Constructor Summary
ChainingUberspector()
           
 
Method Summary
 void init()
          
protected  void initializeUberspector(String classname)
          Instantiates an uberspector class and adds it to the chain.
protected  org.apache.velocity.util.introspection.Uberspect instantiateUberspector(String classname)
          Tries to create an uberspector instance using reflection.
 void setRuntimeServices(org.apache.velocity.runtime.RuntimeServices rs)
           
 
Methods inherited from class org.xwiki.velocity.introspection.AbstractChainableUberspector
getIterator, getMethod, getPropertyGet, getPropertySet, wrap
 
Methods inherited from class org.apache.velocity.util.introspection.UberspectImpl
setLog, setRuntimeLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.velocity.util.introspection.Uberspect
getIterator, getMethod, getPropertyGet, getPropertySet
 
Methods inherited from interface org.apache.velocity.util.introspection.UberspectLoggable
setLog, setRuntimeLogger
 

Field Detail

UBERSPECT_CHAIN_CLASSNAMES

public static final String UBERSPECT_CHAIN_CLASSNAMES
The key of the parameter that allows defining the list of chained uberspectors.

See Also:
Constant Field Values
Constructor Detail

ChainingUberspector

public ChainingUberspector()
Method Detail

setRuntimeServices

public void setRuntimeServices(org.apache.velocity.runtime.RuntimeServices rs)
Specified by:
setRuntimeServices in interface org.apache.velocity.util.RuntimeServicesAware

init

public void init()

This implementation initializes the uberspector chain.

Specified by:
init in interface org.apache.velocity.util.introspection.Uberspect
Overrides:
init in class AbstractChainableUberspector
See Also:
Uberspect.init()

initializeUberspector

protected void initializeUberspector(String classname)
Instantiates an uberspector class and adds it to the chain. Also set the log and runtime services, if the class implements the proper interfaces. The Uberspect.init() method is not called.

Parameters:
classname - The name of the uberspector class to add to the chain.

instantiateUberspector

protected org.apache.velocity.util.introspection.Uberspect instantiateUberspector(String classname)
Tries to create an uberspector instance using reflection.

Parameters:
classname - The name of the uberspector class to instantiate.
Returns:
An instance of the specified Uberspector. If the class cannot be instantiated using the default constructor, or does not implement Uberspect, null is returned.


Copyright © 2004-2012 XWiki. All Rights Reserved.