com.sdm.quasar.client.core.common.services
Class AbstractServiceManager

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.services.AbstractServiceManager
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
DefaultDialogServiceManager

public abstract class AbstractServiceManager
extends java.lang.Object
implements Disposable

Abstract base class for service managers. This implementation is independent of the possible tagging interface of the services.

Version:
1.0
Author:
Bernd Olleck, sd&m AG

Field Summary
protected static int DIRECT
           
protected static int FROM_PARENT
           
protected static int HIERARCHY
           
protected  ID virtualRootNode
          The ID of the root node that is represented by the #parentServiceProvider.
 
Constructor Summary
protected AbstractServiceManager(java.lang.Class taggingInterface, HierarchyProvider hierarchyProvider)
          Constructor that initializes this service manager without forwarding to an ServiceManager.
protected AbstractServiceManager(java.lang.Class taggingInterface, HierarchyProvider hierarchyProvider, ID virtualRootNode, ServiceProvider parentServiceProvider)
          Constructor that initializes this service manager with a forwarding to an ServiceManager for requests concerning the given virtual root node.
 
Method Summary
 void dispose()
          Disposes the component.
protected  java.lang.Object genericFindServiceInHierarchy(ID id, ID rootID, java.lang.Class service)
          Returns the first implementation of a desired service in the hierarchy starting from the node with the given id to the specified root node.
protected  java.lang.Object[] genericGetAllServiceImplementations(ID id, java.lang.Class service)
           
protected  java.lang.Class[] genericGetAllServices(ID id)
          Returns all service key classes for the specified node.
protected  java.lang.Object genericGetServiceDirect(ID id, java.lang.Class service)
          Returns the implementation of a desired service registered at the node with the given id.
protected  boolean genericHasServiceDirect(ID id, java.lang.Class service)
          Tests whether a specific node offers a service.
protected  boolean genericHasServiceInHierarchy(ID id, ID rootID, java.lang.Class service)
          Tests whether the service is offered in the hierarchy starting from the node with the given id to the specified root node.
protected  void genericRegisterService(ID providerId, java.lang.Class service, java.lang.Object implementation, int serviceMode)
          Registers a service for the node with the given id.
protected  void genericUnregisterService(ID providerId, java.lang.Class service, java.lang.Object implementation)
          Unregisters a service for a given node.
protected  boolean hasID(ID id)
          Tests whether the given ID represents a known node in the hierarchy that is used by this service manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FROM_PARENT

protected static final int FROM_PARENT
See Also:
Constant Field Values

DIRECT

protected static final int DIRECT
See Also:
Constant Field Values

HIERARCHY

protected static final int HIERARCHY
See Also:
Constant Field Values

virtualRootNode

protected ID virtualRootNode
The ID of the root node that is represented by the #parentServiceProvider. This value may be null.

If it is not null, then all find/get-requests to that node are forwarded to that node and all register-requests to that node are blocked as illegal. If it is null, there are no restrictions placed on the registration of services and no forward is used.

Constructor Detail

AbstractServiceManager

protected AbstractServiceManager(java.lang.Class taggingInterface,
                                 HierarchyProvider hierarchyProvider)
Constructor that initializes this service manager without forwarding to an ServiceManager.

Parameters:
taggingInterface - the required tagging interface class or null if no tagging interface is required.
hierarchyProvider - the HierarchyProvider that governs the hierarchy that is used to organize the services.

AbstractServiceManager

protected AbstractServiceManager(java.lang.Class taggingInterface,
                                 HierarchyProvider hierarchyProvider,
                                 ID virtualRootNode,
                                 ServiceProvider parentServiceProvider)
Constructor that initializes this service manager with a forwarding to an ServiceManager for requests concerning the given virtual root node. See virtualRootNode for more information.

Parameters:
taggingInterface - the required tagging interface class or null if no tagging interface is required.
hierarchyProvider - the HierarchyProvider that governs the hierarchy that is used to organize the services.
virtualRootNode - the id of the virtual root node
parentServiceProvider - the ServiceManager to which requests concerning the virtual root node are forwarded.
Method Detail

genericRegisterService

protected void genericRegisterService(ID providerId,
                                      java.lang.Class service,
                                      java.lang.Object implementation,
                                      int serviceMode)
Registers a service for the node with the given id. The service class must be an interface that extends #taggingInterface, and the implementation implement that interface.

If there is already an implementation registered for that service, that implementation is replaced by the passed as a parameter.

Please note that a a registered service should be unregistered when the life cycle of the provider ends.

Parameters:
providerId - the id of the node where the service should be registered
service - the interface that defines the service
implementation - the implementation of the service
serviceMode - the service mode, this implementation should be installed for (one of FROM_PARENT, DIRECT or HIERARCHY).
Throws:
java.lang.IllegalArgumentException - if the providerId is unknown, service is not an interface or does not extend #taggingInterface, or the implementation does not implement the interface that defines the service.

hasID

protected boolean hasID(ID id)
Tests whether the given ID represents a known node in the hierarchy that is used by this service manager.

Parameters:
id - the ID to be tested
Returns:
true, iff the given ID represents a known node within the hierarchy

genericUnregisterService

protected void genericUnregisterService(ID providerId,
                                        java.lang.Class service,
                                        java.lang.Object implementation)
Unregisters a service for a given node.

If the service is not registered for the given node or the given implementation is not the one that is registered, nothing happens.

Therefore, if a service implementation is replaced by another implementation, the unregistering of the first implementation is harmless since the second implementation will stay registered. However, if the second implementation is unregistered first, then no service will be available, even though the first service implementation hasn't been unregistered yet.

Parameters:
providerId - the id of the node where the service should be unregistered
service - the interface that defines the service
implementation - the registered implementation of the service
Throws:
java.lang.IllegalArgumentException - if the providerId is unknown, service is not an interface or does not extend #taggingInterface, or the implementation does not implement the interface that defines the service.

genericHasServiceInHierarchy

protected boolean genericHasServiceInHierarchy(ID id,
                                               ID rootID,
                                               java.lang.Class service)
Tests whether the service is offered in the hierarchy starting from the node with the given id to the specified root node.

Parameters:
id - the id of the node at which the search starts towards the root node
rootID - the root id where to stop looking for a parent provider (may be null or not contained in id's hierarchy tree, which will be threated at the root of the current hierarchy tree)
service - the class of the service interface that is searched for
Returns:
true iff the service is available.
Throws:
java.lang.IllegalArgumentException - if the id is unknown or if the service class is not an interface that extends Service.

genericFindServiceInHierarchy

protected java.lang.Object genericFindServiceInHierarchy(ID id,
                                                         ID rootID,
                                                         java.lang.Class service)
Returns the first implementation of a desired service in the hierarchy starting from the node with the given id to the specified root node. The returned Object will implement the service interface.

Parameters:
id - the id of the node at which the search starts towards the root node
rootID - the root id where to stop looking for a parent provider (may be null or not contained in id's hierarchy tree, which will be threated at the root of the current hierarchy tree)
service - the class of the service interface that is searched for
Returns:
the object implementing the service that is registered closest to the node with the given id
Throws:
java.lang.IllegalArgumentException - if the id is unknown, if the service class is not an interface that extends Service, or if the service is not available.

genericHasServiceDirect

protected boolean genericHasServiceDirect(ID id,
                                          java.lang.Class service)
Tests whether a specific node offers a service. In this case, the hierarchical dependency is ignored.

Parameters:
id - the id of the node
service - the class of the service interface that is searched for
Returns:
true, iff the service is available.
Throws:
java.lang.IllegalArgumentException - if the id is unknown or if the service class is not an interface that extends #taggingInterface.

genericGetServiceDirect

protected java.lang.Object genericGetServiceDirect(ID id,
                                                   java.lang.Class service)
Returns the implementation of a desired service registered at the node with the given id. The returned Object will implement the service interface.

Parameters:
id - the id of the node
service - the class of the service interface that is requested
Returns:
the object implementing the service that is registered at the specified node
Throws:
java.lang.IllegalArgumentException - if the id is unknown, if the service class is not an interface that extends #taggingInterface, or if the service is not available at the given node

genericGetAllServices

protected java.lang.Class[] genericGetAllServices(ID id)
Returns all service key classes for the specified node.

Parameters:
id - the id of the node

genericGetAllServiceImplementations

protected java.lang.Object[] genericGetAllServiceImplementations(ID id,
                                                                 java.lang.Class service)

dispose

public void dispose()
             throws DisposeException
Description copied from interface: Disposable
Disposes the component.

Important:
This method is called by an administrating component and must never be called directly.

The implementation should release any resources or objects allocated and any services registered. Furthermore, this method should be developed carefully to free a maximum of resources even when the system may have become unstable. In case of one or multiple errors, you should collect them in a DisposeException, continue with the execution, and throw it at the end of the method.

Note: The implementation must not return before the component is disposed. Any threads or asynchronous calls started must be completed before this method returns.

Specified by:
dispose in interface Disposable
Throws:
DisposeException - if there was one or more errors while disposing the component.