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.
Fields inherited from class | Fields |
---|---|
class groovy.lang.ExpandoMetaClass |
STATIC_QUALIFIER, CONSTRUCTOR, inRegistry, EMPTY_ARGUMENTS |
class groovy.lang.MetaClassImpl |
EMPTY_ARGUMENTS |
Constructor and description |
---|
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 |
Type | Name and description |
---|---|
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 | Name |
---|---|
class groovy.lang.ExpandoMetaClass |
groovy.lang.ExpandoMetaClass#setProperty(java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#setProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.ExpandoMetaClass#getProperty(java.lang.Class, java.lang.Object, java.lang.String, boolean, boolean), groovy.lang.ExpandoMetaClass#getProperty(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#getProperty(java.lang.String), groovy.lang.ExpandoMetaClass#initialize(), groovy.lang.ExpandoMetaClass#getMethods(), groovy.lang.ExpandoMetaClass#getProperties(), groovy.lang.ExpandoMetaClass#isSetter(java.lang.String, [Lorg.codehaus.groovy.reflection.CachedClass;), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.ExpandoMetaClass#invokeMethod(java.lang.Class, java.lang.Object, java.lang.String, [Ljava.lang.Object;, boolean, boolean), groovy.lang.ExpandoMetaClass#getMetaClass(), groovy.lang.ExpandoMetaClass#setMetaClass(groovy.lang.MetaClass), 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(java.lang.String, groovy.lang.Closure), groovy.lang.ExpandoMetaClass#registerInstanceMethod(groovy.lang.MetaMethod), groovy.lang.ExpandoMetaClass#createPojoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Object, [Ljava.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#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#retrieveConstructor([Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#createConstructorSite(org.codehaus.groovy.runtime.callsite.CallSite, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#findMixinMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#isModified(), groovy.lang.ExpandoMetaClass#registerSubclassInstanceMethod(groovy.lang.MetaMethod), groovy.lang.ExpandoMetaClass#registerSubclassInstanceMethod(java.lang.String, java.lang.Class, groovy.lang.Closure), 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#castToMixedType(java.lang.Object, java.lang.Class), groovy.lang.ExpandoMetaClass#define(groovy.lang.Closure), groovy.lang.ExpandoMetaClass#getVersion(), 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#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#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#hasProperty(java.lang.Object, java.lang.String), groovy.lang.ExpandoMetaClass#getClassInfo(), groovy.lang.ExpandoMetaClass#selectConstructorAndTransformArguments(int, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#invokeMissingProperty(java.lang.Object, java.lang.String, java.lang.Object, boolean), groovy.lang.ExpandoMetaClass#pickMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.ExpandoMetaClass#getClassNode(), 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#getMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getStaticMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#getTheClass(), groovy.lang.ExpandoMetaClass#getMetaMethods(), groovy.lang.ExpandoMetaClass#invokeMissingMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#incVersion(), groovy.lang.ExpandoMetaClass#getRegistry(), groovy.lang.ExpandoMetaClass#createPogoCallCurrentSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Class, [Ljava.lang.Object;), groovy.lang.ExpandoMetaClass#retrieveConstructor([Ljava.lang.Class;), 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#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#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#wait(long, int), groovy.lang.ExpandoMetaClass#wait(long), groovy.lang.ExpandoMetaClass#wait(), groovy.lang.ExpandoMetaClass#equals(java.lang.Object), groovy.lang.ExpandoMetaClass#hashCode(), groovy.lang.ExpandoMetaClass#getClass(), groovy.lang.ExpandoMetaClass#notify(), groovy.lang.ExpandoMetaClass#notifyAll() |
class groovy.lang.MetaClassImpl |
groovy.lang.MetaClassImpl#getVersion(), 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#setProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.Object, boolean, boolean), groovy.lang.MetaClassImpl#setProperty(java.lang.Object, java.lang.String, java.lang.Object), 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#initialize(), groovy.lang.MetaClassImpl#getMethods(), groovy.lang.MetaClassImpl#getProperties(), groovy.lang.MetaClassImpl#setProperties(java.lang.Object, java.util.Map), 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#invokeMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object), groovy.lang.MetaClassImpl#invokeMethod(java.lang.Class, java.lang.Object, java.lang.String, [Ljava.lang.Object;, boolean, boolean), groovy.lang.MetaClassImpl#hasProperty(java.lang.Object, java.lang.String), groovy.lang.MetaClassImpl#getClassInfo(), groovy.lang.MetaClassImpl#selectConstructorAndTransformArguments(int, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaProperty(java.lang.String), groovy.lang.MetaClassImpl#invokeMissingProperty(java.lang.Object, java.lang.String, java.lang.Object, boolean), groovy.lang.MetaClassImpl#pickMethod(java.lang.String, [Ljava.lang.Class;), groovy.lang.MetaClassImpl#getClassNode(), 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#getMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getStaticMetaMethod(java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getTheClass(), groovy.lang.MetaClassImpl#invokeConstructor([Ljava.lang.Object;), groovy.lang.MetaClassImpl#invokeStaticMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#getMetaMethods(), groovy.lang.MetaClassImpl#invokeMissingMethod(java.lang.Object, java.lang.String, [Ljava.lang.Object;), groovy.lang.MetaClassImpl#incVersion(), groovy.lang.MetaClassImpl#getRegistry(), groovy.lang.MetaClassImpl#createPojoCallSite(org.codehaus.groovy.runtime.callsite.CallSite, java.lang.Object, [Ljava.lang.Object;), 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#retrieveConstructor([Ljava.lang.Class;), groovy.lang.MetaClassImpl#retrieveConstructor([Ljava.lang.Object;), groovy.lang.MetaClassImpl#createConstructorSite(org.codehaus.groovy.runtime.callsite.CallSite, [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#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#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#wait(long, int), groovy.lang.MetaClassImpl#wait(long), groovy.lang.MetaClassImpl#wait(), groovy.lang.MetaClassImpl#equals(java.lang.Object), groovy.lang.MetaClassImpl#hashCode(), groovy.lang.MetaClassImpl#getClass(), groovy.lang.MetaClassImpl#notify(), groovy.lang.MetaClassImpl#notifyAll() |
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
aClass
- The class to create the MetaClass forConstructs a new DynamicMethodsExpandoMetaClass given the current class and places it in the MetaClassRegistry
aClass
- The class to create the MetaClass forEither invokes a intercepted dyanmic static method or the adapted original MetaClass.
target
- The target objectmethodName
- The method namearguments
- The arguments to the method