## org.eclipse.emf.ecore.util
Class EcoreUtil.Copier

    java.lang.Object
      java.util.AbstractMap<K,V>
          java.util.HashMap<EObject,EObject>
              org.eclipse.emf.ecore.util.EcoreUtil.Copier

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable, java.util.Map<EObject,EObject>

Direct Known Subclasses:
  GenBaseImpl.GenAnnotationCopier

Enclosing class:
  EcoreUtil

    public static class EcoreUtil.Copier

extends java.util.HashMap<EObject,EObject>

A mapping building traverser of a collection of `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.

See Also:
  Serialized Form

Field Summary
`protected boolean` `resolveProxies` Whether proxies should be resolved during copying.
`protected boolean` `useOriginalReferences` Whether non-copied references should be used during copying.

Constructor Summary
`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.

Method Summary
`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` `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` `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 EStructuralFeature` `getTarget(EStructuralFeature eStructuralFeature)` Returns the target feature used to populate a copy instance from the given source feature.

Methods inherited from class java.util.HashMap
`clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values`

Methods inherited from class java.util.AbstractMap
`equals, hashCode, toString`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Map
`equals, hashCode`

Field Detail

### resolveProxies

    protected boolean resolveProxies

  Whether proxies should be resolved during copying.

### useOriginalReferences

    protected boolean useOriginalReferences

  Whether non-copied references should be used during copying.

Constructor Detail

### EcoreUtil.Copier

    public EcoreUtil.Copier()

  Creates an instance.

### EcoreUtil.Copier

    public EcoreUtil.Copier(boolean resolveProxies)

  Creates an instance that resolves proxies or not as specified.

  Parameters:
    `resolveProxies` - whether proxies should be resolved while copying.

### EcoreUtil.Copier

    public EcoreUtil.Copier(boolean resolveProxies,
                            boolean useOriginalReferences)

  Creates an instance that resolves proxies or not and uses non-copied references or not as specified.

  Parameters:
    `resolveProxies` - whether proxies should be resolved while copying.
    `useOriginalReferences` - whether non-copied references should be used while copying.

Method Detail

### copyAll

    public <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.

  Parameters:
    `eObjects` - the collection of objects to copy.
  Returns:
    the collection of copies.

### copy

    public EObject copy(EObject eObject)

  Returns a copy of the given eObject.

  Parameters:
    `eObject` - the object to copy.
  Returns:
    the copy.

### copyProxyURI

    protected void copyProxyURI(EObject eObject,
                                EObject copyEObject)

  Copies the proxy URI from the original to the copy, if present.

  Parameters:
    `eObject` - the object being copied.
    `copyEObject` - the copy being initialized.

### createCopy

    protected EObject createCopy(EObject eObject)

  Returns a new instance of the object's target class.

  Parameters:
    `eObject` - the object to copy.
  Returns:
    a new instance of the target class.
  See Also:
    `getTarget(EClass)`, `EcoreUtil.create(EClass)`

### getTarget

    protected EClass getTarget(EClass eClass)

  Returns the target class used to create a copy instance for objects of the given source class.

  Parameters:
    `eClass` - the source class.
  Returns:
    the target class used to create a copy instance.
  See Also:
    `getTarget(EStructuralFeature)`

### getTarget

    protected EStructuralFeature getTarget(EStructuralFeature eStructuralFeature)

  Returns the target feature used to populate a copy instance from the given source feature.

  Parameters:
    `eStructuralFeature` - the source feature.
  Returns:
    the target feature used to populate a copy instance.
  See Also:
    `getTarget(EClass)`

### copyContainment

    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.

  Parameters:
    `eReference` - the feature to copy.
    `eObject` - the object from which to copy.
    `copyEObject` - the object to copy to.

### copyAttribute

    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.

  Parameters:
    `eAttribute` - the attribute to copy.
    `eObject` - the object from which to copy.
    `copyEObject` - the object to copy to.

### copyReferences

    public void copyReferences()

  Hooks up cross references; it delegates to `copyReference`.

### copyReference

    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.

  Parameters:
    `eReference` - the reference to copy.
    `eObject` - the object from which to copy.
    `copyEObject` - the object to copy to.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.