|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.ecore.util.EcoreUtil
This class contains convenient static methods for working with EMF objects.
Nested Class Summary | |
static class |
EcoreUtil.ContentTreeIterator
An iterator over the tree contents of a collection of EObjects, Resources, and ResourceSets; use getAllContents to create a new instance.
|
static class |
EcoreUtil.Copier
A mapping building traverser of a collection of content trees ;
the map is from EObject to EObject , i.e., from original to copy;
use EcoreUtil.copy or EcoreUtil.copyAll to do routine copies.
|
static class |
EcoreUtil.CrossReferencer
A mapping building traverser of a collection of content trees ;
the map is from target object to a collection of EStructuralFeature.Setting .
|
static class |
EcoreUtil.EqualityHelper
A helper for determining whether two EObject s are structurally equal.
|
static class |
EcoreUtil.ExternalCrossReferencer
A cross referencer that finds all references that are not contained within the content trees. |
static class |
EcoreUtil.FilteredSettingsIterator
An iterator over settings that filters out the ones that aren't of interest.
|
static class |
EcoreUtil.ProperContentIterator
An iterator that can skip over items in a list. |
static class |
EcoreUtil.ProxyCrossReferencer
A cross referencer that finds proxies; the cross referencer will not cause proxies to be resolved. |
static class |
EcoreUtil.UnresolvedProxyCrossReferencer
A cross referencer that finds proxies that cannot be resolved. |
static class |
EcoreUtil.UsageCrossReferencer
A cross referencer that finds each usage of an EObject or collection of EObjects. |
Field Summary | |
protected static String |
GEN_MODEL_PACKAGE_NS_URI
|
static int |
GET
Identifier for the get accessor. |
static int |
IS_SET
Identifier for the isSet accessor. |
static int |
SET
Identifier for the set accessor. |
static int |
UNSET
Identifier for the unset accessor. |
Constructor Summary | |
EcoreUtil()
|
Method Summary | |
static Diagnostic |
computeDiagnostic(Resource resource,
boolean includeWarnings)
Computes a Diagnostic from the errors and warnings stored in the specified resource. |
static String |
convertToString(EDataType eDataType,
Object value)
Converts an instance of the datatype to a string literal representation. |
static EObject |
copy(EObject eObject)
Returns a self-contained copy of the eObject. |
static Collection |
copyAll(Collection eObjects)
Returns a collection of the self-contained copies of each EObject in eObjects. |
static EObject |
create(EClass eClass)
Creates an instance of the class. |
static Object |
createFromString(EDataType eDataType,
String literal)
Creates an instance of the datatype. |
static boolean |
equals(EObject eObject1,
EObject eObject2)
Returns true if eObject1 and eObject2 are equal ,
false otherwise. |
static void |
freeze(EPackage ePackage)
Marks the package to indicate that it and everything it contains or that its contents depend on can no longer be changed. |
static String |
generateUUID()
Generates a universally unique identifier, i.e., a UUID. |
static void |
generateUUID(byte[] uuid)
Generates a universally unique identifier, i.e., a UUID. |
static Adapter |
getAdapter(List adapters,
Object type)
Returns the adapter of the specified type. |
static AdapterFactory |
getAdapterFactory(List adapterFactories,
Object type)
Returns the adapter factory for the specified adapter type. |
static TreeIterator |
getAllContents(Collection emfObjects)
Returns a tree iterator over the content trees recursively defined by ResourceSet.getResources() ,
Resource.getContents() ,
and EObject.eContents() .
|
static TreeIterator |
getAllContents(Collection emfObjects,
boolean resolve)
Returns a tree iterator over the content trees recursively defined by ResourceSet.getResources() ,
Resource.getContents() ,
and EObject.eContents() .
|
static TreeIterator |
getAllContents(EObject eObject,
boolean resolve)
Returns a tree iterator that iterates over all the direct contents and indirect contents of the object. |
static TreeIterator |
getAllContents(Resource resource,
boolean resolve)
Returns a tree iterator that iterates over all the direct contents and indirect contents of the resource. |
static TreeIterator |
getAllContents(ResourceSet resourceSet,
boolean resolve)
Returns a tree iterator that iterates over all the direct resources in the resource set
and over the content tree of each. |
static TreeIterator |
getAllProperContents(Collection emfObjects,
boolean resolve)
Returns a tree iterator over the content trees recursively defined by ResourceSet.getResources() ,
Resource.getContents() ,
and EObject.eContents() ,
skipping over any child object that's in a different resource from its parent.
|
static TreeIterator |
getAllProperContents(EObject eObject,
boolean resolve)
Returns a tree iterator that iterates over all the direct contents and indirect contents of the object,
skipping over any child object that's in a different resource from its parent. |
static TreeIterator |
getAllProperContents(Resource resource,
boolean resolve)
Returns a tree iterator that iterates over all the direct contents and indirect contents of the resource,
skipping over any child object that's in a different resource from its parent. |
static TreeIterator |
getAllProperContents(ResourceSet resourceSet,
boolean resolve)
Returns a tree iterator that iterates over all the direct resources in the resource set
and over the content tree of each,
skipping over any child object that's in a different resource from its parent. |
static String |
getAnnotation(EModelElement eModelElement,
String sourceURI,
String key)
|
static List |
getConstraints(EModelElement eModelElement)
|
static String |
getDocumentation(EModelElement eModelElement)
|
static Adapter |
getExistingAdapter(Notifier notifier,
Object type)
Returns the specified notifier's exisiting adapter of the specified type. |
static String |
getID(EObject eObject)
Returns the value of the object's ID attribute as a String. |
static String |
getIdentification(EObject eObject)
Returns a unique string identification of the eObject; it is structured as follows: <java-class-name>[/<dynamic-eclass-name>]@<java-hex-hash-code>{<uri-of-eobject>} |
static Object |
getObjectByType(Collection objects,
EClassifier type)
Returns the first collection member that is an instance of the type. |
static Collection |
getObjectsByType(Collection objects,
EClassifier type)
Returns a collection containing each collection member that is an instance of the type. |
static Adapter |
getRegisteredAdapter(EObject eObject,
Object type)
Returns the specified eObject's adapter of the specified type. |
static Adapter |
getRegisteredAdapter(Resource resource,
Object type)
Returns the specified resource's adapter of the specified type. |
static EObject |
getRootContainer(EObject eObject)
Returns the root container; it may be this object itself and it will have a null container .
|
static EObject |
getRootContainer(EObject eObject,
boolean resolve)
Returns the root container; it may be this object itself and it will have a null container .
|
static URI |
getURI(EObject eObject)
Returns a URI for the eObject, i.e., either the eProxyURI, the URI of the eResource with the fragment produced by the eResource, or the URI consisting of just the fragment that would be produced by a default Resource with the eObject as its only contents. |
static int |
indexOf(List list,
Object o,
int fromIndex)
Deprecated. replaced by ECollections.indexOf(List, Object, int) in 2.1.0 |
static boolean |
isAncestor(Collection ancestorEMFObjects,
EObject eObject)
Returns whether any EObject, Resource, or ResourceSet in the collection is an ancestor of the EObject. |
static boolean |
isAncestor(EObject ancestorEObject,
EObject eObject)
Returns whether the second object is directly or indirectly contained by the first object, i.e., whether the second object is in the content tree of the first.
|
static boolean |
isAncestor(Resource ancestorResource,
EObject eObject)
Returns whether the given resource is that of the object, i.e., whether the object is in the content tree of the resource. |
static boolean |
isAncestor(ResourceSet ancestorResourceSet,
EObject eObject)
Returns whether the given resource set is that of the object, i.e., whether the object is in the content tree of the resource set. |
static boolean |
isSuppressedVisibility(EStructuralFeature eStructuralFeature,
int accessor)
Tests whether the given structural feature has been annotated to prevent generation of accessor methods in its interface. |
static void |
remove(EObject eObject)
Removes the object from its containing resource
and/or its containing object. |
static void |
remove(EObject eObject,
EStructuralFeature eStructuralFeature,
Object value)
Removes the value from the feature of the object. |
static void |
remove(EStructuralFeature.Setting setting,
Object value)
Removes the value from the setting. |
static void |
replace(EObject eObject,
EObject replacementEObject)
Replace the object in its containing resource
and/or its containing object,
with the replacement object. |
static void |
replace(EObject eObject,
EStructuralFeature eStructuralFeature,
Object oldValue,
Object newValue)
Replaces the old value in the object's feature with the new value. |
static void |
replace(EStructuralFeature.Setting setting,
Object oldValue,
Object newValue)
Replaces the old value in the setting with the new value. |
static EObject |
resolve(EObject proxy,
EObject objectContext)
Returns the resolved object represented by proxy. |
static EObject |
resolve(EObject proxy,
Resource resourceContext)
Returns the resolved object represented by proxy. |
static EObject |
resolve(EObject proxy,
ResourceSet resourceSet)
Returns the resolved object represented by proxy. |
static void |
resolveAll(EObject eObject)
Visits all proxies referenced by the object or recursively any of it's contained object. |
static void |
resolveAll(Resource resource)
Visits all proxies in the resource and tries to resolve them. |
static void |
resolveAll(ResourceSet resourceSet)
Visits all proxies in the resource set and tries to resolve them. |
static void |
setAnnotation(EModelElement eModelElement,
String sourceURI,
String key,
String value)
|
static void |
setConstraints(EModelElement eModelElement,
List constraints)
|
static void |
setDocumentation(EModelElement eModelElement,
String documentation)
|
static void |
setEList(EList eList,
Collection prototypeCollection)
Deprecated. replaced by ECollections.setEList(EList, List) in 2.1.0 |
static void |
setEList(EList eList,
List prototypeList)
Deprecated. replaced by ECollections.setEList(EList, List) in 2.1.0 |
static void |
setID(EObject eObject,
String id)
Sets the value of the object's ID attribute according to the value represented by the String. |
static void |
setSuppressedVisibility(EStructuralFeature eStructuralFeature,
int accessor,
boolean suppress)
Sets or removes annotations on the given structural feature to prevent generation of accessor methods in its interface. |
static Class |
wrapperClassFor(Class javaClass)
Returns the wrapper class for the primitive class, or the original class, if it's not a primitive class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final String GEN_MODEL_PACKAGE_NS_URI
public static final int GET
isSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int)
,
setSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int, boolean)
,
Constant Field Valuespublic static final int SET
isSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int)
,
setSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int, boolean)
,
Constant Field Valuespublic static final int IS_SET
isSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int)
,
setSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int, boolean)
,
Constant Field Valuespublic static final int UNSET
isSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int)
,
setSuppressedVisibility(org.eclipse.emf.ecore.EStructuralFeature, int, boolean)
,
Constant Field ValuesConstructor Detail |
public EcoreUtil()
Method Detail |
public static Adapter getExistingAdapter(Notifier notifier, Object type)
notifier
- the adapted object.type
- the type of adapter.
public static Adapter getRegisteredAdapter(EObject eObject, Object type)
eObject
- the adapted object.type
- the type of adapter.
public static Adapter getRegisteredAdapter(Resource resource, Object type)
resource
- the adapted resource.type
- the type of adapter.
public static Adapter getAdapter(List adapters, Object type)
adapters
- list of adapters to search.type
- the type of adapter.
public static AdapterFactory getAdapterFactory(List adapterFactories, Object type)
adapterFactories
- list of adapter factories to search.type
- the type of adapter.
public static EObject resolve(EObject proxy, ResourceSet resourceSet)
proxy
- the proxy to be resolved.resourceSet
- the resource set in which to resolve.
public static EObject resolve(EObject proxy, Resource resourceContext)
proxy
- the proxy to be resolved.resourceContext
- a context resource whose resource set is used for the resolve.
public static EObject resolve(EObject proxy, EObject objectContext)
proxy
- the proxy to be resolved.objectContext
- a context object whose resource set is used for the resolve.
public static void resolveAll(ResourceSet resourceSet)
resourceSet
- the objects to visit.public static void resolveAll(Resource resource)
resource
- the objects to visit.public static void resolveAll(EObject eObject)
eObject
- the object to visist.public static Object getObjectByType(Collection objects, EClassifier type)
is an instance
of the type.
objects
- a collection of objects to check.type
- the type of object to find.
public static Collection getObjectsByType(Collection objects, EClassifier type)
is an instance
of the type.
objects
- a collection of objects to check.type
- the type of object to find.
public static EObject copy(EObject eObject)
eObject
- the object to copy.
EcoreUtil.Copier
public static Collection copyAll(Collection eObjects)
EObject
in eObjects.
eObjects
- the collection of objects to copy.
EcoreUtil.Copier
public static EObject getRootContainer(EObject eObject)
null
container
.
The root container must be directly contained
in a resource
for its tree
to be serializable
.
eObject
- the object to get the root container for.
getRootContainer(EObject, boolean)
,
EObject.eResource()
,
EObject.eContainer()
public static EObject getRootContainer(EObject eObject, boolean resolve)
null
container
.
Container proxies are resolved or not as specified
The root container must be directly contained
in a resource
for its tree
to be serializable
.
eObject
- the object to get the root container for.resolve
- whether to resolve container proxies.
getRootContainer(EObject)
,
EObject.eResource()
,
InternalEObject.eInternalContainer()
public static boolean isAncestor(EObject ancestorEObject, EObject eObject)
content tree
of the first.
Container proxies are not resolved.
ancestorEObject
- the ancestor object in question.eObject
- the object to test.
EObject.eContainer()
public static boolean isAncestor(Resource ancestorResource, EObject eObject)
content tree
of the resource.
ancestorResource
- the ancestor resource in question.eObject
- the object to test.
EObject.eContainer()
,
EObject.eResource()
public static boolean isAncestor(ResourceSet ancestorResourceSet, EObject eObject)
content tree
of the resource set.
ancestorResourceSet
- the ancestor resource set in question.eObject
- the object to test.
EObject.eContainer()
,
EObject.eResource()
,
Resource.getResourceSet()
public static boolean isAncestor(Collection ancestorEMFObjects, EObject eObject)
ancestorEMFObjects
- the collection of ancestor objects in question.eObject
- the object to test.
public static TreeIterator getAllContents(Collection emfObjects)
ResourceSet.getResources()
,
Resource.getContents()
,
and EObject.eContents()
.
It uses a special iterator for ResourceSet.getResources
that is tolerant of growth in the underlying collection
which result from demand loaded resources;
the iterator will walk these additional resources.
emfObjects
- the collection of objects to iterate over.
EcoreUtil.ContentTreeIterator
public static TreeIterator getAllContents(Collection emfObjects, boolean resolve)
ResourceSet.getResources()
,
Resource.getContents()
,
and EObject.eContents()
.
It uses a special iterator for ResourceSet.getResources
that is tolerant of growth in the underlying collection
which result from demand loaded resources;
the iterator will walk these additional resources.
Contained proxies are resolved or not as specified.
emfObjects
- the collection of objects to iterate over.resolve
- whether proxies should be resolved.
EcoreUtil.ContentTreeIterator
public static TreeIterator getAllContents(EObject eObject, boolean resolve)
direct contents
and indirect contents of the object.
eObject
- the object to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
Resource.getAllContents()
public static TreeIterator getAllContents(Resource resource, boolean resolve)
direct contents
and indirect contents of the resource.
resource
- the resource to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
ResourceSet.getAllContents()
public static TreeIterator getAllContents(ResourceSet resourceSet, boolean resolve)
direct resources
in the resource set
and over the content tree
of each.
resourceSet
- the resource set to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
Resource.getAllContents()
,
getAllContents(java.util.Collection)
public static TreeIterator getAllProperContents(Collection emfObjects, boolean resolve)
ResourceSet.getResources()
,
Resource.getContents()
,
and EObject.eContents()
,
skipping over any child object that's in a different resource from its parent.
It uses a special iterator for ResourceSet.getResources
that is tolerant of growth in the underlying collection
which result from demand loaded resources;
the iterator will walk these additional resources.
Contained proxies are resolved or not as specified.
emfObjects
- the collection of objects to iterate over.resolve
- whether proxies should be resolved.
EcoreUtil.ContentTreeIterator
public static TreeIterator getAllProperContents(EObject eObject, boolean resolve)
direct contents
and indirect contents of the object,
skipping over any child object that's in a different resource from its parent.
eObject
- the object to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
Resource.getAllContents()
public static TreeIterator getAllProperContents(Resource resource, boolean resolve)
direct contents
and indirect contents of the resource,
skipping over any child object that's in a different resource from its parent.
resource
- the resource to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
ResourceSet.getAllContents()
public static TreeIterator getAllProperContents(ResourceSet resourceSet, boolean resolve)
direct resources
in the resource set
and over the content tree
of each,
skipping over any child object that's in a different resource from its parent.
resourceSet
- the resource set to iterate over.resolve
- whether proxies should be resolved.
EObject.eAllContents()
,
Resource.getAllContents()
,
getAllContents(java.util.Collection)
public static boolean equals(EObject eObject1, EObject eObject2)
true
if eObject1
and eObject2
are equal
,
false
otherwise.
eObject1
and eObject2
are equal.EcoreUtil.EqualityHelper
public static String getIdentification(EObject eObject)
<java-class-name>[/<dynamic-eclass-name>]@<java-hex-hash-code>{<uri-of-eobject>}
eObject
- the object for which to get an identification.
public static URI getURI(EObject eObject)
eObject
- the object for which to get the URI.
public static int indexOf(List list, Object o, int fromIndex)
ECollections.indexOf(List, Object, int)
in 2.1.0
list
- o
- an object (can be null)fromIndex
-
public static void setEList(EList eList, Collection prototypeCollection)
ECollections.setEList(EList, List)
in 2.1.0
eList
's contents and order to be exactly that of the prototype
collection.
This implementation mimimizes the number of notifications the operation will produce.
Objects already in the list will be moved, missing objects will be added, and extra objects will be removed.
If eList
's contents and order are already exactly that of the prototype
collection,
no change will be made.
eList
- the list to set.prototypeCollection
- the collection representing the desired content and order.public static void setEList(EList eList, List prototypeList)
ECollections.setEList(EList, List)
in 2.1.0
eList
's contents and order to be exactly that of the prototype
list.
This implementation mimimizes the number of notifications the operation will produce.
Objects already in the list will be moved, missing objects will be added, and extra objects will be removed.
If eList
's contents and order are already exactly that of the prototype
list,
no change will be made.
eList
- the list to set.prototypeList
- the list representing the desired content and order.public static void remove(EStructuralFeature.Setting setting, Object value)
setting
- the setting holding the value.value
- the value to remove.public static void replace(EStructuralFeature.Setting setting, Object oldValue, Object newValue)
setting
- the setting holding the values.oldValue
- the value to replace.newValue
- the replacement value.public static void remove(EObject eObject, EStructuralFeature eStructuralFeature, Object value)
eObject
- the object holding the value.eStructuralFeature
- the feature of the object holding the value.value
- the value to remove.public static void replace(EObject eObject, EStructuralFeature eStructuralFeature, Object oldValue, Object newValue)
eObject
- the object holding the values.eStructuralFeature
- the feature of the object holding the values.oldValue
- the value to replace.newValue
- the replacement value.public static void remove(EObject eObject)
containing
resource
and/or its containing
object.
eObject
- the object to remove.public static void replace(EObject eObject, EObject replacementEObject)
containing
resource
and/or its containing
object,
with the replacement object.
eObject
- the object to replace.replacementEObject
- the replacement object.public static EObject create(EClass eClass)
eClass
- the class to instantiate.
public static Object createFromString(EDataType eDataType, String literal)
eDataType
- the datatype to instantiate.literal
- the string value of the datatype.
convertToString(EDataType, Object)
public static String convertToString(EDataType eDataType, Object value)
eDataType
- the datatype to instantiate.value
- a value of the datatype.
createFromString(EDataType, String)
public static String getID(EObject eObject)
null
.
eObject
- the object in question.
EAttribute.isID()
,
EClass.getEIDAttribute()
,
setID(EObject, String)
public static void setID(EObject eObject, String id)
null
ID will unset the attribute rather than setting it to null
.
eObject
- the object in question.id
- the String value of the new ID.
IllegalArgumentException
- if the object has no ID attribute.getID(EObject)
,
EAttribute.isID()
,
EClass.getEIDAttribute()
public static Class wrapperClassFor(Class javaClass)
javaClass
- public static String getDocumentation(EModelElement eModelElement)
public static void setDocumentation(EModelElement eModelElement, String documentation)
public static List getConstraints(EModelElement eModelElement)
public static void setConstraints(EModelElement eModelElement, List constraints)
public static String getAnnotation(EModelElement eModelElement, String sourceURI, String key)
public static void setAnnotation(EModelElement eModelElement, String sourceURI, String key, String value)
public static boolean isSuppressedVisibility(EStructuralFeature eStructuralFeature, int accessor)
eStructuralFeature
- the structural featureaccessor
- the type of accessor method, one of GET
, SET
, IS_SET
, or UNSET
public static void setSuppressedVisibility(EStructuralFeature eStructuralFeature, int accessor, boolean suppress)
eStructuralFeature
- the structural featureaccessor
- the type of accessor method, one of GET
, SET
, IS_SET
, or UNSET
suppress
- whether the specified accessor's visibility should be suppressedpublic static String generateUUID()
public static void generateUUID(byte[] uuid)
uuid
- the value to receive the result.public static void freeze(EPackage ePackage)
public static Diagnostic computeDiagnostic(Resource resource, boolean includeWarnings)
Diagnostic
from the errors and warnings stored in the specified resource.
resource
- includeWarnings
-
Diagnostic
|
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 |