1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
101 * interface, call its {@code setCommandContext} method.
102 * <p>
103 * If the DataHandler parameter is null, then the bean is
104 * instantiated with no data. NOTE: this may be useful
105 * if for some reason the DataHandler that is passed in
106 * throws IOExceptions when this method attempts to
107 * access its InputStream. It will allow the caller to
108 * retrieve a reference to the bean if it can be
109 * instantiated.
110 * <p>
111 * If the bean does NOT implement the CommandObject interface,
112 * this method will check if it implements the
113 * java.io.Externalizable interface. If it does, the bean's
114 * readExternal method will be called if an InputStream
115 * can be acquired from the DataHandler.<p>
116 *
117 * @param dh The DataHandler that describes the data to be
118 * passed to the command.
119 * @param loader The ClassLoader to be used to instantiate the bean.
120 * @return The bean
121 * @see java.beans.Beans#instantiate
122 * @see javax.activation.CommandObject
123 */
124 public Object getCommandObject(DataHandler dh, ClassLoader loader)
125 throws IOException, ClassNotFoundException {
126 Object new_bean = null;
127
128 // try to instantiate the bean
129 new_bean = Beans.instantiate(loader, className);
130
131 // if we got one and it is a CommandObject
132 if (new_bean != null) {
133 if (new_bean instanceof CommandObject) {
134 ((CommandObject)new_bean).setCommandContext(verb, dh);
135 } else if (new_bean instanceof Externalizable) {
136 if (dh != null) {
137 InputStream is = dh.getInputStream();
138 if (is != null) {
139 ((Externalizable)new_bean).readExternal(
140 new ObjectInputStream(is));
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
101 * interface, call its {@code setCommandContext} method.
102 * <p>
103 * If the DataHandler parameter is null, then the bean is
104 * instantiated with no data. NOTE: this may be useful
105 * if for some reason the DataHandler that is passed in
106 * throws IOExceptions when this method attempts to
107 * access its InputStream. It will allow the caller to
108 * retrieve a reference to the bean if it can be
109 * instantiated.
110 * <p>
111 * If the bean does NOT implement the CommandObject interface,
112 * this method will check if it implements the
113 * java.io.Externalizable interface. If it does, the bean's
114 * readExternal method will be called if an InputStream
115 * can be acquired from the DataHandler.<p>
116 *
117 * @param dh The DataHandler that describes the data to be
118 * passed to the command.
119 * @param loader The ClassLoader to be used to instantiate the bean.
120 * @return The bean
121 * @exception IOException for failures reading data
122 * @exception ClassNotFoundException if command object class can't
123 * be found
124 * @see java.beans.Beans#instantiate
125 * @see javax.activation.CommandObject
126 */
127 public Object getCommandObject(DataHandler dh, ClassLoader loader)
128 throws IOException, ClassNotFoundException {
129 Object new_bean = null;
130
131 // try to instantiate the bean
132 new_bean = Beans.instantiate(loader, className);
133
134 // if we got one and it is a CommandObject
135 if (new_bean != null) {
136 if (new_bean instanceof CommandObject) {
137 ((CommandObject)new_bean).setCommandContext(verb, dh);
138 } else if (new_bean instanceof Externalizable) {
139 if (dh != null) {
140 InputStream is = dh.getInputStream();
141 if (is != null) {
142 ((Externalizable)new_bean).readExternal(
143 new ObjectInputStream(is));
|