## org.eclipse.uml2.common.util
Class UML2Util

    java.lang.Object
      org.eclipse.uml2.common.util.UML2Util

Direct Known Subclasses:
  UMLUtil

    public class UML2Util

extends java.lang.Object

Utilities for working with EMF-based objects and resources.

Since:
  1.2

Nested Class Summary
`static interface` `UML2Util.Converter` An interface for classes that can convert objects to another representation.
`static class` `UML2Util.EClassMatcher` A matcher that determines matches based on the class of candidate objects.
`static interface` `UML2Util.EObjectMatcher` An interface for classes that can determine matches based on some criteria.
`static class` `UML2Util.EStructuralFeatureMatcher` A matcher that determines matches based on the class of, and the value for a specific structural feature held by, candidate objects.
`static class` `UML2Util.QualifiedTextProvider` The abstract parent of classes that can provide a textual representation of objects, classes, and features.

Field Summary
`protected static org.eclipse.emf.ecore.resource.URIConverter` `DEFAULT_URI_CONVERTER` The default URI converter for resource bundle look-ups.
`static java.lang.String` `EMPTY_STRING` The empty string.
`protected static java.lang.String` `LINE_SEPARATOR` The platform line separator.
`static java.lang.String` `PROPERTIES_FILE_EXTENSION` The standard extension for properties files.
`protected static java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<java.util.Locale,java.util.ResourceBundle>>` `RESOURCE_BUNDLES` A cache of resource bundles.
`static java.lang.String` `URI_SCHEME_PLATFORM` The scheme for platform URIs.
`static java.lang.String` `URI_SEGMENT_PLUGIN` The first segment for platform plugin URIs.
`static java.lang.String` `URI_SEGMENT_RESOURCE` The first segment for platform resource URIs.

Constructor Summary
`protected` `UML2Util()`

Method Summary
`protected static boolean` `addConstraint(org.eclipse.emf.ecore.EModelElement eModelElement, java.lang.String constraint)`
`protected static void` `addDocumentation(org.eclipse.emf.ecore.EModelElement eModelElement, java.lang.String text)`
`static org.eclipse.emf.ecore.EAnnotation` `createEAnnotation(org.eclipse.emf.ecore.EModelElement eModelElement, java.lang.String source)` Creates an annotation with the specified source on the specified model element.
`protected static void` `destroy(org.eclipse.emf.ecore.EObject eObject)`
`protected static void` `destroyAll(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects)`
`static org.eclipse.emf.ecore.EObject` `findEObject(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects, UML2Util.EObjectMatcher filter)` Retrieves the first of the specified objects that matches the criteria used by the specified matcher.
`static org.eclipse.emf.ecore.EObject` `findEObject(java.util.Iterator<? extends org.eclipse.emf.ecore.EObject> iterator, UML2Util.EObjectMatcher filter)` Retrieves the first of the specified objects that matches the criteria used by the specified matcher.

`static

`<T> org.eclipse.emf.common.util.TreeIterator<T>`

`

`getAllContents(org.eclipse.emf.ecore.EObject eObject, boolean includeRoot, boolean defensiveCopy)`
Retrieves an iterator over the content tree of the specified object which optionally includes the root object and/or copies contents while iterating.

`protected static org.eclipse.emf.ecore.EClassifier` `getCommonEType(org.eclipse.emf.ecore.EClassifier eType, org.eclipse.emf.ecore.EClassifier otherEType)`
`static org.eclipse.emf.ecore.EAnnotation` `getEAnnotation(org.eclipse.emf.ecore.EModelElement eModelElement, java.lang.String source, boolean createOnDemand)` Retrieves the annotation with the specified source on the specified model element, optionally creating one on demand if no such annotation exists.
`protected static int` `getGreaterUpperBound(int upperBound, int otherUpperBound)`
`static int` `getInstanceCount(java.util.Iterator<?> iterator, org.eclipse.emf.ecore.EClassifier eClassifier)` Counts the number of instances of the specified classifier.
`static java.util.Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting>` `getInverseReferences(org.eclipse.emf.ecore.EObject eObject)` Retrieves a collection of inverse references to the specified object.
`protected static int` `getLesserLowerBound(int lowerBound, int otherLowerBound)`
`protected static java.lang.String` `getMessageSubstitution(java.util.Map<java.lang.Object,java.lang.Object> context, java.lang.Object object)`
`protected static java.lang.Object[]` `getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context, java.lang.Object object0)`
`protected static java.lang.Object[]` `getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context, java.lang.Object object0, java.lang.Object object1)`
`protected static java.lang.Object[]` `getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context, java.lang.Object object0, java.lang.Object object1, java.lang.Object object2)`
`static java.util.Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting>` `getNonNavigableInverseReferences(org.eclipse.emf.ecore.EObject eObject)` Retrieves a collection of non-navigable inverse references to the specified object.
`static java.lang.String` `getQualifiedText(org.eclipse.emf.ecore.EObject eObject, UML2Util.QualifiedTextProvider qualifiedTextProvider)` Retrieves a qualified textual representation of the specified object using the specified qualified text provider.
`protected static java.lang.StringBuffer` `getQualifiedText(org.eclipse.emf.ecore.EObject eObject, UML2Util.QualifiedTextProvider qualifiedTextProvider, java.lang.StringBuffer qualifiedText)`
`protected static java.lang.StringBuffer` `getQualifiedTextSegment(org.eclipse.emf.ecore.EObject eObject, UML2Util.QualifiedTextProvider qualifiedTextProvider, java.lang.StringBuffer qualifiedText)`
`protected static java.util.ResourceBundle` `getResourceBundle(org.eclipse.emf.ecore.EObject eObject, boolean localize)` Retrieves the (cached) resource bundle for the specified object, localized in the default locale if indicated.
`protected static java.util.ResourceBundle` `getResourceBundle(org.eclipse.emf.ecore.EObject eObject, java.util.Locale locale)` Retrieves the (cached) resource bundle for the specified object in the specified locale (if specified).
`protected static java.util.List<org.eclipse.emf.common.util.URI>` `getResourceBundleURIs(org.eclipse.emf.common.util.URI uri, java.util.Locale locale)` Retrieves the candidate resource bundle URIs for the specified URI in the specified locale (if specified).
`protected static java.util.List<org.eclipse.emf.common.util.URI>` `getResourceBundleURIs(org.eclipse.emf.common.util.URI baseURI, java.util.Locale locale, java.lang.String baseSegment)` Retrieves the candidate resource bundle URIs based on the specified base URI and base segment in the specified locale.
`protected static java.util.Collection<org.eclipse.emf.ecore.EObject>` `getRootContainers(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects)`
`protected static java.lang.String` `getString(org.eclipse.emf.ecore.EObject eObject, java.lang.String key, java.lang.String defaultString, boolean localize)` Retrieves a string for the specified object, localized if indicated.
`static java.lang.String` `getValidJavaIdentifier(java.lang.String name)` Obtains a valid Java identifier based on the specified name.
`protected static java.lang.StringBuffer` `getValidJavaIdentifier(java.lang.String name, java.lang.StringBuffer validJavaIdentifier)` Appends a valid Java identifier based on the specified name to the specified buffer.
`protected static java.lang.String` `getValidNCName(java.lang.String name)`
`protected static java.lang.StringBuffer` `getValidNCName(java.lang.String name, java.lang.StringBuffer validNCName)`
`static java.lang.String` `getXMIIdentifier(org.eclipse.emf.ecore.InternalEObject internalEObject)` Obtains a valid XMI identifier for the specified object based on the URI fragment segments of its containment hierarchy.
`protected static java.lang.StringBuffer` `getXMIIdentifier(org.eclipse.emf.ecore.InternalEObject internalEObject, java.lang.StringBuffer xmiIdentifier)`
`protected static boolean` `intersect(java.util.Collection<?> collection, java.util.Collection<?> otherCollection)`
`static boolean` `isEmpty(java.lang.String string)` Determines whether the specified string is empty, i.e. is `null` or has a length of zero.
`protected static boolean` `isNCNamePart(char c)`
`protected static boolean` `isNCNameStart(char c)`

`static

`<T> T`

`

`load(org.eclipse.emf.ecore.resource.ResourceSet resourceSet, org.eclipse.emf.common.util.URI uri, org.eclipse.emf.ecore.EClass eClass)`
Loads a resource with the specified URI into the specified resource set and retrieves the first instance of the specified class from its contents.

`static

`<T> T`

`

`loadClassFromSystemProperty(java.lang.String systemProperty)`
Load a class from the specified system property.

`protected static void` `removeReferences(org.eclipse.emf.ecore.EObject eObject, org.eclipse.emf.ecore.EObject ancestorEObject)`
`static boolean` `safeEquals(java.lang.Object object, java.lang.Object otherObject)` Safely determines whether `object` equals `otherObject`, i.e. without throwing an exception if `object` is `null`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_URI_CONVERTER

    protected static final org.eclipse.emf.ecore.resource.URIConverter DEFAULT_URI_CONVERTER

  The default URI converter for resource bundle look-ups.

### RESOURCE_BUNDLES

    protected static final java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<java.util.Locale,java.util.ResourceBundle>> RESOURCE_BUNDLES

  A cache of resource bundles.

### EMPTY_STRING

    public static final java.lang.String EMPTY_STRING

  The empty string.

  See Also:
    Constant Field Values

### LINE_SEPARATOR

    protected static final java.lang.String LINE_SEPARATOR

  The platform line separator.

### URI_SCHEME_PLATFORM

    public static final java.lang.String URI_SCHEME_PLATFORM

  The scheme for platform URIs.

  See Also:
    Constant Field Values

### URI_SEGMENT_PLUGIN

    public static final java.lang.String URI_SEGMENT_PLUGIN

  The first segment for platform plugin URIs.

  See Also:
    Constant Field Values

### URI_SEGMENT_RESOURCE

    public static final java.lang.String URI_SEGMENT_RESOURCE

  The first segment for platform resource URIs.

  See Also:
    Constant Field Values

### PROPERTIES_FILE_EXTENSION

    public static final java.lang.String PROPERTIES_FILE_EXTENSION

  The standard extension for properties files.

  See Also:
    Constant Field Values

Constructor Detail

### UML2Util

    protected UML2Util()

Method Detail

### getResourceBundleURIs

    protected static java.util.List<org.eclipse.emf.common.util.URI> getResourceBundleURIs(org.eclipse.emf.common.util.URI baseURI,
                                                                                           java.util.Locale locale,
                                                                                           java.lang.String baseSegment)

  Retrieves the candidate resource bundle URIs based on the specified base URI and base segment in the specified locale.

  Parameters:
    `baseURI` - The base URI (i.e. without the last segment) for the candidate resource bundle URIs.
    `locale` - The locale within which to base the candidate resource bundle URIs.
    `baseSegment` - The base segment (i.e. the last segment without the extension) for the candidate resource bundle URIs.
  Returns:
    The candidate resource bundle URIs with the base URI and base segment in the locale.

### getResourceBundleURIs

    protected static java.util.List<org.eclipse.emf.common.util.URI> getResourceBundleURIs(org.eclipse.emf.common.util.URI uri,
                                                                                           java.util.Locale locale)

  Retrieves the candidate resource bundle URIs for the specified URI in the specified locale (if specified).

  Parameters:
    `uri` - The URI upon which to base the candidate resource bundle URIs.
    `locale` - The locale within which to base the candidate resource bundle URIs, or `null`.
  Returns:
    The candidate resource bundle URIs for the URI in the locale (if specified).

### getResourceBundle

    protected static java.util.ResourceBundle getResourceBundle(org.eclipse.emf.ecore.EObject eObject,
                                                                java.util.Locale locale)

  Retrieves the (cached) resource bundle for the specified object in the specified locale (if specified).

  Parameters:
    `eObject` - The object for which to retrieve the resource bundle.
    `locale` - The locale in which to retrieve the resource bundle, or `null`.
  Returns:
    The resource bundle for the object in the locale (if specified).

### getResourceBundle

    protected static java.util.ResourceBundle getResourceBundle(org.eclipse.emf.ecore.EObject eObject,
                                                                boolean localize)

  Retrieves the (cached) resource bundle for the specified object, localized in the default locale if indicated.

  Parameters:
    `eObject` - The object for which to retrieve the resource bundle.
    `localize` - Whether to retrieve the resource bundle based on (the default) locale.
  Returns:
    The resource bundle for the object (in the default locale).

### getString

    protected static java.lang.String getString(org.eclipse.emf.ecore.EObject eObject,
                                                java.lang.String key,
                                                java.lang.String defaultString,
                                                boolean localize)

  Retrieves a string for the specified object, localized if indicated.

  Parameters:
    `eObject` - The object for which to retrieve a (localized) string.
    `key` - The key in the resource bundle.
    `defaultString` - The string to return if no string for the given key can be found.
    `localize` - Whether the string should be localized.
  Returns:
    The (localized) string.

### getQualifiedText

    public static java.lang.String getQualifiedText(org.eclipse.emf.ecore.EObject eObject,
                                                    UML2Util.QualifiedTextProvider qualifiedTextProvider)

  Retrieves a qualified textual representation of the specified object using the specified qualified text provider.

  Parameters:
    `eObject` - The object for which to retrieve qualified text.
    `qualifiedTextProvider` - The provider to be used.
  Returns:
    A qualified textual representation of the object.

### getQualifiedText

    protected static java.lang.StringBuffer getQualifiedText(org.eclipse.emf.ecore.EObject eObject,
                                                             UML2Util.QualifiedTextProvider qualifiedTextProvider,
                                                             java.lang.StringBuffer qualifiedText)

### getQualifiedTextSegment

    protected static java.lang.StringBuffer getQualifiedTextSegment(org.eclipse.emf.ecore.EObject eObject,
                                                                    UML2Util.QualifiedTextProvider qualifiedTextProvider,
                                                                    java.lang.StringBuffer qualifiedText)

### getMessageSubstitution

    protected static java.lang.String getMessageSubstitution(java.util.Map<java.lang.Object,java.lang.Object> context,
                                                             java.lang.Object object)

### getMessageSubstitutions

    protected static java.lang.Object[] getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context,
                                                                java.lang.Object object0)

### getMessageSubstitutions

    protected static java.lang.Object[] getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context,
                                                                java.lang.Object object0,
                                                                java.lang.Object object1)

### getMessageSubstitutions

    protected static java.lang.Object[] getMessageSubstitutions(java.util.Map<java.lang.Object,java.lang.Object> context,
                                                                java.lang.Object object0,
                                                                java.lang.Object object1,
                                                                java.lang.Object object2)

### safeEquals

    public static boolean safeEquals(java.lang.Object object,
                                     java.lang.Object otherObject)

  Safely determines whether `object` equals `otherObject`, i.e. without throwing an exception if `object` is `null`.

  Parameters:
    `object` - The first object to compare.
    `otherObject` - The second object to compare.
  Returns:
    `true` if `object` equals `otherObject`; `false` otherwise.

### isEmpty

    public static boolean isEmpty(java.lang.String string)

  Determines whether the specified string is empty, i.e. is `null` or has a length of zero.

  Parameters:
    `string` - The string in question.
  Returns:
    `true` if the string is empty; `false` otherwise.

### findEObject

    public static org.eclipse.emf.ecore.EObject findEObject(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects,
                                                            UML2Util.EObjectMatcher filter)

  Retrieves the first of the specified objects that matches the criteria used by the specified matcher.

  Parameters:
    `eObjects` - The collection of candidate objects.
    `filter` - The matcher to be used.
  Returns:
    The first object that matches the criteria.

### findEObject

    public static org.eclipse.emf.ecore.EObject findEObject(java.util.Iterator<? extends org.eclipse.emf.ecore.EObject> iterator,
                                                            UML2Util.EObjectMatcher filter)

  Retrieves the first of the specified objects that matches the criteria used by the specified matcher.

  Parameters:
    `iterator` - The iterator for the candidate objects.
    `filter` - The matcher to be used.
  Returns:
    The first object that matches the criteria.

### getCommonEType

    protected static org.eclipse.emf.ecore.EClassifier getCommonEType(org.eclipse.emf.ecore.EClassifier eType,
                                                                      org.eclipse.emf.ecore.EClassifier otherEType)

### getLesserLowerBound

    protected static int getLesserLowerBound(int lowerBound,
                                             int otherLowerBound)

### getGreaterUpperBound

    protected static int getGreaterUpperBound(int upperBound,
                                              int otherUpperBound)

### getValidJavaIdentifier

    public static java.lang.String getValidJavaIdentifier(java.lang.String name)

  Obtains a valid Java identifier based on the specified name.

  Parameters:
    `name` - The name from which to obtain a valid identifier.
  Returns:
    A valid (Java) identifier.

### getValidJavaIdentifier

    protected static java.lang.StringBuffer getValidJavaIdentifier(java.lang.String name,
                                                                   java.lang.StringBuffer validJavaIdentifier)

  Appends a valid Java identifier based on the specified name to the specified buffer.

  Parameters:
    `name` - The name from which to obtain the valid identifier.
    `validJavaIdentifier` - The buffer to which to append the valid identifier.
  Returns:
    The buffer.

### isNCNameStart

    protected static boolean isNCNameStart(char c)

### isNCNamePart

    protected static boolean isNCNamePart(char c)

### getValidNCName

    protected static java.lang.String getValidNCName(java.lang.String name)

### getValidNCName

    protected static java.lang.StringBuffer getValidNCName(java.lang.String name,
                                                           java.lang.StringBuffer validNCName)

### getXMIIdentifier

    public static java.lang.String getXMIIdentifier(org.eclipse.emf.ecore.InternalEObject internalEObject)

  Obtains a valid XMI identifier for the specified object based on the URI fragment segments of its containment hierarchy.

  Parameters:
    `internalEObject` - The object for which to obtain an XMI identifier.
  Returns:
    An XMI identifier for the object.

### getXMIIdentifier

    protected static java.lang.StringBuffer getXMIIdentifier(org.eclipse.emf.ecore.InternalEObject internalEObject,
                                                             java.lang.StringBuffer xmiIdentifier)

### getInstanceCount

    public static int getInstanceCount(java.util.Iterator<?> iterator,
                                       org.eclipse.emf.ecore.EClassifier eClassifier)

  Counts the number of instances of the specified classifier.

  Parameters:
    `iterator` - The iterator for the candidate objects.
    `eClassifier` - The classifier in question.
  Returns:
    The number of the instances of the classifier.

### addConstraint

    protected static boolean addConstraint(org.eclipse.emf.ecore.EModelElement eModelElement,
                                           java.lang.String constraint)

### addDocumentation

    protected static void addDocumentation(org.eclipse.emf.ecore.EModelElement eModelElement,
                                           java.lang.String text)

### getRootContainers

    protected static java.util.Collection<org.eclipse.emf.ecore.EObject> getRootContainers(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects)

### getAllContents

    public static <T> org.eclipse.emf.common.util.TreeIterator<T> getAllContents(org.eclipse.emf.ecore.EObject eObject,
                                                                                 boolean includeRoot,
                                                                                 boolean defensiveCopy)

  Retrieves an iterator over the content tree of the specified object which optionally includes the root object and/or copies contents while iterating.

  Parameters:
    `eObject` - The root of the content hierarchy.
    `includeRoot` - Whether to include the root object.
    `defensiveCopy` - Whether to copy contents while iterating.
  Returns:
    A content tree iterator.

### createEAnnotation

    public static org.eclipse.emf.ecore.EAnnotation createEAnnotation(org.eclipse.emf.ecore.EModelElement eModelElement,
                                                                      java.lang.String source)

  Creates an annotation with the specified source on the specified model element.

  Parameters:
    `eModelElement` - The model element on which to create the annotation.
    `source` - The source for the new annotation.
  Returns:
    A new annotation.

### getEAnnotation

    public static org.eclipse.emf.ecore.EAnnotation getEAnnotation(org.eclipse.emf.ecore.EModelElement eModelElement,
                                                                   java.lang.String source,
                                                                   boolean createOnDemand)

  Retrieves the annotation with the specified source on the specified model element, optionally creating one on demand if no such annotation exists.

  Parameters:
    `eModelElement` - The model element from/on which to retrieve/create the annotation.
    `source` - The source for the (new) annotation.
    `createOnDemand` - Whether to create one if no such annotation exists.
  Returns:
    The (new) annotation.

### getNonNavigableInverseReferences

    public static java.util.Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting> getNonNavigableInverseReferences(org.eclipse.emf.ecore.EObject eObject)

  Retrieves a collection of non-navigable inverse references to the specified object.

  Parameters:
    `eObject` - The referenced object.
  Returns:
    The non-navigable inverse references to the object.

### getInverseReferences

    public static java.util.Collection<org.eclipse.emf.ecore.EStructuralFeature.Setting> getInverseReferences(org.eclipse.emf.ecore.EObject eObject)

  Retrieves a collection of inverse references to the specified object.

  Parameters:
    `eObject` - The referenced object.
  Returns:
    The inverse references to the object.

### removeReferences

    protected static void removeReferences(org.eclipse.emf.ecore.EObject eObject,
                                           org.eclipse.emf.ecore.EObject ancestorEObject)

### destroy

    protected static void destroy(org.eclipse.emf.ecore.EObject eObject)

### destroyAll

    protected static void destroyAll(java.util.Collection<? extends org.eclipse.emf.ecore.EObject> eObjects)

### load

    public static <T> T load(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
                             org.eclipse.emf.common.util.URI uri,
                             org.eclipse.emf.ecore.EClass eClass)

  Loads a resource with the specified URI into the specified resource set and retrieves the first instance of the specified class from its contents.

  Parameters:
    `resourceSet` - The resource set into which to load the resource.
    `uri` - The URI of the resource to be loaded.
    `eClass` - The class of the object to be retrieved.
  Returns:
    The first instance of the class in the resource.

### intersect

    protected static boolean intersect(java.util.Collection<?> collection,
                                       java.util.Collection<?> otherCollection)

### loadClassFromSystemProperty

    public static <T> T loadClassFromSystemProperty(java.lang.String systemProperty)

  Load a class from the specified system property. Any exceptions resulting from class loading failures will be logged. If the system property is separated with a ':' then the first part indicates the pluginId and the trailing part indicates the class name.

  Parameters:
    `systemProperty` - The system property containing the location of the class to be loaded.
  Returns:
    The loaded class.
  Since:
    1.5

Copyright 2003, 2007 IBM Corporation and others. All Rights Reserved.