KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > xmi > impl > EMOFExtendedMetaData


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-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: EMOFExtendedMetaData.java,v 1.3 2005/06/08 06:16:07 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.xmi.impl;
18
19 import org.eclipse.emf.ecore.EClassifier;
20 import org.eclipse.emf.ecore.EPackage;
21 import org.eclipse.emf.ecore.EStructuralFeature;
22 import org.eclipse.emf.ecore.EcorePackage;
23 import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
24 import org.eclipse.emf.ecore.util.ExtendedMetaData;
25 import org.eclipse.emf.ecore.xmi.XMIResource;
26 import org.eclipse.emf.ecore.xmi.XMLResource;
27
28
29 public class EMOFExtendedMetaData extends BasicExtendedMetaData
30 {
31   public static final String JavaDoc EMOF_PACKAGE_NS_PREFIX = "emof";
32   public static final String JavaDoc EMOF_PACKAGE_NS_URI = "http://schema.omg.org/spec/mof/2.0/emof.xmi";
33
34   public static final String JavaDoc EXTENSION = "Extension";
35   public static final String JavaDoc XMI_EXTENSION_ELEMENT = XMIResource.XMI_NS + ":" + EXTENSION;
36   public static final String JavaDoc XMI_EXTENDER_ATTRIBUTE = "extender";
37   public static final String JavaDoc EMOF_XMI_EXTENDER = EcorePackage.eNS_URI;
38
39   public static final String JavaDoc ECORE_EDATATYPE_HREF_PREFIX = EcorePackage.eNS_URI + "#//";
40   public static final String JavaDoc UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX = EcorePackage.eNS_URI + ".emof#ecore.";
41   public static final String JavaDoc MAPPED_EMOF_EDATATYPE_HREF_PREFIX = EMOF_PACKAGE_NS_URI + "#";
42
43   public static final String JavaDoc[] MAPPED_ECORE_EDATATYPES = { "EString", "EBoolean", "EInt", "EBigInteger" };
44   public static final String JavaDoc[] MAPPED_EMOF_EDATATYPES = { "String", "Boolean", "Integer", "UnlimitedNatural" };
45
46   public static final String JavaDoc TAG = "Tag";
47   public static final String JavaDoc EMOF_TAG = EMOF_PACKAGE_NS_PREFIX + ":" + TAG;
48   public static final String JavaDoc EMOF_TAG_NAME = "name";
49   public static final String JavaDoc EMOF_TAG_VALUE = "value";
50   public static final String JavaDoc EMOF_TAG_ELEMENT = "element";
51
52   public static final String JavaDoc EMOF_PROPERTY_CLASS_NAME = "Property";
53
54   protected XMLResource.XMLMap xmlMap;
55
56   public EMOFExtendedMetaData(XMLResource.XMLMap xmlMap)
57   {
58     super();
59     this.xmlMap = xmlMap;
60   }
61
62   public String JavaDoc getNamespace(EPackage ePackage)
63   {
64     return ePackage == EcorePackage.eINSTANCE ? EMOF_PACKAGE_NS_URI : super.getNamespace(ePackage);
65   }
66
67   public EPackage getPackage(String JavaDoc namespace)
68   {
69     return EMOF_PACKAGE_NS_URI.equals(namespace) ? EcorePackage.eINSTANCE : super.getPackage(namespace);
70   }
71
72   public String JavaDoc getName(EClassifier eClassifier)
73   {
74     XMLResource.XMLInfo info = xmlMap.getInfo(eClassifier);
75     if (info != null)
76     {
77       String JavaDoc name = info.getName();
78       if (name != null)
79       {
80         return info.getName();
81       }
82     }
83     return super.getName(eClassifier);
84   }
85   
86   public String JavaDoc getName(EStructuralFeature eStructuralFeature)
87   {
88     XMLResource.XMLInfo info = xmlMap.getInfo(eStructuralFeature);
89     if (info != null)
90     {
91       String JavaDoc name = info.getName();
92       if (name != null)
93       {
94         return info.getName();
95       }
96     }
97     return super.getName(eStructuralFeature);
98   }
99
100   public EClassifier getType(EPackage ePackage, String JavaDoc name)
101   {
102     EClassifier eClassifier = super.getType(ePackage, name);
103     if (eClassifier == null)
104     {
105       eClassifier = xmlMap.getClassifier(ePackage.getNsURI(), name);
106     }
107     return eClassifier;
108   }
109
110   public int getFeatureKind(EStructuralFeature feature)
111   {
112     XMLResource.XMLInfo info = xmlMap.getInfo(feature);
113     if (info != null)
114     {
115       switch (info.getXMLRepresentation())
116       {
117         case XMLResource.XMLInfo.ELEMENT:
118           return ExtendedMetaData.ELEMENT_FEATURE;
119         case XMLResource.XMLInfo.ATTRIBUTE:
120           return ExtendedMetaData.ATTRIBUTE_FEATURE;
121       }
122     }
123     return super.getFeatureKind(feature);
124   }
125 }
126
Popular Tags