Package grails.util
Class GrailsMetaClassUtils
- java.lang.Object
-
- grails.util.GrailsMetaClassUtils
-
public class GrailsMetaClassUtils extends java.lang.ObjectProvides utility methods for working with the Groovy MetaClass API.- Since:
- 0.5
-
-
Constructor Summary
Constructors Constructor Description GrailsMetaClassUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyExpandoMetaClass(java.lang.Class<?> fromClass, java.lang.Class<?> toClass, boolean removeSource)Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.static groovy.lang.ExpandoMetaClassgetExpandoMetaClass(java.lang.Class<?> aClass)static groovy.lang.MetaClassgetMetaClass(java.lang.Object instance)static java.lang.ObjectgetPropertyIfExists(java.lang.Object instance, java.lang.String property)Obtains a property of an instance if it existsstatic <T> TgetPropertyIfExists(java.lang.Object instance, java.lang.String property, java.lang.Class<T> requiredType)Obtains a property of an instance if it existsstatic groovy.lang.MetaClassRegistrygetRegistry()Retrieves the MetaClassRegistry instance.static java.lang.ObjectinvokeMethodIfExists(java.lang.Object instance, java.lang.String methodName)Invokes a method if it exists otherwise returns nullstatic java.lang.ObjectinvokeMethodIfExists(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] args)Invokes a method if it exists otherwise returns null
-
-
-
Method Detail
-
getRegistry
public static groovy.lang.MetaClassRegistry getRegistry()
Retrieves the MetaClassRegistry instance.- Returns:
- The registry
-
copyExpandoMetaClass
public static void copyExpandoMetaClass(java.lang.Class<?> fromClass, java.lang.Class<?> toClass, boolean removeSource)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
public static groovy.lang.ExpandoMetaClass getExpandoMetaClass(java.lang.Class<?> aClass)
-
getMetaClass
public static groovy.lang.MetaClass getMetaClass(java.lang.Object instance)
-
getPropertyIfExists
public static java.lang.Object getPropertyIfExists(java.lang.Object instance, java.lang.String property)Obtains a property of an instance if it exists- Parameters:
instance- The instanceproperty- The property- Returns:
- The value of null if non-exists
-
getPropertyIfExists
public static <T> T getPropertyIfExists(java.lang.Object instance, java.lang.String property, java.lang.Class<T> requiredType)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
public static java.lang.Object invokeMethodIfExists(java.lang.Object instance, java.lang.String methodName)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
public static java.lang.Object invokeMethodIfExists(java.lang.Object instance, java.lang.String methodName, java.lang.Object[] args)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
-
-