KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.eclipse.emf.ecore.xmi.impl;
18
19
20 import java.util.Map JavaDoc;
21
22 import org.eclipse.emf.ecore.EObject;
23
24 import org.eclipse.emf.ecore.xmi.XMIResource;
25 import org.eclipse.emf.ecore.xmi.XMLHelper;
26 import org.eclipse.emf.ecore.xmi.XMLResource;
27
28
29 /**
30  * This class is a SAX handler for creating MOF2 objects from an XMI 2.0 file.
31  */

32 public abstract class XMIHandler extends XMLHandler
33 {
34   protected static final String JavaDoc XMI_ELEMENT_TYPE = "xmi";
35   protected static final String JavaDoc XMI_UUID = "uuid";
36   protected static final String JavaDoc XMI_EXTENSION = "Extension";
37
38   protected final static String JavaDoc XMI_TYPE_ATTRIB = XMIResource.XMI_NS + ":" + XMLResource.TYPE;
39   protected final static String JavaDoc ID_ATTRIB = XMIResource.XMI_NS + ":" + XMIResource.XMI_ID;
40   protected final static String JavaDoc VERSION_ATTRIB = XMIResource.XMI_NS + ":" + XMIResource.VERSION_NAME;
41   protected final static String JavaDoc UUID_ATTRIB = XMIResource.XMI_NS + ":" + XMI_UUID;
42   protected final static String JavaDoc XMI_ELEMENT_NAME = XMIResource.XMI_NS + ":" + XMIResource.XMI_TAG_NAME;
43
44   /**
45    * Constructor.
46    */

47   public XMIHandler(XMLResource xmiResource, XMLHelper helper, Map JavaDoc options)
48   {
49     super(xmiResource, helper, options);
50
51     hrefAttribute = XMLResource.HREF;
52     notFeatures.add(VERSION_ATTRIB);
53     notFeatures.add(XMI_TYPE_ATTRIB);
54     notFeatures.add(UUID_ATTRIB);
55   }
56
57   protected void processElement(String JavaDoc name, String JavaDoc prefix, String JavaDoc localName)
58   {
59     if (name.equals(XMI_ELEMENT_NAME))
60     {
61       types.push(XMI_ELEMENT_TYPE);
62     }
63     else
64     {
65       super.processElement(name, prefix, localName);
66     }
67   }
68
69   protected boolean isTextFeatureValue(Object JavaDoc type)
70   {
71     return super.isTextFeatureValue(type) && type != XMI_ELEMENT_TYPE;
72   }
73
74   protected void handleUnknownFeature(String JavaDoc prefix, String JavaDoc name, boolean isElement, EObject peekObject, String JavaDoc value)
75   {
76     if (XMI_EXTENSION.equals(name) && XMIResource.XMI_URI.equals(helper.getURI(prefix)))
77     {
78       if (extendedMetaData == null)
79       {
80         setExtendedMetaDataOption(Boolean.TRUE);
81       }
82
83       recordUnknownFeature(prefix, name, isElement, peekObject, value);
84     }
85     else
86     {
87       super.handleUnknownFeature(prefix, name, isElement, peekObject, value);
88     }
89   }
90 } // XMIHandler
91
Popular Tags