org.eclipse.wst.server.core
Class ServerUtil

java.lang.Object
  extended byorg.eclipse.wst.server.core.ServerUtil

public class ServerUtil
extends java.lang.Object

Server utility methods. These static methods can be used to perform common operations on server artifacts.

Since:
1.0

Method Summary
static boolean containsModule(IServer server, IModule module, IProgressMonitor monitor)
          Returns true if the given server currently contains the given module.
static IServer[] getAvailableServersForModule(IModule module, boolean includeErrors, IProgressMonitor monitor)
          Returns a list of all servers that this deployable is not currently configured on, but could be added to.
static IModule getModule(java.lang.String moduleId)
          Returns a module from the given moduleId.
static IModule[] getModules(IProject project)
          Returns the project modules attached to a project.
static IRuntime[] getRuntimes(java.lang.String type, java.lang.String version)
          Return a list of all runtime targets that match the given type and version.
static IRuntimeType[] getRuntimeTypes(java.lang.String type, java.lang.String version)
          Return a list of all runtime types that match the given type and version.
static IRuntimeType[] getRuntimeTypes(java.lang.String type, java.lang.String version, java.lang.String runtimeTypeId)
          Return a list of all runtime types that match the given type, version, and partial runtime type id.
static IServer getServer(ILaunchConfiguration configuration)
          Returns the server associated with the given launch configuration.
static IServer[] getServersByModule(IModule module, IProgressMonitor monitor)
          Returns a list of all servers that this module is configured on.
static IFile getUnusedServerFile(IProject project, IServerType type)
          Returns an unused file in the given project.
static boolean isSupportedModule(IModuleType[] moduleTypes, IModuleType mt)
          Returns true if any of the given moduleTypes match the given module type.
static boolean isSupportedModule(IModuleType[] moduleTypes, java.lang.String typeId, java.lang.String versionId)
          Returns true if any of the given moduleTypes have the given module type id and version id.
static boolean isSupportedModule(IModuleType moduleType, IModuleType mt)
          Returns true if the two given module types are compatible.
static void modifyModules(IServerWorkingCopy server, IModule[] add, IModule[] remove, IProgressMonitor monitor)
          Adds or removes modules from a server.
static void setRuntimeDefaultName(IRuntimeWorkingCopy runtime)
          Sets a default name on the given runtime.
static void setServerDefaultName(IServerWorkingCopy server)
          Sets a default name on the given server.
static IStatus validateEdit(java.lang.Object context, IServer server)
          Validates whether this server can be editted.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getModules

public static IModule[] getModules(IProject project)
Returns the project modules attached to a project.

Parameters:
project - a project
Returns:
a possibly empty array of modules

getModule

public static IModule getModule(java.lang.String moduleId)
Returns a module from the given moduleId. The moduleId must not be null.

Parameters:
moduleId - a module id
Returns:
the module, or null if the module could not be found

isSupportedModule

public static boolean isSupportedModule(IModuleType[] moduleTypes,
                                        java.lang.String typeId,
                                        java.lang.String versionId)
Returns true if any of the given moduleTypes have the given module type id and version id.

Parameters:
moduleTypes - an array of module types
typeId - a module type
versionId - a module version
Returns:
true if the module type is supported, and false otherwise

isSupportedModule

public static boolean isSupportedModule(IModuleType[] moduleTypes,
                                        IModuleType mt)
Returns true if any of the given moduleTypes match the given module type.

Parameters:
moduleTypes - an array of modules types
mt - a module type
Returns:
true if the module type is supported, and false otherwise

isSupportedModule

public static boolean isSupportedModule(IModuleType moduleType,
                                        IModuleType mt)
Returns true if the two given module types are compatible. The moduleTypes may not be null.

Parameters:
moduleType - a module type
mt - a module type
Returns:
true if the module type is supported, and false otherwise

modifyModules

public static void modifyModules(IServerWorkingCopy server,
                                 IModule[] add,
                                 IModule[] remove,
                                 IProgressMonitor monitor)
                          throws CoreException
Adds or removes modules from a server. Will search for the first parent module of each module and add it to the server instead. This method will handle multiple modules having the same parent (the parent will only be added once), but may not handle the case where the same module or parent is being both added and removed.

Parameters:
server - a server
add - an array of modules to add, or null to not add any
remove - an array of modules to remove, or null to not remove any
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Throws:
CoreException

setRuntimeDefaultName

public static void setRuntimeDefaultName(IRuntimeWorkingCopy runtime)
Sets a default name on the given runtime.

Parameters:
runtime - a runtime

setServerDefaultName

public static void setServerDefaultName(IServerWorkingCopy server)
Sets a default name on the given server.

Parameters:
server - a server

getUnusedServerFile

public static IFile getUnusedServerFile(IProject project,
                                        IServerType type)
Returns an unused file in the given project.

Parameters:
project - a project
type - a server type
Returns:
an unused file within the given project

getRuntimes

public static IRuntime[] getRuntimes(java.lang.String type,
                                     java.lang.String version)
Return a list of all runtime targets that match the given type and version. If type or version is null, it matches all of that type or version.

Parameters:
type - a module type
version - a module version
Returns:
a possibly-empty array of runtime instances IRuntime

getRuntimeTypes

public static IRuntimeType[] getRuntimeTypes(java.lang.String type,
                                             java.lang.String version)
Return a list of all runtime types that match the given type and version. If type or version is null, it matches all of that type or version.

Parameters:
type - a module type
version - a module version
Returns:
a possibly-empty array of runtime type instances IRuntimeType

getRuntimeTypes

public static IRuntimeType[] getRuntimeTypes(java.lang.String type,
                                             java.lang.String version,
                                             java.lang.String runtimeTypeId)
Return a list of all runtime types that match the given type, version, and partial runtime type id. If type, version, or runtimeTypeId is null, it matches all of that type or version.

Parameters:
type - a module type
version - a module version
runtimeTypeId - the id of a runtime type
Returns:
a possibly-empty array of runtime type instances IRuntimeType

getAvailableServersForModule

public static IServer[] getAvailableServersForModule(IModule module,
                                                     boolean includeErrors,
                                                     IProgressMonitor monitor)
Returns a list of all servers that this deployable is not currently configured on, but could be added to. If includeErrors is true, this method return servers where the parent deployable may throw errors. For instance, this deployable may be the wrong spec level.

Parameters:
module - a module
includeErrors - true to include servers that returned errors when trying to add the module, and false otherwise
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Returns:
a possibly empty array of servers

getServersByModule

public static IServer[] getServersByModule(IModule module,
                                           IProgressMonitor monitor)
Returns a list of all servers that this module is configured on.

Parameters:
module - a module
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Returns:
a possibly-empty array of server instances IServer

containsModule

public static boolean containsModule(IServer server,
                                     IModule module,
                                     IProgressMonitor monitor)
Returns true if the given server currently contains the given module.

Parameters:
server - a server
module - a module
monitor - a progress monitor, or null if progress reporting and cancellation are not desired
Returns:
boolean true if the module is contained on the server, or false otherwise

getServer

public static IServer getServer(ILaunchConfiguration configuration)
                         throws CoreException
Returns the server associated with the given launch configuration.

Parameters:
configuration - a launch configuration
Returns:
the server associated with the launch configuration, or null if no server could be found
Throws:
CoreException - if there is a problem getting the attribute from the launch configuration

validateEdit

public static IStatus validateEdit(java.lang.Object context,
                                   IServer server)
Validates whether this server can be editted.

Parameters:
context - the context (Shell)
server - the server
Returns:
a status object with code IStatus.OK if the server can be edited, otherwise a status object indicating what when wrong with the checkout