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.
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;