public static class EcoreUtil.Copier extends java.util.LinkedHashMap<EObject,EObject>
content trees
;
the map is from EObject
to EObject
, i.e., from original to copy;
use EcoreUtil.copy
or EcoreUtil.copyAll
to do routine copies.
Since this implementation extends a Map implementation, it acts as the result of the over all copy.
The client can call copy
and copyAll
repeatedly.
When all the objects have been copied,
the client should call copyReferences
to copy the appropriate
cross references
.
Copier copier = new Copier(); EObject result = copier.copy(eObject); Collection results = copier.copyAll(eObjects); copier.copyReferences();The copier delegates to
copyContainment
, copyAttribute
during the copy phase
and to copyReference
, during the cross reference phase.
This allows tailored handling through derivation.Modifier and Type | Field and Description |
---|---|
protected boolean |
resolveProxies
Whether proxies should be resolved during copying.
|
protected boolean |
useOriginalReferences
Whether non-copied references should be used during copying.
|
Constructor and Description |
---|
EcoreUtil.Copier()
Creates an instance.
|
EcoreUtil.Copier(boolean resolveProxies)
Creates an instance that resolves proxies or not as specified.
|
EcoreUtil.Copier(boolean resolveProxies,
boolean useOriginalReferences)
Creates an instance that resolves proxies or not and uses non-copied references or not as specified.
|
Modifier and Type | Method and Description |
---|---|
EObject |
copy(EObject eObject)
Returns a copy of the given eObject.
|
<T> java.util.Collection<T> |
copyAll(java.util.Collection<? extends T> eObjects)
Returns a collection containing a copy of each EObject in the given collection.
|
protected void |
copyAttribute(EAttribute eAttribute,
EObject eObject,
EObject copyEObject)
Called to handle the copying of an attribute;
this adds a list of values or sets a single value as appropriate for the multiplicity.
|
protected void |
copyAttributeValue(EAttribute eAttribute,
EObject eObject,
java.lang.Object value,
EStructuralFeature.Setting setting)
Called to handle copying of an attribute's value to the target setting.
|
protected void |
copyContainment(EReference eReference,
EObject eObject,
EObject copyEObject)
Called to handle the copying of a containment feature;
this adds a list of copies or sets a single copy as appropriate for the multiplicity.
|
protected void |
copyFeatureMap(FeatureMap featureMap)
Call to handle copying the contained objects within a feature map.
|
protected void |
copyProxyURI(EObject eObject,
EObject copyEObject)
Copies the proxy URI from the original to the copy, if present.
|
protected void |
copyReference(EReference eReference,
EObject eObject,
EObject copyEObject)
Called to handle the copying of a cross reference;
this adds values or sets a single value as appropriate for the multiplicity
while omitting any bidirectional reference that isn't in the copy map.
|
void |
copyReferences()
Hooks up cross references; it delegates to
copyReference . |
protected EObject |
createCopy(EObject eObject)
Returns a new instance of the object's target class.
|
protected EClass |
getTarget(EClass eClass)
Returns the target class used to create a copy instance for objects of the given source class.
|
protected EClass |
getTarget(EObject eObject)
Returns the target class used to create a copy instance for the given instance object.
|
protected EStructuralFeature |
getTarget(EStructuralFeature eStructuralFeature)
Returns the target feature used to populate a copy instance from the given source feature.
|
protected EStructuralFeature.Setting |
getTarget(EStructuralFeature eStructuralFeature,
EObject eObject,
EObject copyEObject)
Returns a setting for the feature and copy instance to be populated with the original object's source feature's value.
|
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
protected boolean resolveProxies
protected boolean useOriginalReferences
public EcoreUtil.Copier()
public EcoreUtil.Copier(boolean resolveProxies)
resolveProxies
- whether proxies should be resolved while copying.public EcoreUtil.Copier(boolean resolveProxies, boolean useOriginalReferences)
resolveProxies
- whether proxies should be resolved while copying.useOriginalReferences
- whether non-copied references should be used while copying.public <T> java.util.Collection<T> copyAll(java.util.Collection<? extends T> eObjects)
eObjects
- the collection of objects to copy.public EObject copy(EObject eObject)
eObject
- the object to copy.protected void copyProxyURI(EObject eObject, EObject copyEObject)
eObject
- the object being copied.copyEObject
- the copy being initialized.protected EObject createCopy(EObject eObject)
eObject
- the object to copy.getTarget(EObject)
,
EcoreUtil.create(EClass)
protected EClass getTarget(EObject eObject)
eObject
- the object to be copied.protected EClass getTarget(EClass eClass)
eClass
- the source class.getTarget(EStructuralFeature, EObject, EObject)
protected EStructuralFeature.Setting getTarget(EStructuralFeature eStructuralFeature, EObject eObject, EObject copyEObject)
eStructuralFeature
- the source feature.getTarget(EStructuralFeature)
,
getTarget(EObject)
protected EStructuralFeature getTarget(EStructuralFeature eStructuralFeature)
eStructuralFeature
- the source feature.getTarget(EClass)
protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject)
eReference
- the feature to copy.eObject
- the object from which to copy.copyEObject
- the object to copy to.protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject)
eAttribute
- the attribute to copy.eObject
- the object from which to copy.copyEObject
- the object to copy to.protected void copyFeatureMap(FeatureMap featureMap)
featureMap
- the feature map the copy.protected void copyAttributeValue(EAttribute eAttribute, EObject eObject, java.lang.Object value, EStructuralFeature.Setting setting)
eAttribute
- the attribute of the source object corresponding to the value.eObject
- the object being copied.value
- the value to be copied.setting
- the feature-value pair that is the target of of the copy.public void copyReferences()
copyReference
.protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject)
eReference
- the reference to copy.eObject
- the object from which to copy.copyEObject
- the object to copy to.