org.csstudio.startup.application
Class Application

java.lang.Object
  extended by org.csstudio.startup.application.Application

public class Application
extends java.lang.Object

Application is the default implementation of the IApplication interface which acts a an entry point for the Control System Studio. This class uses several extension points through which the user can provide his own code how certain aspects should be handled during the star-up of the application or if they should be handled at all.

This implementation defines the action and the sequence in which the extension points will be executed. For details see #startApplication(IApplicationContext, Display).

Version:
$Revision$
Author:
Alexander Will, Kay Kasemir, Xihui Chen, Jaka Bobnar (code unification, extension points)

Field Summary
protected  java.util.HashMap<java.lang.Class<? extends CSSStartupExtensionPoint>,CSSStartupExtensionPoint[]> configurationElements
          The map of all loaded extension points.
protected  java.util.Map<java.lang.String,java.lang.Object> parameters
          The list of all parameters read at start-up and any other parameters which were created later on during the execution of this application
 
Constructor Summary
Application()
           
 
Method Summary
protected  java.lang.Object applyLocaleSetting(IApplicationContext context)
          Applies the locale setting.
protected  java.lang.Object closeProjects(Display display, IApplicationContext context)
          Loads the ProjectExtPoint and executes the ProjectExtPoint#closeProjects(IApplicationContext) method.
protected  void closeWorkbench()
          This method is called as the last executed action when the application is stopped.
protected  void errorExecutingExtensionPoint(java.lang.String name, java.lang.Throwable t)
          This is a utility method which logs the error that happens during the execution of one of the extension points.
protected
<T extends CSSStartupExtensionPoint>
T[]
getExtensionPoints(java.lang.Class<T> type, java.lang.String name)
          Gathers the loaded extension points which match the parameter criteria.
protected  java.lang.Object openProjects(Display display, IApplicationContext context)
          Loads the ProjectExtPoint and executes the ProjectExtPoint#openProjects(IApplicationContext) method.
protected  java.lang.Object promptForLogin(Display display, IApplicationContext context)
          Loads the LoginExtPoint and executes the LoginExtPoint.login(Display, IApplicationContext, Map) method.
protected  java.lang.Object promptForWorkspace(Display display, IApplicationContext context)
          Loads the WorkspaceExtPoint and executes WorkspaceExtPoint.promptForWorkspace(Display, IApplicationContext, Map) method.
protected  java.util.Map<java.lang.String,java.lang.Object> readStartupParameters(Display display, IApplicationContext context)
          Reads all the startup parameters and returns them in a map.
 java.lang.Object start(IApplicationContext context)
          
protected  java.lang.Object startApplication(IApplicationContext context, Display display, OpenDocumentEventProcessor openDocProcessor)
          Initializes the application.
protected  java.lang.Object startServices(Display display, IApplicationContext context)
          Loads the ServicesStartupExtPoint and executes ServicesStartupExtPoint#startServices(IApplicationContext).
 void stop()
          
protected  void stopApplication()
          Loads all ShutDownExtPoints and executes the ShutDownExtPoint#beforeShutDown() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

protected java.util.Map<java.lang.String,java.lang.Object> parameters
The list of all parameters read at start-up and any other parameters which were created later on during the execution of this application


configurationElements

protected java.util.HashMap<java.lang.Class<? extends CSSStartupExtensionPoint>,CSSStartupExtensionPoint[]> configurationElements
The map of all loaded extension points. When an extension point is requested this map is first searched for the particular type of extension point. If found it is returned otherwise the extension points are loaded using the eclipse loaded (@see getExtensionPoints(Class, String)).

Constructor Detail

Application

public Application()
Method Detail

start

public java.lang.Object start(IApplicationContext context)
                       throws java.lang.Exception

Throws:
java.lang.Exception

startApplication

protected java.lang.Object startApplication(IApplicationContext context,
                                            Display display,
                                            OpenDocumentEventProcessor openDocProcessor)
                                     throws java.lang.Exception
Initializes the application. Method consequently executes all other 'segments' of this class. The sequence is the following: To change the order in which the segments are executes override this method.

The default implementations of the methods listed above make the calls to appropriate extension points. If one of the extension points returns an exit code this method will terminate the operation and return that code immediately. If everything went the appropriate exit code as returned by the #startWorkbench(Display, IApplicationContext) is returned.

Parameters:
context - this application's context
display - the display of the application
openDocProcessor -
Returns:
the exit code of any of the first executed segment that provided one. If no other exit code is given the code returned by #startWorkbench(Display, IApplicationContext) is returned by this method.
Throws:
java.lang.Exception - if anything went wrong during the execution of any of the segments

stop

public void stop()


applyLocaleSetting

protected java.lang.Object applyLocaleSetting(IApplicationContext context)
                                       throws java.lang.Exception
Applies the locale setting. Loads the LocaleSettingsExtPoint and executes the LocaleSettingsExtPoint#applyLocaleSetting() method.

Parameters:
context - the context of this application
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

readStartupParameters

protected java.util.Map<java.lang.String,java.lang.Object> readStartupParameters(Display display,
                                                                                 IApplicationContext context)
                                                                          throws java.lang.Exception
Reads all the startup parameters and returns them in a map. This map will be passed to other extension points, which can use the parameters loaded by this extension point.

Parameters:
display - the display of the application
context - the application's context
Returns:
the map with all parameters
Throws:
java.lang.Exception

promptForLogin

protected java.lang.Object promptForLogin(Display display,
                                          IApplicationContext context)
                                   throws java.lang.Exception
Loads the LoginExtPoint and executes the LoginExtPoint.login(Display, IApplicationContext, Map) method. It is expected that after the execution of this method the user is logged into the application and has the appropriate access rights requested by the setup of this application.

Parameters:
display - the display of this application
context - the application's context
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

promptForWorkspace

protected java.lang.Object promptForWorkspace(Display display,
                                              IApplicationContext context)
                                       throws java.lang.Exception
Loads the WorkspaceExtPoint and executes WorkspaceExtPoint.promptForWorkspace(Display, IApplicationContext, Map) method. After the execution the workspace for the application should be selected. There can be only one extension point of this type in the application. If no extension points are defined the application will load the default workspace as specified and by this rcp.

Parameters:
display - the display of this application
context - this application's context
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

startServices

protected java.lang.Object startServices(Display display,
                                         IApplicationContext context)
                                  throws java.lang.Exception
Loads the ServicesStartupExtPoint and executes ServicesStartupExtPoint#startServices(IApplicationContext).

Parameters:
display - the display of this application
context - this application's context
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

openProjects

protected java.lang.Object openProjects(Display display,
                                        IApplicationContext context)
                                 throws java.lang.Exception
Loads the ProjectExtPoint and executes the ProjectExtPoint#openProjects(IApplicationContext) method.

Parameters:
display - the display of this application
context - this application's context
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

closeProjects

protected java.lang.Object closeProjects(Display display,
                                         IApplicationContext context)
                                  throws java.lang.Exception
Loads the ProjectExtPoint and executes the ProjectExtPoint#closeProjects(IApplicationContext) method.

Parameters:
display - the display of this application
context - this application's context
Returns:
potential exit code (null if everything is ok)
Throws:
java.lang.Exception

stopApplication

protected void stopApplication()
Loads all ShutDownExtPoints and executes the ShutDownExtPoint#beforeShutDown() method.


closeWorkbench

protected void closeWorkbench()
This method is called as the last executed action when the application is stopped. It closes the active workbench. This action is not made as an extension points because it should be executed at each exit of the application.


getExtensionPoints

protected <T extends CSSStartupExtensionPoint> T[] getExtensionPoints(java.lang.Class<T> type,
                                                                      java.lang.String name)
Gathers the loaded extension points which match the parameter criteria.

Type Parameters:
T - the type of the extension point requested
Parameters:
type - the interface/implementation that defines this type
name - the name of the extension point element ("locale", "project", "startupParameters", ...)
Returns:
the array of extension points for that element that have the correct type

errorExecutingExtensionPoint

protected void errorExecutingExtensionPoint(java.lang.String name,
                                            java.lang.Throwable t)
This is a utility method which logs the error that happens during the execution of one of the extension points.

Parameters:
name - the name of the extension point
t - the exception that occurred during execution (could be null)