/** * @see org.teiid.designer.core.util.ModelVisitor#visit(org.eclipse.emf.ecore.EObject) * @since 4.3 */ @Override public boolean visit(final EObject object) { // Find all references ... final EClass eclass = object.eClass(); final Collection allRefs = eclass.getEAllReferences(); for (final Iterator i = allRefs.iterator(); i.hasNext(); ) { final EReference reference = (EReference) i.next(); // Process only non-containment references ... if (!reference.isContainment() && !reference.isContainer() && !reference.isVolatile()) { final Object value = object.eGet(reference, false); if (reference.isMany()) { // There may be many values ... boolean removeRefdValue = false; for (Iterator j = ((List) value).iterator(); j.hasNext(); ) { final Object valueInList = j.next(); if (valueInList instanceof EObject && valueInList == refdObject) { removeRefdValue = true; } } if (removeRefdValue && reference.isChangeable()) { ((List) value).remove(refdObject); this.affectedObjects.add(object); } } else { // There may be 0..1 value ... if (value instanceof EObject && value == refdObject) { if (reference.isChangeable()) { object.eUnset(reference); this.affectedObjects.add(object); } } } } } return true; }
/** Add the specified list any external resource for this EReference feature */ protected void processReference( final Resource eResource, final EObject eObject, final EReference eReference, final List externalResources, final Set unresolvedResourceURIs) { if (!eReference.isContainment() && !eReference.isContainer() && !eReference.isVolatile()) { // The reference is NOT the container NOR a containment feature ... final Object value = eObject.eGet(eReference, false); if (eReference.isMany()) { // There may be many values ... final Iterator valueIter = ((List) value).iterator(); while (valueIter.hasNext()) { final Object valueInList = valueIter.next(); if (valueInList instanceof EObject) { processReferenceValue( eResource, eObject, eReference, (EObject) valueInList, externalResources, unresolvedResourceURIs); } } } else { // There may be 0..1 value ... if (value instanceof EObject) { processReferenceValue( eResource, eObject, eReference, (EObject) value, externalResources, unresolvedResourceURIs); } } } }
/** * @param eObj the EObject whose contents will be checked for references to the original model * and updated to new model * @see org.teiid.designer.core.util.ModelVisitor#visit(org.eclipse.emf.ecore.EObject) * @since 4.2 */ @Override public boolean visit(final EObject eObj) { // Get all EReference features for this EClass final List refs = eObj.eClass().getEAllReferences(); for (final Iterator iter1 = refs.iterator(); iter1.hasNext(); ) { final EReference eReference = (EReference) iter1.next(); // since we are going to visit all children // need not visit container references if (eReference.isContainment() && eReference.isContainer() && eReference.isVolatile()) { continue; } final Object value = eObj.eGet(eReference); if (eReference.isMany()) { // multi-valued feature ... final List values = (List) value; if (!values.isEmpty()) { final Collection newValues = new ArrayList(values.size()); boolean resetList = false; // Check each value in the List for references to // EObjects in the original model. If the value // is found in the map then the EObject was copied // so the reference needs to be reset for (final Iterator iter2 = values.iterator(); iter2.hasNext(); ) { final Object valueInList = iter2.next(); if (valueInList != null && valueInList instanceof EObject) { final EObject orig = (EObject) valueInList; final EObject copy = (EObject) originalsToCopies.get(orig); if (copy != null) { newValues.add(copy); resetList = true; } else { // copy does not exist, // values on the object may need to be updated updateReference(orig); newValues.add(orig); } } } if (resetList) { // always fails (see SetCommand.java:340): // eObj.eSet(eReference,newValues); ModelerCore.getModelEditor().setPropertyValue(eObj, newValues, eReference); } } } else { // There may be 0..1 value ... if (value != null && value instanceof EObject) { final EObject orig = (EObject) value; final EObject copy = (EObject) originalsToCopies.get(orig); if (copy != null) { eObj.eSet(eReference, copy); } else { // copy does not exist, // values on the object may need to be updated updateReference(orig); } } } } return true; }