UML Modeler

com.ibm.xtools.modeler.ui
Class UMLModeler

java.lang.Object
  extended by com.ibm.xtools.modeler.ui.UMLModeler

public final class UMLModeler
extends Object

A utility class that exposes model and profile lifecycle operations and provides access to the modeling platform.

API clients should not instantiate this class.


Method Summary
static EObject absorbFragment(Resource resource)
          Absorbs the specified fragment.
static EObject absorbFragmentSilently(Resource resource, boolean refactorReferences)
          Absorbs the specified fragment.
static List<EModelElement> batchAbsorbFragments(List<? extends Resource> resources, boolean refactorReferences)
          Absorbs the specified fragments.
static List<Resource> batchCreateFragments(List<URI> fragmentUris, List<? extends EModelElement> fragmentRoots, boolean refactorReferences)
          Creates fragment resources.
static void closeModel(Model model)
          Deprecated. Since 7.5, use the UMLModeler.closeModelResource(Element) method, instead
static void closeModelFragment(EObject element)
          Closes the model fragment resource specified by the given root element.
static void closeModelResource(Element element)
          Closes the model specified by the given root element.
static void closeProfile(Profile profile)
          Closes the profile specified by profile
static Resource createFragment(URI fragmentUri, EModelElement fragmentRoot)
          Creates the fragment resource.
static Resource createFragmentSilently(URI fragmentUri, EModelElement fragmentRoot, boolean refactorReferences)
          Creates the fragment resource.
static Model createModel(String file)
          Deprecated. Since 7.5, use the UMLModeler.createModelResource(Class, String) method, instead, with the Model.class root metaclass argument
static Model createModel(URI uri)
          Deprecated. Since 7.5, use the UMLModeler.createModelResource(Class, URI) method, instead, with the Model.class root metaclass argument
static
<E extends Element>
E
createModelResource(Class<E> rootMetaclass, String file)
          Creates a UML model resource (as distinguished from a profile resource) given a file path and a root element metaclass.
static
<E extends Element>
E
createModelResource(Class<E> rootMetaclass, URI uri)
          Creates a UML model resource (as distinguished from a profile resource) given a file path and a root element metaclass.
static Profile createProfile(String file)
          Creates a UML profile given a file path
static Profile createProfile(URI uri)
          Creates a UML profile given a URI
static TransactionalEditingDomain getEditingDomain()
          Returns the UMLModeler's EditingDomain.
static ILogicalResource getLogicalResource(EObject eObj)
          Returns the logical UML resource of the specified EObject.
static ILogicalResource getLogicalResource(Resource resource)
          Returns the logical UML resource of the specified resource.
static IOclQueryHelper getOclQueryHelper()
          Returns a helper to perform OCL queries
static Collection<Model> getOpenedModels()
          Deprecated. Since 7.5, use the UMLModeler.getOpenModelRoots() method, instead.
static Collection<Element> getOpenModelRoots()
          Returns the root elements of all open UML model resources.
static IQueryHelper getQueryHelper()
          Returns a helper to perform queries
static IUMLDiagramHelper getUMLDiagramHelper()
          Returns a user helper to work with classes implementing View
static IUMLHelper getUMLHelper()
          Returns a helper to work with classes implementing Element
static IUMLUIHelper getUMLUIHelper()
          Returns a user interface helper to work with classes implementing Element
static Model openModel(String file)
          Deprecated. Since 7.5, use the UMLModeler.openModelResource(String) method, instead.
static Model openModel(URI uri)
          Deprecated. Since 7.5, use the UMLModeler.openModelResource(URI) method, instead.
static Element openModelResource(String file)
          Opens the UML model resource whose filename is described by file.
static Element openModelResource(URI uri)
          Opens the UML model whose filename is described by uri.
static Profile openProfile(String file)
          Opens the UML profile whose filename is described by file.
static Profile openProfile(URI uri)
          Opens the UML profile whose URI is described by uri.
static void saveModel(Model model)
          Deprecated. Since 7.5, use the UMLModeler.saveModelResource(Element) method, instead.
static void saveModelAs(Model model, String file)
          Deprecated. Since 7.5, use the UMLModeler.saveModelResourceAs(Element, String) method, instead.
static void saveModelAs(Model model, URI uri)
          Deprecated. Since 7.5, use the UMLModeler.saveModelResourceAs(Element, URI) method, instead.
static void saveModelResource(Element model)
          Saves the UML model resource specified by model.
static void saveModelResourceAs(Element model, String file)
          Saves the model specified by a root model element to the location specified by file.
static void saveModelResourceAs(Element model, URI uri)
          Saves the model specified by a root model element to the location specified by uri.
static void saveProfile(Profile profile)
          Saves the UML profile specified by profile.
static void saveProfileAs(Profile profile, String file)
          Saves the profile specified by profile to the location specified by file.
static void saveProfileAs(Profile profile, URI uri)
          Saves the profile specified by profile to the location specified by uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getUMLHelper

public static IUMLHelper getUMLHelper()
Returns a helper to work with classes implementing Element

Returns:
The UMLModeler IUMLHelper

getUMLUIHelper

public static IUMLUIHelper getUMLUIHelper()
Returns a user interface helper to work with classes implementing Element

Returns:
The UMLModeler IUMLUIHelper

getQueryHelper

public static IQueryHelper getQueryHelper()
Returns a helper to perform queries

Returns:
The UMLModeler IQueryHelper

getOclQueryHelper

public static IOclQueryHelper getOclQueryHelper()
Returns a helper to perform OCL queries

Returns:
The UMLModeler IOclQueryHelper

getUMLDiagramHelper

public static IUMLDiagramHelper getUMLDiagramHelper()
Returns a user helper to work with classes implementing View

Returns:
The UMLModeler IUMLDiagramHelper

getEditingDomain

public static TransactionalEditingDomain getEditingDomain()
Returns the UMLModeler's EditingDomain. The latter is used to perform operations on the models managed by the tool. It also provides batched notification support.

Returns:
The UMLModeler EditingDomain

getOpenedModels

public static Collection<Model> getOpenedModels()
Deprecated. Since 7.5, use the UMLModeler.getOpenModelRoots() method, instead.

Returns all open UML models.

Returns:
The collection of all currently open UML Models

getOpenModelRoots

public static Collection<Element> getOpenModelRoots()
Returns the root elements of all open UML model resources. This excludes profiles.

Returns:
The roots of all currently open UML model resources. Usually, these will be Packages of some kind, but this is not guaranteed
Since:
7.5

createModel

@Deprecated
public static Model createModel(String file)
Deprecated. Since 7.5, use the UMLModeler.createModelResource(Class, String) method, instead, with the Model.class root metaclass argument

Creates a UML model given a file path

Parameters:
file - The model file to create
Returns:
The created UML model
Throws:
IllegalArgumentException - file is an empty string
NullPointerException - file is null

createModel

@Deprecated
public static Model createModel(URI uri)
Deprecated. Since 7.5, use the UMLModeler.createModelResource(Class, URI) method, instead, with the Model.class root metaclass argument

Creates a UML model given a URI

Parameters:
uri - The URI of the model to create
Returns:
The created UML model
Throws:
IllegalArgumentException - uri is an empty URI
NullPointerException - uri is null

createModelResource

public static <E extends Element> E createModelResource(Class<E> rootMetaclass,
                                                        String file)
Creates a UML model resource (as distinguished from a profile resource) given a file path and a root element metaclass.

Type Parameters:
E - the metaclass to instantiate as the root element
Parameters:
rootMetaclass - the metaclass to instantiate as the root element. Must be either Model or Package
file - The model resource to create
Returns:
The root element of the new UML resource
Throws:
IllegalArgumentException - if rootMetaclass is not one of the permitted values or file is an empty string
NullPointerException - file is null
Since:
7.5

createModelResource

public static <E extends Element> E createModelResource(Class<E> rootMetaclass,
                                                        URI uri)
Creates a UML model resource (as distinguished from a profile resource) given a file path and a root element metaclass.

Type Parameters:
E - the metaclass to instantiate as the root element
Parameters:
rootMetaclass - the metaclass to instantiate as the root element. Must be either Model or Package
uri - The URI of the model resource to create
Returns:
The root element of the new UML resource
Throws:
IllegalArgumentException - if rootMetaclass is not one of the permitted values or uri is an empty URI
NullPointerException - uri is null
Since:
7.5

openModel

@Deprecated
public static Model openModel(String file)
                       throws IOException
Deprecated. Since 7.5, use the UMLModeler.openModelResource(String) method, instead.

Opens the UML model whose filename is described by file.

Supported extensions are:

Parameters:
file - The model file to open
Returns:
The opened UML model
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Model

openModelResource

public static Element openModelResource(String file)
                                 throws IOException
Opens the UML model resource whose filename is described by file.

Supported extensions are:

Parameters:
file - The model file to open
Returns:
The opened UML model's root element. Usually, this is some kind of Package, but that is not guaranteed
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Model
Since:
7.5

openModel

@Deprecated
public static Model openModel(URI uri)
                       throws IOException
Deprecated. Since 7.5, use the UMLModeler.openModelResource(URI) method, instead.

Opens the UML model whose filename is described by uri.

Supported extensions are:

Parameters:
uri - The URI of the model to open
Returns:
The opened UML model
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Model

openModelResource

public static Element openModelResource(URI uri)
                                 throws IOException
Opens the UML model whose filename is described by uri.

Supported extensions are:

Parameters:
uri - The URI of the model to open
Returns:
The opened UML model's root element. Usually, this is some kind of Package, but that is not guaranteed
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Model
Since:
7.5

saveModel

@Deprecated
public static void saveModel(Model model)
                      throws IOException
Deprecated. Since 7.5, use the UMLModeler.saveModelResource(Element) method, instead.

Saves the UML model specified by model.

Parameters:
model - The UML model to save
Throws:
IOException - The location specified by the root path of model cannot be used to save the model
IllegalArgumentException - model has no associated resource

saveModelResource

public static void saveModelResource(Element model)
                              throws IOException
Saves the UML model resource specified by model. The specified resource and any currently open, modified fragment resource are saved.

Parameters:
model - The root element of the UML model resource to save
Throws:
IOException - The location specified by the root path of model cannot be used to save the model
IllegalArgumentException - model has no associated resource
Since:
7.5

saveModelAs

@Deprecated
public static void saveModelAs(Model model,
                                          String file)
                        throws IOException
Deprecated. Since 7.5, use the UMLModeler.saveModelResourceAs(Element, String) method, instead.

Saves the model specified by model to the location specified by file. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "model.emx" is saved as "model.uml", it is still really using the "emx" format, not the "uml" format.

Parameters:
model - The UML model to save
file - The location to save the UML model
Throws:
IOException - The location specified by file cannot be used to save the model
IllegalArgumentException - model has no associated resource or model is null

saveModelResourceAs

public static void saveModelResourceAs(Element model,
                                       String file)
                                throws IOException
Saves the model specified by a root model element to the location specified by file. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "model.emx" is saved as "model.uml", it is still really using the "emx" format, not the "uml" format.

Parameters:
model - The root of the UML model resource to save
file - The location to save the UML model resource
Throws:
IOException - The location specified by file cannot be used to save the model
IllegalArgumentException - model has no associated resource or model is null
Since:
7.5

saveModelAs

@Deprecated
public static void saveModelAs(Model model,
                                          URI uri)
                        throws IOException
Deprecated. Since 7.5, use the UMLModeler.saveModelResourceAs(Element, URI) method, instead.

Saves the model specified by model to the location specified by uri. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "model.emx" is saved as "model.uml", it is still really using the "emx" format, not the "uml" format.

Parameters:
model - The UML2 model to save
uri - The URI location to save the UML2 model
Throws:
IOException - The location specified by uri cannot be used to save the model
IllegalArgumentException - model has no associated resource or model is null

saveModelResourceAs

public static void saveModelResourceAs(Element model,
                                       URI uri)
                                throws IOException
Saves the model specified by a root model element to the location specified by uri. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "model.emx" is saved as "model.uml", it is still really using the "emx" format, not the "uml" format.

Parameters:
model - The root of the UML model resource to save
uri - The URI location to save the UML model resource
Throws:
IOException - The location specified by uri cannot be used to save the model
IllegalArgumentException - model has no associated resource or model is null
Since:
7.5

closeModel

public static void closeModel(Model model)
Deprecated. Since 7.5, use the UMLModeler.closeModelResource(Element) method, instead

Closes the model specified by model

Parameters:
model - The UML2 model to close
Throws:
IllegalArgumentException - model has no associated resource

closeModelResource

public static void closeModelResource(Element element)
Closes the model specified by the given root element.

Parameters:
element - The root element of the UML model to close
Throws:
IllegalArgumentException - if element has no associated resource or if it is not a root element
Since:
7.5

closeModelFragment

public static void closeModelFragment(EObject element)
Closes the model fragment resource specified by the given root element.

Parameters:
element - The root element of the UML model fragment to close
Throws:
IllegalArgumentException - if element has no associated resource or if it is not the root element of a fragment resource
Since:
7.5

createProfile

public static Profile createProfile(String file)
Creates a UML profile given a file path

Parameters:
file - The profile file to create
Returns:
The created UML Profile
Throws:
IllegalArgumentException - file is an empty string
NullPointerException - file is null

createProfile

public static Profile createProfile(URI uri)
Creates a UML profile given a URI

Parameters:
uri - The URI of the profile to create
Returns:
The created UML Profile
Throws:
IllegalArgumentException - file is an empty string
NullPointerException - file is null

openProfile

public static Profile openProfile(String file)
                           throws IOException
Opens the UML profile whose filename is described by file.

Supported extensions are:

Parameters:
file - The profile file to open
Returns:
The opened UML profile
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Profile

openProfile

public static Profile openProfile(URI uri)
                           throws IOException
Opens the UML profile whose URI is described by uri.

Supported extensions are:

Parameters:
uri - The URI of the profile to open
Returns:
The opened UML profile
Throws:
IllegalArgumentException - file is an empty string
IOException - The file specified by file could not be found or the file is corrupted or could not be opened
NullPointerException - file is null
ClassCastException - file does not point to a Profile

saveProfile

public static void saveProfile(Profile profile)
                        throws IOException
Saves the UML profile specified by profile.

Parameters:
profile - The UML profile to save
Throws:
IOException - The location specified by the root path of profile cannot be used to save the profile
IllegalArgumentException - profile has no associated resource

saveProfileAs

public static void saveProfileAs(Profile profile,
                                 String file)
                          throws IOException
Saves the profile specified by profile to the location specified by file. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "profile.emx" is saved as "profile.uml", it is still really using the "epx" format, not the "uml" format.

Parameters:
profile - The UML2 profile to save
file - The location to save the UML2 profile
Throws:
IOException - The location specified by file cannot be used to save the profile
IllegalArgumentException - profile has no associated resource or profile is null

saveProfileAs

public static void saveProfileAs(Profile profile,
                                 URI uri)
                          throws IOException
Saves the profile specified by profile to the location specified by uri. This method cannot be used to convert from one format to another: the file will be saved in the same format in which it was opened, even if the file extension is changed through this method. For example, if the file "profile.emx" is saved as "profile.uml", it is still really using the "epx" format, not the "uml" format.

Parameters:
profile - The UML2 profile to save
uri - The location to save the UML2 profile
Throws:
IOException - The location specified by file cannot be used to save the profile
IllegalArgumentException - profile has no associated resource or profile is null

closeProfile

public static void closeProfile(Profile profile)
Closes the profile specified by profile

Parameters:
profile - The UML2 profile to close
Throws:
IllegalArgumentException - profile has no associated resource

getLogicalResource

public static ILogicalResource getLogicalResource(EObject eObj)
Returns the logical UML resource of the specified EObject.

Parameters:
eObj - The EObject whose logical resource is returned
Returns:
Logical UML resource

getLogicalResource

public static ILogicalResource getLogicalResource(Resource resource)
Returns the logical UML resource of the specified resource.

Parameters:
resource - The resource whose logical resource is returned. If the resource is not loaded the fragment list is not built and the returned logical resource can be used only as the wrapper. Subsequent invocations for the same resource will return in that case different instance of the logical resource.
Returns:
Logical UML resource

createFragment

public static Resource createFragment(URI fragmentUri,
                                      EModelElement fragmentRoot)
Creates the fragment resource. The specified fragment root is moved from its current resource into the root of the newly created fragment. Also, the corresponding stereotype applications are moved to the new resource. All affected resources are saved. The user is prompted to refactor references.

Parameters:
fragmentUri - URI for the new fragment
fragmentRoot - The element to be moved into the fragment
Returns:
Fragment resource

createFragmentSilently

public static Resource createFragmentSilently(URI fragmentUri,
                                              EModelElement fragmentRoot,
                                              boolean refactorReferences)
Creates the fragment resource. The specified fragment root is moved from its current resource into the root of the newly created fragment. Also, the corresponding stereotype applications are moved to the new resource. All affected resources are saved. The operation is performed silently, without user interaction.

Parameters:
fragmentUri - URI for the new fragment
fragmentRoot - The element to be moved into the fragment
refactorReferences - Indicator if the references should be refactored
Returns:
Fragment resource

batchCreateFragments

public static List<Resource> batchCreateFragments(List<URI> fragmentUris,
                                                  List<? extends EModelElement> fragmentRoots,
                                                  boolean refactorReferences)
Creates fragment resources. The specified fragment roots are moved from their current resource into the root of newly created fragments. Also, the corresponding stereotype applications are moved to the new resource. The operation is performed silently, without user interaction. It is the responsibility of the caller to ensure that the fragmentUris and fragmentRoots lists are of the same size and contain no duplicates.

Parameters:
fragmentUris - List of fragment URIs to create
fragmentRoots - List of EModelElements to use as fragment roots
refactorReferences - Indicator if the references should be refactored
Returns:
List of created fragment Resources
Throws:
IllegalArgumentException

absorbFragment

public static EObject absorbFragment(Resource resource)
Absorbs the specified fragment. The contents of the fragment are moved to its parent resource. The resource and all its parent resources must be in the loaded state. All affected resources are saved. The user is prompted to refactor references.

Parameters:
resource - Fragment resource to be absorbed
Returns:
The former fragment root element

absorbFragmentSilently

public static EObject absorbFragmentSilently(Resource resource,
                                             boolean refactorReferences)
Absorbs the specified fragment. The contents of the fragment are moved to its parent resource. The resource and all its parent resources must be in the loaded state. All affected resources are saved. The operation is performed silently, without user interaction.

Parameters:
resource - Fragment resource to be absorbed
refactorReferences - Indicator if the references should be refactored
Returns:
The former fragment root element

batchAbsorbFragments

public static List<EModelElement> batchAbsorbFragments(List<? extends Resource> resources,
                                                       boolean refactorReferences)
Absorbs the specified fragments. The contents of the fragments are moved to their parent resources. The fragment resources and all their parent resources must be in the loaded state. All affected resources are saved. The operation is performed silently without user interaction.

Parameters:
resources - Fragment resources to be absorbed
refactorReferences - Indicator if the references should be refactored
Returns:
The former fragment root elements

UML Modeler

© Copyright IBM Corp. 2009. All rights reserved.