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

java.lang.Object
  extended byorg.eclipse.emf.ecore.xmi.impl.XMLHandler
Direct Known Subclasses:
SAXXMLHandler, XMIHandler

public abstract class XMLHandler
extends 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.


Nested 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  EClass anySimpleType
           
protected  EClass anyType
           
protected static int ARRAY_SIZE
           
protected  int capacity
           
protected  EStructuralFeature contextFeature
           
protected static boolean DEBUG_DEMANDED_PACKAGES
           
protected  boolean deferIDREFResolution
           
protected  boolean disableNotify
           
protected static String DOCUMENT_ROOT_TYPE
           
protected  XMLHandler.MyStack elements
           
protected  Map eObjectToExtensionMap
           
protected static String ERROR_TYPE
           
protected  ExtendedMetaData extendedMetaData
           
protected  InternalEList extent
           
protected  List forwardManyReferences
           
protected  List forwardSingleReferences
           
protected  XMLHelper helper
           
protected  String hrefAttribute
           
protected  String idAttribute
           
protected  Object[] identifiers
           
protected  boolean isIDREF
           
protected  boolean isSimpleFeature
           
protected  XMLHandler.MyStack mixedTargets
           
protected static String NIL_ATTRIB
           
protected static String NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB
           
protected  Set notFeatures
           
protected static String OBJECT_TYPE
           
protected  XMLHandler.MyStack objects
           
protected  boolean oldStyleProxyURIs
           
protected  EPackage.Registry packageRegistry
           
protected  int[] positions
           
protected  Map prefixesToFactories
           
protected  boolean recordAnyTypeNSDecls
           
protected  boolean recordUnknownFeature
           
protected static int REFERENCE_THRESHOLD
           
protected  boolean resolve
           
protected  ResourceSet resourceSet
           
protected  URI resourceURI
           
protected  List sameDocumentProxies
           
protected static String SCHEMA_LOCATION_ATTRIB
           
protected  StringBuffer text
           
protected static String TYPE_ATTRIB
           
protected  XMLHandler.MyStack types
           
protected static String UNKNOWN_FEATURE_TYPE
           
protected  Map urisToLocations
           
protected  XMLResource.XMLMap xmlMap
           
protected  XMLResource xmlResource
           
protected  EPackage xmlSchemaTypePackage
           
 
Constructor Summary
XMLHandler(XMLResource xmlResource, XMLHelper helper, Map options)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void comment(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 createObjectByType(String prefix, String name, boolean top)
          Create an object based on the prefix and type name.
protected  EObject createObjectFromFactory(EFactory factory, 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, String typeQName, EStructuralFeature feature)
          Create an object from the given qualified type name.
protected  void createTopObject(String prefix, String name)
           
 void endCDATA()
           
 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(String uri, String localName, String name)
          Pop the appropriate stacks and set features whose values are in the content of XML elements.
 void endPrefixMapping(String prefix)
           
 void error(XMIException e)
           
 void fatalError(XMIException e)
           
protected  int getColumnNumber()
           
protected  AnyType getExtension(EObject peekObject)
           
protected  EFactory getFactoryForPrefix(String prefix)
           
protected  EStructuralFeature getFeature(EObject object, String prefix, String name)
          Deprecated.  
protected  EStructuralFeature getFeature(EObject object, String prefix, String name, boolean isElement)
          Get the EStructuralFeature from the metaObject for the given object and feature name.
protected  int getLineNumber()
           
protected  String getLocation()
           
protected  EPackage getPackageForURI(String uriString)
          Attempt to get the namespace for the given prefix, then return ERegister.getPackage() or null.
protected  URIConverter getURIConverter()
           
static String getXMLEncoding(byte[] bytes)
          Searches the array of bytes to determine the XML encoding.
protected abstract  String getXSIType()
          Returns the xsi type attribute's value.
protected  void growArrays()
           
protected  void handleCDATA()
           
protected  void handleComment(String comment)
           
protected  void handleFeature(String prefix, String name)
          The XML element represents a feature.
protected  void handleForwardReferences()
           
protected  void handleForwardReferences(boolean isEndDocument)
          Check if the values of the forward references have been set (they may have been set due to a bi-directional reference being set).
protected  EPackage handleMissingPackage(String uriString)
           
protected  void handleMixedText()
           
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, String uriLiteral)
           
protected  void handleTopLocations(String prefix, String name)
           
protected  void handleUnknownFeature(String prefix, String name, boolean isElement, EObject peekObject, String value)
           
protected  void handleXMLNSAttribute(String attrib, String value)
           
protected  void handleXSINoNamespaceSchemaLocation(String noNamespaceSchemaLocation)
           
protected  void handleXSISchemaLocation(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(Object type)
           
protected  void processElement(String name, String prefix, String localName)
           
 void processingInstruction(String target, String data)
           
protected  void processObject(EObject object)
          Add object to appropriate stacks.
protected  void processTopObject(EObject object)
          Add object to extent and call processObject.
protected  EMap recordNamespacesSchemaLocations(EObject root)
           
protected  void recordUnknownFeature(String prefix, String name, boolean isElement, EObject peekObject, String value)
           
protected  void reportUnknownFeature(String prefix, String name, boolean isElement, EObject peekObject, String value)
           
protected abstract  Object setAttributes(Object attributes)
          Sets the current attributes and returns the old ones.
protected  void setAttribValue(EObject object, String name, String value)
          Create a feature with the given name for the given object with the given values.
protected  void setExtendedMetaDataOption(Object extendedMetaDataOption)
           
protected  void setFeatureValue(EObject object, EStructuralFeature feature, Object value)
           
protected  void setFeatureValue(EObject object, EStructuralFeature feature, 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(Object locator)
          Sets the object that might be used for determining the line and column number.
protected  void setValueFromId(EObject object, EReference eReference, String ids)
          Create a ValueLine object and put it in the list of references to resolve at the end of the document.
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String systemId)
           
 void startElement(String uri, String localName, 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(String prefix, String uri)
           
protected  void validateCreateObjectFromFactory(EFactory factory, String typeName, EObject newObject)
           
protected  EObject validateCreateObjectFromFactory(EFactory factory, String typeName, EObject newObject, EStructuralFeature feature)
           
 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 String ERROR_TYPE
See Also:
Constant Field Values

OBJECT_TYPE

protected static final String OBJECT_TYPE
See Also:
Constant Field Values

UNKNOWN_FEATURE_TYPE

protected static final String UNKNOWN_FEATURE_TYPE
See Also:
Constant Field Values

DOCUMENT_ROOT_TYPE

protected static final String DOCUMENT_ROOT_TYPE
See Also:
Constant Field Values

TYPE_ATTRIB

protected static final String TYPE_ATTRIB
See Also:
Constant Field Values

NIL_ATTRIB

protected static final String NIL_ATTRIB
See Also:
Constant Field Values

SCHEMA_LOCATION_ATTRIB

protected static final String SCHEMA_LOCATION_ATTRIB
See Also:
Constant Field Values

NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB

protected static final String NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB
See Also:
Constant Field Values

DEBUG_DEMANDED_PACKAGES

protected static final boolean DEBUG_DEMANDED_PACKAGES
See Also:
Constant Field Values

xmlResource

protected XMLResource xmlResource

helper

protected XMLHelper helper

elements

protected XMLHandler.MyStack elements

objects

protected XMLHandler.MyStack objects

types

protected XMLHandler.MyStack types

mixedTargets

protected XMLHandler.MyStack mixedTargets

prefixesToFactories

protected Map prefixesToFactories

urisToLocations

protected Map urisToLocations

extent

protected InternalEList extent

resourceSet

protected ResourceSet resourceSet

packageRegistry

protected EPackage.Registry packageRegistry

resourceURI

protected URI resourceURI

resolve

protected boolean resolve

oldStyleProxyURIs

protected boolean oldStyleProxyURIs

disableNotify

protected boolean disableNotify

text

protected StringBuffer text

isIDREF

protected boolean isIDREF

isSimpleFeature

protected boolean isSimpleFeature

sameDocumentProxies

protected List sameDocumentProxies

forwardSingleReferences

protected List forwardSingleReferences

forwardManyReferences

protected List forwardManyReferences

identifiers

protected Object[] identifiers

positions

protected int[] positions

ARRAY_SIZE

protected static final int ARRAY_SIZE
See Also:
Constant Field Values

REFERENCE_THRESHOLD

protected static final int REFERENCE_THRESHOLD
See Also:
Constant Field Values

capacity

protected int capacity

notFeatures

protected Set notFeatures

idAttribute

protected String idAttribute

hrefAttribute

protected String hrefAttribute

xmlMap

protected XMLResource.XMLMap xmlMap

extendedMetaData

protected ExtendedMetaData extendedMetaData

anyType

protected EClass anyType

anySimpleType

protected EClass anySimpleType

recordUnknownFeature

protected boolean recordUnknownFeature

recordAnyTypeNSDecls

protected boolean recordAnyTypeNSDecls

eObjectToExtensionMap

protected Map eObjectToExtensionMap

contextFeature

protected EStructuralFeature contextFeature

xmlSchemaTypePackage

protected EPackage xmlSchemaTypePackage

deferIDREFResolution

protected boolean deferIDREFResolution
Constructor Detail

XMLHandler

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

setExtendedMetaDataOption

protected void setExtendedMetaDataOption(Object extendedMetaDataOption)

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 Object setAttributes(Object attributes)
Sets the current attributes and returns the old ones.


setLocator

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


getXSIType

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


startDocument

public void startDocument()

startElement

public void startElement(String uri,
                         String localName,
                         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(String name,
                              String prefix,
                              String localName)

handleForwardReferences

protected void handleForwardReferences()

handleForwardReferences

protected void handleForwardReferences(boolean isEndDocument)
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. If this is called during end document processing, errors should be diagnosed. If it is called in the middle of a document, we need to clean up the forward reference lists to avoid reprocessing resolved references again later.


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.


recordNamespacesSchemaLocations

protected EMap recordNamespacesSchemaLocations(EObject root)

createObjectByType

protected EObject createObjectByType(String prefix,
                                     String name,
                                     boolean top)
Create an object based on the prefix and type name.


createTopObject

protected void createTopObject(String prefix,
                               String name)

processTopObject

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


endElement

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


isTextFeatureValue

protected boolean isTextFeatureValue(Object type)

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)

endPrefixMapping

public void endPrefixMapping(String prefix)

characters

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

processingInstruction

public void processingInstruction(String target,
                                  String data)

comment

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

startCDATA

public void startCDATA()

endCDATA

public void endCDATA()

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)

handleXMLNSAttribute

protected void handleXMLNSAttribute(String attrib,
                                    String value)

handleXSISchemaLocation

protected void handleXSISchemaLocation(String schemaLocations)

handleXSINoNamespaceSchemaLocation

protected void handleXSINoNamespaceSchemaLocation(String noNamespaceSchemaLocation)

handleTopLocations

protected void handleTopLocations(String prefix,
                                  String name)

handleFeature

protected void handleFeature(String prefix,
                             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 String getLocation()

getExtension

protected AnyType getExtension(EObject peekObject)

handleUnknownFeature

protected void handleUnknownFeature(String prefix,
                                    String name,
                                    boolean isElement,
                                    EObject peekObject,
                                    String value)

recordUnknownFeature

protected void recordUnknownFeature(String prefix,
                                    String name,
                                    boolean isElement,
                                    EObject peekObject,
                                    String value)

reportUnknownFeature

protected void reportUnknownFeature(String prefix,
                                    String name,
                                    boolean isElement,
                                    EObject peekObject,
                                    String value)

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,
                                           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,
                                          String typeName)
Create an object given a content helper, a factory, and a type name, and process the XML attributes.


validateCreateObjectFromFactory

protected void validateCreateObjectFromFactory(EFactory factory,
                                               String typeName,
                                               EObject newObject)

validateCreateObjectFromFactory

protected EObject validateCreateObjectFromFactory(EFactory factory,
                                                  String typeName,
                                                  EObject newObject,
                                                  EStructuralFeature feature)

processObject

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


getFactoryForPrefix

protected EFactory getFactoryForPrefix(String prefix)

getPackageForURI

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


handleMissingPackage

protected EPackage handleMissingPackage(String uriString)

getURIConverter

protected URIConverter getURIConverter()

setFeatureValue

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

setFeatureValue

protected void setFeatureValue(EObject object,
                               EStructuralFeature feature,
                               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,
                              String name,
                              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,
                              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,
                           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,
                                        String prefix,
                                        String name)
Deprecated.  


getFeature

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


getXMLEncoding

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


handleComment

protected void handleComment(String comment)

handleMixedText

protected void handleMixedText()

handleCDATA

protected void handleCDATA()

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