public class ObjectUtil extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ObjectUtil.ClassLoaderObjectInputStream
Protected inner class that load objects from an input stream.
|
Modifier and Type | Field and Description |
---|---|
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
|
protected static Map<String,Object> |
CLASS_NAMES_TO_DEFAULT_INSTANCES |
protected static ClassLoader |
m_classLoader |
protected static Object[] |
ONE_EMPTY_STRING |
protected static Class<?>[] |
ONE_STRING_ARG |
Constructor and Description |
---|
ObjectUtil() |
Modifier and Type | Method and Description |
---|---|
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:
m_classLoader |
static ClassLoader |
getClassLoader()
Gets classLoader
|
static com.webmethods.caf.common.model.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
|
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
protected static ClassLoader m_classLoader
protected static final Class<?>[] ONE_STRING_ARG
protected static final Object[] ONE_EMPTY_STRING
public static Class getClass(String className) throws ClassNotFoundException
m_classLoader
className
- ClassNotFoundException
public static ClassLoader getClassLoader()
m_classLoader
if set, the default ClassLoader otherwisem_classLoader
public static void setClassLoader(ClassLoader classLoader)
classLoader
- m_classLoader
public static Object convertToType(Object srcObj, Class targetType) throws CommonException
CommonException
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 errorsCommonException
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' classpublic 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 checkpublic static void setPropertiesBatch(Object anInstance, Map propertyValues) throws Exception
anInstance
- Object properties are being added topropertyValues
- map containing property names and valuesException
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 setException
public static Object getPropertyValue(Object anInstance, String aPropertyName) throws Exception
anInstance
- object that we are getting property ofaPropertyName
- property name we are looking forException
public static void setPropertyValue(Object anInstance, String aPropertyName, Object value) throws Exception
anInstance
- Object we are setting property foraPropertyName
- name of propertyvalue
- value of propertyException
public static PropertyDescriptor getPropertyDescriptor(Object anInstance, String aPropertyName) throws IntrospectionException
anInstance
- null or objectaPropertyName
- String used to find resultIntrospectionException
public static PropertyDescriptor[] getPropertyDescriptors(Class instanceClass) throws IntrospectionException
instanceClass
- IntrospectionException
public static PropertyDescriptor findPropertyDescriptor(PropertyDescriptor[] anArray, String aPropertyName)
anArray
- array or nullaPropertyName
- Property specific namepublic static Object cloneObjectToMap(Object object, String[] properties) throws Exception
object
- the object to cloneproperties
- selected top level properties of an object will be clonedPortalException
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 clonedPortalException
Exception
public static Object cloneObjectFromMap(Map map, Class objectClass, String[] properties, boolean createDefComplexTypes) throws Exception
map
- objectClass
- properties
- allowed properties to clonePortalException
Exception
public static Object cloneObjectFromMap(Map map, Class objectClass, String[] properties, boolean createDefComplexTypes, boolean useRealFieldNames) throws Exception
map
- objectClass
- properties
- allowed properties to clonePortalException
Exception
public static Object clone(Object object) throws CloneNotSupportedException
object
- Instance of object to cloneCloneNotSupportedException
public static void flushClassCache() throws Exception
Exception
public static com.webmethods.caf.common.model.IDocumentStructureProvider getJavaClassStructure(Class clas) throws Exception
clas
- null or ClassException
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 orderException
public static Object newInstance(Class _class) throws Exception
_class
- primitive class, like Integer, String, Float, etcException
- 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 continueNoSuchFieldException
IllegalAccessException
IOException
ClassNotFoundException
public static Object load(InputStream in, ClassLoader cl)
in
- the InputStream that constitute the object