public class PersistentResourceDecorator extends Object implements PersistentResource
PersistentResource
wrapper that delegates all method calls to the decorated resource.
This class can be extended by external tools to add behavior to an existing PersistentResource
.
Resource.Diagnostic, Resource.Factory, Resource.Internal, Resource.IOWrappedException
Modifier and Type | Field and Description |
---|---|
protected PersistentResource |
resource
The underlying resource.
|
OPTION_CIPHER, OPTION_LINE_DELIMITER, OPTION_LINE_DELIMITER_UNSPECIFIED, 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 and Description |
---|
PersistentResourceDecorator(PersistentResource resource)
Constructs a
PersistentResourceDecorator on the given resource . |
Modifier and Type | Method and Description |
---|---|
void |
attached(EObject eObject)
Called when the object is attached to this resource,
i.e., when it's
eResource changes to be this one. |
NotificationChain |
basicSetResourceSet(ResourceSet resourceSet,
NotificationChain notifications)
Sets the resource to be contained by the given resource set, and returns the notifications this produces.
|
void |
close() |
void |
delete(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. |
EList<Adapter> |
eAdapters()
Returns list of the adapters associated with this notifier.
|
boolean |
eDeliver()
Returns whether this notifier will deliver notifications to the adapters.
|
void |
eNotify(Notification notification)
Notifies a change to a feature of this notifier as described by the notification.
|
void |
eSetDeliver(boolean deliver)
Sets whether this notifier will deliver notifications to the adapters.
|
InternalEObject.EStore |
eStore()
Returns the
InternalEObject.EStore used to store the model. |
TreeIterator<EObject> |
getAllContents()
Returns a tree iterator that iterates over all the
direct contents and indirect contents of this resource. |
EList<EObject> |
getAllInstances(EClass eClass)
Computes the set of instances of the given
EClass (including its sub-types). |
EList<EObject> |
getAllInstances(EClass eClass,
boolean strict)
Computes the set of instances of the given
EClass . |
EList<EObject> |
getContents()
Returns the list of the direct content objects;
each is of type
EObject . |
EObject |
getEObject(String uriFragment)
Returns the resolved object for the given URI
fragment . |
EList<Resource.Diagnostic> |
getErrors()
Returns a list of the errors in the resource;
each error will be of type
Resource.Diagnostic . |
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.
|
String |
getURIFragment(EObject eObject)
Returns the URI
fragment that,
when passed to getEObject will return the given 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 . |
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(InputStream inputStream,
Map<?,?> options)
Loads the resource from the input stream using the specified options.
|
void |
load(Map<?,?> options)
Loads the resource using the specified options.
|
void |
save(Map<?,?> options)
Saves the resource using the specified options.
|
void |
save(OutputStream outputStream,
Map<?,?> options)
Saves the resource to the output stream using the specified options.
|
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.
|
void |
unload()
|
protected final PersistentResource resource
public PersistentResourceDecorator(PersistentResource resource)
PersistentResourceDecorator
on the given resource
.resource
- the underlying resourcepublic ResourceSet getResourceSet()
org.eclipse.emf.ecore.resource.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 URI getURI()
org.eclipse.emf.ecore.resource.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)
org.eclipse.emf.ecore.resource.Resource
setURI
in interface Resource
uri
- the new URI.Resource.getURI()
public long getTimeStamp()
org.eclipse.emf.ecore.resource.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)
org.eclipse.emf.ecore.resource.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()
org.eclipse.emf.ecore.resource.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()
org.eclipse.emf.ecore.resource.Resource
direct contents
and indirect contents of this resource.getAllContents
in interface Resource
EObject.eAllContents()
,
ResourceSet.getAllContents()
,
EcoreUtil.getAllContents(Resource, boolean)
public String getURIFragment(EObject eObject)
org.eclipse.emf.ecore.resource.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)
public EObject getEObject(String uriFragment)
org.eclipse.emf.ecore.resource.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)
public void save(Map<?,?> options) throws IOException
org.eclipse.emf.ecore.resource.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.IOException
Resource.save(OutputStream, Map)
public void load(Map<?,?> options) throws IOException
org.eclipse.emf.ecore.resource.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.IOException
Resource.load(InputStream, Map)
public void save(OutputStream outputStream, Map<?,?> options) throws IOException
org.eclipse.emf.ecore.resource.Resource
Usually, save(Map)
is called directly and it calls this.
save
in interface Resource
outputStream
- the streamoptions
- the save options.IOException
Resource.save(Map)
,
Resource.load(InputStream, Map)
public void load(InputStream inputStream, Map<?,?> options) throws IOException
org.eclipse.emf.ecore.resource.Resource
Usually, load(Map)
is called directly and it calls this.
load
in interface Resource
inputStream
- the streamoptions
- the load options.IOException
Resource.load(Map)
,
Resource.save(OutputStream, Map)
public boolean isTrackingModification()
org.eclipse.emf.ecore.resource.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)
org.eclipse.emf.ecore.resource.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.public boolean isModified()
org.eclipse.emf.ecore.resource.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)
org.eclipse.emf.ecore.resource.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 boolean isLoaded()
org.eclipse.emf.ecore.resource.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.
public void unload()
org.eclipse.emf.ecore.resource.Resource
public void delete(Map<?,?> options) throws IOException
org.eclipse.emf.ecore.resource.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
IOException
public EList<Resource.Diagnostic> getErrors()
org.eclipse.emf.ecore.resource.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()
org.eclipse.emf.ecore.resource.Resource
Resource.Diagnostic
.
These will typically be produced as the resource is loaded
.
getWarnings
in interface Resource
Resource.load(Map)
public EList<Adapter> eAdapters()
org.eclipse.emf.common.notify.Notifier
public boolean eDeliver()
org.eclipse.emf.common.notify.Notifier
eDeliver
in interface Notifier
Notifier.eSetDeliver(boolean)
public void eSetDeliver(boolean deliver)
org.eclipse.emf.common.notify.Notifier
eSetDeliver
in interface Notifier
deliver
- whether or not to deliver.Notifier.eDeliver()
public void eNotify(Notification notification)
org.eclipse.emf.common.notify.Notifier
delivered
to the adapters
via Adapter.notifyChanged
.public void attached(EObject eObject)
org.eclipse.emf.ecore.resource.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)
public void detached(EObject eObject)
org.eclipse.emf.ecore.resource.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)
public NotificationChain basicSetResourceSet(ResourceSet resourceSet, NotificationChain notifications)
org.eclipse.emf.ecore.resource.Resource.Internal
If it was previously contained by a resource set, it will have been removed.
basicSetResourceSet
in interface Resource.Internal
null
if there aren't any.public boolean isLoading()
org.eclipse.emf.ecore.resource.Resource.Internal
This will be true
during a call to load(InputStream, Map)
,
before notifications are dispatched.
isLoading
in interface Resource.Internal
public final void close()
close
in interface PersistentResource
close
in interface Closeable
close
in interface AutoCloseable
public InternalEObject.EStore eStore()
PersistentResource
InternalEObject.EStore
used to store the model.eStore
in interface PersistentResource
InternalEObject.EStore
public EList<EObject> getAllInstances(EClass eClass)
PersistentResource
EClass
(including its sub-types).
This method is similar to PersistentResource.getAllInstances(EClass, boolean)
with strict=false
.
getAllInstances
in interface PersistentResource
eClass
- the EClass
for which look for instancesEClass
from the resourcepublic EList<EObject> getAllInstances(EClass eClass, boolean strict)
PersistentResource
EClass
.getAllInstances
in interface PersistentResource
eClass
- the EClass
for which look for instancesstrict
- true if the lookup searches for strict instancestrue
then the method returns only the strict instances of the given EClass
, otherwise
it also returns the instances of the sub-types of eClass
.Copyright © 2013–2017 Atlanmod INRIA LINA Mines Nantes. All rights reserved.