KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.eclipse.emf.ecore.xmi.impl;
18
19 import java.util.Map JavaDoc;
20
21 import org.eclipse.emf.ecore.EAnnotation;
22 import org.eclipse.emf.ecore.EObject;
23 import org.eclipse.emf.ecore.EcorePackage;
24 import org.eclipse.emf.ecore.InternalEObject;
25 import org.eclipse.emf.ecore.xmi.XMIResource;
26 import org.eclipse.emf.ecore.xmi.XMLHelper;
27 import org.eclipse.emf.ecore.xmi.XMLResource;
28
29
30 public class EMOFHandler extends SAXXMIHandler
31 {
32   protected EMOFHandler.Helper emofHelper;
33   protected static final String JavaDoc ECORE_EXTENSION_TYPE = "ecoreExtension";
34
35   public EMOFHandler(XMLResource xmiResource, EMOFHandler.Helper helper, Map JavaDoc options)
36   {
37     super(xmiResource, helper, options);
38     emofHelper = helper;
39   }
40
41   protected void handleProxy(InternalEObject proxy, String JavaDoc uriLiteral)
42   {
43     if (uriLiteral.startsWith(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPE_HREF_PREFIX))
44     {
45       String JavaDoc dataType = uriLiteral.substring(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPE_HREF_PREFIX.length());
46       for (int i = 0; i < EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPES.length; i++)
47       {
48         if (dataType.equals(EMOFExtendedMetaData.MAPPED_EMOF_EDATATYPES[i]))
49         {
50           uriLiteral = EMOFExtendedMetaData.ECORE_EDATATYPE_HREF_PREFIX + EMOFExtendedMetaData.MAPPED_ECORE_EDATATYPES[i];
51           break;
52         }
53       }
54     }
55     else if (uriLiteral.startsWith(EMOFExtendedMetaData.UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX))
56     {
57       String JavaDoc dataType = uriLiteral.substring(EMOFExtendedMetaData.UNMAPPED_EMOF_EDATATYPE_HREF_PREFIX.length());
58       uriLiteral = EMOFExtendedMetaData.ECORE_EDATATYPE_HREF_PREFIX + dataType;
59     }
60
61     super.handleProxy(proxy, uriLiteral);
62   }
63
64   protected void handleForwardReferences(boolean isEndDocument)
65   {
66     super.handleForwardReferences(isEndDocument);
67
68     if (isEndDocument)
69     {
70       emofHelper.convertPropertyFeatures();
71     }
72   }
73
74   protected void processElement(String JavaDoc name, String JavaDoc prefix, String JavaDoc localName)
75   {
76     if (EMOFExtendedMetaData.EXTENSION.equals(localName) && XMIResource.XMI_URI.equals(helper.getURI(prefix)))
77     {
78       if (attribs != null && EcorePackage.eNS_URI.equals(attribs.getValue(EMOFExtendedMetaData.XMI_EXTENDER_ATTRIBUTE)))
79       {
80         types.push(ECORE_EXTENSION_TYPE);
81       }
82       else
83       {
84         types.push(ERROR_TYPE);
85       }
86     }
87     else
88     {
89       super.processElement(name, prefix, localName);
90     }
91   }
92
93   public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc name)
94   {
95     if (types.peek() == ECORE_EXTENSION_TYPE)
96     {
97       elements.pop();
98       types.pop();
99       helper.popContext();
100       mixedTargets.pop();
101     }
102     else
103     {
104       super.endElement(uri, localName, name);
105     }
106   }
107
108   protected void setAttribValue(EObject object, String JavaDoc name, String JavaDoc value)
109   {
110     if (object instanceof EAnnotation)
111     {
112       EAnnotation annotation = (EAnnotation)object;
113       if (EMOFExtendedMetaData.EMOF_PACKAGE_NS_URI.equals(annotation.getSource()))
114       {
115         if (EMOFExtendedMetaData.EMOF_TAG_NAME.equals(name) || EMOFExtendedMetaData.EMOF_TAG_VALUE.equals(name))
116         {
117           annotation.getDetails().put(name, value);
118           return;
119         }
120       }
121     }
122     super.setAttribValue(object, name, value);
123   }
124
125   public static interface Helper extends XMLHelper
126   {
127     void convertPropertyFeatures();
128   }
129 }
130
Popular Tags