Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.grails.commons.metaclass
[Java] Class DynamicMethodsExpandoMetaClass

    java.lang.Object
      groovy.lang.MetaClassImpl
          groovy.lang.ExpandoMetaClass
              org.codehaus.groovy.grails.commons.metaclass.DynamicMethodsExpandoMetaClass

    public class DynamicMethodsExpandoMetaClass
    extends groovy.lang.ExpandoMetaClass

Extends ExpandoMetaClass and adds the ability to use regex to specified method matches that then get passed to the invocable closure. Example: metaClass./^findBy(\w+)$/ = { matcher, args -> } The first argument to the closure is the Regex Matcher. The second is the arguments to the method. This MetaClass allows you to implement thigns like dynamic finders in a trivial manner. The regular expression MUST start with a ^ and end with a $ otherwise it won't be regarded as a valid regex expression and an error will be thrown. Otherwise the mechanism is similar to that provided by ExpandoMetaClass WARNING: Unlike ExpandoMetaClass this MetaClass uses method proxying, hence there is a an overhead attached to its use. This makes it less suitable for use on commonly used objects like java.lang.Object or java.lang.String if performance is important to your application consider other options like the regular ExpandoMetaClass If usage can be isolated to a small set of use cases (such as dynamic finders in Grails) then there is no problem as proxying is not occuring for every method call WARNING: This MetaClass does not support inheritance heirarchies. In other words a child class will not be able to invoke a dynamically added method that exists on a super class.

Authors:
  Graeme Rocher

Since:
  0.5

Field Summary

Fields inherited from class groovy.lang.ExpandoMetaClass
STATIC_QUALIFIER, CONSTRUCTOR, inRegistry

Constructor Summary
`DynamicMethodsExpandoMetaClass(java.lang.Class aClass)` Constructs a new DynamicMethodsExpandoMetaClass given the current class.
`DynamicMethodsExpandoMetaClass(java.lang.Class aClass, boolean inReg)` Constructs a new DynamicMethodsExpandoMetaClass given the current class and places it in the MetaClassRegistry

Method Summary
`java.lang.Object` | `getProperty(java.lang.Class aClass, java.lang.Object object, java.lang.String property, boolean b, boolean b1)`
`java.lang.Object` | `getProperty(java.lang.String name)`
`java.lang.Object` | `invokeConstructor(java.lang.Object[] arg0)`
`java.lang.Object` | `invokeMethod(java.lang.Class aClass, java.lang.Object target, java.lang.String methodName, java.lang.Object[] arguments, boolean b, boolean b1)`
`java.lang.Object` | `invokeStaticMethod(java.lang.Object target, java.lang.String methodName, java.lang.Object[] arguments)` Either invokes a intercepted dyanmic static method or the adapted original MetaClass.
`void` | `setProperty(java.lang.Class aClass, java.lang.Object object, java.lang.String property, java.lang.Object newValue, boolean b, boolean b1)`
`void` | `setProperty(java.lang.String name, java.lang.Object value)`

Methods inherited from class groovy.lang.ExpandoMetaClass
groovy.lang.ExpandoMetaClass#setProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.ExpandoMetaClass#setProperty(java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#getProperty(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#getProperty(java.lang.String), groovy.lang.ExpandoMetaClass#getProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.ExpandoMetaClass#getMethods(), groovy.lang.ExpandoMetaClass#getProperties(), groovy.lang.ExpandoMetaClass#initialize(), groovy.lang.ExpandoMetaClass#getMetaClass(), groovy.lang.ExpandoMetaClass#setMetaClass(groovy.lang.MetaClass), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.Class, java.lang.Object, java.lang.String, [Ljava.lang.Object;, boolean, boolean), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#getMetaProperty(java.lang.String), groovy.lang.ExpandoMetaClass#invokeConstructor([Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#invokeStaticMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getExpandoMethods(), groovy.lang.ExpandoMetaClass#getExpandoSubclassMethods(), groovy.lang.ExpandoMetaClass#registerInstanceMethod(groovy.lang.MetaMethod), groovy.lang.ExpandoMetaClass#registerInstanceMethod(java.lang.String, groovy.lang.Closure), groovy.lang.ExpandoMetaClass#castToMixedType(java.lang.Object, java.lang.Class), groovy.lang.ExpandoMetaClass#define(groovy.lang.Closure), groovy.lang.ExpandoMetaClass#createPojoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Object, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#findMixinMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#isModified(), groovy.lang.ExpandoMetaClass#registerSubclassInstanceMethod(java.lang.String, java.lang.Class, groovy.lang.Closure), groovy.lang.ExpandoMetaClass#registerSubclassInstanceMethod(groovy.lang.MetaMethod), groovy.lang.ExpandoMetaClass#addMixinClass(org.codehaus.groovy.reflection.MixinInMetaClass), groovy.lang.ExpandoMetaClass#enableGlobally(), groovy.lang.ExpandoMetaClass#disableGlobally(), groovy.lang.ExpandoMetaClass#isValidExpandoProperty(java.lang.String), groovy.lang.ExpandoMetaClass#registerBeanProperty(java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#getJavaClass(), groovy.lang.ExpandoMetaClass#refreshInheritedMethods(java.util.Set), groovy.lang.ExpandoMetaClass#getExpandoProperties(), groovy.lang.ExpandoMetaClass#hasMetaProperty(java.lang.String), groovy.lang.ExpandoMetaClass#hasMetaMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#getPropertyForSetter(java.lang.String), groovy.lang.ExpandoMetaClass#isSetter(java.lang.String, [Lorg.codehaus.groovy.reflection.CachedClass;), groovy.lang.ExpandoMetaClass#createStaticSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#createPogoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#createPogoCallCurrentSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Class, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#createConstructorSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#setProperty(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#toString(), groovy.lang.ExpandoMetaClass#setProperties(java.lang.Object, java.util.Map), groovy.lang.ExpandoMetaClass#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.ExpandoMetaClass#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.ExpandoMetaClass#getAttribute(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#getVersion(), groovy.lang.ExpandoMetaClass#getTheClass(), groovy.lang.ExpandoMetaClass#hasProperty(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#pickMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#invokeMissingMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#invokeMissingProperty(java.lang.Object, java.lang.String, java.lang.Object, boolean), groovy.lang.ExpandoMetaClass#setAttribute(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#setAttribute(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.ExpandoMetaClass#getClassNode(), groovy.lang.ExpandoMetaClass#getMetaMethods(), groovy.lang.ExpandoMetaClass#selectConstructorAndTransformArguments(int, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#respondsTo(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#respondsTo(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getStaticMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getClassInfo(), groovy.lang.ExpandoMetaClass#incVersion(), groovy.lang.ExpandoMetaClass#getTheCachedClass(), groovy.lang.ExpandoMetaClass#getMethodWithoutCaching(java.lang.Class, java.lang.String, [Ljava.lang.Class;, boolean), groovy.lang.ExpandoMetaClass#addMetaBeanProperty(groovy.lang.MetaBeanProperty), groovy.lang.ExpandoMetaClass#createPogoCallCurrentSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Class, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#isGroovyObject(), groovy.lang.ExpandoMetaClass#addNewInstanceMethod(java.lang.reflect.Method), groovy.lang.ExpandoMetaClass#addNewStaticMethod(java.lang.reflect.Method), groovy.lang.ExpandoMetaClass#getMethodWithCaching(java.lang.Class, java.lang.String, [Ljava.lang.Object;, boolean), groovy.lang.ExpandoMetaClass#retrieveConstructor([Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#retrieveStaticMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getEffectiveGetMetaProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.ExpandoMetaClass#addMetaMethod(groovy.lang.MetaMethod), groovy.lang.ExpandoMetaClass#getAdditionalMetaMethods(), groovy.lang.ExpandoMetaClass#getRegistry(), groovy.lang.ExpandoMetaClass#wait(), groovy.lang.ExpandoMetaClass#wait(long), groovy.lang.ExpandoMetaClass#wait(long, int), groovy.lang.ExpandoMetaClass#equals(java.lang.Object), groovy.lang.ExpandoMetaClass#hashCode(), groovy.lang.ExpandoMetaClass#getClass(), groovy.lang.ExpandoMetaClass#notify(), groovy.lang.ExpandoMetaClass#notifyAll()

Methods inherited from class groovy.lang.MetaClassImpl
groovy.lang.MetaClassImpl#setProperty(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#setProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.MetaClassImpl#getProperty(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#getProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.MetaClassImpl#toString(), groovy.lang.MetaClassImpl#getMethods(), groovy.lang.MetaClassImpl#getProperties(), groovy.lang.MetaClassImpl#setProperties(java.lang.Object, java.util.Map), groovy.lang.MetaClassImpl#initialize(), groovy.lang.MetaClassImpl#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.MetaClassImpl#getAttribute(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.MetaClassImpl#getAttribute(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#getVersion(), groovy.lang.MetaClassImpl#getTheClass(), groovy.lang.MetaClassImpl#hasProperty(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Class, java.lang.Object, java.lang.String, [Ljava.lang.Object;, boolean, boolean), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#pickMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.MetaClassImpl#invokeMissingMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeMissingProperty(java.lang.Object, java.lang.String, java.lang.Object, boolean), groovy.lang.MetaClassImpl#setAttribute(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#setAttribute(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.MetaClassImpl#getClassNode(), groovy.lang.MetaClassImpl#getMetaMethods(), groovy.lang.MetaClassImpl#selectConstructorAndTransformArguments(int, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#respondsTo(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#respondsTo(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaProperty(java.lang.String), groovy.lang.MetaClassImpl#getStaticMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeConstructor([Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeStaticMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getClassInfo(), groovy.lang.MetaClassImpl#incVersion(), groovy.lang.MetaClassImpl#createPojoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Object, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getTheCachedClass(), groovy.lang.MetaClassImpl#getMethodWithoutCaching(java.lang.Class, java.lang.String, [Ljava.lang.Class;, boolean), groovy.lang.MetaClassImpl#addMetaBeanProperty(groovy.lang.MetaBeanProperty), groovy.lang.MetaClassImpl#isModified(), groovy.lang.MetaClassImpl#createStaticSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createPogoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createPogoCallCurrentSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Class, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#createConstructorSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#isGroovyObject(), groovy.lang.MetaClassImpl#addNewInstanceMethod(java.lang.reflect.Method), groovy.lang.MetaClassImpl#addNewStaticMethod(java.lang.reflect.Method), groovy.lang.MetaClassImpl#getMethodWithCaching(java.lang.Class, java.lang.String, [Ljava.lang.Object;, boolean), groovy.lang.MetaClassImpl#retrieveConstructor([Ljava.lang.Class;), groovy.lang.MetaClassImpl#retrieveStaticMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getEffectiveGetMetaProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean), groovy.lang.MetaClassImpl#addMetaMethod(groovy.lang.MetaMethod), groovy.lang.MetaClassImpl#getAdditionalMetaMethods(), groovy.lang.MetaClassImpl#getRegistry(), groovy.lang.MetaClassImpl#wait(), groovy.lang.MetaClassImpl#wait(long), groovy.lang.MetaClassImpl#wait(long, int), groovy.lang.MetaClassImpl#equals(java.lang.Object), groovy.lang.MetaClassImpl#hashCode(), groovy.lang.MetaClassImpl#getClass(), groovy.lang.MetaClassImpl#notify(), groovy.lang.MetaClassImpl#notifyAll()

Constructor Detail

### DynamicMethodsExpandoMetaClass

    public DynamicMethodsExpandoMetaClass(java.lang.Class aClass)

  Constructs a new DynamicMethodsExpandoMetaClass given the current class. Note that this constructor will NOT place this MetaClass in the MetaClassRegistry. It is up to you to either place it in the MetaClassRegistry or call setMetaClass on GroovyObject
  Parameters:
    `aClass` - The class to create the MetaClass for

### DynamicMethodsExpandoMetaClass

    public DynamicMethodsExpandoMetaClass(java.lang.Class aClass, boolean inReg)

  Constructs a new DynamicMethodsExpandoMetaClass given the current class and places it in the MetaClassRegistry
  Parameters:
    `aClass` - The class to create the MetaClass for

Method Detail

### getProperty

    @Override
    public java.lang.Object getProperty(@SuppressWarnings("rawtypes") java.lang.Class aClass, java.lang.Object object, java.lang.String property, boolean b, boolean b1)

### getProperty

    @Override
    public java.lang.Object getProperty(java.lang.String name)

### invokeConstructor

    @Override
    public java.lang.Object invokeConstructor(java.lang.Object[] arg0)

### invokeMethod

    @Override
    public java.lang.Object invokeMethod(@SuppressWarnings("rawtypes") java.lang.Class aClass, java.lang.Object target, java.lang.String methodName, java.lang.Object[] arguments, boolean b, boolean b1)

### invokeStaticMethod

    @Override
    public java.lang.Object invokeStaticMethod(java.lang.Object target, java.lang.String methodName, java.lang.Object[] arguments)

  Either invokes a intercepted dyanmic static method or the adapted original MetaClass.
  Parameters:
    `target` - The target object
    `methodName` - The method name
    `arguments` - The arguments to the method
  Returns:
    The return value

### setProperty

    @Override
    public void setProperty(@SuppressWarnings("rawtypes") java.lang.Class aClass, java.lang.Object object, java.lang.String property, java.lang.Object newValue, boolean b, boolean b1)

### setProperty

    @Override
    public void setProperty(java.lang.String name, java.lang.Object value)

Groovy Documentation