Class ChainingUberspector

  • All Implemented Interfaces:
    org.apache.velocity.util.introspection.ChainableUberspector, org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.RuntimeServicesAware, ChainableUberspector

    public class ChainingUberspector
    extends AbstractChainableUberspector
    implements org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.RuntimeServicesAware
    since 8.0M1; Velocity supports the same functionality natively since 1.6; just move the configuration from runtime.introspector.uberspect.chainClasses to runtime.introspector.uberspect

    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).

    $Id: f6c6d9a3669094cd5af96342267dcc9fef488960 $
    See Also:
    • 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

      Modifier and Type Field Description
      The key of the parameter that allows defining the list of chained uberspectors.
      • Fields inherited from class org.apache.velocity.util.introspection.AbstractChainableUberspector

      • Fields inherited from class org.apache.velocity.util.introspection.UberspectImpl

        conversionHandler, introspector, log, rsvc
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      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.
      • Methods inherited from class org.apache.velocity.util.introspection.AbstractChainableUberspector

        getIterator, getMethod, getPropertyGet, getPropertySet, wrap
      • Methods inherited from class org.apache.velocity.util.introspection.UberspectImpl

        getConversionHandler, setLog, setRuntimeServices
      • Methods inherited from interface org.apache.velocity.util.introspection.ChainableUberspector

      • Methods inherited from interface org.apache.velocity.util.RuntimeServicesAware

      • Methods inherited from interface org.apache.velocity.util.introspection.Uberspect

        getIterator, getMethod, getPropertyGet, getPropertySet
    • Field Detail


        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

      • init

        public void init()

        This implementation initializes the uberspector chain.

        Specified by:
        init in interface org.apache.velocity.util.introspection.Uberspect
        init in class org.apache.velocity.util.introspection.AbstractChainableUberspector
        See Also:
      • 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.
        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.
        classname - The name of the uberspector class to instantiate.
        An instance of the specified Uberspector. If the class cannot be instantiated using the default constructor, or does not implement Uberspect, null is returned.