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

java.lang.Object
  extended byorg.eclipse.emf.common.notify.impl.BasicNotifierImpl
      extended byorg.eclipse.emf.common.notify.impl.NotifierImpl
          extended byorg.eclipse.emf.ecore.resource.impl.ResourceImpl
              extended byorg.eclipse.emf.ecore.xmi.impl.XMLResourceImpl
All Implemented Interfaces:
Notifier, Resource, Resource.Internal, XMLResource
Direct Known Subclasses:
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 inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
ResourceImpl.ContentsEList, ResourceImpl.ModificationTrackingAdapter
 
Nested classes inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
BasicNotifierImpl.EAdapterList
 
Nested classes inherited from class org.eclipse.emf.ecore.xmi.XMLResource
XMLResource.XMLInfo, XMLResource.XMLMap
 
Nested classes inherited from class org.eclipse.emf.ecore.resource.Resource
Resource.Diagnostic, Resource.Factory, Resource.Internal, Resource.IOWrappedException
 
Field Summary
protected static Map DETACHED_EOBJECT_TO_ID_MAP
          The map from EObject to ID.
protected  String encoding
           
protected  Map eObjectToExtensionMap
           
protected  Map eObjectToIDMap
          The map from EObject to ID.
protected  Map idToEObjectMap
          The map from ID to EObject.
protected  String publicId
           
protected  String systemId
           
protected  boolean useZip
           
 
Fields inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
contents, defaultLoadOptions, defaultSaveOptions, errors, isLoaded, isModified, modificationTrackingAdapter, resourceSet, 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_DECLARE_XML, OPTION_DISABLE_NOTIFY, OPTION_ENCODING, OPTION_EXTENDED_META_DATA, OPTION_FLUSH_THRESHOLD, OPTION_FORMATTED, 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_UNKNOWN_FEATURE, OPTION_SAVE_DOCTYPE, OPTION_SAVE_TYPE_INFORMATION, OPTION_SCHEMA_LOCATION, OPTION_SCHEMA_LOCATION_IMPLEMENTATION, OPTION_SKIP_ESCAPE, 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, SCHEMA_LOCATION, TYPE, XML_NS, XML_SCHEMA_URI, XSI_NS, XSI_URI
 
Fields inherited from interface org.eclipse.emf.ecore.resource.Resource
RESOURCE__CONTENTS, RESOURCE__ERRORS, RESOURCE__IS_LOADED, RESOURCE__IS_MODIFIED, RESOURCE__IS_TRACKING_MODIFICATION, RESOURCE__RESOURCE_SET, RESOURCE__URI, RESOURCE__WARNINGS
 
Constructor Summary
XMLResourceImpl()
          Constructor for XMLResourceImpl.
XMLResourceImpl(URI uri)
          Constructor for XMLResourceImpl.
 
Method Summary
 void attached(EObject eObject)
          Called when the object is attached to this resource, i.e., when it's eResource changes to be this one.
protected  void attachedHelper(EObject eObject)
           
protected  XMLHelper createXMLHelper()
           
protected  XMLLoad createXMLLoad()
           
protected  XMLSave createXMLSave()
           
 void detached(EObject eObject)
          Called when the object is detached from this resource, i.e., when it's eResource changes to no longer be this one.
protected  void detachedHelper(EObject eObject)
           
 void doLoad(InputStream inputStream, Map options)
          Called to load the resource.
 void doSave(OutputStream outputStream, Map options)
          Called to save the resource.
protected  void doUnload()
          Does all the work of unloading the resource.
 Map getDefaultLoadOptions()
          Returns the map of options that, in addition to the overriding options specified during load, are used to to control load behavior.
 Map getDefaultSaveOptions()
          Returns the map of options that, in addition to the overriding options specified during save, are used to to control save behavior.
 String getEncoding()
          Get the XML encoding for this resource.
protected  EObject getEObjectByID(String id)
          Returns the object based on the fragment as an ID.
 Map getEObjectToExtensionMap()
          Returns the map with EObject as keys and corresponding AnyTypes as the values.
 Map getEObjectToIDMap()
          Returns the Map of EObjects as keys and IDs as values.
 String getID(EObject eObject)
          Returns the ID if there is one for the given object; if there is no ID, it returns null.
 Map getIDToEObjectMap()
          Returns the Map with IDs as keys and EObjects as values.
 String getPublicId()
          Returns public identifier specified on the doctype.
 String getSystemId()
          Returns system identifier specified on the doctype.
 String getURIFragment(EObject eObject)
          Returns the URI fragment that, when passed to getEObject will return the given object.
protected  void init()
           
protected  boolean isPath(String uriFragment)
           
 void setDoctypeInfo(String publicId, String systemId)
          Sets the values of system and public identifiers on this resource.
 void setEncoding(String encoding)
          Set the XML encoding for this resource.
 void setID(EObject eObject, String id)
          Sets the ID of the object.
 void setUseZip(boolean useZip)
          Set whether the contents will be zipped.
 String toKeyString()
          Returns a string representation of the ID map.
protected  boolean useIDAttributes()
           
protected  boolean useIDs()
           
protected  boolean useUUIDs()
           
 boolean useZip()
          Returns whether the contents will be zipped.
 
Methods inherited from class org.eclipse.emf.ecore.resource.impl.ResourceImpl
addModificationTrackingAdapters, basicSetResourceSet, createModificationTrackingAdapter, getAllContents, getContents, getDefaultURIConverter, getEObject, getEObject, getEObjectForURIFragmentRootSegment, getErrors, getResourceSet, getURI, getURIConverter, getURIFragmentRootSegment, getWarnings, isContentZipEntry, isLoaded, isModified, isTrackingModification, load, load, newContentZipEntry, removeModificationTrackingAdapters, save, save, setLoaded, setModified, 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
getAllContents, getContents, getEObject, getErrors, getResourceSet, getURI, getWarnings, isLoaded, isModified, isTrackingModification, load, load, save, save, setModified, setTrackingModification, setURI, unload
 
Methods inherited from interface org.eclipse.emf.common.notify.Notifier
eAdapters, eDeliver, eNotify, eSetDeliver
 

Field Detail

idToEObjectMap

protected Map 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 Map 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 Map eObjectToExtensionMap

encoding

protected String encoding

useZip

protected boolean useZip

publicId

protected String publicId

systemId

protected String systemId

DETACHED_EOBJECT_TO_ID_MAP

protected static final Map 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()

getDefaultSaveOptions

public Map 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 Map 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(InputStream inputStream,
                   Map options)
            throws 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:
IOException

doSave

public void doSave(OutputStream outputStream,
                   Map options)
            throws 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:
IOException

useZip

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

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 String getPublicId()
Description copied from interface: XMLResource
Returns public identifier specified on the doctype.

Specified by:
getPublicId in interface XMLResource

getSystemId

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

Specified by:
getSystemId in interface XMLResource

setDoctypeInfo

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

Specified by:
setDoctypeInfo in interface XMLResource
Parameters:
publicId -
systemId -

getEncoding

public 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(String encoding)
Description copied from interface: XMLResource
Set the XML encoding for this resource.

Specified by:
setEncoding in interface XMLResource

getIDToEObjectMap

public Map 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 Map 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 Map 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 String getID(EObject eObject)
Description copied from interface: XMLResource
Returns the ID if there is one for the given object; if there is no ID, it returns null.

Specified by:
getID in interface XMLResource

setID

public void setID(EObject eObject,
                  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 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

getEObjectByID

protected EObject getEObjectByID(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(String uriFragment)

attached

public void attached(EObject eObject)
Description copied from interface: Resource.Internal
Called when the object is attached to this resource, i.e., when it's eResource changes to be this one.

An implementation that resolves based on IDs will need to walk the tree of this object in order to tabulate an index. An implementation that needs to track modification will also need to walk the tree in order to add the necessary adapter. In either of these cases, editing of containment relations will be significantly more expensive.

Specified by:
attached in interface Resource.Internal
Overrides:
attached in class ResourceImpl

attachedHelper

protected void attachedHelper(EObject eObject)

detached

public void detached(EObject eObject)
Description copied from interface: Resource.Internal
Called when the object is detached from this resource, i.e., when it's eResource changes to no longer be this one.

An implementation that resolves based on IDs will need to walk the tree of this object in order clean up it's index. An implementation that needs to track modification will also need to walk the tree in order to remove the added adapter. In either of these cases, editing of containment relations will be significantly more expensive.

Specified by:
detached in interface Resource.Internal
Overrides:
detached in class ResourceImpl

detachedHelper

protected void detachedHelper(EObject eObject)

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 String toKeyString()
Returns a string representation of the ID map.

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

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