PTP
Release 7.0

org.eclipse.ptp.services.core
Class ServiceModelManager

java.lang.Object
  extended by org.eclipse.core.runtime.PlatformObject
      extended by org.eclipse.ptp.services.core.ServiceModelManager
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, IServiceModelManager

public class ServiceModelManager
extends org.eclipse.core.runtime.PlatformObject
implements IServiceModelManager

A singleton class which is the entry point to a service model which represents: - the set of contributed services - the set of providers which provide those services - the service fProjectConfigurations for each project which specify which services are mapped to which providers. EXPERIMENTAL. This class or interface has been added as part of a work in progress. There is no guarantee that this API will work or that it will remain the same. Please do not use this API without consulting with the RDT team.


Method Summary
 void addConfiguration(org.eclipse.core.resources.IProject project, IServiceConfiguration conf)
          Associate the service configuration with a project.
 void addConfiguration(IServiceConfiguration conf)
          Adds the given service configuration to the model without explicitly associating it with a particular project.
 void addEventListener(IServiceModelEventListener listener, int type)
          Adds the given listener for service model events.
 boolean exportConfigurations(java.lang.String filename, IServiceConfiguration[] configs)
          Export a set of service configurations to a file.
 IServiceConfiguration getActiveConfiguration()
          Get the global "active" service configuration.
 IServiceConfiguration getActiveConfiguration(org.eclipse.core.resources.IProject project)
          Get the configuration that is currently active for the project.
 java.util.Set<IServiceCategory> getCategories()
          Returns all the service categories that have been registered with the system.
 IServiceConfiguration getConfiguration(org.eclipse.core.resources.IProject project, java.lang.String name)
          Get the named configuration for this project.
 IServiceConfiguration getConfiguration(java.lang.String id)
          Get the configuration with the specified ID.
 java.util.Set<IServiceConfiguration> getConfigurations()
          Get all configurations available in the workspace.
 java.util.Set<IServiceConfiguration> getConfigurations(org.eclipse.core.resources.IProject project)
          Get all the configurations that are known by the project
static ServiceModelManager getInstance()
           
 java.util.Set<org.eclipse.core.resources.IProject> getProjectsForConfiguration(IServiceConfiguration serviceConfiguration)
          Get the set of projects which use the specified service configuration
 IService getService(java.lang.String id)
          Retrieves the service corresponding to a given id.
 IServiceProvider getServiceProvider(IServiceProviderDescriptor desc)
          Return a new instance of a service provider based on the descriptor.
 java.util.Set<IService> getServices()
          Get all the services that have been registered with the system.
 java.util.Set<IService> getServices(org.eclipse.core.resources.IProject project)
          Get all the services that are used by a particular project.
 java.util.Set<IService> getServices(java.lang.String natureId)
          Get all the services that are associated with a project nature.
 IServiceConfiguration[] importConfigurations(java.lang.String filename)
          Import a set of service configurations from a file.
 boolean isConfigured(org.eclipse.core.resources.IProject project)
          Returns true if the given project has a configuration.
 boolean isValidConfigurationFile(java.lang.String filename)
          Validate a set of service configurations in a file
 void loadModelConfiguration()
          Replaces the current service model configuration with what is specified in the default save file.
 void loadModelConfiguration(java.io.Reader reader)
          Replaces the current service model configuration with what is specified in the given file.
 IServiceConfiguration newServiceConfiguration(java.lang.String name)
          Obtain a new service configuration with name 'name'.
 void notifyListeners(IServiceModelEvent event)
          Notify listeners of an event occurrence.
 void printServiceModel()
          Prints the current service model to the console, for debugging purposes.
 void remap(org.eclipse.core.resources.IProject removedProject, org.eclipse.core.resources.IProject addedProject)
          Remaps all the configurations and services associated to the removed project to the added project.
 void remove(org.eclipse.core.resources.IProject project)
          Removes all the configurations and services associated to the given project.
 void remove(IServiceConfiguration conf)
          Removes the service configuration.
 void removeConfiguration(org.eclipse.core.resources.IProject project, IServiceConfiguration conf)
          TODO What happens if you try to remove the active configuration?
 void removeEventListener(IServiceModelEventListener listener)
          Removes the given listener for service model events.
 void saveModelConfiguration()
          Saves the model configuration into the plugin's metadata area using the default file name.
 void saveModelConfiguration(java.io.Writer writer)
          Saves the service model configuration to the given file.
 void setActiveConfiguration(org.eclipse.core.resources.IProject project, IServiceConfiguration configuration)
          Set the active configuration for a project.
 void setActiveConfiguration(IServiceConfiguration config)
          Set the global "active" service configuration.
 
Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
 

Method Detail

getInstance

public static ServiceModelManager getInstance()

addConfiguration

public void addConfiguration(org.eclipse.core.resources.IProject project,
                             IServiceConfiguration conf)
Description copied from interface: IServiceModelManager
Associate the service configuration with a project. A project can have multiple service configurations. The service configuration will become the active configuration for the project.

Specified by:
addConfiguration in interface IServiceModelManager
Parameters:
project - the project
conf - the configuration

addConfiguration

public void addConfiguration(IServiceConfiguration conf)
Description copied from interface: IServiceModelManager
Adds the given service configuration to the model without explicitly associating it with a particular project. It may be associated with a project later using the addConfiguration(IProject, IServiceConfiguration) method.

Specified by:
addConfiguration in interface IServiceModelManager
Parameters:
conf - the configuration

addEventListener

public void addEventListener(IServiceModelEventListener listener,
                             int type)
Description copied from interface: IServiceModelManager
Adds the given listener for service model events. Has no effect if an identical listener is already registered.

Listeners can listen for several types of event as defined in IServiceModelEvent. Clients are free to register for any number of event types. Clients are guaranteed to only receive event types for which they are registered.

Specified by:
addEventListener in interface IServiceModelManager
Parameters:
listener - the listener
See Also:
IServiceModelEventListener, IServiceModelEvent, IServiceModelManager.removeEventListener(IServiceModelEventListener)

exportConfigurations

public boolean exportConfigurations(java.lang.String filename,
                                    IServiceConfiguration[] configs)
                             throws java.lang.reflect.InvocationTargetException
Description copied from interface: IServiceModelManager
Export a set of service configurations to a file.

Specified by:
exportConfigurations in interface IServiceModelManager
Returns:
service configurations to export
Throws:
java.lang.reflect.InvocationTargetException - wraps any exceptions thrown during export

getActiveConfiguration

public IServiceConfiguration getActiveConfiguration()
Description copied from interface: IServiceModelManager
Get the global "active" service configuration. The "active" configuration is an arbitrary configuration can be used by tools that do not operate on a project basis.

Specified by:
getActiveConfiguration in interface IServiceModelManager
Returns:
active service configuration, or null if no active configuration has been set

getActiveConfiguration

public IServiceConfiguration getActiveConfiguration(org.eclipse.core.resources.IProject project)
Description copied from interface: IServiceModelManager
Get the configuration that is currently active for the project. Each project has exactly one active configuration, which describes the mapping from services to service providers. By default, the first configuration created for a project will be the active configuration for that project.

Specified by:
getActiveConfiguration in interface IServiceModelManager
Parameters:
project - project for which the configuration will be obtained
Returns:
the service configuration for this project

getCategories

public java.util.Set<IServiceCategory> getCategories()
Description copied from interface: IServiceModelManager
Returns all the service categories that have been registered with the system.

Specified by:
getCategories in interface IServiceModelManager
Returns:

getConfiguration

public IServiceConfiguration getConfiguration(org.eclipse.core.resources.IProject project,
                                              java.lang.String name)
Description copied from interface: IServiceModelManager
Get the named configuration for this project.

Specified by:
getConfiguration in interface IServiceModelManager
Parameters:
project - project for which the configuration will be obtained
name - name of the configuration
Returns:
the service configuration or null if no configurations with the supplied name exist

getConfiguration

public IServiceConfiguration getConfiguration(java.lang.String id)
Description copied from interface: IServiceModelManager
Get the configuration with the specified ID.

Specified by:
getConfiguration in interface IServiceModelManager
Parameters:
id - ID of the configuration
Returns:
the service configuration or null if no configurations with the supplied ID exist

getConfigurations

public java.util.Set<IServiceConfiguration> getConfigurations()
Description copied from interface: IServiceModelManager
Get all configurations available in the workspace.

Specified by:
getConfigurations in interface IServiceModelManager
Returns:
all configurations that could be found, or an empty set

getConfigurations

public java.util.Set<IServiceConfiguration> getConfigurations(org.eclipse.core.resources.IProject project)
Description copied from interface: IServiceModelManager
Get all the configurations that are known by the project

Specified by:
getConfigurations in interface IServiceModelManager
Parameters:
project - project containing the configurations
Returns:
set of configurations known by the project

getProjectsForConfiguration

public java.util.Set<org.eclipse.core.resources.IProject> getProjectsForConfiguration(IServiceConfiguration serviceConfiguration)
Get the set of projects which use the specified service configuration

Specified by:
getProjectsForConfiguration in interface IServiceModelManager
Parameters:
serviceConfiguration - The service configuration
Returns:
Set of projects which use the service configuration

getService

public IService getService(java.lang.String id)
Description copied from interface: IServiceModelManager
Retrieves the service corresponding to a given id.

Specified by:
getService in interface IServiceModelManager
Parameters:
id - The unique id of the service to retrieve.
Returns:
IService or null

getServiceProvider

public IServiceProvider getServiceProvider(IServiceProviderDescriptor desc)
Description copied from interface: IServiceModelManager
Return a new instance of a service provider based on the descriptor.

Specified by:
getServiceProvider in interface IServiceModelManager
Parameters:
desc - extension description
Returns:
service provider

getServices

public java.util.Set<IService> getServices()
Description copied from interface: IServiceModelManager
Get all the services that have been registered with the system.

Specified by:
getServices in interface IServiceModelManager
Returns:
a set of all the services

getServices

public java.util.Set<IService> getServices(org.eclipse.core.resources.IProject project)
Description copied from interface: IServiceModelManager
Get all the services that are used by a particular project.

Specified by:
getServices in interface IServiceModelManager
Parameters:
project - project using the services
Returns:
set of services

getServices

public java.util.Set<IService> getServices(java.lang.String natureId)
Description copied from interface: IServiceModelManager
Get all the services that are associated with a project nature.

Specified by:
getServices in interface IServiceModelManager
Returns:
set of services or null

importConfigurations

public IServiceConfiguration[] importConfigurations(java.lang.String filename)
                                             throws java.lang.reflect.InvocationTargetException
Description copied from interface: IServiceModelManager
Import a set of service configurations from a file. The configurations must be added to the model using IServiceModelManager.addConfiguration(IServiceConfiguration) before they can be used. No model events will be generated while loading the configurations.

Specified by:
importConfigurations in interface IServiceModelManager
Returns:
imported service configurations
Throws:
java.lang.reflect.InvocationTargetException - wraps any exceptions thrown during import

isConfigured

public boolean isConfigured(org.eclipse.core.resources.IProject project)
Description copied from interface: IServiceModelManager
Returns true if the given project has a configuration.

Specified by:
isConfigured in interface IServiceModelManager

isValidConfigurationFile

public boolean isValidConfigurationFile(java.lang.String filename)
Description copied from interface: IServiceModelManager
Validate a set of service configurations in a file

Specified by:
isValidConfigurationFile in interface IServiceModelManager
Returns:
true if valid, false otherwise

loadModelConfiguration

public void loadModelConfiguration()
                            throws java.io.IOException,
                                   org.eclipse.core.runtime.CoreException
Replaces the current service model configuration with what is specified in the default save file. If the file does not exist then this method does nothing. This method is not meant to be called outside of the org.eclipse.ptp.services.core plugin.

Throws:
java.io.IOException
org.eclipse.core.runtime.CoreException

loadModelConfiguration

public void loadModelConfiguration(java.io.Reader reader)
                            throws java.io.IOException,
                                   org.eclipse.core.runtime.CoreException
Replaces the current service model configuration with what is specified in the given file. This method is not meant to be called outside of the org.eclipse.ptp.services.core plugin.

Throws:
java.io.IOException
org.eclipse.core.runtime.CoreException

newServiceConfiguration

public IServiceConfiguration newServiceConfiguration(java.lang.String name)
Description copied from interface: IServiceModelManager
Obtain a new service configuration with name 'name'. The name does not need to be unique. This service configuration will not become part of the service model until it is passed to one of the addConfiguration() methods.

Specified by:
newServiceConfiguration in interface IServiceModelManager
Parameters:
name - name of service configuration
Returns:
new service configuration

notifyListeners

public void notifyListeners(IServiceModelEvent event)
Notify listeners of an event occurrence. This method is not meant to be called outside of the org.eclipse.ptp.services.core plugin.

Parameters:
event - event to notify

printServiceModel

public void printServiceModel()
Prints the current service model to the console, for debugging purposes.


remap

public void remap(org.eclipse.core.resources.IProject removedProject,
                  org.eclipse.core.resources.IProject addedProject)
Description copied from interface: IServiceModelManager
Remaps all the configurations and services associated to the removed project to the added project.

Specified by:
remap in interface IServiceModelManager
Parameters:
removedProject - project removed from workspace
addedProject - project added to workspace
Since:
2.0

remove

public void remove(org.eclipse.core.resources.IProject project)
Description copied from interface: IServiceModelManager
Removes all the configurations and services associated to the given project. If the project has not been configured then this method does nothing.

Specified by:
remove in interface IServiceModelManager

remove

public void remove(IServiceConfiguration conf)
Description copied from interface: IServiceModelManager
Removes the service configuration.

Specified by:
remove in interface IServiceModelManager
Parameters:
conf - the configuration

removeConfiguration

public void removeConfiguration(org.eclipse.core.resources.IProject project,
                                IServiceConfiguration conf)
Description copied from interface: IServiceModelManager
TODO What happens if you try to remove the active configuration? TODO What happens if there are no configurations left after removing the given configuration? Remove the service configuration from a project. If the configuration was not set up on the project then this method does nothing.

Specified by:
removeConfiguration in interface IServiceModelManager
Parameters:
project - the project
conf - the configuration

removeEventListener

public void removeEventListener(IServiceModelEventListener listener)
Description copied from interface: IServiceModelManager
Removes the given listener for service model events. Has no effect if the listener is not registered.

Specified by:
removeEventListener in interface IServiceModelManager
Parameters:
listener - the listener
See Also:
IServiceModelEventListener, IServiceModelEvent, #addEventListener(IServiceModelEventListener)

saveModelConfiguration

public void saveModelConfiguration()
                            throws java.io.IOException
Saves the model configuration into the plugin's metadata area using the default file name. Will not save data for projects that do not exist. This method is not meant to be called outside of the org.eclipse.ptp.services.core plugin.

Throws:
java.io.IOException

saveModelConfiguration

public void saveModelConfiguration(java.io.Writer writer)
                            throws java.io.IOException
Saves the service model configuration to the given file. Will not save data for projects that do not exist. This method is not meant to be called outside of the org.eclipse.ptp.services.core plugin.

Parameters:
file -
Throws:
java.io.IOException
java.lang.NullPointerException - if file is null

setActiveConfiguration

public void setActiveConfiguration(org.eclipse.core.resources.IProject project,
                                   IServiceConfiguration configuration)
Description copied from interface: IServiceModelManager
Set the active configuration for a project. By default, the first configuration created for a project will be the active configuration for that project.

Specified by:
setActiveConfiguration in interface IServiceModelManager
Parameters:
project - project for which the configuration will be obtained
configuration - configuration to set as active for this project

setActiveConfiguration

public void setActiveConfiguration(IServiceConfiguration config)
Description copied from interface: IServiceModelManager
Set the global "active" service configuration. The "active" configuration is an arbitrary configuration can be used by tools that do not operate on a project basis.

Specified by:
setActiveConfiguration in interface IServiceModelManager
Parameters:
config - the service configuration to select as active

PTP
Release 7.0

Copyright (c) 2011 IBM Corporation and others. All Rights Reserved.