public class CloneableBean
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, Cloneable objects and multi-dimensional arrays of any of them.
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.Class<?>> |
BASIC_TYPES |
private java.util.Set<java.lang.String> |
ignoreProperties |
private static org.slf4j.Logger |
LOG |
private static java.lang.Object[] |
NO_PARAMS |
private static java.lang.Class<?>[] |
NO_PARAMS_DEF |
private java.lang.Object |
obj |
private static long |
serialVersionUID |
Modifier | Constructor and Description |
---|---|
protected |
CloneableBean()
Default constructor.
|
|
CloneableBean(java.lang.Object obj)
Creates a CloneableBean to be used in a delegation pattern.
|
|
CloneableBean(java.lang.Object obj,
java.util.Set<java.lang.String> ignoreProperties)
Creates a CloneableBean to be used in a delegation pattern.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
beanClone()
Makes a deep bean clone of the object passed in the constructor.
|
java.lang.Object |
clone()
Makes a deep bean clone of the object.
|
private <T> T |
cloneArray(T array) |
private <T> java.util.Collection<T> |
cloneCollection(java.util.Collection<T> collection) |
private <K,V> java.util.Map<K,V> |
cloneMap(java.util.Map<K,V> map) |
private <T> T |
doClone(T value) |
private boolean |
isBasicType(java.lang.Class<?> vClass) |
private static final long serialVersionUID
private static final org.slf4j.Logger LOG
private static final java.util.Set<java.lang.Class<?>> BASIC_TYPES
private static final java.lang.Class<?>[] NO_PARAMS_DEF
private static final java.lang.Object[] NO_PARAMS
private final java.lang.Object obj
private java.util.Set<java.lang.String> ignoreProperties
protected CloneableBean()
To be used by classes extending CloneableBean only.
public CloneableBean(java.lang.Object obj)
For example:
public class Foo implements Cloneable {
private CloneableBean cloneableBean;
public Foo() {
cloneableBean = new CloneableBean(this);
}
public Object clone() throws CloneNotSupportedException {
return cloneableBean.beanClone();
}
}
obj
- object bean to clone.public CloneableBean(java.lang.Object obj, java.util.Set<java.lang.String> ignoreProperties)
The property names in the ignoreProperties Set will not be copied into the cloned instance. This is useful for cases where the Bean has convenience properties (properties that are actually references to other properties or properties of properties). For example SyndFeed and SyndEntry beans have convenience properties, publishedDate, author, copyright and categories all of them mapped to properties in the DC Module.
obj
- object bean to clone.ignoreProperties
- properties to ignore when cloning.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
To be used by classes extending CloneableBean. Although it works also for classes using CloneableBean in a delegation pattern, for correctness those classes should use the
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- thrown if the object bean could not be cloned.beanClone method.
public java.lang.Object beanClone() throws java.lang.CloneNotSupportedException
To be used by classes using CloneableBean in a delegation pattern,
java.lang.CloneNotSupportedException
- thrown if the object bean could not be cloned.constructor.
private <T> T doClone(T value) throws java.lang.Exception
java.lang.Exception
private <T> T cloneArray(T array) throws java.lang.Exception
java.lang.Exception
private <T> java.util.Collection<T> cloneCollection(java.util.Collection<T> collection) throws java.lang.Exception
java.lang.Exception
private <K,V> java.util.Map<K,V> cloneMap(java.util.Map<K,V> map) throws java.lang.Exception
java.lang.Exception
private boolean isBasicType(java.lang.Class<?> vClass)