1 17 package org.eclipse.emf.ecore.plugin; 18 19 20 import java.util.Map ; 21 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.Platform; 24 25 import org.eclipse.emf.common.util.URI; 26 import org.eclipse.emf.ecore.EPackage; 27 28 33 class GeneratedPackageRegistryReader extends RegistryReader 34 { 35 static final String TAG_PACKAGE = "package"; 36 static final String ATT_URI = "uri"; 37 static final String ATT_CLASS = "class"; 38 static final String ATT_GEN_MODEL = "genModel"; 39 40 protected Map ePackageNsURIToGenModelLocationMap; 41 42 public GeneratedPackageRegistryReader() 43 { 44 super 45 (Platform.getExtensionRegistry(), 46 EcorePlugin.getPlugin().getBundle().getSymbolicName(), 47 EcorePlugin.GENERATED_PACKAGE_PPID); 48 } 49 50 public GeneratedPackageRegistryReader(Map ePackageNsURIToGenModelLocationMap) 51 { 52 this(); 53 this.ePackageNsURIToGenModelLocationMap = ePackageNsURIToGenModelLocationMap; 54 } 55 56 protected boolean readElement(IConfigurationElement element) 57 { 58 if (element.getName().equals(TAG_PACKAGE)) 59 { 60 String packageURI = element.getAttribute(ATT_URI); 61 if (packageURI == null) 62 { 63 logMissingAttribute(element, ATT_URI); 64 } 65 else if (element.getAttribute(ATT_CLASS) == null) 66 { 67 logMissingAttribute(element, ATT_CLASS); 68 } 69 else 70 { 71 EPackage.Registry.INSTANCE.put(packageURI, new EPackageDescriptor(element, ATT_CLASS)); 72 73 if (ePackageNsURIToGenModelLocationMap != null) 74 { 75 String genModel = element.getAttribute(ATT_GEN_MODEL); 76 if (genModel != null) 77 { 78 URI genModelURI = URI.createURI(genModel); 79 if (genModelURI.isRelative()) 80 { 81 genModelURI = URI.createURI("platform:/plugin/" + element.getDeclaringExtension().getNamespace() + "/" + genModel); 82 } 83 ePackageNsURIToGenModelLocationMap.put(packageURI, genModelURI); 84 } 85 } 86 return true; 87 } 88 } 89 90 return false; 91 } 92 } 93 | Popular Tags |