- Get the implementation class of the given metadata instance.
- Create a new instance of the implementation class using the public no-argument constructor.
- Invoke all non-deprecated setter methods on the new instance with the corresponding value from the given metadata.
- If any of the values copied in above step is itself a metadata, recursively performs deep copy on those metadata instances too.
MetadataSource.lookup(Class, String)
) into instances of AbstractMetadata
.
The copier may also be used if a modifiable metadata is desired after
the original metadata has been made final.
Default implementation copies all copiable children, regardless their state. Static factory methods allow to construct some variants, for example skipping the copy of unmodifiable metadata instances since they can be safely shared.
This class supports cyclic graphs in the metadata tree. It may return the given metadata
object directly
if the implementation class does not provide any setter method.
This class is not thread-safe.
In multi-threads environment, each thread should use its own MetadataCopier
instance.
- Since:
- 0.8
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
Performs a potentially deep copy of the given metadata object.Performs a potentially deep copy of a metadata object of unknown type.protected Object
copyRecursively
(Class<?> type, Object metadata) Performs the actual copy operation on a single metadata instance.static MetadataCopier
forModifiable
(MetadataStandard standard) Creates a new metadata copier which avoid copying unmodifiable metadata.Returns the path to the currently copied property.
-
Constructor Details
-
MetadataCopier
Creates a new metadata copier.- Parameters:
standard
- the default metadata standard to use for object that are notAbstractMetadata
instances, ornull
if none.
-
-
Method Details
-
forModifiable
Creates a new metadata copier which avoid copying unmodifiable metadata. More specifically, anyModifiableMetadata
instance in final state will be kept as-is; those final metadata will not be copied since they can be safely shared.- Parameters:
standard
- the default metadata standard to use for object that are notAbstractMetadata
instances, ornull
if none.- Returns:
- a metadata copier which skip the copy of unmodifiable metadata.
- Since:
- 1.0
-
copy
Performs a potentially deep copy of a metadata object of unknown type. The return value does not need to be of the same class than the argument.- Parameters:
metadata
- the metadata object to copy, ornull
.- Returns:
- a copy of the given metadata object, or
null
if the given argument isnull
. - Throws:
UnsupportedOperationException
- if there is no implementation class for a metadata to copy, or an implementation class does not provide a public default constructor.
-
copy
Performs a potentially deep copy of the given metadata object. This method is preferred tocopy(Object)
when the type is known. The specified type should be an interface, not an implementation (for exampleMetadata
, notDefaultMetadata
).- Type Parameters:
T
- compile-time value of thetype
argument.- Parameters:
type
- the interface of the metadata object to copy.metadata
- the metadata object to copy, ornull
.- Returns:
- a copy of the given metadata object, or
null
if the given argument isnull
. - Throws:
IllegalArgumentException
- iftype
is an implementation class instead of interface.UnsupportedOperationException
- if there is no implementation class for a metadata to copy, or an implementation class does not provide a public default constructor.
-
copyRecursively
Performs the actual copy operation on a single metadata instance. This method is invoked by all publiccopy(…)
method with the rootmetadata
object in argument, then is invoked recursively for all properties in that metadata object. If a metadata property is a collection, then this method is invoked for each element in the collection.Subclasses can override this method if they need some control on the copy process.
- Parameters:
type
- the interface of the metadata object to copy, ornull
if unspecified.metadata
- the metadata object to copy, ornull
.- Returns:
- a copy of the given metadata object, or
null
if the given argument isnull
. - Throws:
UnsupportedOperationException
- if there is no implementation class for a metadata to copy, or an implementation class does not provide a public default constructor.
-
getCurrentPropertyPath
Returns the path to the currently copied property. Each element in the list is the UML identifier of a property. Element at index 0 is the name of the property of the root metadata object being copied. Element at index 1 is the name of a property which is a children of above property, etc.The returned list is valid only during
copyRecursively(Class, Object)
method execution. The content of this list become undetermined after thecopyRecursively
method returned.- Returns:
- the path to the currently copied property.
- Since:
- 1.0
-