Package org.kuali.rice.krad.uif.util
Class CopyUtils
java.lang.Object
org.kuali.rice.krad.uif.util.CopyUtils
Provides a lightweight "hands-free" copy implementation to replace the need for copyProperties()
in building
LifecycleElement implementations.- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TMix-in copy implementation for objects that implement theCopyableinterface}static booleanfieldHasAnnotation(Class<?> clazz, String fieldName, Class<? extends Annotation> annotationClass) Determines whether the field of the given class has the given annotation specifiedstatic <T> TgetDeepCopy(T obj) Get a deep copy of an object using cloning.static AnnotationgetFieldAnnotation(Class<?> clazz, String fieldName, Class<? extends Annotation> annotationClass) Returns annotation of the given type for the given field (if present)static Map<String, Annotation> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Retrieves all field names for the given class that have the given annotationstatic <T> TgetShallowCopy(T obj) Get a shallow copy (clone) of an object.static booleanisCopyAvailable(Class<?> type) Determine if deep copying is available for a type.static booleanisDelay()Determine whether or not to use a delayed copy proxy.static <T> Tunwrap(T obj) Unwrap an object from any wrapper class or proxy it may be decorated with related to the copy process.
-
Constructor Details
-
CopyUtils
public CopyUtils()
-
-
Method Details
-
isDelay
public static boolean isDelay()Determine whether or not to use a delayed copy proxy.When true, deep copy operations will be truncated where a copyable represented by an interfaces is specified by the field, array, list or map involved indicated. Rather than copy the object directly, a proxy wrapping the original will be placed, which when used will invoke the copy operation.
This value is controlled by the parameter "krad.uif.copyable.delay". By default, full deep copy will be used.
- Returns:
- True if deep copy will be truncated with a delayed copy proxy, false for full deep copy.
-
copy
Mix-in copy implementation for objects that implement theCopyableinterface}- Type Parameters:
T- copyable type- Parameters:
obj- The object to copy.- Returns:
- A deep copy of the object.
-
isCopyAvailable
Determine if deep copying is available for a type.- Parameters:
type- The type to check.- Returns:
- True if
getDeepCopy(Object)may be expected to follow references to this type. False if the type should not be deeply copied.
-
getShallowCopy
Get a shallow copy (clone) of an object.This method simplifies access to the clone() method.
- Type Parameters:
T- copyable type- Parameters:
obj- The object to clone.- Returns:
- A shallow copy of obj, or null if obj is null.
- Throws:
CloneNotSupportedException- If copying is not available on the object, or if thrown by clone() itself. When isShallowCopyAvailable() returns true, then this exception is not expected and may be considered an internal error.
-
unwrap
public static <T> T unwrap(T obj) Unwrap an object from any wrapper class or proxy it may be decorated with related to the copy process.This method is a public utility passthrough for
DelayedCopyableHandler.getDelayedCopy(Copyable).- Parameters:
obj- an object.- Returns:
- The non-proxied bean represented by source, copied if needed. When source is not copyable, or not proxied, it is returned as-is.
-
getDeepCopy
public static <T> T getDeepCopy(T obj) Get a deep copy of an object using cloning.- Type Parameters:
T- copyable type- Parameters:
obj- The object to get a deep copy of.- Returns:
- A deep copy of the object.
-
getFieldsWithAnnotation
public static Map<String,Annotation> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Retrieves all field names for the given class that have the given annotation- Parameters:
clazz- class to find field annotations forannotationClass- class for annotation to find- Returns:
- map containing the field name that has the annotation as a key and the annotation instance as a value
-
fieldHasAnnotation
public static boolean fieldHasAnnotation(Class<?> clazz, String fieldName, Class<? extends Annotation> annotationClass) Determines whether the field of the given class has the given annotation specified- Parameters:
clazz- class containing the field to checkfieldName- name of the field to checkannotationClass- class for the annotation to look for- Returns:
- true if the named field has the given annotation, false if not
-
getFieldAnnotation
public static Annotation getFieldAnnotation(Class<?> clazz, String fieldName, Class<? extends Annotation> annotationClass) Returns annotation of the given type for the given field (if present)- Parameters:
clazz- class containing the field to checkfieldName- name of the field to checkannotationClass- class for the annotation to look for
-