Class 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 Detail

      • ServiceManager

        public ServiceManager()
    • Method Detail

      • 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 of DefaultArtifactRepository is 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 id to 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 id to 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 id to the appropriate implementation.
      • 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 invoked
        params - A map of service input parametres (depending on the given service)
        inputArtifact - The input artifact to apply the service on (may be null for 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 set
        params - 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 null when the service does not exist.
      • addService

        public void addService​(Service op)
        Adds a new service to the manager.
        Parameters:
        op - a service to add. It must implement a ParametrizedOperation or a ScriptObject interface to be handled properly.
      • 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 scan
        clazz - the required class of the service
        Returns:
        the fisrt service in the collection that is instance of the given class or null when no such servise is present in the collection.