1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 import org.eclipse.emf.ecore.EClassifier; 20 import org.eclipse.emf.ecore.EPackage; 21 import org.eclipse.emf.ecore.EStructuralFeature; 22 import org.eclipse.emf.ecore.EcorePackage; 23 import org.eclipse.emf.ecore.util.BasicExtendedMetaData; 24 import org.eclipse.emf.ecore.util.ExtendedMetaData; 25 import org.eclipse.emf.ecore.xmi.XMIResource; 26 import org.eclipse.emf.ecore.xmi.XMLResource; 27 28 29 public class EMOFExtendedMetaData extends BasicExtendedMetaData 30 { 31 public static final String EMOF_PACKAGE_NS_PREFIX = "emof"; 32 public static final String EMOF_PACKAGE_NS_URI = "http://schema.omg.org/spec/mof/2.0/emof.xmi"; 33 34 public static final String EXTENSION = "Extension"; 35 public static final String XMI_EXTENSION_ELEMENT = XMIResource.XMI_NS + ":" + EXTENSION; 36 public static final String XMI_EXTENDER_ATTRIBUTE = "extender"; 37 public static final String EMOF_XMI_EXTENDER = EcorePackage.eNS_URI; 38 39 public static final String ECORE_EDATATYPE_HREF_PREFIX = EcorePackage.eNS_URI + "#//"; 40 public static final String UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX = EcorePackage.eNS_URI + ".emof#ecore."; 41 public static final String MAPPED_EMOF_EDATATYPE_HREF_PREFIX = EMOF_PACKAGE_NS_URI + "#"; 42 43 public static final String [] MAPPED_ECORE_EDATATYPES = { "EString", "EBoolean", "EInt", "EBigInteger" }; 44 public static final String [] MAPPED_EMOF_EDATATYPES = { "String", "Boolean", "Integer", "UnlimitedNatural" }; 45 46 public static final String TAG = "Tag"; 47 public static final String EMOF_TAG = EMOF_PACKAGE_NS_PREFIX + ":" + TAG; 48 public static final String EMOF_TAG_NAME = "name"; 49 public static final String EMOF_TAG_VALUE = "value"; 50 public static final String EMOF_TAG_ELEMENT = "element"; 51 52 public static final String EMOF_PROPERTY_CLASS_NAME = "Property"; 53 54 protected XMLResource.XMLMap xmlMap; 55 56 public EMOFExtendedMetaData(XMLResource.XMLMap xmlMap) 57 { 58 super(); 59 this.xmlMap = xmlMap; 60 } 61 62 public String getNamespace(EPackage ePackage) 63 { 64 return ePackage == EcorePackage.eINSTANCE ? EMOF_PACKAGE_NS_URI : super.getNamespace(ePackage); 65 } 66 67 public EPackage getPackage(String namespace) 68 { 69 return EMOF_PACKAGE_NS_URI.equals(namespace) ? EcorePackage.eINSTANCE : super.getPackage(namespace); 70 } 71 72 public String getName(EClassifier eClassifier) 73 { 74 XMLResource.XMLInfo info = xmlMap.getInfo(eClassifier); 75 if (info != null) 76 { 77 String name = info.getName(); 78 if (name != null) 79 { 80 return info.getName(); 81 } 82 } 83 return super.getName(eClassifier); 84 } 85 86 public String getName(EStructuralFeature eStructuralFeature) 87 { 88 XMLResource.XMLInfo info = xmlMap.getInfo(eStructuralFeature); 89 if (info != null) 90 { 91 String name = info.getName(); 92 if (name != null) 93 { 94 return info.getName(); 95 } 96 } 97 return super.getName(eStructuralFeature); 98 } 99 100 public EClassifier getType(EPackage ePackage, String name) 101 { 102 EClassifier eClassifier = super.getType(ePackage, name); 103 if (eClassifier == null) 104 { 105 eClassifier = xmlMap.getClassifier(ePackage.getNsURI(), name); 106 } 107 return eClassifier; 108 } 109 110 public int getFeatureKind(EStructuralFeature feature) 111 { 112 XMLResource.XMLInfo info = xmlMap.getInfo(feature); 113 if (info != null) 114 { 115 switch (info.getXMLRepresentation()) 116 { 117 case XMLResource.XMLInfo.ELEMENT: 118 return ExtendedMetaData.ELEMENT_FEATURE; 119 case XMLResource.XMLInfo.ATTRIBUTE: 120 return ExtendedMetaData.ATTRIBUTE_FEATURE; 121 } 122 } 123 return super.getFeatureKind(feature); 124 } 125 } 126 | Popular Tags |