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

java.lang.Object
  extended byorg.eclipse.emf.ecore.xmi.impl.XMLHelperImpl
All Implemented Interfaces:
XMLHelper
Direct Known Subclasses:
EMOFHelperImpl, XMIHelperImpl

public class XMLHelperImpl
extends Object
implements XMLHelper

This class handles the package to use when there is no XML namespace in an XML file.


Nested Class Summary
protected static class XMLHelperImpl.NamespaceSupport
          A helper to encode namespace prefix mappings.
 
Nested classes inherited from class org.eclipse.emf.ecore.xmi.XMLHelper
XMLHelper.ManyReference
 
Field Summary
protected  EClass anySimpleType
           
protected  DanglingHREFException danglingHREFException
           
protected  boolean deresolve
           
protected  ExtendedMetaData extendedMetaData
           
protected  Map featuresToKinds
           
protected static Integer INTEGER_DATATYPE_IS_MANY
           
protected static Integer INTEGER_DATATYPE_SINGLE
           
protected static Integer INTEGER_IS_MANY_ADD
           
protected static Integer INTEGER_IS_MANY_MOVE
           
protected  XMLHelperImpl.NamespaceSupport namespaceSupport
           
protected  EPackage noNamespacePackage
           
protected  EPackage.Registry packageRegistry
           
protected  Map packages
           
protected  EMap prefixesToURIs
           
protected  String processDanglingHREF
           
protected  XMLResource resource
           
protected  URI resourceURI
           
protected  boolean seenEmptyStringMapping
           
protected  XMLResource.XMLMap xmlMap
           
protected  EPackage xmlSchemaTypePackage
           
 
Fields inherited from interface org.eclipse.emf.ecore.xmi.XMLHelper
DATATYPE_IS_MANY, DATATYPE_SINGLE, IS_MANY_ADD, IS_MANY_MOVE, OTHER
 
Constructor Summary
XMLHelperImpl()
           
XMLHelperImpl(XMLResource resource)
           
 
Method Summary
protected  void addNSDeclaration(String prefix, String uri)
           
 void addPrefix(String prefix, String uri)
          Records the prefix to URI mapping while loading an XML document.
protected  void computeFeatureKind(EStructuralFeature feature)
           
 String convertToString(EFactory factory, EDataType dataType, Object value)
          Converts the given valuevalue to string while saving an XML document.
protected  Object createFromString(EFactory eFactory, EDataType eDataType, String value)
           
 EObject createObject(EFactory eFactory, String classXMIName)
          Create an object given an EFactory and a type name.
 URI deresolve(URI uri)
          Returns a relative URI if necessary and if possible.
 DanglingHREFException getDanglingHREFException()
           
 ExtendedMetaData getExtendedMetaData()
          Gets the ExtendedMetaData to use when serializing an XML file.
 EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name)
          Returns the structural feature for the XML element/attribute with the given namespaceURI and name.
 EStructuralFeature getFeature(EClass eClass, String namespaceURI, String name, boolean isElement)
          Returns the structural feature for the XML element/attribute with the given namespaceURI and name.
 int getFeatureKind(EStructuralFeature feature)
          Return the kind of feature.
protected  EStructuralFeature getFeatureWithoutMap(EClass eClass, String name)
           
 String getHREF(EObject obj)
          Returns an HREF to this object from this resource
protected  URI getHREF(Resource otherResource, EObject obj)
           
 String getID(EObject obj)
          Returns the xmi:id or null to supress
 String getIDREF(EObject obj)
          Returns an IDREF to this object
 String getJavaEncoding(String xmlEncoding)
          Return a Java encoding corresponding to the given XML encoding.
 String getName(ENamedElement obj)
          Returns the XML name of the ENamedElement
 EPackage getNoNamespacePackage()
          Gets the package to use when there is no XML namespace in an XML file.
 String getPrefix(EPackage ePackage)
          Return the prefix used for this package.
protected  String getPrefix(EPackage ePackage, boolean mustHavePrefix)
           
 List getPrefixes(EPackage ePackage)
          Return all the prefixes used for this package.
 EMap getPrefixToNamespaceMap()
           
 String getQName(EClass c)
          Returns the nsName:name c.ePackage().nsName() : c.eName() If there is an XMLMap, and the target namespace is null for this eClass, just the name is returned.
 String getQName(EDataType c)
          Returns the nsName:name c.ePackage().nsName() : c.eName() If there is an XMLMap, and the target namespace is null for this eClass, just the name is returned.
protected  String getQName(EPackage ePackage, String name)
           
protected  String getQName(EPackage ePackage, String name, boolean mustHavePrefix)
           
 String getQName(EStructuralFeature feature)
          By default, this method returns the name of the feature.
protected  String getQName(String uri, String name)
           
 XMLResource getResource()
          Returns the resource
 String getURI(String prefix)
          Returns the namespace prefix that's in effect while loading an XML document.
 Object getValue(EObject obj, EStructuralFeature f)
          Returns the XMI value of the EObject's feature
 String getXMLEncoding(String javaEncoding)
          Return an XML encoding corresponding to the given Java encoding.
 XMLResource.XMLMap getXMLMap()
          Gets the XMLMap to use when serializing an XML file.
protected  URI handleDanglingHREF(EObject object)
           
 EPackage[] packages()
          Returns the packages in getQName()
 void popContext()
          Reverts to the previous namespace context while loading XML document.
 void pushContext()
          Starts a new namespace context while loading an XML document.
 URI resolve(URI relative, URI base)
           
static String saveString(Map options, List contents, String encoding, XMLHelper helper)
           
 void setAnySimpleType(EClass type)
          Sets the any simple type class.
 void setExtendedMetaData(ExtendedMetaData extendedMetaData)
          Sets the ExtendedMetaData to use when serializing an XML file.
 List setManyReference(XMLHelper.ManyReference reference, String location)
           
 void setNoNamespacePackage(EPackage pkg)
          Sets the package to use when there is no XML namespace in an XML file.
 void setPrefixToNamespaceMap(EMap prefixToNamespaceMap)
           
 void setProcessDanglingHREF(String value)
           
 void setResource(XMLResource resource)
           
 void setValue(EObject object, EStructuralFeature feature, Object value, int position)
          Set the value of the feature for the object.
 void setXMLMap(XMLResource.XMLMap map)
          Sets the XMLMap to use when serializing an XML file.
protected  String updateQNamePrefix(EFactory factory, EDataType dataType, Object value, boolean list)
           
protected  void updateQNameURI(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER_DATATYPE_IS_MANY

protected static final Integer INTEGER_DATATYPE_IS_MANY

INTEGER_DATATYPE_SINGLE

protected static final Integer INTEGER_DATATYPE_SINGLE

INTEGER_IS_MANY_ADD

protected static final Integer INTEGER_IS_MANY_ADD

INTEGER_IS_MANY_MOVE

protected static final Integer INTEGER_IS_MANY_MOVE

noNamespacePackage

protected EPackage noNamespacePackage

xmlMap

protected XMLResource.XMLMap xmlMap

extendedMetaData

protected ExtendedMetaData extendedMetaData

packageRegistry

protected EPackage.Registry packageRegistry

resource

protected XMLResource resource

resourceURI

protected URI resourceURI

deresolve

protected boolean deresolve

packages

protected Map packages

featuresToKinds

protected Map featuresToKinds

processDanglingHREF

protected String processDanglingHREF

danglingHREFException

protected DanglingHREFException danglingHREFException

prefixesToURIs

protected EMap prefixesToURIs

namespaceSupport

protected XMLHelperImpl.NamespaceSupport namespaceSupport

anySimpleType

protected EClass anySimpleType

seenEmptyStringMapping

protected boolean seenEmptyStringMapping

xmlSchemaTypePackage

protected EPackage xmlSchemaTypePackage
Constructor Detail

XMLHelperImpl

public XMLHelperImpl()

XMLHelperImpl

public XMLHelperImpl(XMLResource resource)
Method Detail

saveString

public static String saveString(Map options,
                                List contents,
                                String encoding,
                                XMLHelper helper)
                         throws Exception
Throws:
Exception

setNoNamespacePackage

public void setNoNamespacePackage(EPackage pkg)
Description copied from interface: XMLHelper
Sets the package to use when there is no XML namespace in an XML file.

Specified by:
setNoNamespacePackage in interface XMLHelper

getNoNamespacePackage

public EPackage getNoNamespacePackage()
Description copied from interface: XMLHelper
Gets the package to use when there is no XML namespace in an XML file.

Specified by:
getNoNamespacePackage in interface XMLHelper

setXMLMap

public void setXMLMap(XMLResource.XMLMap map)
Description copied from interface: XMLHelper
Sets the XMLMap to use when serializing an XML file.

Specified by:
setXMLMap in interface XMLHelper

getXMLMap

public XMLResource.XMLMap getXMLMap()
Description copied from interface: XMLHelper
Gets the XMLMap to use when serializing an XML file.

Specified by:
getXMLMap in interface XMLHelper

setExtendedMetaData

public void setExtendedMetaData(ExtendedMetaData extendedMetaData)
Description copied from interface: XMLHelper
Sets the ExtendedMetaData to use when serializing an XML file.

Specified by:
setExtendedMetaData in interface XMLHelper

getExtendedMetaData

public ExtendedMetaData getExtendedMetaData()
Description copied from interface: XMLHelper
Gets the ExtendedMetaData to use when serializing an XML file.

Specified by:
getExtendedMetaData in interface XMLHelper

getResource

public XMLResource getResource()
Description copied from interface: XMLHelper
Returns the resource

Specified by:
getResource in interface XMLHelper

setResource

public void setResource(XMLResource resource)

getValue

public Object getValue(EObject obj,
                       EStructuralFeature f)
Description copied from interface: XMLHelper
Returns the XMI value of the EObject's feature

Specified by:
getValue in interface XMLHelper

getQName

public String getQName(EClass c)
Description copied from interface: XMLHelper
Returns the nsName:name c.ePackage().nsName() : c.eName() If there is an XMLMap, and the target namespace is null for this eClass, just the name is returned. If the map has a target namespace specified, that target namespace is used rather than the namespace from the EPackage.

Specified by:
getQName in interface XMLHelper

getQName

public String getQName(EDataType c)
Description copied from interface: XMLHelper
Returns the nsName:name c.ePackage().nsName() : c.eName() If there is an XMLMap, and the target namespace is null for this eClass, just the name is returned. If the map has a target namespace specified, that target namespace is used rather than the namespace from the EPackage.

Specified by:
getQName in interface XMLHelper

getQName

public String getQName(EStructuralFeature feature)
Description copied from interface: XMLHelper
By default, this method returns the name of the feature. However, if there is an XMLMap, and the map specifies a target namespace, the nsPrefix:name is returned.

Specified by:
getQName in interface XMLHelper

getQName

protected String getQName(EPackage ePackage,
                          String name)

getQName

protected String getQName(EPackage ePackage,
                          String name,
                          boolean mustHavePrefix)

getPrefix

public String getPrefix(EPackage ePackage)
Description copied from interface: XMLHelper
Return the prefix used for this package.

Specified by:
getPrefix in interface XMLHelper

getPrefix

protected String getPrefix(EPackage ePackage,
                           boolean mustHavePrefix)

getPrefixes

public List getPrefixes(EPackage ePackage)
Description copied from interface: XMLHelper
Return all the prefixes used for this package.

Specified by:
getPrefixes in interface XMLHelper

getQName

protected String getQName(String uri,
                          String name)

getName

public String getName(ENamedElement obj)
Description copied from interface: XMLHelper
Returns the XML name of the ENamedElement

Specified by:
getName in interface XMLHelper

getID

public String getID(EObject obj)
Description copied from interface: XMLHelper
Returns the xmi:id or null to supress

Specified by:
getID in interface XMLHelper

getIDREF

public String getIDREF(EObject obj)
Description copied from interface: XMLHelper
Returns an IDREF to this object

Specified by:
getIDREF in interface XMLHelper

handleDanglingHREF

protected URI handleDanglingHREF(EObject object)

getHREF

public String getHREF(EObject obj)
Description copied from interface: XMLHelper
Returns an HREF to this object from this resource

Specified by:
getHREF in interface XMLHelper

getHREF

protected URI getHREF(Resource otherResource,
                      EObject obj)

deresolve

public URI deresolve(URI uri)
Description copied from interface: XMLHelper
Returns a relative URI if necessary and if possible.

Specified by:
deresolve in interface XMLHelper

getFeatureKind

public int getFeatureKind(EStructuralFeature feature)
Description copied from interface: XMLHelper
Return the kind of feature.

Specified by:
getFeatureKind in interface XMLHelper

createObject

public EObject createObject(EFactory eFactory,
                            String classXMIName)
Description copied from interface: XMLHelper
Create an object given an EFactory and a type name.

Specified by:
createObject in interface XMLHelper

getFeature

public EStructuralFeature getFeature(EClass eClass,
                                     String namespaceURI,
                                     String name)
Description copied from interface: XMLHelper
Returns the structural feature for the XML element/attribute with the given namespaceURI and name.

Specified by:
getFeature in interface XMLHelper

getFeature

public EStructuralFeature getFeature(EClass eClass,
                                     String namespaceURI,
                                     String name,
                                     boolean isElement)
Description copied from interface: XMLHelper
Returns the structural feature for the XML element/attribute with the given namespaceURI and name.

Specified by:
getFeature in interface XMLHelper

getFeatureWithoutMap

protected EStructuralFeature getFeatureWithoutMap(EClass eClass,
                                                  String name)

computeFeatureKind

protected void computeFeatureKind(EStructuralFeature feature)

getJavaEncoding

public String getJavaEncoding(String xmlEncoding)
Description copied from interface: XMLHelper
Return a Java encoding corresponding to the given XML encoding. By default, the XML encoding is returned.

Specified by:
getJavaEncoding in interface XMLHelper

getXMLEncoding

public String getXMLEncoding(String javaEncoding)
Description copied from interface: XMLHelper
Return an XML encoding corresponding to the given Java encoding. By default, the Java encoding is returned.

Specified by:
getXMLEncoding in interface XMLHelper

packages

public EPackage[] packages()
Description copied from interface: XMLHelper
Returns the packages in getQName()

Specified by:
packages in interface XMLHelper

setValue

public void setValue(EObject object,
                     EStructuralFeature feature,
                     Object value,
                     int position)
Description copied from interface: XMLHelper
Set the value of the feature for the object.

Specified by:
setValue in interface XMLHelper

setManyReference

public List setManyReference(XMLHelper.ManyReference reference,
                             String location)
Specified by:
setManyReference in interface XMLHelper

setProcessDanglingHREF

public void setProcessDanglingHREF(String value)
Specified by:
setProcessDanglingHREF in interface XMLHelper

getDanglingHREFException

public DanglingHREFException getDanglingHREFException()
Specified by:
getDanglingHREFException in interface XMLHelper

resolve

public URI resolve(URI relative,
                   URI base)
Specified by:
resolve in interface XMLHelper

pushContext

public void pushContext()
Description copied from interface: XMLHelper
Starts a new namespace context while loading an XML document.

A new context should be pushed at the beginning of each XML element. The new context will automatically inherit the declarations of its parent context, but it will also keep track of which declarations were made within this context.

Specified by:
pushContext in interface XMLHelper

popContext

public void popContext()
Description copied from interface: XMLHelper
Reverts to the previous namespace context while loading XML document.

The context should be popped at the end of each XML element. After popping the context, all namespace prefix mappings that were previously in scope are restored.

Specified by:
popContext in interface XMLHelper

addPrefix

public void addPrefix(String prefix,
                      String uri)
Description copied from interface: XMLHelper
Records the prefix to URI mapping while loading an XML document.

Specified by:
addPrefix in interface XMLHelper

getURI

public String getURI(String prefix)
Description copied from interface: XMLHelper
Returns the namespace prefix that's in effect while loading an XML document.

Specified by:
getURI in interface XMLHelper

getPrefixToNamespaceMap

public EMap getPrefixToNamespaceMap()
Specified by:
getPrefixToNamespaceMap in interface XMLHelper

setPrefixToNamespaceMap

public void setPrefixToNamespaceMap(EMap prefixToNamespaceMap)
Specified by:
setPrefixToNamespaceMap in interface XMLHelper

setAnySimpleType

public void setAnySimpleType(EClass type)
Description copied from interface: XMLHelper
Sets the any simple type class.

Specified by:
setAnySimpleType in interface XMLHelper
See Also:
XMLResource.OPTION_ANY_SIMPLE_TYPE

convertToString

public String convertToString(EFactory factory,
                              EDataType dataType,
                              Object value)
Description copied from interface: XMLHelper
Converts the given valuevalue to string while saving an XML document.

Specified by:
convertToString in interface XMLHelper

createFromString

protected Object createFromString(EFactory eFactory,
                                  EDataType eDataType,
                                  String value)

updateQNameURI

protected void updateQNameURI(Object value)

updateQNamePrefix

protected String updateQNamePrefix(EFactory factory,
                                   EDataType dataType,
                                   Object value,
                                   boolean list)
Parameters:
factory -
dataType -
value - a data value to be converted to string
list - if the value is part of the list of values
Returns:
if the value is not part of the list, return string corresponding to value, otherwise return null

addNSDeclaration

protected void addNSDeclaration(String prefix,
                                String uri)

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