Class PojoWrapper

java.lang.Object
org.codehaus.groovy.runtime.wrappers.Wrapper
org.codehaus.groovy.runtime.wrappers.PojoWrapper
All Implemented Interfaces:
GroovyObject
Direct Known Subclasses:
BooleanWrapper, ByteWrapper, CharWrapper, DoubleWrapper, FloatWrapper, IntWrapper, LongWrapper, ShortWrapper

public class PojoWrapper extends Wrapper
Wraps a plain Java object and routes GroovyObject operations through a delegated MetaClass.
  • Field Details

    • delegate

      protected MetaClass delegate
      The meta class used to dispatch GroovyObject operations to the wrapped object.
    • wrapped

      protected final Object wrapped
      The wrapped plain Java object.
  • Constructor Details

    • PojoWrapper

      public PojoWrapper(Object wrapped, Class constrainedType)
      Creates a wrapper for a plain Java object constrained to the supplied type.
      Parameters:
      wrapped - the wrapped object
      constrainedType - the type the wrapped object should report
  • Method Details

    • unwrap

      public Object unwrap()
      Returns the wrapped value.
      Specified by:
      unwrap in class Wrapper
      Returns:
      the underlying value represented by this wrapper
    • getProperty

      public Object getProperty(String property)
      Returns a property value from the wrapped object using the delegated meta class.
      Parameters:
      property - the property name
      Returns:
      the resolved property value
    • invokeMethod

      public Object invokeMethod(String methodName, Object arguments)
      Invokes a method on the wrapped object using the delegated meta class.
      Parameters:
      methodName - the method name
      arguments - the invocation arguments
      Returns:
      the invocation result
    • setMetaClass

      public void setMetaClass(MetaClass metaClass)
      Sets the meta class used to dispatch GroovyObject operations for the wrapped object.
      Parameters:
      metaClass - the meta class to delegate to
    • setProperty

      public void setProperty(String property, Object newValue)
      Sets a property on the wrapped object using the delegated meta class.
      Parameters:
      property - the property name
      newValue - the new property value
    • getWrapped

      protected Object getWrapped()
      Returns the object used as the delegation target for meta-class-based operations.
      Specified by:
      getWrapped in class Wrapper
      Returns:
      the underlying wrapped object
    • getDelegatedMetaClass

      protected MetaClass getDelegatedMetaClass()
      Returns the meta class that should handle GroovyObject operations for the wrapped value.
      Specified by:
      getDelegatedMetaClass in class Wrapper
      Returns:
      the delegated meta class