Package org.eclipse.emf.cdo.common.model

# Class EMFUtil

java.lang.Object
org.eclipse.emf.cdo.common.model.EMFUtil

public final class EMFUtil extends Object
Various static helper methods for dealing with EMF meta models.

Since:
  2.0
Author:
  Eike Stepper

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`EMFUtil.ExtResourceSet`
An extension of `ResourceSetImpl` that allows demandLoading of resources and delegation of resource lookups, to be switched on/off as desired.
`static final class`
`EMFUtil.TreeMapping<T extends EObject>`
A mapping between two `EObject`s and their contents based on their URIs as returned by `EcoreUtil.getURI(EObject)`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final org.eclipse.net4j.util.Predicate<EStructuralFeature>`
`ATTRIBUTES`
Deprecated.
As of 4.9 use `EMFPredicates.ATTRIBUTES`.
`static final String`
`CDO_ANNOTATION_KEY_PERSISTENT`
`static final String`
`CDO_ANNOTATION_SOURCE`
`static final org.eclipse.net4j.util.Predicate<EStructuralFeature>`
`CONTAINER_REFERENCES`
Deprecated.
As of 4.9 use `EMFPredicates.CONTAINER_REFERENCES`.
`static final org.eclipse.net4j.util.Predicate<EStructuralFeature>`
`CONTAINMENT_REFERENCES`
Deprecated.
As of 4.9 use `EMFPredicates.CONTAINMENT_REFERENCES`.
`static final org.eclipse.net4j.util.Predicate<EStructuralFeature>`
`CROSS_REFERENCES`
Deprecated.
As of 4.9 use `EMFPredicates.CROSS_REFERENCES`.
`static final EReference`
`ECLASS_EGENERIC_SUPER_TYPES`
`static final EReference`
`ECLASS_ESUPER_TYPES`
`static final EAttribute`
`ECLASSIFIER_INSTANCE_CLASS_NAME`
`static final EAttribute`
`ECLASSIFIER_INSTANCE_TYPE_NAME`
`static final EReference`
`EOPERATION_EEXCEPTIONS`
`static final EReference`
`EOPERATION_EGENERIC_EXCEPTIONS`
`static final EReference`
`ETYPED_ELEMENT_EGENERIC_TYPE`
`static final EReference`
`ETYPED_ELEMENT_ETYPE`
`static final org.eclipse.net4j.util.Predicate<EStructuralFeature>`
`REFERENCES`
Deprecated.
As of 4.9 use `EMFPredicates.REFERENCES`.

## Method Summary

Modifier and Type
Method
Description
`static void`
`addAdapter(Notifier notifier, Adapter adapter)`
`static EAttribute`
`createEAttribute(EClass eClass, String name, EClassifier type)`
`static EClass`
`createEClass(EPackage ePackage, String name)`
`static EClass`
`createEClass(EPackage ePackage, String name, boolean isAbstract, boolean isInterface)`
`static EEnum`
`createEEnum(EPackage ePackage, String name)`
`static EEnum`
`createEEnum(EPackage ePackage, String name, String... literals)`
`static EEnumLiteral`
`createEEnumLiteral(EEnum eEnum, String name)`
`static EEnumLiteral`
`createEEnumLiteral(EEnum eEnum, String name, int value)`
`static EPackage`
`createEPackage(String uri, byte[] bytes, boolean zipped, ResourceSet resourceSet, boolean lookForResource)`
Creates an `EPackage` from the given byte array by loading it into a resource in the given resource set.
`static EPackage`
`createEPackage(String uri, byte[] bytes, ResourceSet resourceSet, boolean lookForResource)`
Creates an `EPackage` from the given byte array by loading it into a resource in the given resource set.
`static EPackage`
`createEPackage(String name, String nsPrefix, String nsURI)`
`static EReference`
`createEReference(EClass eClass, String name, EClassifier type)`
`static EReference`
`createEReference(EClass eClass, String name, EClassifier type, boolean isRequired, boolean isMany)`
`static EMFUtil.ExtResourceSet`
`createExtResourceSet(InternalCDOPackageRegistry packageRegistry, boolean delegating, boolean demandLoading)`
`static void`
`forAllConcreteClasses(EPackage ePackage, boolean includeSubPackages, Consumer<EClass> consumer)`
`static <T> T`
`getAdapter(Notifier notifier, Class<T> type)`
`static EPackage[]`
`getAllPackages(EPackage ePackage)`
`static void`
`getAllPackages(EPackage ePackage, Consumer<EPackage> consumer)`
`static EList<EAnnotation>`
`getAnnotations(EClass eClass, String sourceURI)`
`static EClass`
`getAnyConcreteEClass(EPackage ePackage, boolean includeSubPackages)`
`static EClass[]`
`getConcreteClasses(EPackage ePackage)`
`static EClass[]`
`getConcreteClasses(EPackage ePackage, boolean includeSubPackages)`
`static byte[]`
`getEPackageBytes(EPackage ePackage, boolean zipped, EPackage.Registry packageRegistry)`
`static String`
`getFullyQualifiedName(EObject modelElement)`
`static String`
`getFullyQualifiedName(EObject modelElement, String separator)`
`static EPackage`
`getGeneratedEPackage(EPackage ePackage)`
`static <T extends EObject>
T`
`getNearestObject(EObject object, Class<T> type)`
`static String`
`getParentURI(EPackage ePackage)`
`static EClass[]`
`getPersistentClasses(EPackage ePackage)`
`static List<EStructuralFeature>`
`getPersistentFeatures(EList<EStructuralFeature> eFeatures)`
Deprecated.
This method is expensive and will be removed in the future.
`static URI`
`getPositionalURI(InternalEObject internalEObject)`
`static String`
`getQualifiedName(EClassifier classifier, String separator)`
`static String`
`getQualifiedName(EPackage ePackage, String separator)`
`static String`
`getQualifiedName(EStructuralFeature feature, String separator)`
`static Map.Entry<String,Object>[]`
`getSortedRegistryEntries(EPackage.Registry packageRegistry)`
`static EPackage`
`getTopLevelPackage(EPackage ePackage)`
`static String`
`getXMI(EPackage ePackage)`
`static boolean`
`isDynamicEPackage(Object value)`
`static boolean`
`isPersistent(EStructuralFeature feature)`
Returns `true` if CDO considers the given feature persistent, `false` otherwise.
`static ResourceSet`
`newEcoreResourceSet()`
`static ResourceSet`
`newEcoreResourceSet(EPackage.Registry packageRegistry)`
`static ResourceSet`
`newResourceSet(Resource.Factory resourceFactory)`
`static void`
`registerPackage(EPackage ePackage, EPackage.Registry... packageRegistries)`
`static EObject`
`safeResolve(EObject proxy, ResourceSet resourceSet)`
`static void`
`safeResolveAll(ResourceSet resourceSet)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### CDO_ANNOTATION_SOURCE

public static final String CDO_ANNOTATION_SOURCE

Since:
  3.0
See Also:
  - Constant Field Values

### CDO_ANNOTATION_KEY_PERSISTENT

public static final String CDO_ANNOTATION_KEY_PERSISTENT

Since:
  3.0
See Also:
  - Constant Field Values

### EOPERATION_EEXCEPTIONS

public static final EReference EOPERATION_EEXCEPTIONS

Since:
  4.2

### ETYPED_ELEMENT_ETYPE

public static final EReference ETYPED_ELEMENT_ETYPE

Since:
  4.2

### ECLASS_ESUPER_TYPES

public static final EReference ECLASS_ESUPER_TYPES

Since:
  4.2

### ECLASSIFIER_INSTANCE_CLASS_NAME

public static final EAttribute ECLASSIFIER_INSTANCE_CLASS_NAME

Since:
  4.2

### EOPERATION_EGENERIC_EXCEPTIONS

public static final EReference EOPERATION_EGENERIC_EXCEPTIONS

Since:
  4.2

### ETYPED_ELEMENT_EGENERIC_TYPE

public static final EReference ETYPED_ELEMENT_EGENERIC_TYPE

Since:
  4.2

### ECLASS_EGENERIC_SUPER_TYPES

public static final EReference ECLASS_EGENERIC_SUPER_TYPES

Since:
  4.2

### ECLASSIFIER_INSTANCE_TYPE_NAME

public static final EAttribute ECLASSIFIER_INSTANCE_TYPE_NAME

Since:
  4.2

### ATTRIBUTES

@Deprecated public static final org.eclipse.net4j.util.Predicate<EStructuralFeature> ATTRIBUTES
Deprecated.
As of 4.9 use `EMFPredicates.ATTRIBUTES`.

Since:
  4.2

### REFERENCES

@Deprecated public static final org.eclipse.net4j.util.Predicate<EStructuralFeature> REFERENCES
Deprecated.
As of 4.9 use `EMFPredicates.REFERENCES`.

Since:
  4.2

### CONTAINER_REFERENCES

@Deprecated public static final org.eclipse.net4j.util.Predicate<EStructuralFeature> CONTAINER_REFERENCES
Deprecated.
As of 4.9 use `EMFPredicates.CONTAINER_REFERENCES`.

Since:
  4.2

### CROSS_REFERENCES

@Deprecated public static final org.eclipse.net4j.util.Predicate<EStructuralFeature> CROSS_REFERENCES
Deprecated.
As of 4.9 use `EMFPredicates.CROSS_REFERENCES`.

Since:
  4.2

### CONTAINMENT_REFERENCES

@Deprecated public static final org.eclipse.net4j.util.Predicate<EStructuralFeature> CONTAINMENT_REFERENCES
Deprecated.
As of 4.9 use `EMFPredicates.CONTAINMENT_REFERENCES`.

Since:
  4.2

## Method Details

### getNearestObject

public static <T extends EObject> T getNearestObject(EObject object, Class<T> type)

Since:
  4.26

### getPositionalURI

public static URI getPositionalURI(InternalEObject internalEObject)

Since:
  4.2

### getGeneratedEPackage

public static EPackage getGeneratedEPackage(EPackage ePackage)

### getSortedRegistryEntries

public static Map.Entry<String,Object>[] getSortedRegistryEntries(EPackage.Registry packageRegistry)

### getAnnotations

public static EList<EAnnotation> getAnnotations(EClass eClass, String sourceURI)

Since:
  4.6

### getTopLevelPackage

public static EPackage getTopLevelPackage(EPackage ePackage)

### createEPackage

public static EPackage createEPackage(String name, String nsPrefix, String nsURI)

Since:
  2.0

### createEClass

public static EClass createEClass(EPackage ePackage, String name)

Since:
  4.27

### createEClass

public static EClass createEClass(EPackage ePackage, String name, boolean isAbstract, boolean isInterface)

Since:
  2.0

### createEAttribute

public static EAttribute createEAttribute(EClass eClass, String name, EClassifier type)

Since:
  2.0

### createEReference

public static EReference createEReference(EClass eClass, String name, EClassifier type)

Since:
  4.27

### createEReference

public static EReference createEReference(EClass eClass, String name, EClassifier type, boolean isRequired, boolean isMany)

Since:
  2.0

### createEEnum

public static EEnum createEEnum(EPackage ePackage, String name)

Since:
  4.27

### createEEnum

public static EEnum createEEnum(EPackage ePackage, String name, String... literals)

Since:
  4.27

### createEEnumLiteral

public static EEnumLiteral createEEnumLiteral(EEnum eEnum, String name)

Since:
  4.27

### createEEnumLiteral

public static EEnumLiteral createEEnumLiteral(EEnum eEnum, String name, int value)

Since:
  4.27

### getConcreteClasses

public static EClass[] getConcreteClasses(EPackage ePackage)

Since:
  4.2

### getConcreteClasses

public static EClass[] getConcreteClasses(EPackage ePackage, boolean includeSubPackages)

Since:
  4.10

### forAllConcreteClasses

public static void forAllConcreteClasses(EPackage ePackage, boolean includeSubPackages, Consumer<EClass> consumer)

Since:
  4.10

### getAnyConcreteEClass

public static EClass getAnyConcreteEClass(EPackage ePackage, boolean includeSubPackages)

Since:
  4.13

### getPersistentClasses

public static EClass[] getPersistentClasses(EPackage ePackage)

### getPersistentFeatures

@Deprecated public static List<EStructuralFeature> getPersistentFeatures(EList<EStructuralFeature> eFeatures)
Deprecated.
This method is expensive and will be removed in the future.

Since:
  3.0
See Also:
  - `isPersistent(EStructuralFeature)`

### isPersistent

public static boolean isPersistent(EStructuralFeature feature)
Returns `true` if CDO considers the given feature persistent, `false` otherwise.

Note that CDO persistent is not identical to `non-transient` because that can be overridden with `CDO_ANNOTATION_KEY_PERSISTENT`. Another reason for possible deviations is that CDO considers transient `references` persistent if they have a persistent `opposite`.

Note also that the checks for the aforementioned deviations from `EStructuralFeature.isTransient()` make this method somewhat expensive. Whenever possible `CDOClassInfo.isPersistent()` should be called instead.

Since:
  3.0

### isDynamicEPackage

public static boolean isDynamicEPackage(Object value)

### getParentURI

public static String getParentURI(EPackage ePackage)

### registerPackage

public static void registerPackage(EPackage ePackage, EPackage.Registry... packageRegistries)

### getEPackageBytes

public static byte[] getEPackageBytes(EPackage ePackage, boolean zipped, EPackage.Registry packageRegistry)

### createEPackage

public static EPackage createEPackage(String uri, byte[] bytes, ResourceSet resourceSet, boolean lookForResource)
Creates an `EPackage` from the given byte array by loading it into a resource in the given resource set.

If `lookForResource` is `true`, then an attempt is made to find an existing resource with the given URI before creating a new one.

The method automatically detects whether the byte array is zipped.

Note that the byte array is not copied, so it must not be modified while the resource is in use.

Since:
  4.27
See Also:
  - `createEPackage(String, byte[], boolean, ResourceSet, boolean)`

### createEPackage

public static EPackage createEPackage(String uri, byte[] bytes, boolean zipped, ResourceSet resourceSet, boolean lookForResource)
Creates an `EPackage` from the given byte array by loading it into a resource in the given resource set.

If `lookForResource` is `true`, then an attempt is made to find an existing resource with the given URI before creating a new one.

If the byte array is zipped, then set `zipped` to `true`.

Note that the byte array is not copied, so it must not be modified while the resource is in use.

Since:
  3.0
See Also:
  - `createEPackage(String, byte[], ResourceSet, boolean)`

### getXMI

public static String getXMI(EPackage ePackage)

Since:
  4.27

### getAdapter

public static <T> T getAdapter(Notifier notifier, Class<T> type)

Since:
  4.2

### addAdapter

public static void addAdapter(Notifier notifier, Adapter adapter)

### getAllPackages

public static EPackage[] getAllPackages(EPackage ePackage)

### getAllPackages

public static void getAllPackages(EPackage ePackage, Consumer<EPackage> consumer)

Since:
  4.27

### getQualifiedName

public static String getQualifiedName(EPackage ePackage, String separator)

### getQualifiedName

public static String getQualifiedName(EClassifier classifier, String separator)

### getQualifiedName

public static String getQualifiedName(EStructuralFeature feature, String separator)

Since:
  4.27

### getFullyQualifiedName

public static String getFullyQualifiedName(EObject modelElement)

Since:
  4.27

### getFullyQualifiedName

public static String getFullyQualifiedName(EObject modelElement, String separator)

Since:
  4.27

### newResourceSet

public static ResourceSet newResourceSet(Resource.Factory resourceFactory)

### newEcoreResourceSet

public static ResourceSet newEcoreResourceSet(EPackage.Registry packageRegistry)

### newEcoreResourceSet

public static ResourceSet newEcoreResourceSet()

### safeResolve

public static EObject safeResolve(EObject proxy, ResourceSet resourceSet)

Since:
  3.0

### safeResolveAll

public static void safeResolveAll(ResourceSet resourceSet)

Since:
  3.0

### createExtResourceSet

public static EMFUtil.ExtResourceSet createExtResourceSet(InternalCDOPackageRegistry packageRegistry, boolean delegating, boolean demandLoading)

Since:
  4.0
See Also:
  - `EMFUtil.ExtResourceSet`