Class CopyUtils

java.lang.Object
org.kuali.rice.krad.uif.util.CopyUtils

public final class CopyUtils extends Object
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 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

      public static <T> T copy(Copyable obj)
      Mix-in copy implementation for objects that implement the Copyable interface}
      Type Parameters:
      T - copyable type
      Parameters:
      obj - The object to copy.
      Returns:
      A deep copy of the object.
    • isCopyAvailable

      public static boolean isCopyAvailable(Class<?> type)
      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

      public static <T> T getShallowCopy(T obj) throws CloneNotSupportedException
      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 for
      annotationClass - 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 check
      fieldName - name of the field to check
      annotationClass - 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 check
      fieldName - name of the field to check
      annotationClass - class for the annotation to look for