|
From: jistrawn <jis...@us...> - 2006-10-31 22:50:19
|
Update of /cvsroot/modelwizard/source/Chameleon Plugin/src/net/sourceforge/modelWizard/chameleon/exporters In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv21465/src/net/sourceforge/modelWizard/chameleon/exporters Modified Files: SubModelGenerator.java Log Message: Added hack to get around version conflicts with RSM (emf/uml2) Index: SubModelGenerator.java =================================================================== RCS file: /cvsroot/modelwizard/source/Chameleon Plugin/src/net/sourceforge/modelWizard/chameleon/exporters/SubModelGenerator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SubModelGenerator.java 30 Oct 2006 15:36:06 -0000 1.9 --- SubModelGenerator.java 31 Oct 2006 22:50:15 -0000 1.10 *************** *** 22,25 **** --- 22,26 ---- import java.util.Iterator; import java.util.List; + import java.util.Map; import java.util.TreeMap; *************** *** 38,41 **** --- 39,44 ---- import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + import org.eclipse.emf.ecore.util.FeatureMap; + import org.eclipse.emf.ecore.util.FeatureMapUtil; import org.eclipse.emf.ecore.util.EcoreUtil.Copier; import org.eclipse.uml2.Association; *************** *** 74,78 **** /** - * Override super * Returns a copy of the given eObject. * --- 77,80 ---- *************** *** 82,99 **** */ public EObject copy(EObject eObject) { - - // do not include the class interfaces that are not included in the sub-model. - // throwing a runtime so if this - if (eObject instanceof Implementation) { - if (!isInterfaceInSubModel((Implementation) eObject)) { - throw new RuntimeException(); - } - } - EObject copyEObject = createCopy(eObject); put(eObject, copyEObject); ! EClass eClass = eObject.eClass(); ! for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) { ! EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i); if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) { if (eStructuralFeature instanceof EAttribute) { --- 84,91 ---- */ public EObject copy(EObject eObject) { EObject copyEObject = createCopy(eObject); put(eObject, copyEObject); ! for (Iterator i = eObject.eClass().getEAllStructuralFeatures().iterator(); i.hasNext();) { ! EStructuralFeature eStructuralFeature = (EStructuralFeature) i.next(); if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) { if (eStructuralFeature instanceof EAttribute) { *************** *** 112,118 **** /** ! * Override super ! * Returns a collection containing a copy of each EObject in the given ! * collection. * * @param eObjects --- 104,109 ---- /** ! * Override super Returns a collection containing a copy of each EObject ! * in the given collection. * * @param eObjects *************** *** 124,132 **** for (Iterator i = eObjects.iterator(); i.hasNext();) { EObject eObject; ! try { ! eObject = copy((EObject) i.next()); ! } catch (RuntimeException e) { ! continue; } result.add(eObject); } --- 115,125 ---- for (Iterator i = eObjects.iterator(); i.hasNext();) { EObject eObject; ! EObject next = (EObject) i.next(); ! if (next instanceof Implementation) { ! if (!isInterfaceInSubModel((Implementation) next)) { ! continue; ! } } + eObject = copy(next); result.add(eObject); } *************** *** 134,137 **** --- 127,169 ---- } + /** + * Hooks up cross references; it delegates to + * {@link #copyReference copyReference}. + */ + public void copyReferences() { + for (Iterator i = entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + EObject eObject = (EObject) entry.getKey(); + EObject copyEObject = (EObject) entry.getValue(); + EClass eClass = eObject.eClass(); + for (Iterator j = eClass.getEAllStructuralFeatures().iterator(); j.hasNext();) { + EStructuralFeature eStructuralFeature = (EStructuralFeature) j.next(); + if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) { + if (eStructuralFeature instanceof EReference) { + EReference eReference = (EReference) eStructuralFeature; + if (!eReference.isContainment()) { + copyReference(eReference, eObject, copyEObject); + } + } else if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) { + FeatureMap featureMap = (FeatureMap) eObject.eGet(eStructuralFeature); + FeatureMap copyFeatureMap = (FeatureMap) copyEObject.eGet(getTarget(eStructuralFeature)); + for (Iterator k = featureMap.iterator(); k.hasNext();) { + FeatureMap.Entry featureMapEntry = (FeatureMap.Entry) k.next(); + EStructuralFeature feature = featureMapEntry.getEStructuralFeature(); + if (feature instanceof EReference) { + Object referencedEObject = featureMapEntry.getValue(); + Object copyReferencedEObject = get(referencedEObject); + copyFeatureMap.add(feature, copyReferencedEObject == null ? referencedEObject + : copyReferencedEObject); + } else { + copyFeatureMap.add(featureMapEntry); + } + } + } + } + } + } + } + private boolean isInterfaceInSubModel(Implementation theElement) { if (classList.contains(theElement.getRealizingClassifier().getName())) { |