UML Modeling Layer

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

java.lang.Object
  extended by org.eclipse.emf.common.notify.impl.AdapterImpl
      extended by com.ibm.xtools.uml.msl.internal.resources.LogicalUMLResourceProvider
All Implemented Interfaces:
ILogicalUMLResourceAdapter, Adapter, Adapter.Internal

public class LogicalUMLResourceProvider
extends AdapterImpl
implements ILogicalUMLResourceAdapter

Represents the provider of a logical UML resource. It manages groupings of UML resources into logical resources.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.emf.common.notify.Adapter
Adapter.Internal
 
Field Summary
 
Fields inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl
target
 
Method Summary
protected static void addChildrenUnits(LogicalUMLUnit unit)
          Adds children units to the specified unit.
protected  ILogicalUMLResource buildLogicalResource(Resource resource)
          Builds the logical resource for the specified root resource
 ILogicalUMLResource findLogicalResource(Resource resource)
          Returns a logical UML resource for a resource even if no part of that logical resource is loaded.
static ILogicalUMLResource findLogicalUMLResouce(Resource resource)
          Returns a logical UML resource for a resource even if no part of that logical resource is loaded.
static List<EObject> getAllContainedLoadedFragmentRoots(EObject eObj)
          Returns the list of all fragments contained in the model branch rooted at the specified object.
static List<EObject> getContainedFragments(EObject eObj, boolean selfIncluded, boolean resolve)
          Returns the list of fragments contained in the model branch rooted at the specified object.
static Resource getContainerResource(Resource resource)
          Gets the resource referred to by a resources fragment container annotation.
static List<ILogicalUnit> getFirstLevelChildren(Resource rootResource)
          Returns the first level children of the specified resource.
static EObject getFragmentDirectContainer(EModelElement fragmentRoot)
          Returns the direct container of the fragment.
static List<EObject> getFragments(EModelElement resourceRoot)
          Returns fragments of the resource.
static ILogicalUnit getHierarchicalStructure(Resource rootResource)
          Builds and returns hierarchical structure of the logical resource.
static LogicalUMLResourceProvider getInstance()
           
protected static ILogicalUMLUnit getInternalHierarchicalStructure(Resource rootResource)
          Builds and returns the partial UML hierarchical structure of a logical resource starting at a particular resource.
 ILogicalUMLResource getLogicalResource(Resource resource)
          Returns the logical UML resource of the specified resource.
 ILogicalUMLResource getLogicalResource(Resource resource, boolean trackUnknowns)
          Returns the logical UML resource of the specified resource.
static ILogicalUMLResource getLogicalUMLResource(EObject eObj)
          Returns the logical UML resource of the specified EObject.
static ILogicalUMLResource getLogicalUMLResource(EObject eObj, boolean trackUnknowns)
          Returns the logical UML resource of the specified EObject.
static ILogicalUMLResource getLogicalUMLResource(Resource resource)
          Returns the logical UML resource of the specified resource.
static Resource getResource(IResource resource)
          Find the EMF resource of an IResource if there is one
static EObject getRootContainerInResource(EObject eObject)
          Finds the root container in the same resource.
static boolean isFragmentable(EObject eObj)
          Determines if the specified element can be moved into a fragment.
static boolean isFragmentRoot(EObject eObj)
          Tests if the specified object is a fragment root.
static boolean isLogicalResourceRoot(EObject eObj)
          Tests if the specified object is a logical resource root.
 void notifyChanged(Notification msg)
           
protected  void processResourceUnloaded(Resource resource)
          Processes the RESOURCE UNLOADED event.
static void registerFragmentExtension(String fragmentExtension)
          Registers the file extension with the provider to be considered as a logical resource fragment.
static void registerRootExtension(String rootExtension)
          Registers the file extension with the provider to be considered as a logical resource root.
static void registerSaveProvider(ISaveProvider saveProvider)
          Registers save provider.
 void reset(ILogicalUMLResource lResource)
          Resets the list of loaded fragments of the logical resource.
static void resolveNestedFragments(Resource fragment)
          Resolves specified fragment's first level nested fragments.
static void saveResource(ILogicalUMLResource lResource)
          Saves logical resource.
 
Methods inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl
getTarget, isAdapterForType, setTarget, unsetTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static final LogicalUMLResourceProvider getInstance()
Returns:
The singleton manager instance

getLogicalUMLResource

public static ILogicalUMLResource getLogicalUMLResource(Resource resource)
Returns the logical UML resource of the specified resource.

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

findLogicalResource

public ILogicalUMLResource findLogicalResource(Resource resource)
Description copied from interface: ILogicalUMLResourceAdapter
Returns a logical UML resource for a resource even if no part of that logical resource is loaded. Unlike other logicalResource methods the result returned here may not be canonical. If a canonical logical resource can be found it will be returned otherwise an UnloadedLogicalUMLResource is returned.

Specified by:
findLogicalResource in interface ILogicalUMLResourceAdapter
Parameters:
resource - The resource whose logical resource is returned
Returns:
The canonical logical model for as resource if it exists or an UnloadedLogicalUMLResource otherwise.

findLogicalUMLResouce

public static ILogicalUMLResource findLogicalUMLResouce(Resource resource)
Returns a logical UML resource for a resource even if no part of that logical resource is loaded. Unlike other logicalResource methods the result returned here may not be canonical. If a canonical logical resource can be found it will be returned otherwise an UnloadedLogicalUMLResource is returned.

Parameters:
resource - The resource whose logical resource is returned
Returns:
The canonical logical model for as resource if it exists or an UnloadedLogicalUMLResource otherwise.

getContainerResource

public static Resource getContainerResource(Resource resource)
Gets the resource referred to by a resources fragment container annotation.

Parameters:
resource -
Returns:

getLogicalUMLResource

public static ILogicalUMLResource getLogicalUMLResource(EObject eObj)
Returns the logical UML resource of the specified EObject.

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

getLogicalUMLResource

public static ILogicalUMLResource getLogicalUMLResource(EObject eObj,
                                                        boolean trackUnknowns)
Returns the logical UML resource of the specified EObject.

Parameters:
eObj - The EObject whose logical resource is returned
trackUnknown - Indicates whether the provider should keep track of unknown resources, if this is set to false any returned UnknownLogicalUMLResource may not be canonical.
Returns:
Logical UML resource

getLogicalResource

public ILogicalUMLResource getLogicalResource(Resource resource,
                                              boolean trackUnknowns)
Returns the logical UML resource of the specified resource.

Specified by:
getLogicalResource in interface ILogicalUMLResourceAdapter
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.
trackUnknown - Indicates whether the provider should keep track of unknown resources, if this is set to false any returned UnknownLogicalUMLResource may not be canonical.
Returns:
Logical UML resource

getLogicalResource

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

Specified by:
getLogicalResource in interface ILogicalUMLResourceAdapter
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

notifyChanged

public void notifyChanged(Notification msg)
Specified by:
notifyChanged in interface Adapter
Overrides:
notifyChanged in class AdapterImpl
See Also:
AdapterImpl.notifyChanged(org.eclipse.emf.common.notify.Notification)

buildLogicalResource

protected ILogicalUMLResource buildLogicalResource(Resource resource)
Builds the logical resource for the specified root resource

Parameters:
resource - The root resource

processResourceUnloaded

protected void processResourceUnloaded(Resource resource)
Processes the RESOURCE UNLOADED event.

Parameters:
resource - The unloaded resource

reset

public void reset(ILogicalUMLResource lResource)
Resets the list of loaded fragments of the logical resource.

Parameters:
lResource - Logical resource

isLogicalResourceRoot

public static boolean isLogicalResourceRoot(EObject eObj)
Tests if the specified object is a logical resource root.

Parameters:
eObj - Object to be tested
Returns:
'true' if the object is logical resource root; 'false' otherwise

isFragmentRoot

public static boolean isFragmentRoot(EObject eObj)
Tests if the specified object is a fragment root.

Parameters:
eObj - Object to be tested
Returns:
'true' if the object is fragment root; 'false' otherwise

getFragmentDirectContainer

public static EObject getFragmentDirectContainer(EModelElement fragmentRoot)
Returns the direct container of the fragment.

Parameters:
fragmentRoot - The fragment root
Returns:
The direct container of the fragment

getFragments

public static List<EObject> getFragments(EModelElement resourceRoot)
Returns fragments of the resource. The fragments might not be resolved.

Parameters:
resourceRoot - The resource root
Returns:
The fragments of the resource

getRootContainerInResource

public static EObject getRootContainerInResource(EObject eObject)
Finds the root container in the same resource.

Parameters:
eObject - Object whose root container is returned
Returns:
The root container in the same resource

getResource

public static Resource getResource(IResource resource)
Find the EMF resource of an IResource if there is one

Parameters:
resource -
Returns:

getAllContainedLoadedFragmentRoots

public static List<EObject> getAllContainedLoadedFragmentRoots(EObject eObj)
Returns the list of all fragments contained in the model branch rooted at the specified object. If those fragments are further fragmented then those additional fragments are included in the list. The objects in the list are the root objects (EObject) of the corresponding fragments.

Parameters:
eObj - The root of the model branch to be queried.
Returns:
The list of fragment roots (instances of EObject)

getContainedFragments

public static List<EObject> getContainedFragments(EObject eObj,
                                                  boolean selfIncluded,
                                                  boolean resolve)
Returns the list of fragments contained in the model branch rooted at the specified object. These are only the first level fragments; that is, the fragments of the resource owning the specified object. If those fragments are further fragmented then those additional fragments are not included in the list. The objects in the list are the root objects (EObject) of the corresponding fragments. These objects could be proxies depending on the value of the resolve flag.

Parameters:
eObj - The root of the model branch to be queried.
selfIncluded - Indicates how the specified object should be considered. If the flag is set to true and this object is a fragment root then it is considered to be the only contained fragment root - it is the only item in the returned list. If the flag is set to false then there is no special behavior when the specified element is fragment root.
resolve - Indicates if the objects in the returned list should be resolved or not. Even if it is set to 'true' the objects might still be proxies - if they cannot be resolved.
Returns:
The list of fragment roots (instances of EObject)

resolveNestedFragments

public static void resolveNestedFragments(Resource fragment)
Resolves specified fragment's first level nested fragments.

Parameters:
fragment - Fragment whose nested fragments are resolved

registerRootExtension

public static void registerRootExtension(String rootExtension)
Registers the file extension with the provider to be considered as a logical resource root.

Parameters:
rootExtension - The file extension

registerFragmentExtension

public static void registerFragmentExtension(String fragmentExtension)
Registers the file extension with the provider to be considered as a logical resource fragment.

Parameters:
fragmentExtension - The file extension

registerSaveProvider

public static void registerSaveProvider(ISaveProvider saveProvider)
Registers save provider.

Parameters:
saveProvider - The save provider

saveResource

public static void saveResource(ILogicalUMLResource lResource)
                         throws IOException
Saves logical resource. Uses registered save providers for the save operation. If no save provider supports the particular resource, uses the resource's save implementation.

Parameters:
lResource - Logical resource to be saved
Throws:
IOException

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

getHierarchicalStructure

public static ILogicalUnit getHierarchicalStructure(Resource rootResource)
Builds and returns hierarchical structure of the logical resource. The structure is a snapshot at the time of the call and is not dynamically updated.

Returns:
The logical unit of the top resource in the hierarchical structure

getInternalHierarchicalStructure

protected static ILogicalUMLUnit getInternalHierarchicalStructure(Resource rootResource)
Builds and returns the partial UML hierarchical structure of a logical resource starting at a particular resource. The structure is a snapshot at the time of the call and is not dynamically updated. The root unit of a logical UML resource must be a UML logical unit. This method really returns the same unit as getHierarchicalStructure() - it only enforces the type.

Parameters:
rootResource - resource to
Returns:
The logical unit of the top resource in the hierarchical structure as UML unit
See Also:

getFirstLevelChildren

public static List<ILogicalUnit> getFirstLevelChildren(Resource rootResource)
Returns the first level children of the specified resource.

Parameters:
rootResource -
Returns:
A list of children logical units

addChildrenUnits

protected static void addChildrenUnits(LogicalUMLUnit unit)
Adds children units to the specified unit. Recursively builds the hierarchy.

Parameters:
unit - Logical unit whose children are calculated

UML Modeling Layer

© Copyright IBM Corp. 2009. All rights reserved.