|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webmethods.caf.portalclient.util.ObjectUtil
public class ObjectUtil
ObjectUtil provides convenience functions for java reflection using
Class.forName
It also provides some System property convenience function(s) and
reflection utilities.
Nested Class Summary | |
---|---|
protected static class |
ObjectUtil.ClassLoaderObjectInputStream
|
Field Summary | |
---|---|
static String |
DOT_SIGN
Package/Class Name separator |
protected static ClassLoader |
m_classLoader
The current ClassLoader used by ObjectUtil.createObject(java.lang.String) & ObjectUtil.getClass(java.lang.String) |
protected static Map |
m_Fields
Map of object fields, used for property caching |
protected static Map |
m_Properties
Map of object properties, used for property caching |
protected static boolean |
m_UsePropertyCache
Use the property cache when resolving properties via reflection |
protected static Object |
NOT_CACHED_CLASS
Class used when unable to resolve a cached property |
Constructor Summary | |
---|---|
ObjectUtil()
|
Method Summary | |
---|---|
static Object |
clone(Object object)
Clone an object that implements serializable |
static int |
compare(Object o1,
Object o2)
Compares two object. |
static Object[] |
convertListTypes(Class[] types,
Object[] values)
Converts source object value to the target type |
static Object |
convertToPropertyType(Object anInstance,
String aPropertyName,
String aStringValue)
|
static Object |
convertToType(Object srcObj,
Class targetType)
Converts source object value to the target type |
static Object |
createObject(String className)
A class factory method that uses the pluggable classLoader: ObjectUtil.m_classLoader
Note, all exceptions are caught |
static Object |
createObject(String className,
Object[] parms)
A class factory method that uses the pluggable classLoader: ObjectUtil.m_classLoader
Note, all exceptions are caught |
static boolean |
equal(Object obj1,
Object obj2)
Simply compares two objects using equals() method and takes care about nulls null == null = false |
static void |
flushPropertyDescriptorCache()
Clears the property descriptors cache NOTE: needs to be called after cached classes are reloaded |
static Object |
getCachedPropertyDescriptor(Object anInstance,
String aPropertyName)
Returns cached property descriptor from the cache. |
static Class |
getClass(String className)
A class factory method that uses the pluggable classLoader: ObjectUtil.m_classLoader |
static ClassLoader |
getClassLoader()
Get the current classloader, using the classloader of the current thread if not found |
static Constructor |
getConstructor(Class clazz,
Object[] args)
Get a constructor for a class that uses the given set of arguments |
static List |
getEnumerationValues(Class type)
Retrieve a list of all the possible values for the given enumeration type |
static Field |
getField(Class klass,
String property)
|
static Object |
getField(Object instance,
String name)
Retrieves a data field, potentially defined by a super class. |
static Field |
getFieldDescriptor(Class cls,
String property)
Returns field descriptor of the selected property for the selected object instance. |
static Method |
getMatchingMethod(Class clas,
String methodName,
List arguments)
|
static int |
getNamedValue(Class clazz,
String name)
use some reflection to get the named property |
static Object |
getPrivilegedProperty(Object instance,
String propertyName)
Retrieves a privilged property |
static Object |
getPrivilegedStaticProperty(Class clazz,
String propertyName)
Retrieves a privilged property from a static class |
static Map |
getProperties(Object instance)
|
static Object |
getProperty(Object anInstance,
String aPropertyName)
Obtains a value of the property specified by name for the specified instance |
static boolean |
getPropertyAsBoolean(Object sourceObj,
String propertyName,
boolean defaultValue)
|
static int |
getPropertyAsInt(Object sourceObj,
String propertyName,
int defaultValue)
|
static String |
getPropertyAsString(Object sourceObj,
String propertyName,
String defaultValue)
|
static PropertyDescriptor |
getPropertyDescriptor(Object anInstance,
String aPropertyName)
Returns property descriptor of the selected property for the selected object instance. |
static PropertyDescriptor[] |
getPropertyDescriptors(Class instanceClass)
Returns property descriptor list for a given object class selected object instance. |
static Object |
getPropertyOrFieldValue(Object target,
String property)
Obtains object property via getter method (preferred), or directly via member field. |
static Object |
getStaticProperty(Class clazz,
String fieldName)
Returns the named static variable. |
static boolean |
hadValueChange(Object oldValue,
Object newValue)
Checks wether there was a change in the value |
static boolean |
isArray(Object toCheck)
Checks whether given instance is an array |
static boolean |
isArrayOf(Object toCheck,
Class arrayItem)
Checks whether given instance is an array of the given classes |
static boolean |
isEnumeration(Class type)
Determine if the given class is an enumeration |
static String |
justClassName(String aFullClassName)
Return short class name without package names |
static Object |
load(byte[] buffer)
Load an object from an array of bytes. |
static Object |
load(InputStream in)
Load an object from an inputstream |
static Object |
load(InputStream in,
ClassLoader cl)
|
static byte[] |
save(Object object)
Serialize an object to an array of bytes. |
static void |
setClassLoader(ClassLoader classLoader)
Set the classloader to be used by this ObjectUtil instance |
static boolean |
setPrivilegedProperty(Object instance,
Class clazz,
String propertyName,
Object value)
Gets a priviledged property from an object |
static boolean |
setPrivilegedProperty(Object instance,
String propertyName,
Object value)
Gets a priviledged property from an object |
static boolean |
setPrivilegedStaticProperty(Class clazz,
String propertyName,
Object value)
Gets a priviledged property from a static class |
static void |
setPropertiesBatch(Object anInstance,
Map propertyValues)
|
static void |
setPropertiesByMap(Object fromObject,
Object toObject,
String[][] propMap,
boolean reverse)
Sets object properties using translation map to resolve property names |
static void |
setProperty(Object anInstance,
String aPropertyName,
Object aValue)
Set's a particular property of the instance Usage:
SomeBean bean = new SomeBean();
Integer propertyValue = new Integer(10);
ClassTools.setProperty(bean, "propertyName", propertyValue);
is in fact equal to
bean.setPropertyValue(propertyValue);
Simple types are also supported
int propertyValue = 10;
ClassTools.setProperty(bean, "intPropertyName", new Integer(propertyValue));
|
static boolean |
setPropertyByString(Object anInstance,
String aPropertyName,
String aStringValue)
Set's a particular property of the instance by string value Usage: SomeBean bean = new SomeBean(); ObjectUtil.setPropertyByString(bean, "someProperty", "10"); |
static void |
setStaticProperty(Class clazz,
String fieldName,
Object value)
Sets a value into static member of the class |
static Object |
StringToValue(String s,
Class t)
Deprecated. use ObjectUtil.convertToType(Object, Class) instead |
static String |
toString(String comment,
Object instance)
|
static String |
toString(String comment,
Object instance,
boolean filterNulls)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DOT_SIGN
protected static ClassLoader m_classLoader
ObjectUtil.createObject(java.lang.String)
& ObjectUtil.getClass(java.lang.String)
protected static boolean m_UsePropertyCache
protected static Map m_Properties
protected static Map m_Fields
protected static final Object NOT_CACHED_CLASS
Constructor Detail |
---|
public ObjectUtil()
Method Detail |
---|
public static Object createObject(String className)
ObjectUtil.m_classLoader
Note, all exceptions are caught
className
-
ObjectUtil.getClass(java.lang.String)
public static Object createObject(String className, Object[] parms)
ObjectUtil.m_classLoader
Note, all exceptions are caught
className
- the class to create an instance ofparms
- the parameter array to pass to the object constructor
ObjectUtil.getClass(java.lang.String)
public static Constructor getConstructor(Class clazz, Object[] args)
clazz
- the class to retrieve the constructor forargs
- the arguments to be passed the constructor
public static Class getClass(String className) throws ClassNotFoundException
ObjectUtil.m_classLoader
className
-
ClassNotFoundException
ObjectUtil.createObject(java.lang.String)
public static ClassLoader getClassLoader()
ObjectUtil.m_classLoader
if set, the default ClassLoader otherwiseObjectUtil.m_classLoader
public static void setClassLoader(ClassLoader classLoader)
classLoader
- ObjectUtil.m_classLoader
public static Object StringToValue(String s, Class t)
ObjectUtil.convertToType(Object, Class)
instead
s
- the source string to convertt
- the Class to attempt to convert the string to
public static boolean isArrayOf(Object toCheck, Class arrayItem)
toCheck
- the Object to check for typearrayItem
- the Class to check if the object is an array of
public static boolean isArray(Object toCheck)
toCheck
- the object to determine is an array
public static Object getCachedPropertyDescriptor(Object anInstance, String aPropertyName)
anInstance
- the object instance to get properties foraPropertyName
- the name of the property to retrieve the descriptor for
public static void flushPropertyDescriptorCache()
public static Field getFieldDescriptor(Class cls, String property) throws Exception
cls
- the class to get the field descriptor fromproperty
- the property name of the descriptor
Exception
public static PropertyDescriptor getPropertyDescriptor(Object anInstance, String aPropertyName) throws RuntimeException
anInstance
-
RuntimeException
public static PropertyDescriptor[] getPropertyDescriptors(Class instanceClass)
instanceClass
-
public static void setProperty(Object anInstance, String aPropertyName, Object aValue) throws Exception
SomeBean bean = new SomeBean();
Integer propertyValue = new Integer(10);
ClassTools.setProperty(bean, "propertyName", propertyValue);
is in fact equal to
bean.setPropertyValue(propertyValue);
Simple types are also supported
int propertyValue = 10;
ClassTools.setProperty(bean, "intPropertyName", new Integer(propertyValue));
Exception
public static boolean setPropertyByString(Object anInstance, String aPropertyName, String aStringValue)
public static Object getPropertyOrFieldValue(Object target, String property) throws Exception
Exception
public static Object getProperty(Object anInstance, String aPropertyName) throws RuntimeException
anInstance
-
RuntimeException
public static Object getStaticProperty(Class clazz, String fieldName)
Object value = ObjectUtil.getStaticProperty(metaUtilClass, "PUBLIC");
public static void setStaticProperty(Class clazz, String fieldName, Object value)
clazz
- source classfieldName
- field namevalue
- value to be setpublic static Object convertToPropertyType(Object anInstance, String aPropertyName, String aStringValue)
public static Map getProperties(Object instance)
public static void setPropertiesBatch(Object anInstance, Map propertyValues)
public static boolean hadValueChange(Object oldValue, Object newValue)
public static String justClassName(String aFullClassName)
public static Object clone(Object object) throws CloneNotSupportedException
object
- Instance of object to clone
CloneNotSupportedException
public static boolean equal(Object obj1, Object obj2)
public static byte[] save(Object object)
object
- the object to serialize. Must implement Serializable
public static Object load(byte[] buffer)
buffer
- the array of bytes that constitute the object
public static Object load(InputStream in, ClassLoader cl)
public static Object load(InputStream in)
in
- the InputStream that constitute the object
public static boolean setPrivilegedProperty(Object instance, String propertyName, Object value) throws IllegalAccessException
IllegalAccessException
public static boolean setPrivilegedProperty(Object instance, Class clazz, String propertyName, Object value) throws IllegalAccessException
IllegalAccessException
public static Object getPrivilegedProperty(Object instance, String propertyName) throws IllegalAccessException
IllegalAccessException
public static Object getField(Object instance, String name) throws IllegalAccessException
IllegalAccessException
public static Field getField(Class klass, String property)
public static boolean setPrivilegedStaticProperty(Class clazz, String propertyName, Object value) throws IllegalAccessException
IllegalAccessException
public static Object getPrivilegedStaticProperty(Class clazz, String propertyName) throws IllegalAccessException
IllegalAccessException
public static String toString(String comment, Object instance, boolean filterNulls)
public static String toString(String comment, Object instance)
public static int getNamedValue(Class clazz, String name)
ObjectUtil.getStaticProperty(java.lang.Class, java.lang.String)
public static void setPropertiesByMap(Object fromObject, Object toObject, String[][] propMap, boolean reverse) throws RuntimeException
fromObject
- toObject
- propMap
- reverse
-
RtlException
RuntimeException
public static int compare(Object o1, Object o2)
o1
- o2
-
public static boolean isEnumeration(Class type)
type
- the class to check
public static List getEnumerationValues(Class type) throws RuntimeException
type
-
RuntimeException
public static Method getMatchingMethod(Class clas, String methodName, List arguments)
public static Object[] convertListTypes(Class[] types, Object[] values) throws RuntimeException
RuntimeException
public static Object convertToType(Object srcObj, Class targetType) throws RuntimeException
RuntimeException
public static boolean getPropertyAsBoolean(Object sourceObj, String propertyName, boolean defaultValue)
public static int getPropertyAsInt(Object sourceObj, String propertyName, int defaultValue)
public static String getPropertyAsString(Object sourceObj, String propertyName, String defaultValue)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |