Package org.kuali.rice.krad.util
Class ObjectUtils
java.lang.Object
org.kuali.rice.krad.util.ObjectUtils
Deprecated.
use new KRAD data framework instead
Contains various Object, Proxy, and serialization utilities
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringDeprecated.Removes all query characters from a string.static booleancollectionContainsObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.static intcountObjectsWithIdentitcalKey(Collection<? extends PersistableBusinessObject> collection, PersistableBusinessObject bo) Deprecated.Compares a business object with a Collection ofPersistableBusinessObjects to count how many have the same key as the BO.static voidcreateHybridBusinessObject(org.kuali.rice.krad.bo.BusinessObject businessObject, org.kuali.rice.krad.bo.BusinessObject source, Map<String, String> template) Deprecated.static ObjectcreateNewObjectFromClass(Class clazz) Deprecated.This method safely creates a object from a class Convenience method to create new object and throw a runtime exception if it cannot If the class is anExternalizableBusinessObject, this method will determine the interface for the EBO and query the appropriate module service to create a new instance.static SerializabledeepCopy(Serializable src) Deprecated.Uses Serialization mechanism to create a deep copy of the given Object.static org.kuali.rice.core.api.util.cache.CopiedObjectDeprecated.Uses Serialization mechanism to create a deep copy of the given Object, and returns a CacheableObject instance containing the deepCopy and its size in bytes.static ClasseasyGetPropertyType(Object object, String propertyName) Deprecated.This method simply uses PojoPropertyUtilsBean logic to get the Class of a Class property.static booleanDeprecated.useDataObjectWrapper.equalsByPrimaryKey(Object)static StringformatPropertyValue(Object propertyValue) Deprecated.Based on the value type selects a formatter and returns the formatted value as a stringstatic ObjectfromByteArray(byte[] bytes) Deprecated.reconstitutes the object that was converted into a byte array by toByteArraystatic StringgetFormattedPropertyValue(org.kuali.rice.krad.bo.BusinessObject businessObject, String propertyName, org.kuali.rice.core.web.format.Formatter formatter) Deprecated.static StringgetFormattedPropertyValueUsingDataDictionary(org.kuali.rice.krad.bo.BusinessObject businessObject, String propertyName) Deprecated.References the data dictionary to find any registered formatter class then if not found checks for associated formatter for the property type.static org.kuali.rice.core.web.format.FormattergetFormatterWithDataDictionary(Object bo, String propertyName) Deprecated.static StringgetNestedAttributePrefix(String attributeName) Deprecated.Returns the prefix of a nested attribute name, or the empty string if the attribute name is not nested.static StringgetNestedAttributePrimitive(String attributeName) Deprecated.Returns the primitive part of an attribute name string.static ObjectgetNestedValue(Object bo, String fieldName) Deprecated.This method safely extracts either simple values OR nested values.static ClassgetPropertyType(Object object, String propertyName, PersistenceStructureService persistenceStructureService) Deprecated.static ObjectgetPropertyValue(Object businessObject, String propertyName) Deprecated.useDataObjectWrapper.getPropertyValueNullSafe(String)insteadstatic booleanisNestedAttribute(String attributeName) Deprecated.Determines if a given string could represent a nested attribute of an object.static booleanDeprecated.This method is a OJB Proxy-safe way to test for notNull on a proxied object that may or may not be materialized yet.static booleanDeprecated.This method is a OJB Proxy-safe way to test for null on a proxied object that may or may not be materialized yet.static booleanisWriteable(Object object, String property, PersistenceStructureService persistenceStructureService) Deprecated.Return whether or not an attribute is writeable.static voidDeprecated.Replaced byDataObjectWrapper.materializeReferencedObjectsToDepth(int, org.kuali.rice.krad.data.MaterializeOption...)static <T> Class<T> materializeClassForProxiedObject(T object) Deprecated.Attempts to find the Class for the given potentially proxied objectstatic voidmaterializeObjects(Collection possiblyProxiedObjects) Deprecated.This method runs the ObjectUtils.isNotNull() method for each item in a list of BOs.static voidmaterializeSubObjectsToDepth(PersistableBusinessObject bo, int depth) Deprecated.Replaced byDataObjectWrapper.materializeReferencedObjectsToDepth(int, org.kuali.rice.krad.data.MaterializeOption...)static voidDeprecated.Replaced byDataObjectWrapper.materializeReferencedObjects(org.kuali.rice.krad.data.MaterializeOption...)static <T> TnewInstance(Class<T> clazz) Deprecated.Helper method for creating a new instance of the given classstatic voidremoveObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.there is no replacement for this methodstatic org.kuali.rice.krad.bo.BusinessObjectretrieveObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.there is no replacement for this methodstatic voidsetObjectProperty(Object bo, String propertyName, Class propertyType, Object propertyValue) Deprecated.Sets the property of an object with the given value.static voidsetObjectProperty(Object bo, String propertyName, Object propertyValue) Deprecated.Sets the property of an object with the given value.static voidsetObjectProperty(org.kuali.rice.core.web.format.Formatter formatter, Object bo, String propertyName, Class type, Object propertyValue) Deprecated.Sets the property of an object with the given value.static voidsetObjectPropertyDeep(Object bo, String propertyName, Class type, Object propertyValue) Deprecated.Recursive; sets all occurences of the property in the object, its nested objects and its object lists with the given value.static voidsetObjectPropertyDeep(Object bo, String propertyName, Class type, Object propertyValue, int depth) Deprecated.static byte[]toByteArray(Object object) Deprecated.Converts the object to a byte array using the output stream.
-
Method Details
-
deepCopy
Deprecated.Uses Serialization mechanism to create a deep copy of the given Object. As a special case, deepCopy of null returns null, just to make using this method simpler. For a detailed discussion see: http://www.javaworld.com/javaworld/javatips/jw-javatip76.html- Returns:
- deep copy of the given Serializable
-
deepCopyForCaching
Deprecated.Uses Serialization mechanism to create a deep copy of the given Object, and returns a CacheableObject instance containing the deepCopy and its size in bytes. As a special case, deepCopy of null returns a cacheableObject containing null and a size of 0, to make using this method simpler. For a detailed discussion see: http://www.javaworld.com/javaworld/javatips/jw-javatip76.html- Returns:
- CopiedObject containing a deep copy of the given Serializable and its size in bytes
-
toByteArray
Deprecated.Converts the object to a byte array using the output stream.- Returns:
- byte array of the object
- Throws:
Exception
-
fromByteArray
Deprecated.reconstitutes the object that was converted into a byte array by toByteArray- Throws:
Exception
-
createHybridBusinessObject
public static void createHybridBusinessObject(org.kuali.rice.krad.bo.BusinessObject businessObject, org.kuali.rice.krad.bo.BusinessObject source, Map<String, String> template) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodExceptionDeprecated.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
easyGetPropertyType
public static Class easyGetPropertyType(Object object, String propertyName) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException Deprecated.This method simply uses PojoPropertyUtilsBean logic to get the Class of a Class property. This method does not have any of the logic needed to obtain the Class of an element of a Collection specified in the DataDictionary.- Parameters:
object- An instance of the Class of which we're trying to get the property Class.propertyName- The name of the property.- Throws:
IllegalAccessExceptionNoSuchMethodExceptionInvocationTargetException
-
getPropertyType
@Deprecated public static Class getPropertyType(Object object, String propertyName, PersistenceStructureService persistenceStructureService) Deprecated.Returns the type of the property in the object. This implementation is not smart enough to look through a Collection to get the property type of an attribute of an element in the collection.NOTE: A patch file attached to https://test.kuali.org/jira/browse/KULRNE-4435 contains a modified version of this method which IS smart enough to look through Collections. This patch is currently under review.
- Parameters:
object- An instance of the Class for which we're trying to get the property type.propertyName- The name of the property of the Class the Class of which we're trying to get. Dot notation is used to separate properties. TODO: The rules about this dot notation needs to be explained in Confluence using examples.persistenceStructureService- Needed to get the type of elements in a Collection from OJB.- Returns:
- Object will be null if any parent property for the given property is null.
-
getPropertyValue
Deprecated.useDataObjectWrapper.getPropertyValueNullSafe(String)insteadReturns the value of the property in the object.- Returns:
- Object will be null if any parent property for the given property is null.
-
getFormattedPropertyValue
@Deprecated public static String getFormattedPropertyValue(org.kuali.rice.krad.bo.BusinessObject businessObject, String propertyName, org.kuali.rice.core.web.format.Formatter formatter) Deprecated.Gets the property value from the business object, then based on the value type select a formatter and format the value- Parameters:
businessObject- BusinessObject instance that contains the propertypropertyName- Name of property in BusinessObject to get value forformatter- Default formatter to use (or null)- Returns:
- Formatted property value as String, or empty string if value is null
-
getFormattedPropertyValueUsingDataDictionary
public static String getFormattedPropertyValueUsingDataDictionary(org.kuali.rice.krad.bo.BusinessObject businessObject, String propertyName) Deprecated.References the data dictionary to find any registered formatter class then if not found checks for associated formatter for the property type. Value is then formatted using the found Formatter- Parameters:
businessObject- BusinessObject instance that contains the propertypropertyName- Name of property in BusinessObject to get value for- Returns:
- Formatted property value as String, or empty string if value is null
-
formatPropertyValue
Deprecated.Based on the value type selects a formatter and returns the formatted value as a string- Parameters:
propertyValue- Object value to be formatted- Returns:
- formatted value as a String
-
setObjectProperty
public static void setObjectProperty(Object bo, String propertyName, Object propertyValue) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Deprecated.Sets the property of an object with the given value. Converts using the formatter of the type for the property. Note: propertyType does not need passed, is found by util method.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
setObjectProperty
public static void setObjectProperty(Object bo, String propertyName, Class propertyType, Object propertyValue) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Deprecated.Sets the property of an object with the given value. Converts using the formatter of the given type if one is found.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
setObjectProperty
public static void setObjectProperty(org.kuali.rice.core.web.format.Formatter formatter, Object bo, String propertyName, Class type, Object propertyValue) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Deprecated.Sets the property of an object with the given value. Converts using the given formatter, if it isn't null.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
getFormatterWithDataDictionary
@Deprecated public static org.kuali.rice.core.web.format.Formatter getFormatterWithDataDictionary(Object bo, String propertyName) Deprecated.Returns a Formatter instance for the given property name in the given given business object. First checks if a formatter is defined for the attribute in the data dictionary, is not found then returns the registered formatter for the property type in Formatter- Parameters:
bo- - business object instance with property to get formatter forpropertyName- - name of property to get formatter for- Returns:
- Formatter instance
-
setObjectPropertyDeep
public static void setObjectPropertyDeep(Object bo, String propertyName, Class type, Object propertyValue) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Deprecated.Recursive; sets all occurences of the property in the object, its nested objects and its object lists with the given value.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
setObjectPropertyDeep
public static void setObjectPropertyDeep(Object bo, String propertyName, Class type, Object propertyValue, int depth) throws org.kuali.rice.core.web.format.FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Deprecated.- Throws:
org.kuali.rice.core.web.format.FormatExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
materializeUpdateableCollections
@Deprecated public static void materializeUpdateableCollections(Object bo) throws org.kuali.rice.core.web.format.FormatException Deprecated.Replaced byDataObjectWrapper.materializeReferencedObjects(org.kuali.rice.krad.data.MaterializeOption...)This method checks for updateable collections on the business object provided and materializes the corresponding collection proxies- Parameters:
bo- The business object for which you want unpdateable, proxied collections materialized- Throws:
org.kuali.rice.core.web.format.FormatException
-
clean
Deprecated.Removes all query characters from a string.- Returns:
- Cleaned string
-
equalByKeys
@Deprecated public static boolean equalByKeys(PersistableBusinessObject bo1, PersistableBusinessObject bo2) Deprecated.useDataObjectWrapper.equalsByPrimaryKey(Object)Compares twoPersistableBusinessObjectinstances for equality of type and key values.- Returns:
- boolean indicating whether the two objects are equal.
-
collectionContainsObjectWithIdentitcalKey
@Deprecated public static boolean collectionContainsObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.Compares a business object with a List ofPersistableBusinessObjects to determine if an object with the same key as the BO exists in the list.- Parameters:
controlList- - The list of items to checkbo- - The BO whose keys we are looking for in the controlList- Returns:
- boolean
-
countObjectsWithIdentitcalKey
public static int countObjectsWithIdentitcalKey(Collection<? extends PersistableBusinessObject> collection, PersistableBusinessObject bo) Deprecated.Compares a business object with a Collection ofPersistableBusinessObjects to count how many have the same key as the BO.- Parameters:
collection- - The collection of items to checkbo- - The BO whose keys we are looking for in the collection- Returns:
- how many have the same keys
-
removeObjectWithIdentitcalKey
@Deprecated public static void removeObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.there is no replacement for this methodCompares a business object with a List ofPersistableBusinessObjects to determine if an object with the same key as the BO exists in the list. If it does, the item is removed from the List. This is functionally similar to List.remove() that operates only on Key values.- Parameters:
controlList- - The list of items to checkbo- - The BO whose keys we are looking for in the controlList
-
retrieveObjectWithIdentitcalKey
@Deprecated public static org.kuali.rice.krad.bo.BusinessObject retrieveObjectWithIdentitcalKey(Collection<? extends PersistableBusinessObject> controlList, PersistableBusinessObject bo) Deprecated.there is no replacement for this methodCompares a business object with a List of BOs to determine if an object with the same key as the BO exists in the list. If it does, the item is returned.- Parameters:
controlList- - The list of items to checkbo- - The BO whose keys we are looking for in the controlList
-
isNestedAttribute
Deprecated.Determines if a given string could represent a nested attribute of an object.- Returns:
- true if the attribute is nested
-
getNestedAttributePrefix
Deprecated.Returns the prefix of a nested attribute name, or the empty string if the attribute name is not nested.- Returns:
- everything BEFORE the last "." character in attributeName
-
getNestedAttributePrimitive
Deprecated.Returns the primitive part of an attribute name string.- Returns:
- everything AFTER the last "." character in attributeName
-
isNull
Deprecated.This method is a OJB Proxy-safe way to test for null on a proxied object that may or may not be materialized yet. It is safe to use on a proxy (materialized or non-materialized) or on a non-proxy (ie, regular object). Note that this will force a materialization of the proxy if the object is a proxy and unmaterialized.- Parameters:
object- - any object, proxied or not, materialized or not- Returns:
- true if the object (or underlying materialized object) is null, false otherwise
-
isNotNull
Deprecated.This method is a OJB Proxy-safe way to test for notNull on a proxied object that may or may not be materialized yet. It is safe to use on a proxy (materialized or non-materialized) or on a non-proxy (ie, regular object). Note that this will force a materialization of the proxy if the object is a proxy and unmaterialized.- Parameters:
object- - any object, proxied or not, materialized or not- Returns:
- true if the object (or underlying materialized object) is not null, true if its null
-
materializeClassForProxiedObject
Deprecated.Attempts to find the Class for the given potentially proxied object- Parameters:
object- the potentially proxied object to find the Class of- Returns:
- the best Class which could be found for the given object
-
materializeObjects
Deprecated.This method runs the ObjectUtils.isNotNull() method for each item in a list of BOs. ObjectUtils.isNotNull() will materialize the objects if they are currently OJB proxies.- Parameters:
possiblyProxiedObjects- - a Collection of objects that may be proxies
-
materializeSubObjectsToDepth
@Deprecated public static void materializeSubObjectsToDepth(PersistableBusinessObject bo, int depth) Deprecated.Replaced byDataObjectWrapper.materializeReferencedObjectsToDepth(int, org.kuali.rice.krad.data.MaterializeOption...)This method attempts to materialize all of the proxied reference objects (ie, sub-objects) hanging off the passed-in BO object. It will do it down to the specified depth. An IllegalArgumentException will be thrown if the bo object passed in is itself a non-materialized proxy object. If the bo passed in has no proxied sub-objects, then the object will not be modified, and no errors will be thrown. WARNING: Be careful using depth any greater than 2. The number of DB hits, time, and memory consumed grows exponentially with each additional increment to depth. Make sure you really need that depth before doing so.- Parameters:
bo- A valid, populated BusinessObject containing (possibly) proxied sub-objects. This object will be modified in place.depth- int Value 0-5 indicating how deep to recurse the materialization. If a zero (0) is passed in, then no work will be done.
-
materializeAllSubObjects
Deprecated.Replaced byDataObjectWrapper.materializeReferencedObjectsToDepth(int, org.kuali.rice.krad.data.MaterializeOption...)This method attempts to materialize all of the proxied reference objects (ie, sub-objects) hanging off the passed-in BO object. It will do it just three levels down. In other words, it will only materialize the objects that are direct members of the bo, objects that are direct members of those bos, that one more time, and no further down. An IllegalArgumentException will be thrown if the bo object passed in is itself a non-materialized proxy object. If the bo passed in has no proxied sub-objects, then the object will not be modified, and no errors will be thrown.- Parameters:
bo- A valid, populated BusinessObject containing (possibly) proxied sub-objects. This object will be modified in place.
-
getNestedValue
Deprecated.This method safely extracts either simple values OR nested values. For example, if the bo is SubAccount, and the fieldName is a21SubAccount.subAccountTypeCode, this thing makes sure it gets the value off the very end attribute, no matter how deeply nested it is. The code would be slightly simpler if this was done recursively, but this is safer, and consumes a constant amount of memory, no matter how deeply nested it goes.- Returns:
- The field value if it exists. If it doesnt, and the name is invalid, and
-
createNewObjectFromClass
Deprecated.This method safely creates a object from a class Convenience method to create new object and throw a runtime exception if it cannot If the class is anExternalizableBusinessObject, this method will determine the interface for the EBO and query the appropriate module service to create a new instance.- Returns:
- a newInstance() of clazz
-
isWriteable
public static boolean isWriteable(Object object, String property, PersistenceStructureService persistenceStructureService) throws IllegalArgumentException Deprecated.Return whether or not an attribute is writeable. This method is aware that that Collections may be involved and handles them consistently with the way in which OJB handles specifying the attributes of elements of a Collection.- Throws:
IllegalArgumentException
-
newInstance
Deprecated.Helper method for creating a new instance of the given class- Parameters:
clazz- - class of object to create- Returns:
- T object of type given by the clazz parameter
-