KickJava   Java API By Example, From Geeks To Geeks.

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


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: URIMappingRegistryReader.java,v 1.3 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.plugin;
18
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21 import org.eclipse.core.runtime.Platform;
22
23 import org.eclipse.emf.common.util.URI;
24 import org.eclipse.emf.ecore.resource.URIConverter;
25
26
27 /**
28  * A plugin extension reader that populates the
29  * {@link org.eclipse.emf.ecore.resource.URIConverter#URI_MAP global} mapping registry.
30  * Clients are not expected to use this class directly.
31  */

32 class URIMappingRegistryReader extends RegistryReader
33 {
34   static final String JavaDoc TAG_MAPPING = "mapping";
35   static final String JavaDoc ATT_SOURCE = "source";
36   static final String JavaDoc ATT_TARGET = "target";
37    
38   public URIMappingRegistryReader()
39   {
40     super
41       (Platform.getExtensionRegistry(),
42        EcorePlugin.getPlugin().getBundle().getSymbolicName(),
43        EcorePlugin.URI_MAPPING_PPID);
44   }
45
46   protected boolean readElement(IConfigurationElement element)
47   {
48     if (element.getName().equals(TAG_MAPPING))
49     {
50       String JavaDoc sourceURIValue = element.getAttribute(ATT_SOURCE);
51       if (sourceURIValue == null)
52       {
53         logMissingAttribute(element, ATT_SOURCE);
54       }
55       else
56       {
57         String JavaDoc targetURIValue = element.getAttribute(ATT_TARGET);
58         if (targetURIValue == null)
59         {
60           logMissingAttribute(element, ATT_TARGET);
61         }
62         else
63         {
64           URI sourceURI = URI.createURI(sourceURIValue);
65           URI targetURI = URI.createURI(targetURIValue);
66           if (targetURI.isRelative() && targetURI.hasRelativePath())
67           {
68             targetURI =
69               targetURI.resolve
70                 (URI.createURI
71                   (Platform.getBundle(element.getDeclaringExtension().getNamespace()).getEntry("/").toString()));
72           }
73           URIConverter.URI_MAP.put(sourceURI, targetURI);
74           return true;
75         }
76       }
77     }
78     return false;
79   }
80 }
81
Popular Tags