net.wotonomy.foundation.internal
Class Duplicator

java.lang.Object
  extended by net.wotonomy.foundation.internal.Duplicator

public class Duplicator
extends java.lang.Object

Duplicator makes use of Introspector to duplicate objects, either by shallow copy, deep copy, or by copying properties from one object to apply to another object. You may find this class useful because java.lang.Object.clone() only supports shallow copying.

Version:
$Revision: 895 $
Author:
michael@mpowers.net, $Author: cgruber $

Field Summary
static java.lang.Object NULL
          Used to represent null values for properties in the maps returned by readProperties and cloneProperties and in the parameter to writeProperties.
 
Constructor Summary
Duplicator()
           
 
Method Summary
static java.lang.Object clone(java.lang.Object aSource)
          Creates a new copy of the specified object.
static java.util.Map clonePropertiesForObject(java.lang.Object anObject)
          Returns a Map containing only the mutable properties for the specified object and deep clones of their values.
static java.lang.Object copy(java.lang.Object aSource, java.lang.Object aDestination)
          Copies values from one object to another.
static java.lang.Object deepClone(java.lang.Object aSource)
          Creates a deep copy of the specified object.
static java.lang.Object deepCopy(java.lang.Object aSource, java.lang.Object aDestination)
          Deeply clones the values from one object and applies them to another object.
static java.util.List editablePropertiesForObject(java.lang.Object anObject)
          Returns a list of properties for the specified class that are both readable and writable.
static java.util.Map readPropertiesForObject(java.lang.Object anObject)
          Returns a Map containing only the mutable properties for the specified object and their values.
static void writePropertiesForObject(java.util.Map aMap, java.lang.Object anObject)
          Applies the map of properties and values to the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final java.lang.Object NULL
Used to represent null values for properties in the maps returned by readProperties and cloneProperties and in the parameter to writeProperties. This actually references the NSNull instance.

Constructor Detail

Duplicator

public Duplicator()
Method Detail

editablePropertiesForObject

public static java.util.List editablePropertiesForObject(java.lang.Object anObject)
Returns a list of properties for the specified class that are both readable and writable.


readPropertiesForObject

public static java.util.Map readPropertiesForObject(java.lang.Object anObject)
Returns a Map containing only the mutable properties for the specified object and their values. Any null values for properties will be represented with the NULL object.


clonePropertiesForObject

public static java.util.Map clonePropertiesForObject(java.lang.Object anObject)
Returns a Map containing only the mutable properties for the specified object and deep clones of their values. Nulls are represented by the NULL object.


writePropertiesForObject

public static void writePropertiesForObject(java.util.Map aMap,
                                            java.lang.Object anObject)
Applies the map of properties and values to the specified object. Null values for properties must be represented by the NULL object.


clone

public static java.lang.Object clone(java.lang.Object aSource)
Creates a new copy of the specified object. This implementation tries to call clone(), and failing that, calls newInstance and then calls copy() to transfer the values.

Throws:
WotonomyException - if any operation fails.

deepClone

public static java.lang.Object deepClone(java.lang.Object aSource)
Creates a deep copy of the specified object. Every object in this objects graph will be duplicated with new instances.

Throws:
WotonomyException - if any operation fails.

copy

public static java.lang.Object copy(java.lang.Object aSource,
                                    java.lang.Object aDestination)
Copies values from one object to another. Returns the destination object.

Throws:
WotonomyException - if any operation fails.

deepCopy

public static java.lang.Object deepCopy(java.lang.Object aSource,
                                        java.lang.Object aDestination)
Deeply clones the values from one object and applies them to another object. Returns the destination object.

Throws:
WotonomyException - if any operation fails.


Copyright © 2006 null. All Rights Reserved.