Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaf_classes/javax/activation/CommandInfo.java
38874 views
/*1* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.activation;2627import java.io.*;28import java.beans.Beans;2930/**31* The CommandInfo class is used by CommandMap implementations to32* describe the results of command requests. It provides the requestor33* with both the verb requested, as well as an instance of the34* bean. There is also a method that will return the name of the35* class that implements the command but <i>it is not guaranteed to36* return a valid value</i>. The reason for this is to allow CommandMap37* implmentations that subclass CommandInfo to provide special38* behavior. For example a CommandMap could dynamically generate39* JavaBeans. In this case, it might not be possible to create an40* object with all the correct state information solely from the class41* name.42*43* @since 1.644*/4546public class CommandInfo {47private String verb;48private String className;4950/**51* The Constructor for CommandInfo.52* @param verb The command verb this CommandInfo decribes.53* @param className The command's fully qualified class name.54*/55public CommandInfo(String verb, String className) {56this.verb = verb;57this.className = className;58}5960/**61* Return the command verb.62*63* @return the command verb.64*/65public String getCommandName() {66return verb;67}6869/**70* Return the command's class name. <i>This method MAY return null in71* cases where a CommandMap subclassed CommandInfo for its72* own purposes.</i> In other words, it might not be possible to73* create the correct state in the command by merely knowing74* its class name. <b>DO NOT DEPEND ON THIS METHOD RETURNING75* A VALID VALUE!</b>76*77* @return The class name of the command, or <i>null</i>78*/79public String getCommandClass() {80return className;81}8283/**84* Return the instantiated JavaBean component.85* <p>86* Begin by instantiating the component with87* <code>Beans.instantiate()</code>.88* <p>89* If the bean implements the <code>javax.activation.CommandObject</code>90* interface, call its <code>setCommandContext</code> method.91* <p>92* If the DataHandler parameter is null, then the bean is93* instantiated with no data. NOTE: this may be useful94* if for some reason the DataHandler that is passed in95* throws IOExceptions when this method attempts to96* access its InputStream. It will allow the caller to97* retrieve a reference to the bean if it can be98* instantiated.99* <p>100* If the bean does NOT implement the CommandObject interface,101* this method will check if it implements the102* java.io.Externalizable interface. If it does, the bean's103* readExternal method will be called if an InputStream104* can be acquired from the DataHandler.<p>105*106* @param dh The DataHandler that describes the data to be107* passed to the command.108* @param loader The ClassLoader to be used to instantiate the bean.109* @return The bean110* @see java.beans.Beans#instantiate111* @see javax.activation.CommandObject112*/113public Object getCommandObject(DataHandler dh, ClassLoader loader)114throws IOException, ClassNotFoundException {115Object new_bean = null;116117// try to instantiate the bean118new_bean = java.beans.Beans.instantiate(loader, className);119120// if we got one and it is a CommandObject121if (new_bean != null) {122if (new_bean instanceof CommandObject) {123((CommandObject)new_bean).setCommandContext(verb, dh);124} else if (new_bean instanceof Externalizable) {125if (dh != null) {126InputStream is = dh.getInputStream();127if (is != null) {128((Externalizable)new_bean).readExternal(129new ObjectInputStream(is));130}131}132}133}134135return new_bean;136}137}138139140