Package grails.util

Class GrailsMetaClassUtils

java.lang.Object
grails.util.GrailsMetaClassUtils

public final class GrailsMetaClassUtils extends Object
Provides utility methods for working with the Groovy MetaClass API.
Since:
0.5
  • Method Details

    • getRegistry

      public static groovy.lang.MetaClassRegistry getRegistry()
      Retrieves the MetaClassRegistry instance.
      Returns:
      The registry
    • copyExpandoMetaClass

      public static void copyExpandoMetaClass(Class<?> fromClass, Class<?> toClass, boolean removeSource)
      Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.
      Parameters:
      fromClass - The source class
      toClass - The destination class
      removeSource - Whether to remove the source class after completion. True if yes
    • getExpandoMetaClass

      public static groovy.lang.ExpandoMetaClass getExpandoMetaClass(Class<?> aClass)
    • getMetaClass

      public static groovy.lang.MetaClass getMetaClass(Object instance)
    • getPropertyIfExists

      public static Object getPropertyIfExists(Object instance, String property)
      Obtains a property of an instance if it exists
      Parameters:
      instance - The instance
      property - The property
      Returns:
      The value of null if non-exists
    • getPropertyIfExists

      public static <T> T getPropertyIfExists(Object instance, String property, Class<T> requiredType)
      Obtains a property of an instance if it exists
      Parameters:
      instance - The instance
      property - The property
      requiredType - The required type of the property
      Returns:
      The property value
    • invokeMethodIfExists

      public static Object invokeMethodIfExists(Object instance, String methodName)
      Invokes a method if it exists otherwise returns null
      Parameters:
      instance - The instance
      methodName - The method name
      Returns:
      The result of the method call or null
    • invokeMethodIfExists

      public static Object invokeMethodIfExists(Object instance, String methodName, Object[] args)
      Invokes a method if it exists otherwise returns null
      Parameters:
      instance - The instance
      methodName - The method name
      args - The arguments
      Returns:
      The result of the method call or null