FileDocCategorySizeDatePackage
ComponentAdmin.javaAPI DocGlassfish v2 API18744Fri May 04 22:32:42 BST 2007org.apache.tools.ant.taskdefs.optional.sun.appserv

ComponentAdmin

public abstract class ComponentAdmin extends AppServerAdmin
Abstract class which includes base functionality for Tasks which utilize J2EE components. This includes support for the following component-related attributes:
  • file -- The filename of the component. Although this is often refers to a J2EE archive file, some commands may allow this attribute to refer to a directory where a J2EE archive has been exploded
  • name -- The display-name for the J2EE component. This is the "friendly name" which will appear in the admin GUI and administrative commands
  • type -- The component type. Valid types are "application", "ejb", "web", "connector" and "client"
  • force -- A boolean attribute which indicates if the command should overwrite existing values or components. Defaults to true
  • upload -- A boolean attribute which indicates if the component should be transferred to the (potentially) remote server before executing the command. If the application server is running on the local machine, this may be set to false to reduce execution time. Defaults to true
  • contextroot -- The context root for a web module (WAR file). This attribute is only used when deploying WAR files to the application server

In addition, this abstract class provides support for nested <component> elements. These nested elements enable commands to be executed using multiple components in a single Ant command. Attributes may be specified in the "root" command element and those values will be used ("inherited") by all of the nested <component> components. If an attribute is specified in both elements, the value specified in the <component> element will be used. Furthermore, this abstract class provides support for nested <fileset> elements. These may be used to match multiple components which will be used for the respective application server admin commands.

author
Greg Nelson gn@sun.com

Fields Summary
LocalStringsManager
lsm
protected Component
component
This Component instance will store user settings from the "root" command element.
protected List
components
The list of components will store user settings from nested <component> elements.
private List
filesets
The list of component archives which match a nested element.
protected static final String
TYPE_APP
protected static final String
TYPE_EJB
protected static final String
TYPE_WEB
protected static final String
TYPE_CONN
protected static final String
TYPE_CLIENT
protected static final Map
TYPE_MAP
Constants for each of the component types. In addition, the archive file extensions are mapped to their appropriate component types. Note that ".jar" maps only to EJB although this is a valid file extension for both EJB JARs and application clients.
Constructors Summary
public ComponentAdmin()
Creates a new instance with the infrastructure for running admin commands which use components (EARs, WARs, JARs, and RARs).

	 
		TYPE_MAP.put("ear", TYPE_APP);
		TYPE_MAP.put("jar", TYPE_EJB);
		TYPE_MAP.put("war", TYPE_WEB);
		TYPE_MAP.put("rar", TYPE_CONN);
	
		super();
		component = getNewComponent();
	
Methods Summary
public voidaddFileset(org.apache.tools.ant.types.FileSet fileset)
Adds a nested fileset element.

param
fileset The nested fileset component.

        filesets.add(fileset);
    
protected voidcheckComponentConfig(Server aServer, org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin$Component comp)
Verifies the options and parameters selected by the user are valid and consistent for a given server and given component.

param
aServer The server where the command will be executed.
param
comp The component which is the target of the command.

		log("Checking config for server \"" + aServer + "\" and component \""
				+ comp + "\"", Project.MSG_DEBUG);

		// if specified, file must exist (either directory or file)
		File theFile = comp.getFile();
		log("The file for this component: " + theFile, Project.MSG_DEBUG);
		if ((theFile != null) && (!theFile.exists())) {
			throw new BuildException(lsm.getString("FileCouldNotBeFound",
							       new Object[] {theFile}), 
							       getLocation());
		}

		// name must be >0 characters
		String theName = comp.getName();
		if ((theName == null) || (theName.length() == 0)) {
			throw new BuildException(lsm.getString("CouldNotDetermineComponentName"),
						 getLocation());
		}

		// type must be valid
		String theType = comp.getType();
		if ((theType != null) && (!TYPE_MAP.values().contains(theType))) {
			throw new BuildException(lsm.getString("TypeNotValid", 
							       new Object[] {theType}), 
						 getLocation());
		}

	
protected voidcheckConfiguration()

		super.checkConfiguration();

		log(components.size() + " components were found.", Project.MSG_DEBUG);

		if (components.size() == 0) {  // This isn't necessarily a failure
			log(lsm.getString("NoComponentsSpecified"), Project.MSG_WARN);
		}

	
protected voidcheckConfiguration(Server aServer)
Verifies that the options and parameters selected by the user are valid and consistent for a given server.

param
aServer The server whose configuration is to be validated.
throws
BuildException If the user selections are invalid.

		String hostname = aServer.getHost();
		if (hostname == null) {
			hostname = "localhost";
		}
		log("Checking server config for " + hostname, Project.MSG_DEBUG);

		if (!aServer.hasPassword()) {
			throw new BuildException(lsm.getString("PasswordMustBeSpecified", 
							       new Object[] {getTaskName(), 
							       hostname}), getLocation());
		}

		Iterator iterator = components.iterator();
		while (iterator.hasNext()) {  // Check the config on each component found
			Component comp = (Component)iterator.next();
			checkComponentConfig(aServer, comp);
		}
	
public org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin$ComponentcreateComponent()
Creates a nested component element.

return
Component which has been added

		Component newComponent = getNewComponent();
		components.add(newComponent);
		return newComponent;
	
protected voidexecute(Server aServer)

		Iterator iterator = components.iterator();
		while (iterator.hasNext()) {  // Execute command using each component
			Component comp = (Component)iterator.next();
			String cmdString = getCommandString(aServer, comp);
			execAdminCommand(cmdString);
		}
	
protected abstract java.lang.StringgetCommandString(Server aServer, org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin$Component comp)
Gets the Sun ONE Application Server command to be executed on the specified server for the given component.

param
aServer The server where the command will be executed.
param
comp The component which is the target of the command.

protected org.apache.tools.ant.taskdefs.optional.sun.appserv.ComponentAdmin$ComponentgetNewComponent()
Builds a new component instance. This method is intended to be overridden by subclasses which implement their own subclass of Component.

return
new Component instance.

		 return new Component(component);
	
protected voidprepareToExecute()

		super.prepareToExecute();
		processFilesets();
		if (components.size() == 0) {
			components.add(component);
		}

	
private voidprocessFilesets()
Examines each nested fileset and adds the matching files and directories to the "components" List object.

		for (int i = 0; i < filesets.size(); i++) {
			FileSet fileset = (FileSet) filesets.get(i);
			DirectoryScanner scanner = fileset.getDirectoryScanner(project);
			File baseDir = scanner.getBasedir();

			String[] files = scanner.getIncludedFiles();
			for (int j = 0; j < files.length; j++) {
				Component archive = getNewComponent();
				archive.setFile(new File(baseDir, files[j]));
				components.add(archive);
			}

			String[] dirs = scanner.getIncludedDirectories();
			for (int j = 0; j < dirs.length; j++) {
				Component expandedArchive = getNewComponent();
				expandedArchive.setFile(new File(baseDir, dirs[j]));
				components.add(expandedArchive);
			}
		}
	
public voidsetFile(java.io.File file)
Sets the filename for the component file (or directory) which is used by the administrative command.

param
file The component file archive or directory

		component.setFile(file);  // Delegates to component object
	
public voidsetName(java.lang.String name)
Sets the display-name for the J2EE component. This is the "friendly name" which will appear in the admin GUI and administrative commands

param
name The component display-name

		component.setName(name);  // Delegates to component object
	
public voidsetTarget(java.lang.String target)
Sets the deployment target.

param
target The deployment target

		component.setTarget(target);  // Delegates to component object
	
public voidsetType(java.lang.String type)
Sets the component type. Valid types are "application", "ejb", "web", "connector" and "client"

param
type The component type

		component.setType(type);  // Delegates to component object