|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgroovy.lang.MetaClassImpl
groovy.lang.ExpandoMetaClass
org.codehaus.groovy.grails.commons.metaclass.DynamicMethodsExpandoMetaClass
public class DynamicMethodsExpandoMetaClass
This MetaClass 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
| Nested Class Summary | |
|---|---|
(package private) class |
DynamicMethodsExpandoMetaClass.DynamicExpandoMetaProperty
Wraps an existing ExpandoMetaBeanProperty and interceptors methods registration to check if the specified method addition is a regex method |
| Nested classes/interfaces inherited from class groovy.lang.ExpandoMetaClass |
|---|
groovy.lang.ExpandoMetaClass.ExpandoMetaConstructor, groovy.lang.ExpandoMetaClass.ExpandoMetaProperty |
| Nested classes/interfaces inherited from class groovy.lang.MetaClassImpl |
|---|
groovy.lang.MetaClassImpl.Index |
| Field Summary |
|---|
| Fields inherited from class groovy.lang.ExpandoMetaClass |
|---|
CONSTRUCTOR, inRegistry, STATIC_QUALIFIER |
| Fields inherited from class groovy.lang.MetaClassImpl |
|---|
getPropertyMethod, INVOKE_METHOD_METHOD, invokeMethodMethod, isGroovyObject, isMap, metaMethodIndex, METHOD_MISSING, PROPERTY_MISSING, registry, setPropertyMethod, STATIC_METHOD_MISSING, STATIC_PROPERTY_MISSING, theCachedClass, theClass |
| Constructor Summary | |
|---|---|
DynamicMethodsExpandoMetaClass(Class aClass)
Constructs a new DynamicMethodsExpandoMetaClass given the current class. |
|
DynamicMethodsExpandoMetaClass(Class aClass,
boolean inReg)
Constructs a new DynamicMethodsExpandoMetaClass given the current class and places it in the MetaClassRegistry |
|
| Method Summary | |
|---|---|
Object |
getProperty(Class aClass,
Object object,
String property,
boolean b,
boolean b1)
|
Object |
getProperty(String name)
|
Object |
invokeConstructor(Object[] arg0)
|
Object |
invokeMethod(Class aClass,
Object target,
String methodName,
Object[] arguments,
boolean b,
boolean b1)
|
Object |
invokeStaticMethod(Object target,
String methodName,
Object[] arguments)
Either invokes a intercepted dyanmic static method or the adapted original MetaClass |
void |
setProperty(Class aClass,
Object object,
String property,
Object newValue,
boolean b,
boolean b1)
|
void |
setProperty(String name,
Object value)
|
| Methods inherited from class groovy.lang.ExpandoMetaClass |
|---|
addMixinClass, castToMixedType, createConstructorSite, createPogoCallCurrentSite, createPogoCallSite, createPojoCallSite, createStaticSite, define, disableGlobally, enableGlobally, findMixinMethod, getExpandoMethods, getExpandoProperties, getExpandoSubclassMethods, getJavaClass, getMetaClass, getMetaProperty, getMethods, getProperties, getProperty, getPropertyForSetter, getSubclassMetaMethods, hasMetaMethod, hasMetaProperty, initialize, invokeMethod, isInitialized, isModified, isSetter, isValidExpandoProperty, onGetPropertyFoundInHierarchy, onInvokeMethodFoundInHierarchy, onSetPropertyFoundInHierarchy, onSuperMethodFoundInHierarchy, onSuperPropertyFoundInHierarchy, performOperationOnMetaClass, refreshInheritedMethods, registerBeanProperty, registerInstanceMethod, registerInstanceMethod, registerStaticMethod, registerStaticMethod, registerSubclassInstanceMethod, registerSubclassInstanceMethod, setInitialized, setMetaClass |
| Methods inherited from class groovy.lang.MetaClassImpl |
|---|
addMetaBeanProperty, addMetaMethod, addMetaMethodToIndex, addNewInstanceMethod, addNewStaticMethod, checkIfGroovyObjectMethod, checkInitalised, chooseMethod, clearInvocationCaches, createPogoCallCurrentSite, dropMethodCache, dropStaticMethodCache, findMethodInClassHierarchy, findOwnMethod, findPropertyInClassHierarchy, getAdditionalMetaMethods, getAttribute, getAttribute, getAttribute, getClassInfo, getClassNode, getEffectiveGetMetaProperty, getMetaMethod, getMetaMethods, getMethodWithCaching, getMethodWithoutCaching, getStaticMetaMethod, getSuperClasses, getTheCachedClass, getTheClass, getVersion, hasProperty, incVersion, invokeConstructorAt, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMissingProperty, isGroovyObject, onMixinMethodFound, pickMethod, respondsTo, respondsTo, retrieveConstructor, retrieveMethod, retrieveStaticMethod, selectConstructorAndTransformArguments, setAttribute, setAttribute, setProperties, setProperty, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DynamicMethodsExpandoMetaClass(Class aClass)
throws IntrospectionException
aClass - The class to create the MetaClass for
IntrospectionException - Thrown if an error occurs introspecting the class
public DynamicMethodsExpandoMetaClass(Class aClass,
boolean inReg)
throws IntrospectionException
aClass - The class to create the MetaClass for
IntrospectionException - Thrown if an error occurs introspecting the class| Method Detail |
|---|
public Object invokeStaticMethod(Object target,
String methodName,
Object[] arguments)
invokeStaticMethod in interface groovy.lang.MetaObjectProtocolinvokeStaticMethod in class groovy.lang.ExpandoMetaClasstarget - The target objectmethodName - The method namearguments - The arguments to the method
public void setProperty(Class aClass,
Object object,
String property,
Object newValue,
boolean b,
boolean b1)
setProperty in interface groovy.lang.MetaClasssetProperty in class groovy.lang.ExpandoMetaClass
public Object getProperty(Class aClass,
Object object,
String property,
boolean b,
boolean b1)
getProperty in interface groovy.lang.MetaClassgetProperty in class groovy.lang.ExpandoMetaClasspublic Object invokeConstructor(Object[] arg0)
invokeConstructor in interface groovy.lang.MetaObjectProtocolinvokeConstructor in class groovy.lang.ExpandoMetaClass
public Object invokeMethod(Class aClass,
Object target,
String methodName,
Object[] arguments,
boolean b,
boolean b1)
invokeMethod in interface groovy.lang.MetaClassinvokeMethod in class groovy.lang.ExpandoMetaClasspublic Object getProperty(String name)
getProperty in interface groovy.lang.GroovyObjectgetProperty in class groovy.lang.ExpandoMetaClass
public void setProperty(String name,
Object value)
setProperty in interface groovy.lang.GroovyObjectsetProperty in class groovy.lang.ExpandoMetaClass
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||