de.cau.cs.kieler.core.model.util
Class ModelingUtil

java.lang.Object
  extended by de.cau.cs.kieler.core.model.util.ModelingUtil

public final class ModelingUtil
extends Object

Utility class with static methods to handle EMF models and GEF EditParts.

Rating proposed yellow
(2010-01-19) proposed by haf

Method Summary
static String fragmentUriToKielerUri(String fragmentUri, Resource resource)
          Method to get a (more readable) KIELER URI from a EMF Fragment URI and its resource.
static String fragmentUriToKielerUri(String fragmentUri, Resource resource, String nameProperty)
          Method to get a (more readable) KIELER URI from a EMF Fragment URI and its resource.
static Collection<EObject> getAllAncestorsByType(EClassifier eObjectClass, EObject rootObject)
          Get all objects that are direct or indirect parents of the given root EObject if they are of the given type.
static Collection<EObject> getAllByType(EClassifier eObjectClass, EObject rootObject)
          Get all objects that are direct or indirect children of the given root EObject if they are of the specified type.
static String getFragmentUri(EObject eo)
          Method to get the EMF Fragment URI for a given EObject.
static
<T> Collection<T>
iterator2Collection(Iterator<T> iter)
          Convert an Iterator to a Collection.
static String kielerUriToFragmentUri(String kielerUri, Resource resource)
          Translate a KIELER URI to an EMF Fragment URI.
static String kielerUriToFragmentUri(String kielerUri, Resource resource, String nameProperty)
          Translate a KIELER URI to an EMF Fragment URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAllByType

public static Collection<EObject> getAllByType(EClassifier eObjectClass,
                                               EObject rootObject)
Get all objects that are direct or indirect children of the given root EObject if they are of the specified type.

Parameters:
eObjectClass - The type of object
rootObject - The root object
Returns:
Collection of found EObject matching the type

getAllAncestorsByType

public static Collection<EObject> getAllAncestorsByType(EClassifier eObjectClass,
                                                        EObject rootObject)
Get all objects that are direct or indirect parents of the given root EObject if they are of the given type.

Parameters:
eObjectClass - The type of object
rootObject - The root object to start the search
Returns:
Collection of found EObject matching the type

iterator2Collection

public static <T> Collection<T> iterator2Collection(Iterator<T> iter)
Convert an Iterator to a Collection. Useful if some method returns only an iterator but some other method takes a Collection as input to iterate over that collection. However, it has linear runtime and many such transformations should be avoided.

Type Parameters:
T - the base type
Parameters:
iter - The input Iterator
Returns:
A Collection containing all elements of the Iterator.

kielerUriToFragmentUri

public static String kielerUriToFragmentUri(String kielerUri,
                                            Resource resource)
Translate a KIELER URI to an EMF Fragment URI.

Parameters:
kielerUri - The KIELER URI referring an EObject.
resource - The Resource holding the EObject.
Returns:
The Fragment URI for the EObject referred by the given KIELER URI. Null, if EObject doesn't exists.

kielerUriToFragmentUri

public static String kielerUriToFragmentUri(String kielerUri,
                                            Resource resource,
                                            String nameProperty)
Translate a KIELER URI to an EMF Fragment URI.

Parameters:
kielerUri - The KIELER URI referring an EObject.
resource - The Resource holding the EObject.
nameProperty - the name of the structural feature that is used to get a name for elements
Returns:
The Fragment URI for the EObject referred by the given KIELER URI. Null, if EObject doesn't exists.

fragmentUriToKielerUri

public static String fragmentUriToKielerUri(String fragmentUri,
                                            Resource resource)
Method to get a (more readable) KIELER URI from a EMF Fragment URI and its resource. Will return the Fragment URI, if EObjects are not NamedObjects. If using NamedObjects, it is required that names on the same level are unique.

Parameters:
fragmentUri - The Fragment URI from which the KIELER URI is generated (must not be null).
resource - The resource in which the referred EObject is held.
Returns:
A KIELER URI corresponding to the Fragment URI.
See Also:
NamedObject

fragmentUriToKielerUri

public static String fragmentUriToKielerUri(String fragmentUri,
                                            Resource resource,
                                            String nameProperty)
Method to get a (more readable) KIELER URI from a EMF Fragment URI and its resource. Will return the Fragment URI, if EObjects are not NamedObjects.

Parameters:
fragmentUri - The Fragment URI from which the KIELER URI is generated (must not be null).
resource - The resource in which the referred EObject is held.
nameProperty - the name of the structural feature that is used to get a name for elements
Returns:
A KIELER URI corresponding to the Fragment URI.

getFragmentUri

public static String getFragmentUri(EObject eo)
Method to get the EMF Fragment URI for a given EObject.

Parameters:
eo - The EObject for which the URI is requested (must not be null).
Returns:
The full Fragment URI.