Class SingletonUberspector

java.lang.Object
com.atlassian.velocity.allowlist.uberspect.SingletonUberspector
All Implemented Interfaces:
org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.introspection.UberspectLoggable, org.apache.velocity.util.RuntimeServicesAware
Direct Known Subclasses:
PluginAwareSecureUberspector

public class SingletonUberspector extends Object implements org.apache.velocity.util.introspection.Uberspect, org.apache.velocity.util.introspection.UberspectLoggable, org.apache.velocity.util.RuntimeServicesAware
Useful for enforcing a single Uberspect instance is used for all constructed Velocity engines rather than creating a new instance for each engine. This is particularly useful when the Uberspect implementation is expensive to create or has state that should be shared across all engines.

Simply extend this class and override newUberspector() to return the desired Uberspect implementation, then wire in the new class name using the runtime.introspector.uberspect property in the Velocity configuration. If you instantiate this class directly, it will use the default SecureUberspector.

This class can also optionally track the coupled Introspector if one exists by overriding newIntrospector(org.apache.velocity.runtime.log.Log, org.apache.velocity.runtime.RuntimeServices) and replacing the Introspector construction within your Uberspector with getIntrospectorInternal(org.apache.velocity.runtime.log.Log, org.apache.velocity.runtime.RuntimeServices). You may then call getIntrospector() at any time to access the coupled Introspector instance.

There is however one caveat, and that is that the Uberspect instance will be initialised with the RuntimeServices provided by the first engine that calls init(). It is thus important that the first engine initialisation is deterministic for consistent, reproducible configuration.

Since:
6.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.velocity.util.introspection.Introspector
     
    protected org.apache.velocity.util.introspection.Introspector
    getIntrospectorInternal(org.apache.velocity.runtime.log.Log log, org.apache.velocity.runtime.RuntimeServices runtimeServices)
     
    getIterator(Object obj, org.apache.velocity.util.introspection.Info info)
     
    org.apache.velocity.util.introspection.VelMethod
    getMethod(Object obj, String method, Object[] args, org.apache.velocity.util.introspection.Info info)
     
    org.apache.velocity.util.introspection.VelPropertyGet
    getPropertyGet(Object obj, String identifier, org.apache.velocity.util.introspection.Info info)
     
    org.apache.velocity.util.introspection.VelPropertySet
    getPropertySet(Object obj, String identifier, Object arg, org.apache.velocity.util.introspection.Info info)
     
    void
    This guarantees the Uberspector will only be initialised once but doesn't guarantee which RuntimeServices it will be initialised with.
    protected org.apache.velocity.util.introspection.Introspector
    newIntrospector(org.apache.velocity.runtime.log.Log log, org.apache.velocity.runtime.RuntimeServices runtimeServices)
     
    protected org.apache.velocity.util.introspection.Uberspect
     
    void
    setLog(org.apache.velocity.runtime.log.Log log)
     
    void
    setRuntimeLogger(org.apache.velocity.runtime.RuntimeLogger logger)
     
    void
    setRuntimeServices(org.apache.velocity.runtime.RuntimeServices rs)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SingletonUberspector

      public SingletonUberspector()
  • Method Details

    • newUberspector

      protected org.apache.velocity.util.introspection.Uberspect newUberspector()
    • getIntrospectorInternal

      protected org.apache.velocity.util.introspection.Introspector getIntrospectorInternal(org.apache.velocity.runtime.log.Log log, org.apache.velocity.runtime.RuntimeServices runtimeServices)
    • newIntrospector

      protected org.apache.velocity.util.introspection.Introspector newIntrospector(org.apache.velocity.runtime.log.Log log, org.apache.velocity.runtime.RuntimeServices runtimeServices)
    • getIntrospector

      public org.apache.velocity.util.introspection.Introspector getIntrospector()
    • init

      public void init() throws Exception
      This guarantees the Uberspector will only be initialised once but doesn't guarantee which RuntimeServices it will be initialised with.
      Specified by:
      init in interface org.apache.velocity.util.introspection.Uberspect
      Throws:
      Exception
    • getIterator

      public Iterator getIterator(Object obj, org.apache.velocity.util.introspection.Info info) throws Exception
      Specified by:
      getIterator in interface org.apache.velocity.util.introspection.Uberspect
      Throws:
      Exception
    • getMethod

      public org.apache.velocity.util.introspection.VelMethod getMethod(Object obj, String method, Object[] args, org.apache.velocity.util.introspection.Info info) throws Exception
      Specified by:
      getMethod in interface org.apache.velocity.util.introspection.Uberspect
      Throws:
      Exception
    • getPropertyGet

      public org.apache.velocity.util.introspection.VelPropertyGet getPropertyGet(Object obj, String identifier, org.apache.velocity.util.introspection.Info info) throws Exception
      Specified by:
      getPropertyGet in interface org.apache.velocity.util.introspection.Uberspect
      Throws:
      Exception
    • getPropertySet

      public org.apache.velocity.util.introspection.VelPropertySet getPropertySet(Object obj, String identifier, Object arg, org.apache.velocity.util.introspection.Info info) throws Exception
      Specified by:
      getPropertySet in interface org.apache.velocity.util.introspection.Uberspect
      Throws:
      Exception
    • setRuntimeServices

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

      public void setLog(org.apache.velocity.runtime.log.Log log)
      Specified by:
      setLog in interface org.apache.velocity.util.introspection.UberspectLoggable
    • setRuntimeLogger

      public void setRuntimeLogger(org.apache.velocity.runtime.RuntimeLogger logger)
      Specified by:
      setRuntimeLogger in interface org.apache.velocity.util.introspection.UberspectLoggable