1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 import java.util.Map ; 20 21 import org.eclipse.emf.ecore.EAnnotation; 22 import org.eclipse.emf.ecore.EObject; 23 import org.eclipse.emf.ecore.EcorePackage; 24 import org.eclipse.emf.ecore.InternalEObject; 25 import org.eclipse.emf.ecore.xmi.XMIResource; 26 import org.eclipse.emf.ecore.xmi.XMLHelper; 27 import org.eclipse.emf.ecore.xmi.XMLResource; 28 29 30 public class EMOFHandler extends SAXXMIHandler 31 { 32 protected EMOFHandler.Helper emofHelper; 33 protected static final String ECORE_EXTENSION_TYPE = "ecoreExtension"; 34 35 public EMOFHandler(XMLResource xmiResource, EMOFHandler.Helper helper, Map options) 36 { 37 super(xmiResource, helper, options); 38 emofHelper = helper; 39 } 40 41 protected void handleProxy(InternalEObject proxy, String uriLiteral) 42 { 43 if (uriLiteral.startsWith(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPE_HREF_PREFIX)) 44 { 45 String dataType = uriLiteral.substring(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPE_HREF_PREFIX.length()); 46 for (int i = 0; i < EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPES.length; i++) 47 { 48 if (dataType.equals(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPES[i])) 49 { 50 uriLiteral = EMOFExtendedMetaData.ECORE_EDATATYPE_HREF_PREFIX + EMOFExtendedMetaData.MAPPED_ECORE_EDATATYPES[i]; 51 break; 52 } 53 } 54 } 55 else if (uriLiteral.startsWith(EMOFExtendedMetaData.UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX)) 56 { 57 String dataType = uriLiteral.substring(EMOFExtendedMetaData.UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX.length()); 58 uriLiteral = EMOFExtendedMetaData.ECORE_EDATATYPE_HREF_PREFIX + dataType; 59 } 60 61 super.handleProxy(proxy, uriLiteral); 62 } 63 64 protected void handleForwardReferences(boolean isEndDocument) 65 { 66 super.handleForwardReferences(isEndDocument); 67 68 if (isEndDocument) 69 { 70 emofHelper.convertPropertyFeatures(); 71 } 72 } 73 74 protected void processElement(String name, String prefix, String localName) 75 { 76 if (EMOFExtendedMetaData.EXTENSION.equals(localName) && XMIResource.XMI_URI.equals(helper.getURI(prefix))) 77 { 78 if (attribs != null && EcorePackage.eNS_URI.equals(attribs.getValue(EMOFExtendedMetaData.XMI_EXTENDER_ATTRIBUTE))) 79 { 80 types.push(ECORE_EXTENSION_TYPE); 81 } 82 else 83 { 84 types.push(ERROR_TYPE); 85 } 86 } 87 else 88 { 89 super.processElement(name, prefix, localName); 90 } 91 } 92 93 public void endElement(String uri, String localName, String name) 94 { 95 if (types.peek() == ECORE_EXTENSION_TYPE) 96 { 97 elements.pop(); 98 types.pop(); 99 helper.popContext(); 100 mixedTargets.pop(); 101 } 102 else 103 { 104 super.endElement(uri, localName, name); 105 } 106 } 107 108 protected void setAttribValue(EObject object, String name, String value) 109 { 110 if (object instanceof EAnnotation) 111 { 112 EAnnotation annotation = (EAnnotation)object; 113 if (EMOFExtendedMetaData.EMOF_PACKAGE_NS_URI.equals(annotation.getSource())) 114 { 115 if (EMOFExtendedMetaData.EMOF_TAG_NAME.equals(name) || EMOFExtendedMetaData.EMOF_TAG_VALUE.equals(name)) 116 { 117 annotation.getDetails().put(name, value); 118 return; 119 } 120 } 121 } 122 super.setAttribValue(object, name, value); 123 } 124 125 public static interface Helper extends XMLHelper 126 { 127 void convertPropertyFeatures(); 128 } 129 } 130 | Popular Tags |