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

java.lang.Object
  extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
      extended by org.eclipse.emf.common.notify.impl.NotifierImpl
          extended by org.eclipse.emf.ecore.resource.impl.ResourceImpl
              extended by org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl
All Implemented Interfaces:
Notifier, Resource, Resource.Internal, XMLResource
Direct Known Subclasses:
GenericXMLResourceImpl, XMIResourceImpl

public class XMLResourceImpl
extends ResourceImpl
implements XMLResource

This class implements the XMLResource interface. It overloads the doLoad method to invoke the XML deserializer rather than using the default XMI loader.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
ResourceImpl.ContentsEList<E extends java.lang.Object & EObject>, ResourceImpl.ModificationTrackingAdapter
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
BasicNotifierImpl.EAdapterList<E extends java.lang.Object & Adapter>
 
Nested classes/interfaces inherited from interface org.eclipse.emf.ecore.xmi.XMLResource
XMLResource.ElementHandler, XMLResource.ResourceEntityHandler, XMLResource.ResourceHandler, XMLResource.URIHandler, XMLResource.XMLInfo, XMLResource.XMLMap
 
Nested classes/interfaces inherited from interface org.eclipse.emf.ecore.resource.Resource
Resource.Diagnostic, Resource.Factory, Resource.Internal, Resource.IOWrappedException
 
Field Summary
protected static java.util.Map<EObject,java.lang.String> DETACHED_EOBJECT_TO_ID_MAP
          The map from EObject to ID.
protected  DOMHandler domHandler
           
protected  java.lang.String encoding
           
protected  java.util.Map<EObject,AnyType> eObjectToExtensionMap
           
protected  java.util.Map<EObject,java.lang.String> eObjectToIDMap
          The map from EObject to ID.
protected  java.util.Map<java.lang.String,EObject> idToEObjectMap
          The map from ID to EObject.
protected  java.lang.String publicId
           
protected  java.lang.String systemId
           
protected  boolean useZip
           
protected  java.lang.String xmlVersion
           
 
Fields inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
contents, defaultDeleteOptions, defaultLoadOptions, defaultSaveOptions, errors, intrinsicIDToEObjectMap, isLoaded, isLoading, isModified, modificationTrackingAdapter, resourceSet, timeStamp, unloadingContents, uri, warnings
 
Fields inherited from class org.eclipse.emf.common.notify.impl.NotifierImpl
eAdapters, EDELIVER, eFlags, ELAST_NOTIFIER_FLAG
 
Fields inherited from interface org.eclipse.emf.ecore.xmi.XMLResource
HREF, NIL, NO_NAMESPACE_SCHEMA_LOCATION, OPTION_ANY_SIMPLE_TYPE, OPTION_ANY_TYPE, OPTION_CONFIGURATION_CACHE, OPTION_DECLARE_XML, OPTION_DEFER_ATTACHMENT, OPTION_DEFER_IDREF_RESOLUTION, OPTION_DISABLE_NOTIFY, OPTION_DOM_USE_NAMESPACES_IN_SCOPE, OPTION_ELEMENT_HANDLER, OPTION_ENCODING, OPTION_ESCAPE_USING_CDATA, OPTION_EXTENDED_META_DATA, OPTION_FLUSH_THRESHOLD, OPTION_FORMATTED, OPTION_KEEP_DEFAULT_CONTENT, OPTION_LAX_FEATURE_PROCESSING, OPTION_LAX_WILDCARD_PROCESSING, OPTION_LINE_WIDTH, OPTION_PARSER_FEATURES, OPTION_PARSER_PROPERTIES, OPTION_PROCESS_DANGLING_HREF, OPTION_PROCESS_DANGLING_HREF_DISCARD, OPTION_PROCESS_DANGLING_HREF_RECORD, OPTION_PROCESS_DANGLING_HREF_THROW, OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, OPTION_RECORD_UNKNOWN_FEATURE, OPTION_RESOURCE_ENTITY_HANDLER, OPTION_RESOURCE_HANDLER, OPTION_ROOT_OBJECTS, OPTION_SAVE_DOCTYPE, OPTION_SAVE_TYPE_INFORMATION, OPTION_SCHEMA_LOCATION, OPTION_SCHEMA_LOCATION_IMPLEMENTATION, OPTION_SKIP_ESCAPE, OPTION_SKIP_ESCAPE_URI, OPTION_SUPPRESS_DOCUMENT_ROOT, OPTION_URI_HANDLER, OPTION_USE_CACHED_LOOKUP_TABLE, OPTION_USE_DEPRECATED_METHODS, OPTION_USE_ENCODED_ATTRIBUTE_STYLE, OPTION_USE_FILE_BUFFER, OPTION_USE_LEXICAL_HANDLER, OPTION_USE_PARSER_POOL, OPTION_USE_XML_NAME_TO_FEATURE_MAP, OPTION_XML_MAP, OPTION_XML_OPTIONS, OPTION_XML_VERSION, SCHEMA_LOCATION, TYPE, XML_NS, XML_SCHEMA_URI, XSI_NS, XSI_URI
 
Fields inherited from interface org.eclipse.emf.ecore.resource.Resource
OPTION_CIPHER, OPTION_SAVE_ONLY_IF_CHANGED, OPTION_SAVE_ONLY_IF_CHANGED_FILE_BUFFER, OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER, OPTION_ZIP, RESOURCE__CONTENTS, RESOURCE__ERRORS, RESOURCE__IS_LOADED, RESOURCE__IS_MODIFIED, RESOURCE__IS_TRACKING_MODIFICATION, RESOURCE__RESOURCE_SET, RESOURCE__TIME_STAMP, RESOURCE__URI, RESOURCE__WARNINGS
 
Constructor Summary
XMLResourceImpl()
          Constructor for XMLResourceImpl.
XMLResourceImpl(URI uri)
          Constructor for XMLResourceImpl.
 
Method Summary
protected  boolean assignIDsWhileLoading()
           
protected  void attachedHelper(EObject eObject)
           
protected  XMLHelper createXMLHelper()
           
protected  XMLLoad createXMLLoad()
           
protected  XMLSave createXMLSave()
           
protected  void detachedHelper(EObject eObject)
           
 void doLoad(org.xml.sax.InputSource inputSource, java.util.Map<?,?> options)
           
 void doLoad(java.io.InputStream inputStream, java.util.Map<?,?> options)
          Called to load the resource.
 void doLoad(org.w3c.dom.Node node, java.util.Map<?,?> options)
           
 void doSave(java.io.OutputStream outputStream, java.util.Map<?,?> options)
          Called to save the resource.
 void doSave(java.io.Writer writer, java.util.Map<?,?> options)
           
protected  void doUnload()
          Does all the work of unloading the resource.
 java.util.Map<java.lang.Object,java.lang.Object> getDefaultLoadOptions()
          Returns the map of options that, in addition to the overriding options specified during load, are used to to control load behavior.
 java.util.Map<java.lang.Object,java.lang.Object> getDefaultSaveOptions()
          Returns the map of options that, in addition to the overriding options specified during save, are used to to control save behavior.
 DOMHelper getDOMHelper()
          Returns the DOMHelper
 java.lang.String getEncoding()
          Get the XML encoding for this resource.
protected  EObject getEObjectByID(java.lang.String id)
          Returns the object based on the fragment as an ID.
 java.util.Map<EObject,AnyType> getEObjectToExtensionMap()
          Returns the map with EObject as keys and corresponding AnyTypes as the values.
 java.util.Map<EObject,java.lang.String> getEObjectToIDMap()
          Returns the Map of EObjects as keys and IDs as values.
 java.lang.String getID(EObject eObject)
          Returns the ID that was assigned with XMLResource.setID(EObject, String); if there is no ID, it returns null.
 java.util.Map<java.lang.String,EObject> getIDToEObjectMap()
          Returns the Map with IDs as keys and EObjects as values.
 java.lang.String getPublicId()
          Returns public identifier specified on the doctype.
 java.lang.String getSystemId()
          Returns system identifier specified on the doctype.
 java.lang.String getURIFragment(EObject eObject)
          Returns the URI fragment that, when passed to getEObject will return the given object.
 java.lang.String getXMLVersion()
          Returns the XML version for this resource.
protected  void init()
           
protected  boolean isAttachedDetachedHelperRequired()
           
protected  boolean isPath(java.lang.String uriFragment)
           
 void load(org.xml.sax.InputSource inputSource, java.util.Map<?,?> options)
           
 void load(org.w3c.dom.Node node, java.util.Map<?,?> options)
          Loads the resource from the DOM node, either an Element or Document, using the specified options.
 org.w3c.dom.Document save(org.w3c.dom.Document doc, java.util.Map<?,?> options, DOMHandler handler)
          Create a DOM tree representing contents of this resource.
 void save(java.io.Writer writer, java.util.Map<?,?> options)
          Saves the resource to the writer using the specified options.
 void setDoctypeInfo(java.lang.String publicId, java.lang.String systemId)
          Sets the values of system and public identifiers on this resource.
 void setEncoding(java.lang.String encoding)
          Set the XML encoding for this resource.
 void setID(EObject eObject, java.lang.String id)
          Sets the ID of the object.
 void setUseZip(boolean useZip)
          Set whether the contents will be zipped.
 void setXMLVersion(java.lang.String version)
          Set the XML version for this resource
 java.lang.String toKeyString()
          Returns a string representation of the ID map.
protected  boolean useIDAttributes()
           
protected  boolean useIDs()
           
protected  boolean useUUIDs()
           
 boolean useZip()
          Returns whether contents will be compressed.
 
Methods inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
addModificationTrackingAdapters, attached, basicSetResourceSet, createModificationTrackingAdapter, delete, detached, getAllContents, getAllProperContents, getAllProperContents, getContents, getDefaultURIConverter, getEObject, getEObject, getEObjectForURIFragmentRootSegment, getErrors, getIntrinsicIDToEObjectMap, getResourceSet, getTimeStamp, getURI, getURIConverter, getURIFragmentRootSegment, getWarnings, isContentZipEntry, isLoaded, isLoading, isModified, isTrackingModification, load, load, mergeMaps, newContentZipEntry, removeModificationTrackingAdapters, save, save, saveOnlyIfChangedWithFileBuffer, saveOnlyIfChangedWithMemoryBuffer, setIntrinsicIDToEObjectMap, setLoaded, setModified, setTimeStamp, setTrackingModification, setURI, toString, unload, unloaded
 
Methods inherited from class org.eclipse.emf.common.notify.impl.NotifierImpl
eAdapters, eBasicAdapters, eDeliver, eSetDeliver
 
Methods inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
eNotificationRequired, eNotify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.ecore.resource.Resource
delete, getAllContents, getContents, getEObject, getErrors, getResourceSet, getTimeStamp, getURI, getWarnings, isLoaded, isModified, isTrackingModification, load, load, save, save, setModified, setTimeStamp, setTrackingModification, setURI, unload
 
Methods inherited from interface org.eclipse.emf.common.notify.Notifier
eAdapters, eDeliver, eNotify, eSetDeliver
 

Field Detail

idToEObjectMap

protected java.util.Map<java.lang.String,EObject> idToEObjectMap
The map from ID to EObject. It is used to store IDs during a load or if the user sets the ID of an object.


eObjectToIDMap

protected java.util.Map<EObject,java.lang.String> eObjectToIDMap
The map from EObject to ID. It is used to store IDs during a load or if the user sets the ID of an object.


eObjectToExtensionMap

protected java.util.Map<EObject,AnyType> eObjectToExtensionMap

encoding

protected java.lang.String encoding

xmlVersion

protected java.lang.String xmlVersion

useZip

protected boolean useZip

publicId

protected java.lang.String publicId

systemId

protected java.lang.String systemId

domHandler

protected DOMHandler domHandler

DETACHED_EOBJECT_TO_ID_MAP

protected static final java.util.Map<EObject,java.lang.String> DETACHED_EOBJECT_TO_ID_MAP
The map from EObject to ID. It is used to store IDs for objects that have been detached.

Constructor Detail

XMLResourceImpl

public XMLResourceImpl()
Constructor for XMLResourceImpl.


XMLResourceImpl

public XMLResourceImpl(URI uri)
Constructor for XMLResourceImpl.

Parameters:
uri -
Method Detail

init

protected void init()

useIDs

protected boolean useIDs()

useIDAttributes

protected boolean useIDAttributes()

useUUIDs

protected boolean useUUIDs()

assignIDsWhileLoading

protected boolean assignIDsWhileLoading()

getDefaultSaveOptions

public java.util.Map<java.lang.Object,java.lang.Object> getDefaultSaveOptions()
Description copied from interface: XMLResource
Returns the map of options that, in addition to the overriding options specified during save, are used to to control save behavior.

Specified by:
getDefaultSaveOptions in interface XMLResource

getDefaultLoadOptions

public java.util.Map<java.lang.Object,java.lang.Object> getDefaultLoadOptions()
Description copied from interface: XMLResource
Returns the map of options that, in addition to the overriding options specified during load, are used to to control load behavior.

Specified by:
getDefaultLoadOptions in interface XMLResource

createXMLHelper

protected XMLHelper createXMLHelper()

createXMLLoad

protected XMLLoad createXMLLoad()

createXMLSave

protected XMLSave createXMLSave()

doLoad

public void doLoad(java.io.InputStream inputStream,
                   java.util.Map<?,?> options)
            throws java.io.IOException
Description copied from class: ResourceImpl
Called to load the resource. This implementation throws an exception; clients must override it.

Overrides:
doLoad in class ResourceImpl
Parameters:
inputStream - the stream
options - the load options.
Throws:
java.io.IOException

doSave

public void doSave(java.io.OutputStream outputStream,
                   java.util.Map<?,?> options)
            throws java.io.IOException
Description copied from class: ResourceImpl
Called to save the resource. This implementation throws an exception; clients must override it.

Overrides:
doSave in class ResourceImpl
Parameters:
outputStream - the stream
options - the save options.
Throws:
java.io.IOException

save

public final void save(java.io.Writer writer,
                       java.util.Map<?,?> options)
                throws java.io.IOException
Saves the resource to the writer using the specified options.

This implementation is final; clients should override doSave.

Specified by:
save in interface XMLResource
Parameters:
writer - the writer
options - the save options.
Throws:
java.io.IOException
See Also:
doSave(Writer, Map)

doSave

public void doSave(java.io.Writer writer,
                   java.util.Map<?,?> options)
            throws java.io.IOException
Throws:
java.io.IOException

save

public org.w3c.dom.Document save(org.w3c.dom.Document doc,
                                 java.util.Map<?,?> options,
                                 DOMHandler handler)
Description copied from interface: XMLResource
Create a DOM tree representing contents of this resource.

Specified by:
save in interface XMLResource
Parameters:
doc - an empty Document to use or null. If no document is specified, the new Document will be created using JAXP API.
options - the "save" options
handler - the DOMHandler to record mappings or null. If no DOMHandler is passed, the default DOMHandler will be created.
Returns:
the Document. In the case the document is specified as a parameter, the returned document is the same as the one specified, otherwise the newly created document is returned.

getDOMHelper

public DOMHelper getDOMHelper()
Description copied from interface: XMLResource
Returns the DOMHelper

Specified by:
getDOMHelper in interface XMLResource

useZip

public boolean useZip()
Description copied from class: ResourceImpl
Returns whether contents will be compressed. This implementation returns false. When this returns true, ResourceImpl.save(OutputStream, Map) and ResourceImpl.load(InputStream, Map) will zip compress and decompress contents.

Specified by:
useZip in interface XMLResource
Overrides:
useZip in class ResourceImpl
Returns:
whether contents will be compressed.
See Also:
ResourceImpl.newContentZipEntry(), ResourceImpl.isContentZipEntry(ZipEntry)

setUseZip

public void setUseZip(boolean useZip)
Description copied from interface: XMLResource
Set whether the contents will be zipped.

Specified by:
setUseZip in interface XMLResource

getPublicId

public java.lang.String getPublicId()
Description copied from interface: XMLResource
Returns public identifier specified on the doctype.

Specified by:
getPublicId in interface XMLResource

getSystemId

public java.lang.String getSystemId()
Description copied from interface: XMLResource
Returns system identifier specified on the doctype.

Specified by:
getSystemId in interface XMLResource

setDoctypeInfo

public void setDoctypeInfo(java.lang.String publicId,
                           java.lang.String systemId)
Description copied from interface: XMLResource
Sets the values of system and public identifiers on this resource.

Specified by:
setDoctypeInfo in interface XMLResource

getEncoding

public java.lang.String getEncoding()
Description copied from interface: XMLResource
Get the XML encoding for this resource. The default is ASCII.

Specified by:
getEncoding in interface XMLResource

setEncoding

public void setEncoding(java.lang.String encoding)
Description copied from interface: XMLResource
Set the XML encoding for this resource.

Specified by:
setEncoding in interface XMLResource

getXMLVersion

public java.lang.String getXMLVersion()
Description copied from interface: XMLResource
Returns the XML version for this resource. The default is 1.0.

Specified by:
getXMLVersion in interface XMLResource
Returns:
the XML version.

setXMLVersion

public void setXMLVersion(java.lang.String version)
Description copied from interface: XMLResource
Set the XML version for this resource

Specified by:
setXMLVersion in interface XMLResource

getIDToEObjectMap

public java.util.Map<java.lang.String,EObject> getIDToEObjectMap()
Description copied from interface: XMLResource
Returns the Map with IDs as keys and EObjects as values.

Specified by:
getIDToEObjectMap in interface XMLResource

getEObjectToIDMap

public java.util.Map<EObject,java.lang.String> getEObjectToIDMap()
Description copied from interface: XMLResource
Returns the Map of EObjects as keys and IDs as values.

Specified by:
getEObjectToIDMap in interface XMLResource

getEObjectToExtensionMap

public java.util.Map<EObject,AnyType> getEObjectToExtensionMap()
Description copied from interface: XMLResource
Returns the map with EObject as keys and corresponding AnyTypes as the values. It's used to record unrecognized elements and attributes.

Specified by:
getEObjectToExtensionMap in interface XMLResource

getID

public java.lang.String getID(EObject eObject)
Description copied from interface: XMLResource
Returns the ID that was assigned with XMLResource.setID(EObject, String); if there is no ID, it returns null.

Specified by:
getID in interface XMLResource

setID

public void setID(EObject eObject,
                  java.lang.String id)
Sets the ID of the object. This default implementation will update the eObjectToIDMap. Clients may override it to set the ID as an actual attribute object the object.

Specified by:
setID in interface XMLResource
Parameters:
eObject - the object.
id - the object's ID.

getURIFragment

public java.lang.String getURIFragment(EObject eObject)
Description copied from interface: Resource
Returns the URI fragment that, when passed to getEObject will return the given object.

In other words, the following is true for any object contained by a resource:

   Resource resource = eObject.eResource();
   eObject == resource.getEObject(resource.getURIFragment(eObject))
An implementation may choose to use IDs or to use structured URI fragments, as supported by eURIFragmentSegment.

Specified by:
getURIFragment in interface Resource
Overrides:
getURIFragment in class ResourceImpl
Parameters:
eObject - the object to identify.
Returns:
the URI fragment for the object.
See Also:
Resource.getEObject(String), InternalEObject.eURIFragmentSegment(org.eclipse.emf.ecore.EStructuralFeature, EObject)

getEObjectByID

protected EObject getEObjectByID(java.lang.String id)
Description copied from class: ResourceImpl
Returns the object based on the fragment as an ID.

Overrides:
getEObjectByID in class ResourceImpl

isPath

protected boolean isPath(java.lang.String uriFragment)

isAttachedDetachedHelperRequired

protected boolean isAttachedDetachedHelperRequired()
Overrides:
isAttachedDetachedHelperRequired in class ResourceImpl

attachedHelper

protected void attachedHelper(EObject eObject)
Overrides:
attachedHelper in class ResourceImpl

detachedHelper

protected void detachedHelper(EObject eObject)
Overrides:
detachedHelper in class ResourceImpl

doUnload

protected void doUnload()
Does all the work of unloading the resource. It calls doUnload in ResourceImpl, then it clears idToEObjectMap and eObjectToIDMap as necessary.

Overrides:
doUnload in class ResourceImpl

toKeyString

public java.lang.String toKeyString()
Returns a string representation of the ID map.

Overrides:
toKeyString in class ResourceImpl
Returns:
a string representation of the ID map.

load

public final void load(org.w3c.dom.Node node,
                       java.util.Map<?,?> options)
                throws java.io.IOException
Description copied from interface: XMLResource
Loads the resource from the DOM node, either an Element or Document, using the specified options.

This method assumes that no namespace fixup needs to be done. To process comments and CDATA section nodes, please set XMLResource.OPTION_USE_LEXICAL_HANDLER option to Boolean.TRUE.

Specified by:
load in interface XMLResource
Parameters:
node - DOM Element or Document node.
options - the load options.
Throws:
java.io.IOException
See Also:
XMLResource.save(Document, Map, DOMHandler)

doLoad

public void doLoad(org.w3c.dom.Node node,
                   java.util.Map<?,?> options)
            throws java.io.IOException
Throws:
java.io.IOException

load

public final void load(org.xml.sax.InputSource inputSource,
                       java.util.Map<?,?> options)
                throws java.io.IOException
Specified by:
load in interface XMLResource
Throws:
java.io.IOException

doLoad

public void doLoad(org.xml.sax.InputSource inputSource,
                   java.util.Map<?,?> options)
            throws java.io.IOException
Throws:
java.io.IOException

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