UML Modeling Layer

com.ibm.xtools.uml.msl.internal.resources
Class FragmentFactory

java.lang.Object
  extended by com.ibm.xtools.uml.msl.internal.resources.FragmentFactory

public class FragmentFactory
extends Object

The factory class for manipulating model fragments. Its focus is to provide means to create and absorb fragments. However, it also exposes a number of utility methods.


Method Summary
static EObject absorbFragment(Resource resource)
          Absorbs the specified fragment.
static List<EObject> absorbFragments(List<Resource> resources)
          Absorbs the specified fragments.
static Resource createFragment(URI fragmentUri, EModelElement fragmentRoot)
          Creates the fragment resource.
static List<Resource> createFragments(List<URI> fragmentUris, List<EModelElement> fragmentRoots)
          Creates the fragment resources.
static boolean isFragmentable(EObject eObj)
          Determines if the specified element can be moved into a fragment.
static void postProcessFragmentReparenting(EModelElement fragmentRoot)
          Adjusts the fragment and its current owner after re-parenting.
static void preProcessFragmentReparenting(EModelElement fragmentRoot)
          Prepares the fragment and its current owner for re-parenting.
static void transferFragmentDefinition(EObject oldRoot, EObject newRoot)
          Replaces the fragment definition in the parent resource and also sets up the back reference in the fragment itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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. Both resources are augmented with the fragment metadata. Also, the corresponding stereotype applications are moved to the new resource. Neither resource is saved; it is up to the caller to ensure that the files are saved, if desired.

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

createFragments

public static List<Resource> createFragments(List<URI> fragmentUris,
                                             List<EModelElement> fragmentRoots)
Creates the fragment resources. The specified fragment roots are moved from their current resources into the root of the newly created fragments. All resources are augmented with the fragment metadata. Also, the corresponding stereotype applications are moved to the new resources. No resources are saved; it is up to the caller to ensure that the files are saved, if desired.

Parameters:
fragmentUris - URI for the new fragment
fragmentRoots - The element to be moved into the fragment
Returns:
Fragment resources

absorbFragment

public static EObject absorbFragment(Resource resource)
Absorbs the specified fragment. The contents of the fragment are moved to its parent resource. Neither resource is saved; it is up to the caller to ensure that the files are saved, if desired. The caller should also consider deleting the fragment resource altogether.

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

absorbFragments

public static List<EObject> absorbFragments(List<Resource> resources)
Absorbs the specified fragments. The contents of the fragments are moved to their parent resources. No resource is saved; it is up to the caller to ensure that the files are saved, if desired. The caller should also consider deleting the fragment resource altogether.

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

preProcessFragmentReparenting

public static void preProcessFragmentReparenting(EModelElement fragmentRoot)
Prepares the fragment and its current owner for re-parenting. If this action results in the movement of a fragment from one logical resource to another then it is the responsibility of the caller to ensure that LogicalUMLResourceProvider.getInstance().reset(logicalUMLResource) gets called for the old owner of the fragment.

Parameters:
fragmentRoot - The fragment root

postProcessFragmentReparenting

public static void postProcessFragmentReparenting(EModelElement fragmentRoot)
Adjusts the fragment and its current owner after re-parenting. If this action results in the movement of a fragment from one logical resource to another then it is the responsibility of the caller to ensure that LogicalUMLResourceProvider.getInstance().reset(logicalUMLResource) gets called for the new owner of the fragment.

Parameters:
fragmentRoot - The fragment root

transferFragmentDefinition

public static void transferFragmentDefinition(EObject oldRoot,
                                              EObject newRoot)
Replaces the fragment definition in the parent resource and also sets up the back reference in the fragment itself.

Parameters:
oldRoot - Old fragment definition
newRoot - New fragment definition

isFragmentable

public static boolean isFragmentable(EObject eObj)
Determines if the specified element can be moved into a fragment. That is, if the element can serve as a fragment root.

Parameters:
eObj - The element to be tested
Returns:
'true' if the element can be moved into a fragment root; 'false' otherwise

UML Modeling Layer

© Copyright IBM Corp. 2009. All rights reserved.