|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webmethods.caf.common.ObjectUtil
public class ObjectUtil
Utility class to deal with different objects Certain functions can be converting object type x to object type y Checking if an object can be converted State checking of an object etc.
Field Summary | |
---|---|
static String |
BOOLEAN_FALSE
String variable 'false' |
static String |
BOOLEAN_NO
String variable 'no' |
static String |
BOOLEAN_OFF
String variable 'off' |
static String |
BOOLEAN_ON
String variable 'on' |
static String |
BOOLEAN_TRUE
String variable 'true' |
static String |
BOOLEAN_YES
String variable 'yes' |
static String |
CLASS_KEY
String for class key |
Constructor Summary | |
---|---|
ObjectUtil()
|
Method Summary | |
---|---|
static Object |
clone(Object object)
Clone an object that implements serializable |
static Object |
cloneObjectFromMap(Map map,
Class objectClass,
String[] properties,
boolean createDefComplexTypes)
Clones an object from Map |
static Object |
cloneObjectFromMap(Map map,
Class objectClass,
String[] properties,
boolean createDefComplexTypes,
boolean useRealFieldNames)
Clones an object from Map |
static Object |
cloneObjectToMap(Object object,
String[] properties)
Clones object to the Map implementation contains |
static Object |
cloneObjectToMap(Object object,
String[] properties,
boolean useRealFieldNames)
Clones object to the Map implementation contains |
static void |
closeURLClassLoader(URLClassLoader classLoader,
boolean ignoreExceptions)
Tries to close opened by URLClassLoader jars to release file lock that causes problems during hot deployment |
static Object |
convertToType(Object srcObj,
Class targetType)
Converts source object value to the target type |
static Object |
convertToType(Object srcObj,
Class targetType,
boolean throwsError)
Converts source object value to the target type |
static boolean |
equal(Object obj1,
Object obj2)
Simply compares two objects using equals() method and takes care about nulls null == null = false |
static PropertyDescriptor |
findPropertyDescriptor(PropertyDescriptor[] anArray,
String aPropertyName)
Finds a specific PropertyDescriptor from an array of PropertyDescriptor. |
static void |
flushClassCache()
Flushes internal Class cache. |
static Class |
getClass(String className)
A class factory method that uses the pluggable classLoader: ObjectUtil.m_classLoader |
static ClassLoader |
getClassLoader()
Gets classLoader |
static IDocumentStructureProvider |
getJavaClassStructure(Class clas)
Grabs Java class structure of specific class in DocumentStuctureProdiver structure. |
static PropertyDescriptor |
getPropertyDescriptor(Object anInstance,
String aPropertyName)
Finds the property descriptor of an object and specific property name. |
static PropertyDescriptor[] |
getPropertyDescriptors(Class instanceClass)
Returns property descriptor list for a given object class selected object instance. |
static Object |
getPropertyValue(Object anInstance,
String aPropertyName)
Gets a property of an instance based on a property name |
static Object |
getStaticProperty(Class clazz,
String fieldName)
Returns the named static variable. |
static boolean |
isAssignableFrom(Class to,
Class from)
Extends Class.isAssignableFrom(Class) to work with primitives. |
static boolean |
isAssignableFromObject(Class to,
Object from)
Extends Class.isAssignableFrom(Class) to work with primitives. |
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(InputStream in,
ClassLoader cl)
Load an object from an inputstream |
static boolean |
mapEqual(Map map1,
Map map2)
Special version of equals function for Maps, designed specifically to compare maps produced from cloneObjectToMap() methods. |
static Object |
newInstance(Class _class)
Creates new object instance handling for privimite types |
static void |
setClassLoader(ClassLoader classLoader)
Sets given classLoader |
static void |
setPropertiesBatch(Object anInstance,
Map propertyValues)
Add multiple properties to a object at once. |
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 |
setPropertyValue(Object anInstance,
String aPropertyName,
Object value)
Sets property value of an instance with a value and name. |
static void |
setStaticProperty(Class clazz,
String fieldName,
Object value)
Sets a value into static member of the class |
static void |
sortObjectArray(Object[] objects,
String propName,
boolean ascending)
Sorts passed in object array according to natural order of specified object property |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String BOOLEAN_TRUE
public static final String BOOLEAN_FALSE
public static final String BOOLEAN_YES
public static final String BOOLEAN_NO
public static final String BOOLEAN_ON
public static final String BOOLEAN_OFF
public static final String CLASS_KEY
Constructor Detail |
---|
public ObjectUtil()
Method Detail |
---|
public static Class getClass(String className) throws ClassNotFoundException
ObjectUtil.m_classLoader
className
-
ClassNotFoundException
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 convertToType(Object srcObj, Class targetType) throws CommonException
CommonException
ObjectUtil.convertToType(java.lang.Object, java.lang.Class)
public static Object convertToType(Object srcObj, Class targetType, boolean throwsError) throws CommonException
srcObj
- object to be convertedtargetType
- class type to convert tothrowsError
- if true, throw errors
CommonException
public static boolean isAssignableFromObject(Class to, Object from)
Class.isAssignableFrom(Class)
to work with primitives.
to
- Class we want to assign object tofrom
- object we are checking if it can be assigned to 'to' class
public static boolean isAssignableFrom(Class to, Class from)
Class.isAssignableFrom(Class)
to work with primitives.
Returns true if the first argument is assignable from the second.
public static boolean isEnumeration(Class type)
type
- the class to check
public static void setPropertiesBatch(Object anInstance, Map propertyValues) throws Exception
anInstance
- Object properties are being added topropertyValues
- map containing property names and values
Exception
public static boolean setPropertyByString(Object anInstance, String aPropertyName, String aStringValue) throws Exception
Exception
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 Object getStaticProperty(Class clazz, String fieldName) throws Exception
Object value = ObjectUtil.getStaticProperty(metaUtilClass, "PUBLIC");
Exception
public static void setStaticProperty(Class clazz, String fieldName, Object value) throws Exception
clazz
- source classfieldName
- field namevalue
- value to be set
Exception
public static Object getPropertyValue(Object anInstance, String aPropertyName) throws Exception
anInstance
- object that we are getting property ofaPropertyName
- property name we are looking for
Exception
public static void setPropertyValue(Object anInstance, String aPropertyName, Object value) throws Exception
anInstance
- Object we are setting property foraPropertyName
- name of propertyvalue
- value of property
Exception
public static PropertyDescriptor getPropertyDescriptor(Object anInstance, String aPropertyName) throws IntrospectionException
anInstance
- null or objectaPropertyName
- String used to find result
IntrospectionException
public static PropertyDescriptor[] getPropertyDescriptors(Class instanceClass) throws IntrospectionException
instanceClass
-
IntrospectionException
public static PropertyDescriptor findPropertyDescriptor(PropertyDescriptor[] anArray, String aPropertyName)
anArray
- array or nullaPropertyName
- Property specific name
public static Object cloneObjectToMap(Object object, String[] properties) throws Exception
object
- the object to cloneproperties
- selected top level properties of an object will be cloned
PortalException
Exception
public static Object cloneObjectToMap(Object object, String[] properties, boolean useRealFieldNames) throws Exception
object
- the object to cloneproperties
- selected top level properties of an object will be cloned
PortalException
Exception
public static Object cloneObjectFromMap(Map map, Class objectClass, String[] properties, boolean createDefComplexTypes) throws Exception
map
- objectClass
- properties
- allowed properties to clone
PortalException
Exception
public static Object cloneObjectFromMap(Map map, Class objectClass, String[] properties, boolean createDefComplexTypes, boolean useRealFieldNames) throws Exception
map
- objectClass
- properties
- allowed properties to clone
PortalException
Exception
public static Object clone(Object object) throws CloneNotSupportedException
object
- Instance of object to clone
CloneNotSupportedException
public static void flushClassCache() throws Exception
Exception
public static IDocumentStructureProvider getJavaClassStructure(Class clas) throws Exception
clas
- null or Class
Exception
public static boolean equal(Object obj1, Object obj2)
public static boolean mapEqual(Map map1, Map map2)
map1
- map2
- public static String justClassName(String aFullClassName)
public static void sortObjectArray(Object[] objects, String propName, boolean ascending) throws Exception
propName
- object property name to be sortedascending
- sort order
Exception
public static Object newInstance(Class _class) throws Exception
_class
- primitive class, like Integer, String, Float, etc
Exception
- if className is invalidpublic static void closeURLClassLoader(URLClassLoader classLoader, boolean ignoreExceptions) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, IOException
classLoader
- URLClassLoader instanceignoreExceptions
- if true fail on first exception, if false, ignore errors and continue
NoSuchFieldException
IllegalAccessException
IOException
ClassNotFoundException
public static Object load(InputStream in, ClassLoader cl)
in
- the InputStream that constitute the object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |