org.eclipse.wst.server.core.model
Class ServerDelegate

java.lang.Object
  extended byorg.eclipse.wst.server.core.model.ServerDelegate

public abstract class ServerDelegate
extends java.lang.Object

A server delegate provides the implementation for various generic and server-type-specific operations for a specific type of server. A server delegate is specified by the class attribute of a serverTypes extension.

When the server instance needs to be given a delegate, the delegate class specified for the server type is instantiated with a 0-argument constructor and primed with delegate.initialize(((IServerState)server), which it is expected to hang on to. Later, when delegate.dispose() is called as the server instance is being discarded, the delegate is expected to let go of the server instance.

ServerDelegate supports an open-ended set of attribute-value pairs. All state stored in this manner will be saved when the server working copy is saved, and persisted across workbench sessions. Server delegates may keep state in instance fields, but that state is transient and will not be persisted across workbench sessions. To save state across workbench sessions, it must be persisted using the attributes.

This abstract class is intended to be extended only by clients to extend the serverTypes extension point.

Caveat: The server core API is still in an early form, and is likely to change significantly before the initial release.

Since:
1.0
See Also:
IServer, IServerWorkingCopy

Constructor Summary
ServerDelegate()
          Delegates must have a public 0-arg constructor.
 
Method Summary
abstract  IStatus canModifyModules(IModule[] add, IModule[] remove)
          Returns whether the specified module modifications could be made to this server at this time.
 void configurationChanged()
          This method is called whenever the server configuration folder has changed.
 void dispose()
          Disposes of this server delegate.
 boolean getAttribute(java.lang.String id, boolean defaultValue)
          Returns the value of the specified boolean-valued attribute.
 int getAttribute(java.lang.String id, int defaultValue)
          Returns the value of the specified int-valued attribute.
 java.util.List getAttribute(java.lang.String id, java.util.List defaultValue)
          Returns the value of the specified List-valued attribute.
 java.util.Map getAttribute(java.lang.String id, java.util.Map defaultValue)
          Returns the value of the specified Map-valued attribute.
 java.lang.String getAttribute(java.lang.String id, java.lang.String defaultValue)
          Returns the value of the specified String-valued attribute.
abstract  IModule[] getChildModules(IModule[] module)
          Returns the child module(s) of this module.
abstract  IModule[] getRootModules(IModule module)
          Returns the parent module(s) of this module.
 IServer getServer()
          Returns the server that this server delegate corresponds to.
 ServerPort[] getServerPorts()
          Returns an array of IServerPorts that this server has.
 IServerWorkingCopy getServerWorkingCopy()
          Returns the server working copy that this server delegate corresponds to.
 void importConfiguration(IRuntime runtime, IProgressMonitor monitor)
          This method is called to import the server configuration from the given runtime.
 void initialize()
          Initializes this server delegate.
 void initialize(org.eclipse.wst.server.core.internal.Server newServer)
          Initializes this server delegate with its life-long server instance.
abstract  void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor)
          Modifies the list of modules associated with the server.
 void saveConfiguration(IProgressMonitor monitor)
          This method is called whenever the server configuration should be saved.
 void setAttribute(java.lang.String id, boolean value)
          Sets the value of the specified boolean-valued attribute of this element.
 void setAttribute(java.lang.String id, int value)
          Sets the value of the specified integer-valued attribute of this element.
 void setAttribute(java.lang.String id, java.util.List value)
          Sets the value of the specified list-valued attribute of this element.
 void setAttribute(java.lang.String id, java.util.Map value)
          Sets the value of the specified map-valued attribute of this element.
 void setAttribute(java.lang.String id, java.lang.String value)
          Sets the value of the specified string-valued attribute of this element.
 void setDefaults()
          Initializes this server with default values.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerDelegate

public ServerDelegate()
Delegates must have a public 0-arg constructor.

Method Detail

initialize

public final void initialize(org.eclipse.wst.server.core.internal.Server newServer)
Initializes this server delegate with its life-long server instance.

This method is called by the server core framework. Clients should never call this method.

Parameters:
newServer - the server instance

initialize

public void initialize()
Initializes this server delegate. This method gives delegates a chance to do their own initialization.

This method is called by the server core framework. Clients should never call this method.


getServer

public IServer getServer()
Returns the server that this server delegate corresponds to.

Returns:
the server

getServerWorkingCopy

public IServerWorkingCopy getServerWorkingCopy()
Returns the server working copy that this server delegate corresponds to.

Returns:
the server

getAttribute

public int getAttribute(java.lang.String id,
                        int defaultValue)
Returns the value of the specified int-valued attribute.

Parameters:
id - the attribute id
defaultValue - the default value of the specified attribute
Returns:
the attribute value
See Also:
setAttribute(String, int)

getAttribute

public boolean getAttribute(java.lang.String id,
                            boolean defaultValue)
Returns the value of the specified boolean-valued attribute.

Parameters:
id - the attribute id
defaultValue - the default value of the specified attribute
Returns:
the attribute value
See Also:
setAttribute(String, boolean)

getAttribute

public java.lang.String getAttribute(java.lang.String id,
                                     java.lang.String defaultValue)
Returns the value of the specified String-valued attribute.

Parameters:
id - the attribute id
defaultValue - the default value of the specified attribute
Returns:
the attribute value
See Also:
setAttribute(String, String)

getAttribute

public java.util.List getAttribute(java.lang.String id,
                                   java.util.List defaultValue)
Returns the value of the specified List-valued attribute.

Parameters:
id - the attribute id
defaultValue - the default value of the specified attribute
Returns:
the attribute value
See Also:
setAttribute(String, List)

getAttribute

public java.util.Map getAttribute(java.lang.String id,
                                  java.util.Map defaultValue)
Returns the value of the specified Map-valued attribute.

Parameters:
id - the attribute id
defaultValue - the default value of the specified attribute
Returns:
the attribute value
See Also:
setAttribute(String, Map)

dispose

public void dispose()
Disposes of this server delegate.

This method is called by the web server core framework. Clients should never call this method.

Implementations are expected to let go of the delegate's reference to the server, deregister listeners, etc.


canModifyModules

public abstract IStatus canModifyModules(IModule[] add,
                                         IModule[] remove)
Returns whether the specified module modifications could be made to this server at this time. See the specification of IServerAttributes.canModifyModules(IModule[], IModule[], IProgressMonitor) for further details.

This method is called by the web server core framework, in response to a call to IServer.canModifyModules. Clients should never call this method.

[issue: See IServerAttributes.canModifyModules(IModule[], IModule[], IProgressMonitor).]

[issue: doc that it should be quick]

Parameters:
add - a possibly-empty list of modules to add
remove - a possibly-empty list of modules to remove
Returns:
a status object with code IStatus.OK if the modules can be modified, otherwise a status object indicating why they can't

getChildModules

public abstract IModule[] getChildModules(IModule[] module)
Returns the child module(s) of this module. If this module contains other modules, it should list those modules. If not, it should return an empty list.

This method should only return the direct children. To obtain the full module tree, this method may be recursively called on the children.

Parameters:
module - a module
Returns:
the child modules
See Also:
IServerAttributes.getChildModules(IModule[], IProgressMonitor)

getRootModules

public abstract IModule[] getRootModules(IModule module)
                                  throws CoreException
Returns the parent module(s) of this module. When determining if a given project can run on a server, this method will be used to find the actual module(s) that may be run on the server. For instance, a Web module may return a list of EAR modules that it is contained in if the server only supports configuring EAR modules.

If the module type is not supported, this method will return null. If the type is normally supported but there is a configuration problem or missing parent, etc., this method will fire a CoreException that may then be presented to the user.

If it does return valid parent(s), this method will always return the topmost parent module(s), even if there are a few levels (a heirarchy) of modules.

[issue: should the parameter be IModule[]?]

Parameters:
module - a module
Returns:
an array of possible root modules
Throws:
CoreException - if anything went wrong
See Also:
IServerAttributes.getRootModules(IModule, IProgressMonitor)

getServerPorts

public ServerPort[] getServerPorts()
Returns an array of IServerPorts that this server has.

Returns:
the server's ports

setDefaults

public void setDefaults()
Initializes this server with default values. This method is called when a new server is created so that the server can be initialized with meaningful values.


setAttribute

public void setAttribute(java.lang.String id,
                         int value)
Sets the value of the specified integer-valued attribute of this element.

Parameters:
id - the attribute id
value - the value of the specified attribute
See Also:
getAttribute(String, int)

setAttribute

public void setAttribute(java.lang.String id,
                         boolean value)
Sets the value of the specified boolean-valued attribute of this element.

Parameters:
id - the attribute id
value - the value of the specified attribute
See Also:
getAttribute(String, boolean)

setAttribute

public void setAttribute(java.lang.String id,
                         java.lang.String value)
Sets the value of the specified string-valued attribute of this element.

Parameters:
id - the attribute id
value - the value of the specified attribute
See Also:
getAttribute(String, String)

setAttribute

public void setAttribute(java.lang.String id,
                         java.util.List value)
Sets the value of the specified list-valued attribute of this element. The list may only contain String values.

Parameters:
id - the attribute id
value - the value of the specified attribute
See Also:
getAttribute(String, List)

setAttribute

public void setAttribute(java.lang.String id,
                         java.util.Map value)
Sets the value of the specified map-valued attribute of this element. The map may only contain String values.

Parameters:
id - the attribute id
value - the value of the specified attribute
See Also:
getAttribute(String, Map)

modifyModules

public abstract void modifyModules(IModule[] add,
                                   IModule[] remove,
                                   IProgressMonitor monitor)
                            throws CoreException
Modifies the list of modules associated with the server. See the specification of IServerWorkingCopy.modifyModules(IModule[], IModule[], IProgressMonitor) for further details.

This method is called by the web server core framework, in response to a call to IServerWorkingCopy.modifyModules. Clients should never call this method.

This method is called to update the server configuration (if any) or update the delegates internal state. Note that the actual list of modules is stored on the server and can be accessed at any time using server.getModules(). getModules() will not be updated until after this method successfully returns.

This method will not communicate with the server. After saving, publish() can be used to sync up with the server.

Parameters:
add - a possibly-empty list of modules to add
remove - a possibly-empty list of modules to remove
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Throws:
CoreException - [missing]

importConfiguration

public void importConfiguration(IRuntime runtime,
                                IProgressMonitor monitor)
This method is called to import the server configuration from the given runtime.

Parameters:
runtime - a server runtime
monitor - a progress monitor, or null if progress reporting and cancellation are not desired

saveConfiguration

public void saveConfiguration(IProgressMonitor monitor)
                       throws CoreException
This method is called whenever the server configuration should be saved.

Parameters:
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Throws:
CoreException - if there was a problem saving

configurationChanged

public void configurationChanged()
This method is called whenever the server configuration folder has changed. It gives the server a chance to throw out any old data and be ready to reload the server configuration when it is needed next.