1 17 package org.eclipse.emf.mapping.ecore2xml; 18 19 20 import java.util.Map ; 21 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.IExtensionPoint; 24 import org.eclipse.core.runtime.IExtensionRegistry; 25 import org.eclipse.emf.common.util.URI; 26 import org.eclipse.emf.common.util.WrappedException; 27 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; 28 import org.eclipse.emf.ecore.util.EcoreUtil; 29 import org.eclipse.emf.ecore.xmi.XMLResource; 30 import org.eclipse.emf.mapping.ecore2xml.impl.Ecore2XMLRegistryImpl; 31 32 33 36 public interface Ecore2XMLRegistry extends Map 37 { 38 39 42 public interface Descriptor 43 { 44 XMLResource.XMLMap getXMLMap(); 45 } 46 47 50 public static class Reader 51 { 52 53 protected static class Ecore2XMLDescriptor implements Descriptor 54 { 55 private final IConfigurationElement element; 56 57 private XMLResource.XMLMap xmlMap = null; 58 59 protected Ecore2XMLDescriptor(IConfigurationElement element) 60 { 61 super(); 62 63 this.element = element; 64 } 65 66 public XMLResource.XMLMap getXMLMap() 67 { 68 if (xmlMap == null) 69 { 70 try 71 { 72 xmlMap = (XMLResource.XMLMap)EcoreUtil.getObjectByType(new ResourceSetImpl().getResource( 73 URI.createURI(element.getAttribute(ATT_XMLMAP)), 74 true).getContents(), Ecore2XMLPackage.eINSTANCE.getXMLMap()); 75 } 76 catch (Exception e) 77 { 78 throw new WrappedException(e); 79 } 80 } 81 82 return xmlMap; 83 } 84 } 85 86 protected static final String TAG_ECORE2XML = "ecore2xml"; 88 protected static final String ATT_URI = "uri"; 90 protected static final String ATT_XMLMAP = "xmlmap"; 92 private final IExtensionRegistry extensionRegistry; 93 94 private final String namespace; 95 96 private final String extensionPointID; 97 98 public Reader(IExtensionRegistry extensionRegistry, String namespace, String extensionPointID) 99 { 100 super(); 101 102 this.extensionRegistry = extensionRegistry; 103 this.namespace = namespace; 104 this.extensionPointID = extensionPointID; 105 } 106 107 protected void readElement(IConfigurationElement element) 108 { 109 if (TAG_ECORE2XML.equals(element.getName())) 110 { 111 String uri = element.getAttribute(ATT_URI); 112 113 if (uri == null || element.getAttribute(ATT_XMLMAP) == null) 114 { 115 } 117 else 118 { 119 Ecore2XMLRegistry.INSTANCE.put(uri, new Ecore2XMLDescriptor(element)); 120 } 121 } 122 else 123 { 124 } 126 } 127 128 public void readRegistry() 129 { 130 IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(namespace, extensionPointID); 131 132 if (extensionPoint != null) 133 { 134 IConfigurationElement[] elements = extensionPoint.getConfigurationElements(); 135 136 for (int i = 0; i < elements.length; i++) 137 { 138 readElement(elements[i]); 139 } 140 } 141 } 142 143 } 144 145 Ecore2XMLRegistry INSTANCE = new Ecore2XMLRegistryImpl(); 146 147 XMLResource.XMLMap getXMLMap(String nsURI); 148 149 } | Popular Tags |