FileDocCategorySizeDatePackage
CommandInfo.javaAPI DocGlassfish v2 API5751Mon May 14 15:29:52 BST 2007javax.activation

CommandInfo

public class CommandInfo extends Object
The CommandInfo class is used by CommandMap implementations to describe the results of command requests. It provides the requestor with both the verb requested, as well as an instance of the bean. There is also a method that will return the name of the class that implements the command but it is not guaranteed to return a valid value. The reason for this is to allow CommandMap implmentations that subclass CommandInfo to provide special behavior. For example a CommandMap could dynamically generate JavaBeans. In this case, it might not be possible to create an object with all the correct state information solely from the class name.

Fields Summary
private String
verb
private String
className
Constructors Summary
public CommandInfo(String verb, String className)
The Constructor for CommandInfo.

param
verb The command verb this CommandInfo decribes.
param
className The command's fully qualified class name.

	this.verb = verb;
	this.className = className;
    
Methods Summary
public java.lang.StringgetCommandClass()
Return the command's class name. This method MAY return null in cases where a CommandMap subclassed CommandInfo for its own purposes. In other words, it might not be possible to create the correct state in the command by merely knowing its class name. DO NOT DEPEND ON THIS METHOD RETURNING A VALID VALUE!

return
The class name of the command, or null

	return className;
    
public java.lang.StringgetCommandName()
Return the command verb.

return
the command verb.

	return verb;
    
public java.lang.ObjectgetCommandObject(javax.activation.DataHandler dh, java.lang.ClassLoader loader)
Return the instantiated JavaBean component.

Begin by instantiating the component with Beans.instantiate().

If the bean implements the javax.activation.CommandObject interface, call its setCommandContext method.

If the DataHandler parameter is null, then the bean is instantiated with no data. NOTE: this may be useful if for some reason the DataHandler that is passed in throws IOExceptions when this method attempts to access its InputStream. It will allow the caller to retrieve a reference to the bean if it can be instantiated.

If the bean does NOT implement the CommandObject interface, this method will check if it implements the java.io.Externalizable interface. If it does, the bean's readExternal method will be called if an InputStream can be acquired from the DataHandler.

param
dh The DataHandler that describes the data to be passed to the command.
param
loader The ClassLoader to be used to instantiate the bean.
return
The bean
see
java.beans.Beans#instantiate
see
javax.activation.CommandObject

	Object new_bean = null;

	// try to instantiate the bean
	new_bean = java.beans.Beans.instantiate(loader, className);

	// if we got one and it is a CommandObject
	if (new_bean != null) {
	    if (new_bean instanceof CommandObject) {
		((CommandObject)new_bean).setCommandContext(verb, dh);
	    } else if (new_bean instanceof Externalizable) {
		if (dh != null) {
		    InputStream is = dh.getInputStream();
		    if (is != null) {
			((Externalizable)new_bean).readExternal(
					       new ObjectInputStream(is));
		    }
		}
	    }
	}

	return new_bean;