Package cz.vutbr.fit.layout.api
Class ServiceManager
- java.lang.Object
-
- cz.vutbr.fit.layout.api.ServiceManager
-
public class ServiceManager extends Object
This class provides access to registered services. It holds the instances of the available services and their configuration.- Author:
- burgetr
-
-
Constructor Summary
Constructors Constructor Description ServiceManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAreaTreeOperator(AreaTreeOperator op)Adds a new area tree operator to the manager.voidaddArtifactService(ArtifactService op)Adds a new artifact service to the manager.voidaddScriptObject(String id, ScriptObject op)Adds a new script object to the manager.ArtifactapplyArtifactService(String serviceId, Map<String,Object> params, Artifact inputArtifact)Configures and invokes an artifact service for an input artifact.static ServiceManagercreate()Creates a new empty service manager with no services.static ServiceManagercreateAndDiscover()Creates a new service manager which is initialized by the automatic service discovery.Map<String,AreaTreeOperator>findAreaTreeOperators()Discovers all the AreaTreeOperator service implementations.Map<String,ArtifactService>findArtifactProviders(org.eclipse.rdf4j.model.IRI artifactType)Discovers all the ArtifactService implementations that produce a given artifact type.Map<String,ArtifactService>findArtifactSevices()Discovers all the ArtifactService implementations.<T> TfindByClass(Collection<?> services, Class<T> clazz)Finds a service in a collection of services based on its class.ParametrizedOperationfindParmetrizedService(String id)Finds a parametrized service based on its ID.Map<String,ScriptObject>findScriptObjects()Discovers all the ScriptObject service implementations.ArtifactRepositorygetArtifactRepository()Gets the artifact repository currently used by the services.Map<String,ParametrizedOperation>getParametrizedServices()Gets a map of all available parametrized operations.static Map<String,Object>getServiceParams(ParametrizedOperation op)Obtains the values of all the parametres of the given operation.protected voidinitAndDiscover()protected voidinitEmpty()static ServiceManagerinstance()<T extends Service>
Map<String,T>loadServicesByType(Class<T> clazz)Discovers the registered services of the given class.voidsetArtifactRepository(ArtifactRepository repository)Changes the artifact repository used by the services.static voidsetServiceParams(ParametrizedOperation op, Map<String,Object> params)Sets the operation parametres based on a map of values.
-
-
-
Method Detail
-
instance
public static ServiceManager instance()
-
createAndDiscover
public static ServiceManager createAndDiscover()
Creates a new service manager which is initialized by the automatic service discovery.- Returns:
- A ServiceManager instance
-
initAndDiscover
protected void initAndDiscover()
-
create
public static ServiceManager create()
Creates a new empty service manager with no services.- Returns:
- A ServiceManager instance
-
initEmpty
protected void initEmpty()
-
getArtifactRepository
public ArtifactRepository getArtifactRepository()
Gets the artifact repository currently used by the services. By default, an instance ofDefaultArtifactRepositoryis used.- Returns:
- The artifact repository.
-
setArtifactRepository
public void setArtifactRepository(ArtifactRepository repository)
Changes the artifact repository used by the services.- Parameters:
repository- the repository to be used
-
addArtifactService
public void addArtifactService(ArtifactService op)
Adds a new artifact service to the manager.- Parameters:
op- The service to add.
-
findArtifactSevices
public Map<String,ArtifactService> findArtifactSevices()
Discovers all the ArtifactService implementations.- Returns:
- A map that assigns the service
idto the appropriate implementation.
-
findArtifactProviders
public Map<String,ArtifactService> findArtifactProviders(org.eclipse.rdf4j.model.IRI artifactType)
Discovers all the ArtifactService implementations that produce a given artifact type.- Parameters:
artifactType- the artifact type to produce- Returns:
- A map that assigns the service
idto the appropriate implementation.
-
addAreaTreeOperator
public void addAreaTreeOperator(AreaTreeOperator op)
Adds a new area tree operator to the manager.- Parameters:
op- The operator to add.
-
findAreaTreeOperators
public Map<String,AreaTreeOperator> findAreaTreeOperators()
Discovers all the AreaTreeOperator service implementations.- Returns:
- A map that assigns the service
idto the appropriate implementation.
-
findScriptObjects
public Map<String,ScriptObject> findScriptObjects()
Discovers all the ScriptObject service implementations.- Returns:
- A map that assigns the service
idto the appropriate implementation.
-
loadServicesByType
public <T extends Service> Map<String,T> loadServicesByType(Class<T> clazz)
Discovers the registered services of the given class.- Parameters:
clazz- the class of the required services- Returns:
- A map that maps the services to their identifiers
-
applyArtifactService
public Artifact applyArtifactService(String serviceId, Map<String,Object> params, Artifact inputArtifact)
Configures and invokes an artifact service for an input artifact.- Parameters:
serviceId- the ID of the service to be invokedparams- A map of service input parametres (depending on the given service)inputArtifact- The input artifact to apply the service on (may benullfor services that do not use input artifacts, e.g. page rendering)- Returns:
- The created output artifact.
- Throws:
IllegalArgumentException- when the service with the given ID is not available
-
setServiceParams
public static void setServiceParams(ParametrizedOperation op, Map<String,Object> params)
Sets the operation parametres based on a map of values.- Parameters:
op- The operation whose parametres should be setparams- A map that assigns values to parameter names
-
getServiceParams
public static Map<String,Object> getServiceParams(ParametrizedOperation op)
Obtains the values of all the parametres of the given operation.- Parameters:
op- The operation whose parametres should be set- Returns:
- A map that assigns values to parameter names
-
getParametrizedServices
public Map<String,ParametrizedOperation> getParametrizedServices()
Gets a map of all available parametrized operations.- Returns:
- a map from service ID to the service instance
-
findParmetrizedService
public ParametrizedOperation findParmetrizedService(String id)
Finds a parametrized service based on its ID.- Parameters:
id- the service ID.- Returns:
- the parametrized operation object or
nullwhen the service does not exist.
-
addScriptObject
public void addScriptObject(String id, ScriptObject op)
Adds a new script object to the manager.- Parameters:
id-op-
-
findByClass
public <T> T findByClass(Collection<?> services, Class<T> clazz)
Finds a service in a collection of services based on its class.- Parameters:
services- the collection of services to scanclazz- the required class of the service- Returns:
- the fisrt service in the collection that is instance of the given class or
nullwhen no such servise is present in the collection.
-
-