de.cau.cs.kieler.kiml
Class LayoutDataService

java.lang.Object
  extended by de.cau.cs.kieler.kiml.LayoutDataService
Direct Known Subclasses:
ExtensionLayoutDataService

public class LayoutDataService
extends Object

Singleton class for access to the KIML layout data. This class is used globally to retrieve data for automatic layout through KIML. The class cannot be instantiated directly, but only through a subclass that calls createLayoutServices(). The subclass is then responsible to add appropriate data to the nested registry instance. Multiple instances of subclasses can register themselves by calling createLayoutServices(subInstance), where subInstance is the instance of the subclass, but only one instance per subclass is allowed. Registering another instance will overwrite the prior instance. The different instances are identified by class name and the currently used instance can be determined by calling getMode(). You can switch between the different instances by calling setMode(final String mode) where mode is one of the predefined Strings ECLIPSEDATASERVICE, REMOTEDATASERVICE or SERVICEDATASERVICE. The SERVICEDATASERVICE mode is intended to be used only by the KWebS server so using it inside the KIELER modeling environment will introduce undefined behavior.

Rating yellow
(2011-03-14) reviewed by cmot, cds

Nested Class Summary
 class LayoutDataService.Registry
          Class used to register the layout services.
 
Field Summary
static String DIAGRAM_TYPE_GENERAL
          identifier of the 'general' diagram type, which applies to all diagrams.
static String ECLIPSEDATASERVICE
          Mode constant for local data service instance.
static String REMOTEDATASERVICE
          Mode constant for remote data service instance.
static String SERVICEDATASERVICE
          Mode constant for server data service instance.
 
Constructor Summary
protected LayoutDataService()
          The default constructor is hidden to prevent others from instantiating this class.
 
Method Summary
protected static void addService(LayoutDataService subInstance)
          Registers a layout data service instance created by a specific subclass and assigns it an instance of the registry.
 Collection<LayoutAlgorithmData> getAlgorithmData()
          Returns a data collection for all registered layout algorithms.
 LayoutAlgorithmData getAlgorithmData(String id)
          Returns the layout algorithm data associated with the given identifier.
 LayoutAlgorithmData getAlgorithmDataBySuffix(String suffix)
          Returns a layout algorithm data that has the given suffix in its identifier.
 String getCategoryName(String id)
          Returns the name of the given category.
static LayoutDataService getInstance()
          Returns the layout data service instance belonging to the currently selected mode.
static
<T extends LayoutDataService>
T
getInstanceOf(String type)
          Returns the instance of a layout data service specified by it's fully qualified class name.
static String getMode()
          Returns the current operation mode of the layout data service.
 Collection<LayoutOptionData<?>> getOptionData()
          Returns a data collection for all registered layout options.
 List<LayoutOptionData<?>> getOptionData(LayoutAlgorithmData algorithmData, LayoutOptionData.Target targetType)
          Returns a list of layout options that are suitable for the given layout algorithm and layout option target.
 LayoutOptionData<?> getOptionData(String id)
          Returns the layout option data associated with the given identifier.
 LayoutOptionData<?> getOptionDataBySuffix(String suffix)
          Returns a layout option data that has the given suffix in its identifier.
static LayoutDataService.Registry getRegistry()
          Returns the instance of the registry class associated with the current layout data service.
 Collection<LayoutTypeData> getTypeData()
          Returns a list of layout type identifiers and names.
 LayoutTypeData getTypeData(String id)
          Returns the data instance of the layout type with given identifier.
 LayoutTypeData getTypeDataBySuffix(String suffix)
          Returns a layout type data that has the given suffix in its identifier.
static void removeService(LayoutDataService subInstance)
          Removes a layout data service instance.
static void setMode(String mode)
          Sets the mode to mode where mode has to be an element of LayoutDataService.ECLIPSEDATASERVICE, LayoutDataService.REMOTEDATASERVICE or LayoutDataService.SERVERDATASERVICE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIAGRAM_TYPE_GENERAL

public static final String DIAGRAM_TYPE_GENERAL
identifier of the 'general' diagram type, which applies to all diagrams.

See Also:
Constant Field Values

ECLIPSEDATASERVICE

public static final String ECLIPSEDATASERVICE
Mode constant for local data service instance.

See Also:
Constant Field Values

REMOTEDATASERVICE

public static final String REMOTEDATASERVICE
Mode constant for remote data service instance.

See Also:
Constant Field Values

SERVICEDATASERVICE

public static final String SERVICEDATASERVICE
Mode constant for server data service instance.

See Also:
Constant Field Values
Constructor Detail

LayoutDataService

protected LayoutDataService()
The default constructor is hidden to prevent others from instantiating this class.

Method Detail

addService

protected static void addService(LayoutDataService subInstance)
Registers a layout data service instance created by a specific subclass and assigns it an instance of the registry.

Parameters:
subInstance - an instance created by a subclass

removeService

public static void removeService(LayoutDataService subInstance)
Removes a layout data service instance. The instance belonging to the currently selected mode can not be removed.

Parameters:
subInstance - the sub instance to be removed
Throws:
IllegalArgumentException - if the instance belonging to the currently selected mode is to be removed or the sub instance is not supported

getMode

public static String getMode()
Returns the current operation mode of the layout data service. The returned mode is either LayoutDataService.ECLIPSEDATASERVICE, LayoutDataService.REMOTEDATASERVICE or LayoutDataService.SERVERDATASERVICE or null if no layout data service has been registered yet.

Returns:
the mode of operation or null

setMode

public static void setMode(String mode)
Sets the mode to mode where mode has to be an element of LayoutDataService.ECLIPSEDATASERVICE, LayoutDataService.REMOTEDATASERVICE or LayoutDataService.SERVERDATASERVICE.

Parameters:
mode - the mode to be set
Throws:
IllegalArgumentException - if the given mode is not valid or the according layout data service has not been registered yet

getInstance

public static LayoutDataService getInstance()
Returns the layout data service instance belonging to the currently selected mode.

Returns:
the layout data service instance belonging to the currently selected mode

getInstanceOf

public static <T extends LayoutDataService> T getInstanceOf(String type)
Returns the instance of a layout data service specified by it's fully qualified class name.

Type Parameters:
T - type of the returned instance
Parameters:
type - fully qualified class name of the data service instance
Returns:
the data service instance or null if no such instance has been registered or the given type is not valid specifier.

getRegistry

public static final LayoutDataService.Registry getRegistry()
Returns the instance of the registry class associated with the current layout data service.

Returns:
the registry instance, or null if either no layout data service has been registered yet or it has been removed

getAlgorithmData

public final LayoutAlgorithmData getAlgorithmData(String id)
Returns the layout algorithm data associated with the given identifier.

Parameters:
id - layout algorithm identifier
Returns:
the corresponding layout algorithm data, or null if there is no algorithm with the given identifier

getAlgorithmData

public final Collection<LayoutAlgorithmData> getAlgorithmData()
Returns a data collection for all registered layout algorithms. The collection is unmodifiable.

Returns:
collection of registered layout algorithms

getAlgorithmDataBySuffix

public final LayoutAlgorithmData getAlgorithmDataBySuffix(String suffix)
Returns a layout algorithm data that has the given suffix in its identifier.

Parameters:
suffix - a layout algorithm identifier suffix
Returns:
the first layout algorithm data that has the given suffix

getOptionData

public final LayoutOptionData<?> getOptionData(String id)
Returns the layout option data associated with the given identifier.

Parameters:
id - layout option identifier
Returns:
the corresponding layout option data, or null if there is no option with the given identifier

getOptionData

public final Collection<LayoutOptionData<?>> getOptionData()
Returns a data collection for all registered layout options. The collection is unmodifiable.

Returns:
collection of registered layout options

getOptionDataBySuffix

public final LayoutOptionData<?> getOptionDataBySuffix(String suffix)
Returns a layout option data that has the given suffix in its identifier.

Parameters:
suffix - a layout option identifier suffix
Returns:
the first layout option data that has the given suffix

getOptionData

public final List<LayoutOptionData<?>> getOptionData(LayoutAlgorithmData algorithmData,
                                                     LayoutOptionData.Target targetType)
Returns a list of layout options that are suitable for the given layout algorithm and layout option target. The layout algorithm must know the layout options and at the target must be active for each option.

Parameters:
algorithmData - layout algorithm data
targetType - type of layout option target
Returns:
list of suitable layout options

getTypeData

public final LayoutTypeData getTypeData(String id)
Returns the data instance of the layout type with given identifier.

Parameters:
id - identifier of the type
Returns:
layout type data instance with given identifier, or null if the layout type is not registered

getTypeData

public final Collection<LayoutTypeData> getTypeData()
Returns a list of layout type identifiers and names. The first string in each entry is the identifier, and the second string is the name.

Returns:
a list of all layout types

getTypeDataBySuffix

public final LayoutTypeData getTypeDataBySuffix(String suffix)
Returns a layout type data that has the given suffix in its identifier.

Parameters:
suffix - a layout type identifier suffix
Returns:
the first layout type data that has the given suffix

getCategoryName

public final String getCategoryName(String id)
Returns the name of the given category.

Parameters:
id - identifier of the category
Returns:
user friendly name of the category, or null if there is no category with the given identifier