|
||||||||||
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 |
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 boolean |
getBooleanFromMap(String key,
Map map)
Retrieves a boolean value from a Map for the given key |
static String |
getClassName(String logicalName,
String trailingName)
Returns the class name for the given logical name and trailing name. |
static String |
getClassNameRepresentation(String name)
Returns the class name representation of the given name |
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)
Retrieves the logical class name of a Grails artifact given the Grails class and a specified trailing name |
static String |
getLogicalName(String name,
String trailingName)
Retrieves the logical name of the classs without the trailing name |
static String |
getLogicalPropertyName(String className,
String trailingName)
|
static String |
getNameFromScript(String scriptName)
Calculates the class name from a script name in the form my-funk-grails-script |
static String |
getNaturalName(String name)
Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name') |
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)
Shorter version of getPropertyNameRepresentation |
static String |
getPropertyName(String name)
Shorter version of getPropertyNameRepresentation |
static String |
getPropertyNameForLowerCaseHyphenSeparatedName(String name)
Converts foo-bar into fooBar |
static String |
getPropertyNameRepresentation(Class targetClass)
Returns the property name equivalent for the specified class |
static String |
getPropertyNameRepresentation(String name)
Returns the property name representation of the given name |
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)
Retrieves the script name representation of the supplied class. |
static String |
getScriptName(String name)
|
static String |
getSetterName(String propertyName)
Retrieves the name of a setter for the specified property name |
static String |
getShortName(Class targetClass)
Returns the class name without the package prefix |
static String |
getShortName(String className)
Returns the class name without the package prefix |
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 |
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 |
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 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 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)
targetClass
- The class to get a short name for
public static String getShortName(String className)
className
- The class name to get a short name for
public static String getPropertyNameRepresentation(Class targetClass)
targetClass
- The class to get the property name for
public static String getPropertyNameRepresentation(String name)
name
- The name to convert
public static String getClassNameRepresentation(String name)
name
- The name to convert
public static String getPropertyName(String name)
name
- The name to convert
public static String getPropertyName(Class clazz)
clazz
- The clazz to convert
public static String getScriptName(Class clazz)
clazz
- The class to convert
public static String getScriptName(String name)
public static String getNameFromScript(String scriptName)
scriptName
- The script name
public static String getPropertyNameForLowerCaseHyphenSeparatedName(String name)
name
- The lower case hyphen separated name
public static String getNaturalName(String name)
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)
clazz
- The classtrailingName
- The trailing name such as "Controller" or "TagLib"
public static String getLogicalName(String name, String trailingName)
name
- The name of the classtrailingName
- The trailing name
public static String getLogicalPropertyName(String className, String trailingName)
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)
logicalName
- The logical nametrailingName
- The trailing name
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |