KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > plugin > GeneratedPackageRegistryReader


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: GeneratedPackageRegistryReader.java,v 1.4 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.plugin;
18
19
20 import java.util.Map JavaDoc;
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 /**
29  * A plugin extension reader that populates the
30  * {@link org.eclipse.emf.ecore.EPackage.Registry#INSTANCE global} package registry.
31  * Clients are not expected to use this class directly.
32  */

33 class GeneratedPackageRegistryReader extends RegistryReader
34 {
35   static final String JavaDoc TAG_PACKAGE = "package";
36   static final String JavaDoc ATT_URI = "uri";
37   static final String JavaDoc ATT_CLASS = "class";
38   static final String JavaDoc ATT_GEN_MODEL = "genModel";
39   
40   protected Map JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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