Package grails.util
Class GrailsMetaClassUtils
java.lang.Object
grails.util.GrailsMetaClassUtils
Provides utility methods for working with the Groovy MetaClass API.
- Since:
- 0.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyExpandoMetaClass(Class<?> fromClass, Class<?> toClass, boolean removeSource) Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.static groovy.lang.ExpandoMetaClassgetExpandoMetaClass(Class<?> aClass) static groovy.lang.MetaClassgetMetaClass(Object instance) static ObjectgetPropertyIfExists(Object instance, String property) Obtains a property of an instance if it existsstatic <T> TgetPropertyIfExists(Object instance, String property, Class<T> requiredType) Obtains a property of an instance if it existsstatic groovy.lang.MetaClassRegistryRetrieves the MetaClassRegistry instance.static ObjectinvokeMethodIfExists(Object instance, String methodName) Invokes a method if it exists otherwise returns nullstatic ObjectinvokeMethodIfExists(Object instance, String methodName, Object[] args) Invokes a method if it exists otherwise returns null
-
Method Details
-
getRegistry
public static groovy.lang.MetaClassRegistry getRegistry()Retrieves the MetaClassRegistry instance.- Returns:
- The registry
-
copyExpandoMetaClass
Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.- Parameters:
fromClass- The source classtoClass- The destination classremoveSource- Whether to remove the source class after completion. True if yes
-
getExpandoMetaClass
-
getMetaClass
-
getPropertyIfExists
Obtains a property of an instance if it exists- Parameters:
instance- The instanceproperty- The property- Returns:
- The value of null if non-exists
-
getPropertyIfExists
Obtains a property of an instance if it exists- Parameters:
instance- The instanceproperty- The propertyrequiredType- The required type of the property- Returns:
- The property value
-
invokeMethodIfExists
Invokes a method if it exists otherwise returns null- Parameters:
instance- The instancemethodName- The method name- Returns:
- The result of the method call or null
-
invokeMethodIfExists
Invokes a method if it exists otherwise returns null- Parameters:
instance- The instancemethodName- The method nameargs- The arguments- Returns:
- The result of the method call or null
-