public class GrailsClassUtils extends java.lang.Object
Utility methods for dealing with Grails class artifacts.
Modifiers | Name | Description |
---|---|---|
static java.util.Map<java.lang.Class<?>, java.lang.Class<?>> |
PRIMITIVE_TYPE_COMPATIBLE_CLASSES |
Type Params | Return Type | Name and description |
---|---|---|
|
public static java.lang.Object[] |
collectionToObjectArray(java.util.Collection c) Convenience method for converting a collection to an Object[] |
|
public static java.util.Collection |
createConcreteCollection(java.lang.Class interfaceType) Creates a concrete collection for the suppied interface |
|
public static org.springframework.cglib.reflect.FastClass |
fastClass(java.lang.Class superClass) |
|
public static java.lang.String |
findPropertyNameForValue(java.lang.Object target, java.lang.Object obj) Locates the name of a property for the given value on the target object using Groovy's meta APIs. |
|
public static java.lang.Class[] |
getAllInterfaces(java.lang.Object instance) Return all interfaces that the given instance implements as array, including ones implemented by superclasses. |
|
public static java.util.Set<java.lang.Class> |
getAllInterfacesAsSet(java.lang.Object instance) Return all interfaces that the given instance implements as Set, including ones implemented by superclasses. |
|
public static java.lang.Class<?>[] |
getAllInterfacesForClass(java.lang.Class<?> clazz) Return all interfaces that the given class implements as array, including ones implemented by superclasses. |
|
public static java.lang.Class<?>[] |
getAllInterfacesForClass(java.lang.Class<?> clazz, java.lang.ClassLoader classLoader) Return all interfaces that the given class implements as array, including ones implemented by superclasses. |
|
public static java.util.Set<java.lang.Class> |
getAllInterfacesForClassAsSet(java.lang.Class clazz) Return all interfaces that the given class implements as Set, including ones implemented by superclasses. |
|
public static java.util.Set<java.lang.Class> |
getAllInterfacesForClassAsSet(java.lang.Class clazz, java.lang.ClassLoader classLoader) Return all interfaces that the given class implements as Set, including ones implemented by superclasses. |
|
public static boolean |
getBooleanFromMap(java.lang.String key, java.util.Map<?, ?> map) Retrieves a boolean value from a Map for the given key |
|
public static boolean |
getBooleanFromMap(java.lang.String key, java.util.Map<?, ?> map, boolean defaultValue) Retrieves a boolean value from a Map for the given key |
|
public static groovy.lang.MetaClass |
getExpandoMetaClass(java.lang.Class clazz) |
|
public static java.lang.Object |
getFieldValue(java.lang.Object obj, java.lang.String name) Get the value of a declared field on an object |
|
public static java.lang.String |
getGetterName(java.lang.String propertyName) Calculate the name for a getter method to retrieve the specified property |
|
public static java.beans.PropertyDescriptor[] |
getPropertiesAssignableToType(java.lang.Class<?> clazz, java.lang.Class<?> propertySuperType) Retrieves all the properties of the given class which are assignable to the given type |
|
public static java.beans.PropertyDescriptor[] |
getPropertiesOfType(java.lang.Class<?> clazz, java.lang.Class<?> propertyType) Retrieves all the properties of the given class for the given type |
|
public static java.beans.PropertyDescriptor |
getProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> propertyType) Retrieves a property of the given class of the specified name and type |
|
public static java.beans.PropertyDescriptor |
getProperty(java.lang.Class<?> clazz, java.lang.String propertyName) Retrieves a property of the given class of the specified name and type |
|
public static java.beans.PropertyDescriptor |
getPropertyDescriptorForValue(java.lang.Object instance, java.lang.Object propertyValue) Retrieves a PropertyDescriptor for the specified instance and property value |
|
public static java.lang.String |
getPropertyForGetter(java.lang.String getterName) Returns a property name equivalent for the given getter name or null if it is not a valid getter. |
|
public static java.lang.String |
getPropertyForGetter(java.lang.String getterName, java.lang.Class returnType) Returns a property name equivalent for the given getter name and return type or null if it is not a valid getter. |
|
public static java.lang.String |
getPropertyForGetter(java.lang.String getterName, java.lang.String returnType) Returns a property name equivalent for the given getter name and return type or null if it is not a valid getter. |
|
public static java.lang.String |
getPropertyForSetter(java.lang.String setterName) Returns a property name equivalent for the given setter name or null if it is not a valid setter. |
|
public static java.lang.Object |
getPropertyOrStaticPropertyOrFieldValue(java.lang.Object obj, java.lang.String name) |
|
public static java.lang.Object |
getPropertyOrStaticPropertyOrFieldValue(org.springframework.beans.BeanWrapper ref, java.lang.Object obj, java.lang.String name) |
|
public static java.lang.Class<?> |
getPropertyType(java.lang.Class<?> clazz, java.lang.String propertyName) Returns the type of the given property contained within the specified class |
|
public static java.lang.Object |
getPropertyValueOfNewInstance(java.lang.Class clazz, java.lang.String propertyName, java.lang.Class<?> propertyType) Returns the value of the specified property and type from an instance of the specified Grails class |
|
public static java.lang.Object |
getPropertyValueOfNewInstance(java.lang.Class<?> clazz, java.lang.String propertyName) Returns the value of the specified property and type from an instance of the specified Grails class |
|
public static java.lang.String |
getSetterName(java.lang.String propertyName) Retrieves the name of a setter for the specified property name |
|
public static java.lang.Object |
getStaticFieldValue(java.lang.Class<?> clazz, java.lang.String name) |
|
public static java.lang.Object |
getStaticPropertyValue(java.lang.Class<?> clazz, java.lang.String name) |
|
public static java.lang.Boolean |
hasBeenEnhancedForFeature(java.lang.Class<?> controllerClass, java.lang.String featureName) Checks to see if a class is marked with
|
|
public static java.lang.Object |
instantiateFromConfig(groovy.util.ConfigObject config, java.lang.String configKey, java.lang.String defaultClassName) |
|
public static java.lang.Object |
instantiateFromFlatConfig(java.util.Map<java.lang.String, java.lang.Object> flatConfig, java.lang.String configKey, java.lang.String defaultClassName) |
|
public static boolean |
isAssignableOrConvertibleFrom(java.lang.Class<?> clazz, java.lang.Class<?> type) Returns true if the specified clazz parameter is either the same as, or is a superclass or superinterface of, the specified type parameter. |
|
public static boolean |
isClassBelowPackage(java.lang.Class<?> theClass, java.util.List<?> packageList) Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages |
|
public static boolean |
isGetter(java.lang.String name, java.lang.Class<?>[] args) Returns true if the name of the method specified and the number of arguments make it a javabean property getter. |
|
public static boolean |
isGetter(java.lang.String name, java.lang.Class returnType, java.lang.Class<?>[] args) Returns true if the name of the method specified and the number of arguments make it a javabean property getter. |
|
public static boolean |
isGroovyAssignableFrom(java.lang.Class<?> leftType, java.lang.Class<?> rightType) |
|
public static boolean |
isMatchBetweenPrimativeAndWrapperTypes(java.lang.Class leftType, java.lang.Class rightType) Detect if left and right types are matching types. |
|
public static boolean |
isPropertyGetter(java.lang.reflect.Method method) Check whether the specified method is a property getter |
|
public static boolean |
isPropertyInherited(java.lang.Class clz, java.lang.String propertyName) Checks whether the specified property is inherited from a super class |
|
public static boolean |
isPropertyOfType(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> type) Returns true if the specified property in the specified class is of the specified type |
|
public static boolean |
isPublicField(java.lang.Object obj, java.lang.String name) Work out if the specified object has a public field with the name supplied. |
|
public static boolean |
isPublicStatic(java.lang.reflect.Method m) Determine whether the method is declared public static |
|
public static boolean |
isPublicStatic(java.lang.reflect.Field f) Determine whether the field is declared public static |
|
public static boolean |
isSetter(java.lang.String name, java.lang.Class[] args) Returns true if the name of the method specified and the number of arguments make it a javabean property setter. |
|
public static boolean |
isStaticProperty(java.lang.Class clazz, java.lang.String propertyName) |
|
public static boolean |
isVisible(java.lang.Class<?> clazz, java.lang.ClassLoader classLoader) Check whether the given class is visible in the given ClassLoader. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Convenience method for converting a collection to an Object[]
c
- The collectionCreates a concrete collection for the suppied interface
interfaceType
- The interfaceLocates the name of a property for the given value on the target object using Groovy's meta APIs. Note that this method uses the reference so the incorrect result could be returned for two properties that refer to the same reference. Use with caution.
target
- The targetobj
- The property valueReturn all interfaces that the given instance implements as array, including ones implemented by superclasses.
instance
- the instance to analyze for interfacesReturn all interfaces that the given instance implements as Set, including ones implemented by superclasses.
instance
- the instance to analyze for interfacesReturn all interfaces that the given class implements as array, including ones implemented by superclasses.
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyze for interfacesReturn all interfaces that the given class implements as array, including ones implemented by superclasses.
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyze for interfacesclassLoader
- the ClassLoader that the interfaces need to be visible in
(may be null
when accepting all declared interfaces)Return all interfaces that the given class implements as Set, including ones implemented by superclasses.
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyze for interfacesReturn all interfaces that the given class implements as Set, including ones implemented by superclasses.
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyze for interfacesclassLoader
- the ClassLoader that the interfaces need to be visible in
(may be null
when accepting all declared interfaces)Retrieves a boolean value from a Map for the given key
key
- The key that references the boolean valuemap
- The map to look inRetrieves a boolean value from a Map for the given key
key
- The key that references the boolean valuemap
- The map to look inGet the value of a declared field on an object
Calculate the name for a getter method to retrieve the specified property
Retrieves all the properties of the given class which are assignable to the given type
clazz
- The class to retrieve the properties frompropertySuperType
- The type of the properties you wish to retrieveRetrieves all the properties of the given class for the given type
clazz
- The class to retrieve the properties frompropertyType
- The type of the properties you wish to retrieveRetrieves a property of the given class of the specified name and type
clazz
- The class to retrieve the property frompropertyName
- The name of the propertypropertyType
- The type of the propertyRetrieves a property of the given class of the specified name and type
clazz
- The class to retrieve the property frompropertyName
- The name of the propertyRetrieves a PropertyDescriptor for the specified instance and property value
instance
- The instancepropertyValue
- The value of the propertyReturns a property name equivalent for the given getter name or null if it is not a valid getter. If not null or empty the getter name is assumed to be a valid identifier.
getterName
- The getter nameReturns a property name equivalent for the given getter name and return type or null if it is not a valid getter. If not null or empty the getter name is assumed to be a valid identifier.
getterName
- The getter namereturnType
- The type the method returnsReturns a property name equivalent for the given getter name and return type or null if it is not a valid getter. If not null or empty the getter name is assumed to be a valid identifier.
getterName
- The getter namereturnType
- The class name the method returnsReturns a property name equivalent for the given setter name or null if it is not a valid setter. If not null or empty the setter name is assumed to be a valid identifier.
setterName
- The setter name, must be null or empty or a valid identifier name
Looks for a property of the reference instance with a given name.
If found its value is returned. We follow the Java bean conventions with augmentation for groovy support and static fields/properties. We will therefore match, in this order:
Returns the type of the given property contained within the specified class
clazz
- The class which contains the propertypropertyName
- The name of the propertyReturns the value of the specified property and type from an instance of the specified Grails class
clazz
- The name of the class which contains the propertypropertyName
- The property namepropertyType
- The property typeReturns the value of the specified property and type from an instance of the specified Grails class
clazz
- The name of the class which contains the propertypropertyName
- The property nameRetrieves the name of a setter for the specified property name
propertyName
- The property name
Get a static field value.
clazz
- The class to check for static propertyname
- The field name
Get a static property value, which has a public static getter or is just a public static field.
clazz
- The class to check for static propertyname
- The property nameChecks to see if a class is marked with
controllerClass
- The class to inspectfeatureName
- The name of a feature to check forReturns true if the specified clazz parameter is either the same as, or is a superclass or superinterface of, the specified type parameter. Converts primitive types to compatible class automatically.
Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages
theClass
- The classpackageList
- The list of packagesReturns true if the name of the method specified and the number of arguments make it a javabean property getter. The name is assumed to be a valid Java method name, that is not verified.
name
- The name of the methodargs
- The argumentsReturns true if the name of the method specified and the number of arguments make it a javabean property getter. The name is assumed to be a valid Java method name, that is not verified.
name
- The name of the methodreturnType
- The return type of the methodargs
- The arguments
Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e. can the left type be assigned a value of the right hand type in Groovy.
This handles Java primitive type equivalence and uses isAssignableFrom for all other types, with a bit of magic for native types and polymorphism i.e. Number assigned an int. If either parameter is null an exception is thrown
leftType
- The type of the left hand part of a notional assignmentrightType
- The type of the right hand part of a notional assignmentDetect if left and right types are matching types. In particular, test if one is a primitive type and the other is the corresponding Java wrapper type. Primitive and wrapper classes may be passed to either arguments.
Check whether the specified method is a property getter
method
- The methodChecks whether the specified property is inherited from a super class
clz
- The class to checkpropertyName
- The property nameReturns true if the specified property in the specified class is of the specified type
clazz
- The class which contains the propertypropertyName
- The property nametype
- The type to checkWork out if the specified object has a public field with the name supplied.
Determine whether the method is declared public static
Determine whether the field is declared public static
Returns true if the name of the method specified and the number of arguments make it a javabean property setter. The name is assumed to be a valid Java method name, that is not verified.
name
- The name of the methodargs
- The arguments
Work out if the specified property is readable and static. Java introspection does not recognize this concept of static properties but Groovy does. We also consider public static fields as static properties with no getters/setters
clazz
- The class to check for static propertypropertyName
- The property nameCheck whether the given class is visible in the given ClassLoader.
clazz
- the class to check (typically an interface)classLoader
- the ClassLoader to check against (may be null
,
in which case this method will always return true
)