|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.grails.commons.GrailsClassUtils
public class GrailsClassUtils
Field Summary | |
---|---|
static Map<Class<?>,Class<?>> |
PRIMITIVE_TYPE_COMPATIBLE_CLASSES
|
Constructor Summary | |
---|---|
GrailsClassUtils()
|
Method Summary | |
---|---|
static Object[] |
collectionToObjectArray(Collection c)
Convenience method for converting a collection to an Object[] |
static Collection |
createConcreteCollection(Class interfaceType)
Creates a concrete collection for the suppied interface |
static String |
findPropertyNameForValue(Object target,
Object obj)
Locates the name of a property for the given value on the target object using Groovy's meta APIs. |
static boolean |
getBooleanFromMap(String key,
Map map)
Retrieves a boolean value from a Map for the given key |
static String |
getClassName(String logicalName,
String trailingName)
Deprecated. Use GrailsNameUtils.getClassName(String, String) instead. |
static String |
getClassNameRepresentation(String name)
Deprecated. Use GrailsNameUtils.getClassNameRepresentation(String) instead. |
static groovy.lang.MetaClass |
getExpandoMetaClass(Class clazz)
|
static Object |
getFieldValue(Object obj,
String name)
Get the value of a declared field on an object |
static String |
getGetterName(String propertyName)
Calculate the name for a getter method to retrieve the specified property |
static String |
getLogicalName(Class clazz,
String trailingName)
Deprecated. Use GrailsNameUtils.getLogicalName(Class, String) instead. |
static String |
getLogicalName(String name,
String trailingName)
Deprecated. Use GrailsNameUtils.getLogicalName(String, String) instead. |
static String |
getLogicalPropertyName(String className,
String trailingName)
Deprecated. Use GrailsNameUtils.getLogicalPropertyName(String, String) instead. |
static String |
getNameFromScript(String scriptName)
Deprecated. Use GrailsNameUtils.getNameFromScript(String) instead. |
static String |
getNaturalName(String name)
Deprecated. Use GrailsNameUtils.getNaturalName(String) instead. |
static PropertyDescriptor[] |
getPropertiesAssignableToType(Class<?> clazz,
Class<?> propertySuperType)
Retrieves all the properties of the given class which are assignable to the given type |
static PropertyDescriptor[] |
getPropertiesOfType(Class<?> clazz,
Class<?> propertyType)
Retrieves all the properties of the given class for the given type |
static PropertyDescriptor |
getProperty(Class<?> clazz,
String propertyName,
Class<?> propertyType)
Retrieves a property of the given class of the specified name and type |
static PropertyDescriptor |
getPropertyDescriptorForValue(Object instance,
Object propertyValue)
Retrieves a PropertyDescriptor for the specified instance and property value |
static String |
getPropertyForGetter(String getterName)
Returns a property name equivalent for the given getter name or null if it is not a getter |
static String |
getPropertyForSetter(String setterName)
Returns a property name equivalent for the given setter name or null if it is not a getter |
static String |
getPropertyName(Class clazz)
Deprecated. Use GrailsNameUtils.getPropertyName(Class) instead. |
static String |
getPropertyName(String name)
Deprecated. Use GrailsNameUtils.getPropertyName(String) instead. |
static String |
getPropertyNameForLowerCaseHyphenSeparatedName(String name)
Deprecated. Use GrailsNameUtils.getPropertyNameForLowerCaseHyphenSeparatedName(String) instead. |
static String |
getPropertyNameRepresentation(Class targetClass)
Deprecated. Use GrailsNameUtils.getPropertyNameRepresentation(Class) instead. |
static String |
getPropertyNameRepresentation(String name)
Deprecated. Use GrailsNameUtils.getPropertyNameRepresentation(String) instead. |
static Object |
getPropertyOrStaticPropertyOrFieldValue(Object obj,
String name)
Looks for a property of the reference instance with a given name. |
static Class<?> |
getPropertyType(Class<?> clazz,
String propertyName)
Returns the type of the given property contained within the specified class |
static Object |
getPropertyValueOfNewInstance(Class<?> clazz,
String propertyName)
Returns the value of the specified property and type from an instance of the specified Grails class |
static Object |
getPropertyValueOfNewInstance(Class clazz,
String propertyName,
Class<?> propertyType)
Returns the value of the specified property and type from an instance of the specified Grails class |
static String |
getScriptName(Class clazz)
Deprecated. Use GrailsNameUtils.getScriptName(Class) instead. |
static String |
getScriptName(String name)
Deprecated. Use GrailsNameUtils.getScriptName(String) instead. |
static String |
getSetterName(String propertyName)
Retrieves the name of a setter for the specified property name |
static String |
getShortName(Class targetClass)
Deprecated. Use GrailsNameUtils.getShortName(Class) instead. |
static String |
getShortName(String className)
Deprecated. Use GrailsNameUtils.getShortName(String) instead. |
static Object |
getStaticPropertyValue(Class<?> clazz,
String name)
Get a static property value, which has a public static getter or is just a public static field. |
static boolean |
isAssignableOrConvertibleFrom(Class<?> clazz,
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. |
static boolean |
isClassBelowPackage(Class<?> theClass,
List packageList)
Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages |
static boolean |
isGetter(String name,
Class<?>[] args)
Returns true if the name of the method specified and the number of arguments make it a javabean property |
static boolean |
isGroovyAssignableFrom(Class<?> leftType,
Class<?> rightType)
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. |
static boolean |
isJdk5Enum(Class<?> type)
Checks whether the given class is a JDK 1.5 enum or not |
static boolean |
isMatchBetweenPrimativeAndWrapperTypes(Class leftType,
Class rightType)
Detect if left and right types are matching types. |
static boolean |
isPropertyInherited(Class clz,
String propertyName)
Checks whether the specified property is inherited from a super class |
static boolean |
isPropertyOfType(Class<?> clazz,
String propertyName,
Class<?> type)
Returns true if the specified property in the specified class is of the specified type |
static boolean |
isPublicField(Object obj,
String name)
Work out if the specified object has a public field with the name supplied. |
static boolean |
isPublicStatic(Field f)
Determine whether the field is declared public static |
static boolean |
isPublicStatic(Method m)
Determine whether the method is declared public static |
static boolean |
isSetter(String name,
Class[] args)
|
static boolean |
isStaticProperty(Class clazz,
String propertyName)
Work out if the specified property is readable and static. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Map<Class<?>,Class<?>> PRIMITIVE_TYPE_COMPATIBLE_CLASSES
Constructor Detail |
---|
public GrailsClassUtils()
Method Detail |
---|
public static boolean isPropertyOfType(Class<?> clazz, String propertyName, Class<?> type)
clazz
- The class which contains the propertypropertyName
- The property nametype
- The type to check
public static Object getPropertyValueOfNewInstance(Class clazz, String propertyName, Class<?> propertyType)
clazz
- The name of the class which contains the propertypropertyName
- The property namepropertyType
- The property type
public static Object getPropertyValueOfNewInstance(Class<?> clazz, String propertyName)
clazz
- The name of the class which contains the propertypropertyName
- The property name
public static PropertyDescriptor getPropertyDescriptorForValue(Object instance, Object propertyValue)
instance
- The instancepropertyValue
- The value of the property
public static Class<?> getPropertyType(Class<?> clazz, String propertyName)
clazz
- The class which contains the propertypropertyName
- The name of the property
public static PropertyDescriptor[] getPropertiesOfType(Class<?> clazz, Class<?> propertyType)
clazz
- The class to retrieve the properties frompropertyType
- The type of the properties you wish to retrieve
public static PropertyDescriptor[] getPropertiesAssignableToType(Class<?> clazz, Class<?> propertySuperType)
clazz
- The class to retrieve the properties frompropertySuperType
- The type of the properties you wish to retrieve
public static PropertyDescriptor getProperty(Class<?> clazz, String propertyName, Class<?> propertyType)
clazz
- The class to retrieve the property frompropertyName
- The name of the propertypropertyType
- The type of the property
public static String getShortName(Class targetClass)
GrailsNameUtils.getShortName(Class)
instead.
targetClass
- The class to get a short name for
public static String getShortName(String className)
GrailsNameUtils.getShortName(String)
instead.
className
- The class name to get a short name for
public static String getPropertyNameRepresentation(Class targetClass)
GrailsNameUtils.getPropertyNameRepresentation(Class)
instead.
targetClass
- The class to get the property name for
public static String getPropertyNameRepresentation(String name)
GrailsNameUtils.getPropertyNameRepresentation(String)
instead.
name
- The name to convert
public static String getClassNameRepresentation(String name)
GrailsNameUtils.getClassNameRepresentation(String)
instead.
name
- The name to convert
public static String getPropertyName(String name)
GrailsNameUtils.getPropertyName(String)
instead.
name
- The name to convert
public static String getPropertyName(Class clazz)
GrailsNameUtils.getPropertyName(Class)
instead.
clazz
- The clazz to convert
public static String getScriptName(Class clazz)
GrailsNameUtils.getScriptName(Class)
instead.
clazz
- The class to convert
public static String getScriptName(String name)
GrailsNameUtils.getScriptName(String)
instead.
public static String getNameFromScript(String scriptName)
GrailsNameUtils.getNameFromScript(String)
instead.
scriptName
- The script name
public static String getPropertyNameForLowerCaseHyphenSeparatedName(String name)
GrailsNameUtils.getPropertyNameForLowerCaseHyphenSeparatedName(String)
instead.
name
- The lower case hyphen separated name
public static String getNaturalName(String name)
GrailsNameUtils.getNaturalName(String)
instead.
name
- The property name to convert
public static Object[] collectionToObjectArray(Collection c)
c
- The collection
public static boolean isMatchBetweenPrimativeAndWrapperTypes(Class leftType, Class rightType)
leftType
- rightType
-
public static boolean isGroovyAssignableFrom(Class<?> leftType, Class<?> rightType)
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 assignment
public static boolean isStaticProperty(Class clazz, String propertyName)
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 name
public static boolean isPublicStatic(Method m)
m
-
public static boolean isPublicStatic(Field f)
f
-
public static String getGetterName(String propertyName)
propertyName
-
public static Object getStaticPropertyValue(Class<?> clazz, String 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 name
public static Object getPropertyOrStaticPropertyOrFieldValue(Object obj, String name) throws BeansException
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:
BeansException
public static Object getFieldValue(Object obj, String name)
obj
- name
-
public static boolean isPublicField(Object obj, String name)
obj
- name
-
public static boolean isPropertyInherited(Class clz, String propertyName)
clz
- The class to checkpropertyName
- The property name
public static Collection createConcreteCollection(Class interfaceType)
interfaceType
- The interface
public static String getLogicalName(Class clazz, String trailingName)
GrailsNameUtils.getLogicalName(Class, String)
instead.
clazz
- The classtrailingName
- The trailing name such as "Controller" or "TagLib"
public static String getLogicalName(String name, String trailingName)
GrailsNameUtils.getLogicalName(String, String)
instead.
name
- The name of the classtrailingName
- The trailing name
public static String getLogicalPropertyName(String className, String trailingName)
GrailsNameUtils.getLogicalPropertyName(String, String)
instead.
public static String getSetterName(String propertyName)
propertyName
- The property name
public static boolean isGetter(String name, Class<?>[] args)
name
- True if its a Javabean propertyargs
- The arguments
public static String getPropertyForGetter(String getterName)
getterName
- The getter name
public static String getPropertyForSetter(String setterName)
setterName
- The setter name
public static boolean isSetter(String name, Class[] args)
public static groovy.lang.MetaClass getExpandoMetaClass(Class clazz)
public static boolean isAssignableOrConvertibleFrom(Class<?> clazz, Class<?> type)
clazz
- type
-
Class.isAssignableFrom(Class)
public static boolean getBooleanFromMap(String key, Map map)
key
- The key that references the boolean valuemap
- The map to look in
public static String getClassName(String logicalName, String trailingName)
GrailsNameUtils.getClassName(String, String)
instead.
logicalName
- The logical nametrailingName
- The trailing name
public static boolean isJdk5Enum(Class<?> type)
type
- The class to check
public static String findPropertyNameForValue(Object target, Object obj)
target
- The targetobj
- The property value
public static boolean isClassBelowPackage(Class<?> theClass, List packageList)
theClass
- The classpackageList
- The list of packages
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |