org.eclipse.emf.ecore.xmi.impl
Class XMLHandler

java.lang.Object
  |
  +--org.eclipse.emf.ecore.xmi.impl.XMLHandler
Direct Known Subclasses:
SAXXMLHandler, XMIHandler

public abstract class XMLHandler
extends java.lang.Object

This class is a generic interface for loading XML files and creating EObjects from them. Its subclasses include the SAXXMLHandler class, which wraps this class in a SAX default handler.


Inner Class Summary
protected static class XMLHandler.ManyReference
           
protected static class XMLHandler.MyStack
           
protected static class XMLHandler.SingleReference
          For unresolved forward references, the line number where the incorrect id appeared in an XML resource is needed, so the Value for the forward reference and the line number where the forward reference occurred must be saved until the end of the XML resource is encountered.
 
Field Summary
protected static int ARRAY_SIZE
           
protected  int capacity
           
protected  boolean disableNotify
           
protected  XMLHandler.MyStack elements
           
protected static java.lang.String ERROR_TYPE
           
protected  InternalEList extent
           
protected  java.util.List forwardManyReferences
           
protected  java.util.List forwardSingleReferences
           
protected  XMLHelper helper
           
protected  java.lang.String idAttribute
           
protected  java.lang.Object[] identifiers
           
protected static java.lang.String NIL_ATTRIB
           
protected static java.lang.String NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB
           
protected  java.util.Set notFeatures
           
protected static java.lang.String OBJECT_TYPE
           
protected  XMLHandler.MyStack objects
           
protected  boolean oldStyleProxyURIs
           
protected  int[] positions
           
protected  java.util.Map prefixesToFactories
           
protected static int REFERENCE_THRESHOLD
           
protected  boolean resolve
           
protected  ResourceSet resourceSet
           
protected  URI resourceURI
           
protected  java.util.List sameDocumentProxies
           
protected static java.lang.String SCHEMA_LOCATION_ATTRIB
           
protected  java.lang.StringBuffer text
           
protected static java.lang.String TYPE_ATTRIB
           
protected  XMLHandler.MyStack types
           
protected  java.util.Map urisToLocations
           
protected  XMLResource.XMLMap xmlMap
           
protected  XMLResource xmlResource
           
 
Constructor Summary
XMLHandler(XMLResource xmlResource, XMLHelper helper, java.util.Map options)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
protected  void createObject(EObject peekObject, EStructuralFeature feature)
          Create an object based on the given feature and attributes.
protected  EObject createObjectFromFactory(EFactory factory, java.lang.String typeName)
          Create an object given a content helper, a factory, and a type name, and process the XML attributes.
protected  EObject createObjectFromFeatureType(EObject peekObject, EStructuralFeature feature)
          Create an object based on the type of the given feature.
protected  EObject createObjectFromTypeName(EObject peekObject, java.lang.String typeQName, EStructuralFeature feature)
          Create an object from the given qualified type name.
protected  void createTopObject(java.lang.String prefix, java.lang.String name)
          Create a top object based on the prefix and name.
 void endDocument()
          Check if the values of the forward references have been set (they may have been set due to a bi-directional reference being set).
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
          Pop the appropriate stacks and set features whose values are in the content of XML elements.
 void endPrefixMapping(java.lang.String prefix)
           
 void error(XMIException e)
           
 void fatalError(XMIException e)
           
protected  int getColumnNumber()
           
protected  EFactory getFactoryForPrefix(java.lang.String prefix)
           
protected  EStructuralFeature getFeature(EObject object, java.lang.String prefix, java.lang.String name)
          Get the EStructuralFeature from the metaObject for the given object and feature name.
protected  int getLineNumber()
           
protected  java.lang.String getLocation()
           
protected  EPackage getPackageForURI(java.lang.String uriString)
          Attempt to get the namespace for the given prefix, then return ERegister.getPackage() or null.
static java.lang.String getXMLEncoding(byte[] bytes)
          Searches the array of bytes to determine the XML encoding.
protected abstract  java.lang.String getXSIType()
          Returns the xsi type attribute's value.
protected  void growArrays()
           
protected  void handleFeature(java.lang.String prefix, java.lang.String name)
          The XML element represents a feature.
protected abstract  void handleNamespaceAttribs()
          Process the XML namespace declarations.
protected abstract  void handleObjectAttribs(EObject obj)
          Process the XML attributes for the newly created object.
protected  void handleProxy(InternalEObject proxy, java.lang.String uriLiteral)
           
protected  void handleXMLNSAttribute(java.lang.String attrib, java.lang.String value)
           
protected  void handleXSINoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)
           
protected  void handleXSISchemaLocation(java.lang.String schemaLocations)
           
protected  boolean isError()
          Returns true if there was an error in the last XML element; false otherwise.
protected abstract  boolean isNull()
          Returns true if the xsi:nil attribute is in the list of attributes.
protected  boolean isTextFeatureValue(java.lang.Object type)
           
protected  void processElement(java.lang.String name, java.lang.String prefix, java.lang.String localName)
           
protected  void processObject(EObject object)
          Add object to appropriate stacks.
protected  void processTopObject(EObject object)
          Add object to extent and call processObject.
protected abstract  java.lang.Object setAttributes(java.lang.Object attributes)
          Sets the current attributes and returns the old ones.
protected  void setAttribValue(EObject object, java.lang.String name, java.lang.String value)
          Create a feature with the given name for the given object with the given values.
protected  void setFeatureValue(EObject object, EStructuralFeature feature, java.lang.Object value)
           
protected  void setFeatureValue(EObject object, EStructuralFeature feature, java.lang.Object value, int position)
          Set the given feature of the given object to the given value.
protected  void setFeatureValues(XMLHandler.ManyReference reference)
          Set the values for the given multi-valued forward reference.
protected abstract  void setLocator(java.lang.Object locator)
          Sets the object that might be used for determining the line and column number.
protected  void setValueFromId(EObject object, EReference eReference, java.lang.String ids)
          Create a ValueLine object and put it in the list of references to resolve at the end of the document.
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
          This method determines whether to make an object or not, then makes an object based on the XML attributes and the metamodel.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 void warning(XMIException e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_TYPE

protected static final java.lang.String ERROR_TYPE

OBJECT_TYPE

protected static final java.lang.String OBJECT_TYPE

TYPE_ATTRIB

protected static final java.lang.String TYPE_ATTRIB

NIL_ATTRIB

protected static final java.lang.String NIL_ATTRIB

SCHEMA_LOCATION_ATTRIB

protected static final java.lang.String SCHEMA_LOCATION_ATTRIB

NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB

protected static final java.lang.String NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB

xmlResource

protected XMLResource xmlResource

helper

protected XMLHelper helper

elements

protected XMLHandler.MyStack elements

objects

protected XMLHandler.MyStack objects

types

protected XMLHandler.MyStack types

prefixesToFactories

protected java.util.Map prefixesToFactories

urisToLocations

protected java.util.Map urisToLocations

extent

protected InternalEList extent

resourceSet

protected ResourceSet resourceSet

resourceURI

protected URI resourceURI

resolve

protected boolean resolve

oldStyleProxyURIs

protected boolean oldStyleProxyURIs

disableNotify

protected boolean disableNotify

text

protected java.lang.StringBuffer text

sameDocumentProxies

protected java.util.List sameDocumentProxies

forwardSingleReferences

protected java.util.List forwardSingleReferences

forwardManyReferences

protected java.util.List forwardManyReferences

identifiers

protected java.lang.Object[] identifiers

positions

protected int[] positions

ARRAY_SIZE

protected static final int ARRAY_SIZE

REFERENCE_THRESHOLD

protected static final int REFERENCE_THRESHOLD

capacity

protected int capacity

notFeatures

protected java.util.Set notFeatures

idAttribute

protected java.lang.String idAttribute

xmlMap

protected XMLResource.XMLMap xmlMap
Constructor Detail

XMLHandler

public XMLHandler(XMLResource xmlResource,
                  XMLHelper helper,
                  java.util.Map options)
Method Detail

handleObjectAttribs

protected abstract void handleObjectAttribs(EObject obj)
Process the XML attributes for the newly created object.

handleNamespaceAttribs

protected abstract void handleNamespaceAttribs()
Process the XML namespace declarations.

isNull

protected abstract boolean isNull()
Returns true if the xsi:nil attribute is in the list of attributes.

setAttributes

protected abstract java.lang.Object setAttributes(java.lang.Object attributes)
Sets the current attributes and returns the old ones.

setLocator

protected abstract void setLocator(java.lang.Object locator)
Sets the object that might be used for determining the line and column number.

getXSIType

protected abstract java.lang.String getXSIType()
Returns the xsi type attribute's value.

startDocument

public void startDocument()

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String name)
This method determines whether to make an object or not, then makes an object based on the XML attributes and the metamodel.

processElement

protected void processElement(java.lang.String name,
                              java.lang.String prefix,
                              java.lang.String localName)

endDocument

public void endDocument()
Check if the values of the forward references have been set (they may have been set due to a bi-directional reference being set). If not, set them.

createTopObject

protected void createTopObject(java.lang.String prefix,
                               java.lang.String name)
Create a top object based on the prefix and name.

processTopObject

protected void processTopObject(EObject object)
Add object to extent and call processObject.

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String name)
Pop the appropriate stacks and set features whose values are in the content of XML elements.

isTextFeatureValue

protected boolean isTextFeatureValue(java.lang.Object type)

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)

characters

public void characters(char[] ch,
                       int start,
                       int length)

handleXMLNSAttribute

protected void handleXMLNSAttribute(java.lang.String attrib,
                                    java.lang.String value)

handleXSISchemaLocation

protected void handleXSISchemaLocation(java.lang.String schemaLocations)

handleXSINoNamespaceSchemaLocation

protected void handleXSINoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)

handleFeature

protected void handleFeature(java.lang.String prefix,
                             java.lang.String name)
The XML element represents a feature. There are two cases to handle: 1. The feature has a type that is a datatype. 2. The feature has a type that is a class.

getLineNumber

protected int getLineNumber()

getColumnNumber

protected int getColumnNumber()

getLocation

protected java.lang.String getLocation()

error

public void error(XMIException e)

warning

public void warning(XMIException e)

fatalError

public void fatalError(XMIException e)

createObject

protected void createObject(EObject peekObject,
                            EStructuralFeature feature)
Create an object based on the given feature and attributes.

createObjectFromTypeName

protected EObject createObjectFromTypeName(EObject peekObject,
                                           java.lang.String typeQName,
                                           EStructuralFeature feature)
Create an object from the given qualified type name.

createObjectFromFeatureType

protected EObject createObjectFromFeatureType(EObject peekObject,
                                              EStructuralFeature feature)
Create an object based on the type of the given feature.

createObjectFromFactory

protected EObject createObjectFromFactory(EFactory factory,
                                          java.lang.String typeName)
Create an object given a content helper, a factory, and a type name, and process the XML attributes.

processObject

protected void processObject(EObject object)
Add object to appropriate stacks.

getFactoryForPrefix

protected EFactory getFactoryForPrefix(java.lang.String prefix)

getPackageForURI

protected EPackage getPackageForURI(java.lang.String uriString)
Attempt to get the namespace for the given prefix, then return ERegister.getPackage() or null.

setFeatureValue

protected void setFeatureValue(EObject object,
                               EStructuralFeature feature,
                               java.lang.Object value)

setFeatureValue

protected void setFeatureValue(EObject object,
                               EStructuralFeature feature,
                               java.lang.Object value,
                               int position)
Set the given feature of the given object to the given value.

setFeatureValues

protected void setFeatureValues(XMLHandler.ManyReference reference)
Set the values for the given multi-valued forward reference.

setAttribValue

protected void setAttribValue(EObject object,
                              java.lang.String name,
                              java.lang.String value)
Create a feature with the given name for the given object with the given values.

setValueFromId

protected void setValueFromId(EObject object,
                              EReference eReference,
                              java.lang.String ids)
Create a ValueLine object and put it in the list of references to resolve at the end of the document.

handleProxy

protected void handleProxy(InternalEObject proxy,
                           java.lang.String uriLiteral)

growArrays

protected void growArrays()

isError

protected boolean isError()
Returns true if there was an error in the last XML element; false otherwise.

getFeature

protected EStructuralFeature getFeature(EObject object,
                                        java.lang.String prefix,
                                        java.lang.String name)
Get the EStructuralFeature from the metaObject for the given object and feature name.

getXMLEncoding

public static java.lang.String getXMLEncoding(byte[] bytes)
Searches the array of bytes to determine the XML encoding.

Copyright 2001-2003 IBM Corporation and others.
All Rights Reserved.