|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.common.notify.impl.BasicNotifierImpl org.eclipse.emf.common.notify.impl.NotifierImpl org.eclipse.emf.ecore.resource.impl.ResourceImpl
public class ResourceImpl
A highly extensible resource implementation.
The following configuration and control mechanisms are provided:
Nested Class Summary | |
---|---|
protected class |
ResourceImpl.ContentsEList<E extends java.lang.Object & EObject>
A notifying list implementation for supporting Resource.getContents() . |
protected class |
ResourceImpl.ModificationTrackingAdapter
An adapter implementation for tracking resource modification. |
Nested classes/interfaces inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl |
---|
BasicNotifierImpl.EAdapterList<E extends java.lang.Object & Adapter> |
Field Summary | |
---|---|
protected ResourceImpl.ContentsEList<EObject> |
contents
The contents. |
protected java.util.Map<java.lang.Object,java.lang.Object> |
defaultDeleteOptions
The storage for the default delete options. |
protected java.util.Map<java.lang.Object,java.lang.Object> |
defaultLoadOptions
The storage for the default load options. |
protected java.util.Map<java.lang.Object,java.lang.Object> |
defaultSaveOptions
The storage for the default save options. |
protected EList<Resource.Diagnostic> |
errors
The errors. |
protected java.util.Map<java.lang.String,EObject> |
intrinsicIDToEObjectMap
A map to retrieve the EObject based on the value of its ID feature. |
protected boolean |
isLoaded
The loaded flag. |
protected boolean |
isLoading
The loading flag. |
protected boolean |
isModified
The modified flag. |
protected Adapter |
modificationTrackingAdapter
The modification tracking adapter. |
protected ResourceSet |
resourceSet
The containing resource set. |
protected long |
timeStamp
The time stamp. |
protected java.util.List<EObject> |
unloadingContents
A copy of the contents list while the contents are being unloaded . |
protected URI |
uri
The URI. |
protected EList<Resource.Diagnostic> |
warnings
The warnings. |
Fields inherited from class org.eclipse.emf.common.notify.impl.NotifierImpl |
---|
eAdapters, EDELIVER, eFlags, ELAST_NOTIFIER_FLAG |
Constructor Summary | |
---|---|
ResourceImpl()
Creates a empty instance. |
|
ResourceImpl(URI uri)
Creates an instance with the given URI. |
Method Summary | |
---|---|
protected void |
addModificationTrackingAdapters(EObject eObject)
Deprecated. since 2.1.0. This method is not invoked anymore. See attachedHelper(EObject) . |
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)
|
NotificationChain |
basicSetResourceSet(ResourceSet resourceSet,
NotificationChain notifications)
Sets the new containing resource set, and removes the resource from a previous containing resource set, if necessary. |
protected Adapter |
createModificationTrackingAdapter()
Creates a modification tracking adapter. |
void |
delete(java.util.Map<?,?> options)
deletes the resource using the specified options,
unloads it,
and then removes it from the containing resource set. |
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)
|
protected void |
doLoad(java.io.InputStream inputStream,
java.util.Map<?,?> options)
Called to load the resource. |
protected void |
doSave(java.io.OutputStream outputStream,
java.util.Map<?,?> options)
Called to save the resource. |
protected void |
doUnload()
Does all the work of unloading the resource. |
TreeIterator<EObject> |
getAllContents()
Returns a tree iterator that iterates over all the direct contents and indirect contents of this resource. |
protected TreeIterator<EObject> |
getAllProperContents(EObject eObject)
|
protected TreeIterator<EObject> |
getAllProperContents(java.util.List<EObject> contents)
|
EList<EObject> |
getContents()
Returns the list of the direct content objects; each is of type EObject . |
protected static URIConverter |
getDefaultURIConverter()
Returns the default URI converter that's used when there is no resource set. |
protected EObject |
getEObject(java.util.List<java.lang.String> uriFragmentPath)
Returns the object based on the fragment path as a list of Strings. |
EObject |
getEObject(java.lang.String uriFragment)
Returns the resolved object for the given URI fragment . |
protected EObject |
getEObjectByID(java.lang.String id)
Returns the object based on the fragment as an ID. |
protected EObject |
getEObjectForURIFragmentRootSegment(java.lang.String uriFragmentRootSegment)
Returns the object associated with the URI fragment root segment. |
EList<Resource.Diagnostic> |
getErrors()
Returns a list of the errors in the resource; each error will be of type Resource.Diagnostic . |
java.util.Map<java.lang.String,EObject> |
getIntrinsicIDToEObjectMap()
Returns the map used to cache the EObject that is identified by the value
of its ID feature. |
ResourceSet |
getResourceSet()
Returns the containing resource set. |
long |
getTimeStamp()
Returns the cached value of the time stamp
when this resource was last loaded or saved ,
or NULL_TIME_STAMP
if the resource is not loaded
and the time stamp has not been set . |
URI |
getURI()
Returns the URI of this resource. |
protected URIConverter |
getURIConverter()
Returns the URI converter. |
java.lang.String |
getURIFragment(EObject eObject)
Returns the URI fragment that,
when passed to getEObject will return the given object. |
protected java.lang.String |
getURIFragmentRootSegment(EObject eObject)
Returns the URI fragment root segment for reaching the given direct content object. |
EList<Resource.Diagnostic> |
getWarnings()
Returns a list of the warnings and informational messages in the resource; each warning will be of type Resource.Diagnostic . |
protected boolean |
isAttachedDetachedHelperRequired()
|
protected boolean |
isContentZipEntry(java.util.zip.ZipEntry zipEntry)
Returns whether the given entry is the content entry for this resource. |
boolean |
isLoaded()
Returns whether the resource is loaded. |
boolean |
isLoading()
Indicates whether the resource is currently being loaded. |
boolean |
isModified()
Returns whether this resource has been modified. |
boolean |
isTrackingModification()
Returns whether modification tracking is enabled. |
void |
load(java.io.InputStream inputStream,
java.util.Map<?,?> options)
Loads the resource from the input stream using the specified options. |
void |
load(java.util.Map<?,?> options)
Loads the resource using the specified options. |
protected static java.util.Map<?,?> |
mergeMaps(java.util.Map<?,?> map1,
java.util.Map<?,?> map2)
Merges 2 maps, without changing any of them. |
protected java.util.zip.ZipEntry |
newContentZipEntry()
Returns a new zip entry for saving the resource contents. |
protected void |
removeModificationTrackingAdapters(EObject eObject)
Deprecated. since 2.1.0. This method is not invoked anymore. See attachedHelper(EObject) . |
void |
save(java.util.Map<?,?> options)
Saves the resource using the specified options. |
void |
save(java.io.OutputStream outputStream,
java.util.Map<?,?> options)
Saves the resource to the output stream using the specified options. |
protected void |
saveOnlyIfChangedWithFileBuffer(java.util.Map<?,?> options)
|
protected void |
saveOnlyIfChangedWithMemoryBuffer(java.util.Map<?,?> options)
|
void |
setIntrinsicIDToEObjectMap(java.util.Map<java.lang.String,EObject> intrinsicIDToEObjectMap)
Sets the map used to cache the EObject identified by the value of its ID feature. |
protected Notification |
setLoaded(boolean isLoaded)
Sets the load state as indicated, and returns a notification, if required . |
void |
setModified(boolean isModified)
Sets whether this resource has been modified. |
void |
setTimeStamp(long timeStamp)
Sets the value of the time stamp . |
void |
setTrackingModification(boolean isTrackingModification)
Sets whether modification tracking is enabled. |
void |
setURI(URI uri)
Sets the URI of this resource. |
java.lang.String |
toKeyString()
If an implementation uses IDs and stores the IDs as part of the resource rather than as objects, this method should return a string representation of the ID to object mapping, which might be implemented as a Java Map. |
java.lang.String |
toString()
|
void |
unload()
Clears the contents ,
errors ,
and warnings of the resource
and marks it as unloaded. |
protected void |
unloaded(InternalEObject internalEObject)
Called when the object is unloaded. |
protected boolean |
useZip()
Returns whether contents will be compressed. |
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 |
Field Detail |
---|
protected java.util.Map<java.lang.Object,java.lang.Object> defaultSaveOptions
protected java.util.Map<java.lang.Object,java.lang.Object> defaultLoadOptions
protected java.util.Map<java.lang.Object,java.lang.Object> defaultDeleteOptions
protected ResourceSet resourceSet
getResourceSet()
protected URI uri
getURI()
protected long timeStamp
getTimeStamp()
protected ResourceImpl.ContentsEList<EObject> contents
getContents()
protected EList<Resource.Diagnostic> errors
getErrors()
protected EList<Resource.Diagnostic> warnings
getErrors()
protected boolean isModified
isModified
protected boolean isLoaded
isLoaded
protected boolean isLoading
isLoading
protected java.util.List<EObject> unloadingContents
contents
list while the contents are being unloaded
.
I.e., if this is not null
, then the resource is in the process of unloading.
unload()
protected Adapter modificationTrackingAdapter
isTrackingModification()
,
attached(EObject)
,
detached(EObject)
protected java.util.Map<java.lang.String,EObject> intrinsicIDToEObjectMap
setIntrinsicIDToEObjectMap(Map)
Constructor Detail |
---|
public ResourceImpl()
public ResourceImpl(URI uri)
uri
- the URI.Method Detail |
---|
protected static URIConverter getDefaultURIConverter()
getURIConverter()
protected static java.util.Map<?,?> mergeMaps(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
public ResourceSet getResourceSet()
Resource
resources
, i.e., the contents, of that resource set.
This reference can only be modified by altering the contents of the resource set directly.
getResourceSet
in interface Resource
null
if there isn't one.EObject.eContainer()
,
EObject.eResource()
,
ResourceSet.getResources()
public NotificationChain basicSetResourceSet(ResourceSet resourceSet, NotificationChain notifications)
basicSetResourceSet
in interface Resource.Internal
resourceSet
- the new containing resource set.notifications
- the accumulating notifications.
public URI getURI()
Resource
absolute
and hierarchical
;
document-relative references will not be serialized and will not be resolved
,
if this is not the case.
getURI
in interface Resource
null
if there isn't one.Resource.setURI(URI)
,
URI.isRelative()
,
URI.isHierarchical()
public void setURI(URI uri)
Resource
setURI
in interface Resource
uri
- the new URI.Resource.getURI()
public long getTimeStamp()
Resource
time stamp
when this resource was last loaded
or saved
,
or NULL_TIME_STAMP
if the resource is not loaded
and the time stamp has not been set
.
The return value is represented as the number of milliseconds
since the epoch (00:00:00 GMT, January 1, 1970).
The returned value may not be the same as the actual time stamp
if the resource has been modified via external means since the last load or save.
getTimeStamp
in interface Resource
Resource.setTimeStamp(long)
public void setTimeStamp(long timeStamp)
Resource
time stamp
.
The time stamp is typically set indirectly via other operations on the resource
such as loading
and saving
.
setTimeStamp
in interface Resource
timeStamp
- the new value of the time stamp.Resource.getTimeStamp()
,
Resource.RESOURCE__TIME_STAMP
public EList<EObject> getContents()
Resource
EObject
.
The contents may be directly modified.
Removing an object will have the same effect as
EcoreUtil.remove(EObject)
.
Adding an object will remove it from the previous container;
it's container
will be null
and it's resource
will the this
.
getContents
in interface Resource
public TreeIterator<EObject> getAllContents()
Resource
direct contents
and indirect contents of this resource.
getAllContents
in interface Resource
EObject.eAllContents()
,
ResourceSet.getAllContents()
,
EcoreUtil.getAllContents(Resource, boolean)
protected TreeIterator<EObject> getAllProperContents(EObject eObject)
protected TreeIterator<EObject> getAllProperContents(java.util.List<EObject> contents)
public EList<Resource.Diagnostic> getErrors()
Resource
Resource.Diagnostic
.
These will typically be produced as the resource is loaded
.
getErrors
in interface Resource
Resource.load(Map)
public EList<Resource.Diagnostic> getWarnings()
Resource
Resource.Diagnostic
.
These will typically be produced as the resource is loaded
.
getWarnings
in interface Resource
Resource.load(Map)
protected boolean useZip()
false
.
When this returns true
,
save(OutputStream, Map)
and load(InputStream, Map)
will zip compress and decompress contents.
newContentZipEntry()
,
isContentZipEntry(ZipEntry)
protected java.lang.String getURIFragmentRootSegment(EObject eObject)
"/"
.
public java.lang.String getURIFragment(EObject eObject)
Resource
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
.
getURIFragment
in interface Resource
eObject
- the object to identify.
fragment
for the object.Resource.getEObject(String)
,
InternalEObject.eURIFragmentSegment(org.eclipse.emf.ecore.EStructuralFeature, EObject)
protected EObject getEObjectForURIFragmentRootSegment(java.lang.String uriFragmentRootSegment)
"0"
.
public EObject getEObject(java.lang.String uriFragment)
Resource
fragment
.
The fragment encoding will typically be that produced by getURIFragment
.
getEObject
in interface Resource
uriFragment
- the fragment to resolve.
null
if it can't be resolved.Resource.getURIFragment(EObject)
,
ResourceSet.getEObject(URI, boolean)
,
EcoreUtil.resolve(EObject, ResourceSet)
,
InternalEObject.eObjectForURIFragmentSegment(String)
protected EObject getEObject(java.util.List<java.lang.String> uriFragmentPath)
public java.util.Map<java.lang.String,EObject> getIntrinsicIDToEObjectMap()
value
of its ID feature.
setIntrinsicIDToEObjectMap(java.util.Map)
public void setIntrinsicIDToEObjectMap(java.util.Map<java.lang.String,EObject> intrinsicIDToEObjectMap)
null
.
The map will be lazily loaded by the getEObjectByID
method.
It is up to the client to clear the cache when it becomes invalid,
e.g., when the ID of a previously mapped EObject is changed.
intrinsicIDToEObjectMap
- the new map or null
.getIntrinsicIDToEObjectMap()
protected EObject getEObjectByID(java.lang.String id)
public void attached(EObject eObject)
Resource.Internal
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.
attached
in interface Resource.Internal
eObject
- the attached object.Resource.Internal.detached(EObject)
protected boolean isAttachedDetachedHelperRequired()
protected void attachedHelper(EObject eObject)
@Deprecated protected final void addModificationTrackingAdapters(EObject eObject)
attachedHelper(EObject)
.
eObject
- the object.attached(EObject)
public void detached(EObject eObject)
Resource.Internal
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.
detached
in interface Resource.Internal
eObject
- the attached object.Resource.Internal.attached(EObject)
protected void detachedHelper(EObject eObject)
@Deprecated protected final void removeModificationTrackingAdapters(EObject eObject)
attachedHelper(EObject)
.
eObject
- the object.detached(EObject)
protected URIConverter getURIConverter()
converter
from the containing
resource set,
but it calls getDefaultURIConverter()
when there is no containing resource set.
public void save(java.util.Map<?,?> options) throws java.io.IOException
Resource
Options are handled generically as feature-to-setting entries; the resource will ignore options it doesn't recognize. The options could even include things like an Eclipse progress monitor...
An implementation typically uses the URI converter
of the containing
resource set
to create
an output stream,
and then delegates to save(OutputStream, Map)
.
save
in interface Resource
options
- the save options.
java.io.IOException
Resource.save(OutputStream, Map)
protected void saveOnlyIfChangedWithFileBuffer(java.util.Map<?,?> options) throws java.io.IOException
java.io.IOException
protected void saveOnlyIfChangedWithMemoryBuffer(java.util.Map<?,?> options) throws java.io.IOException
java.io.IOException
public void load(java.util.Map<?,?> options) throws java.io.IOException
Resource
Options are handled generically as feature-to-setting entries; the resource will ignore options it doesn't recognize. The options could even include things like an Eclipse progress monitor...
An implementation typically uses the URI converter
of the containing
resource set
to create
an input stream,
and then delegates to load(InputStream, Map)
.
When the load completes, the errors
and warnings
can be consulted.
An implementation will typically deserialize as much of a document as possible
while producing diagnostics for any problems that are encountered.
load
in interface Resource
options
- the load options.
java.io.IOException
Resource.load(InputStream, Map)
protected java.util.zip.ZipEntry newContentZipEntry()
saving
the resource contents.
It is called by save(OutputStream, Map)
when writing zipped
contents.
This implementation creates an entry called ResourceContents
.
isContentZipEntry(ZipEntry)
public final void save(java.io.OutputStream outputStream, java.util.Map<?,?> options) throws java.io.IOException
This implementation is final
;
clients should override doSave
.
save
in interface Resource
options
- the save options.outputStream
- the stream
java.io.IOException
save(Map)
,
doSave(OutputStream, Map)
,
load(InputStream, Map)
protected void doSave(java.io.OutputStream outputStream, java.util.Map<?,?> options) throws java.io.IOException
outputStream
- the streamoptions
- the save options.
java.lang.UnsupportedOperationException
java.io.IOException
protected boolean isContentZipEntry(java.util.zip.ZipEntry zipEntry)
load(InputStream, Map)
when reading zipped
contents.
This implementation return true
;
i.e., the first entry will be read.
newContentZipEntry()
public final void load(java.io.InputStream inputStream, java.util.Map<?,?> options) throws java.io.IOException
Resource
Usually, load(Map)
is called directly and it calls this.
load
in interface Resource
inputStream
- the streamoptions
- the load options.
java.io.IOException
Resource.load(Map)
,
Resource.save(OutputStream, Map)
protected void doLoad(java.io.InputStream inputStream, java.util.Map<?,?> options) throws java.io.IOException
inputStream
- the streamoptions
- the load options.
java.lang.UnsupportedOperationException
java.io.IOException
public boolean isLoaded()
Resource
This will be false
when the resource is first created
and will be set to false
, when the resource is unloaded
.
It will be set to true
when the resource is loaded
and when contents
are first added to a resource that isn't loaded.
Calling clear
for the contents
of a resource that isn't loaded,
will set the resource to be loaded;
this is the simplest way to create an empty resource that's considered loaded.
isLoaded
in interface Resource
public boolean isLoading()
Resource.Internal
This will be true
during a call to load(InputStream, Map)
,
before notifications are dispatched.
isLoading
in interface Resource.Internal
protected void unloaded(InternalEObject internalEObject)
sets
the object to be a proxy
and clears the adapters
.
protected Notification setLoaded(boolean isLoaded)
required
.
Clients are not expected to call this directly; it is managed by the implementation.
isLoaded
- whether the resource is loaded.
protected void doUnload()
unloaded
for each object it the content tree
,
and clears the contents
, errors
, and warnings
.
public final void unload()
Resource
contents
,
errors
,
and warnings
of the resource
and marks
it as unloaded.
It walks the content tree
,
and sets
each content object to be a proxy.
The resource will remain in the resource set
,
and can be subsequently reloaded.
unload
in interface Resource
public void delete(java.util.Map<?,?> options) throws java.io.IOException
Resource
deletes
the resource using the specified options,
unloads
it,
and then removes it from the containing
resource set.
Options are handled generically as feature-to-setting entries; the resource will ignore options it doesn't recognize. The options could even include things like an Eclipse progress monitor...
An implementation typically uses the URI converter
of the containing
resource set
to URIConverter.delete(URI, Map)
the resource's URI
.
delete
in interface Resource
java.io.IOException
public boolean isTrackingModification()
Resource
If modification tracking is enabled,
each object of the resource must be adapted in order to listen for changes.
This will make the processing of attached
and detached
significantly more expensive.
as well as all model editing, in general.
isTrackingModification
in interface Resource
public void setTrackingModification(boolean isTrackingModification)
Resource
Calling this method is expensive because it walks the content tree
to add or remove adapters.
setTrackingModification
in interface Resource
isTrackingModification
- whether modification tracking is to be enabled.protected Adapter createModificationTrackingAdapter()
ResourceImpl.ModificationTrackingAdapter
.
Clients may override this to any adapter.
modificationTrackingAdapter
,
isTrackingModification()
public boolean isModified()
Resource
A resource is set to be unmodified after it is loaded or saved.
Automatic
modification tracking is supported, but it is expensive.
Moreover, it is a poor fit for a model that supports undoable commands,
since an undo looks like a change when it's really exactly the opposite.
isModified
in interface Resource
Resource.setModified(boolean)
public void setModified(boolean isModified)
Resource
A resource is automatically set to be unmodified after it is loaded or saved.
Automatic
modification tracking typically calls this directly.
setModified
in interface Resource
isModified
- whether this resource has been modified.Resource.isModified()
public java.lang.String toKeyString()
public java.lang.String toString()
toString
in class java.lang.Object
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |