1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.ListIterator ; 22 23 import org.eclipse.emf.common.util.URI; 24 import org.eclipse.emf.ecore.EClass; 25 import org.eclipse.emf.ecore.ENamedElement; 26 import org.eclipse.emf.ecore.EObject; 27 import org.eclipse.emf.ecore.EcorePackage; 28 import org.eclipse.emf.ecore.InternalEObject; 29 import org.eclipse.emf.ecore.xmi.XMIResource; 30 import org.eclipse.emf.ecore.xmi.XMLHelper; 31 import org.eclipse.emf.ecore.xmi.XMLLoad; 32 import org.eclipse.emf.ecore.xmi.XMLSave; 33 34 35 38 public class EMOFResourceImpl extends XMIResourceImpl implements XMIResource 39 { 40 public EMOFResourceImpl() 41 { 42 super(); 43 } 44 45 public EMOFResourceImpl(URI uri) 46 { 47 super(uri); 48 } 49 50 protected XMLHelper createXMLHelper() 51 { 52 return null; 53 } 54 55 protected XMLLoad createXMLLoad() 56 { 57 return new EMOFLoadImpl(new EMOFHelperImpl(this)); 58 } 59 60 protected XMLSave createXMLSave() 61 { 62 return new EMOFSaveImpl(new EMOFHelperImpl(this)); 63 } 64 65 public String getID(EObject eObject) 66 { 67 String id = super.getID(eObject); 68 if (id == null) 69 { 70 EClass eClass = eObject.eClass(); 71 if ((eClass != EcorePackage.eINSTANCE.getEAnnotation() || eObject.eContainer() == null) && 72 eClass != EcorePackage.eINSTANCE.getEStringToStringMapEntry()) 73 { 74 id = makeID(eObject); 75 getEObjectToIDMap().put(eObject, id); 76 } 77 } 78 return id; 79 } 80 81 protected String makeID(EObject eObject) 82 { 83 List uriFragmentPath = new ArrayList (); 84 for (EObject container = eObject.eContainer(); container != null; container = eObject.eContainer()) 85 { 86 uriFragmentPath.add(((InternalEObject)container).eURIFragmentSegment(eObject.eContainmentFeature(), eObject)); 87 eObject = container; 88 } 89 90 StringBuffer result = new StringBuffer (eObject instanceof ENamedElement ? 91 ((ENamedElement)eObject).getName() : 92 "_" + Integer.toString(getContents().indexOf(eObject))); 93 for (ListIterator i = uriFragmentPath.listIterator(uriFragmentPath.size()); i.hasPrevious(); ) 94 { 95 result.append('.'); 96 result.append((String )i.previous()); 97 } 98 99 return result.toString(); 100 } 101 } 102 | Popular Tags |