4
|
1 |
/*
|
5555
|
2 |
* Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
|
4
|
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
|
5555
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
4
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5555
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
4
|
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 |
*
|
5555
|
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
|
|
23 |
* questions.
|
4
|
24 |
*/
|
|
25 |
/*
|
|
26 |
* Licensed Materials - Property of IBM
|
|
27 |
* RMI-IIOP v1.0
|
|
28 |
* Copyright IBM Corp. 1998 1999 All Rights Reserved
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
package com.sun.corba.se.impl.io;
|
|
33 |
|
|
34 |
import javax.rmi.CORBA.Util;
|
|
35 |
import javax.rmi.PortableRemoteObject;
|
|
36 |
|
|
37 |
import java.util.Hashtable;
|
|
38 |
import java.util.Stack;
|
|
39 |
import java.io.IOException;
|
|
40 |
import java.util.EmptyStackException;
|
|
41 |
|
|
42 |
import com.sun.corba.se.impl.util.Utility;
|
|
43 |
import com.sun.corba.se.impl.io.IIOPInputStream;
|
|
44 |
import com.sun.corba.se.impl.io.IIOPOutputStream;
|
|
45 |
import com.sun.corba.se.impl.util.RepositoryId;
|
|
46 |
import com.sun.corba.se.impl.util.Utility;
|
|
47 |
|
|
48 |
import org.omg.CORBA.TCKind;
|
|
49 |
|
|
50 |
import org.omg.CORBA.MARSHAL;
|
|
51 |
import org.omg.CORBA.BAD_PARAM;
|
|
52 |
import org.omg.CORBA.CompletionStatus;
|
|
53 |
import org.omg.CORBA.portable.IndirectionException;
|
|
54 |
import com.sun.org.omg.SendingContext.CodeBase;
|
|
55 |
import com.sun.org.omg.SendingContext.CodeBaseHelper;
|
|
56 |
|
|
57 |
import java.security.AccessController;
|
|
58 |
import java.security.PrivilegedAction;
|
|
59 |
|
|
60 |
import com.sun.corba.se.impl.io.IIOPInputStream.ActiveRecursionManager;
|
|
61 |
|
|
62 |
import com.sun.corba.se.spi.logging.CORBALogDomains;
|
|
63 |
import com.sun.corba.se.impl.logging.OMGSystemException;
|
|
64 |
import com.sun.corba.se.impl.logging.UtilSystemException;
|
|
65 |
|
|
66 |
public class ValueHandlerImpl implements javax.rmi.CORBA.ValueHandlerMultiFormat {
|
|
67 |
|
|
68 |
// Property to override our maximum stream format version
|
|
69 |
public static final String FORMAT_VERSION_PROPERTY
|
|
70 |
= "com.sun.CORBA.MaxStreamFormatVersion";
|
|
71 |
|
|
72 |
private static final byte MAX_SUPPORTED_FORMAT_VERSION = (byte)2;
|
|
73 |
private static final byte STREAM_FORMAT_VERSION_1 = (byte)1;
|
|
74 |
|
|
75 |
// The ValueHandler's maximum stream format version to advertise,
|
|
76 |
// set in a static initializer.
|
|
77 |
private static final byte MAX_STREAM_FORMAT_VERSION;
|
|
78 |
|
|
79 |
static {
|
|
80 |
MAX_STREAM_FORMAT_VERSION = getMaxStreamFormatVersion();
|
|
81 |
}
|
|
82 |
|
|
83 |
// Looks for the FORMAT_VERSION_PROPERTY system property
|
|
84 |
// to allow the user to override our default stream format
|
|
85 |
// version. Note that this still only allows them to pick
|
|
86 |
// a supported version (1 through MAX_STREAM_FORMAT_VERSION).
|
|
87 |
private static byte getMaxStreamFormatVersion() {
|
|
88 |
|
|
89 |
try {
|
|
90 |
|
|
91 |
String propValue = (String) AccessController.doPrivileged(
|
|
92 |
new PrivilegedAction() {
|
|
93 |
public java.lang.Object run() {
|
|
94 |
return System.getProperty(ValueHandlerImpl.FORMAT_VERSION_PROPERTY);
|
|
95 |
}
|
|
96 |
});
|
|
97 |
|
|
98 |
// The property wasn't set
|
|
99 |
if (propValue == null)
|
|
100 |
return MAX_SUPPORTED_FORMAT_VERSION;
|
|
101 |
|
|
102 |
byte result = Byte.parseByte(propValue);
|
|
103 |
|
|
104 |
// REVISIT. Just set to MAX_SUPPORTED_FORMAT_VERSION
|
|
105 |
// or really let the system shutdown with this Error?
|
|
106 |
if (result < 1 || result > MAX_SUPPORTED_FORMAT_VERSION)
|
|
107 |
// XXX I18N, logging needed.
|
|
108 |
throw new ExceptionInInitializerError("Invalid stream format version: "
|
|
109 |
+ result
|
|
110 |
+ ". Valid range is 1 through "
|
|
111 |
+ MAX_SUPPORTED_FORMAT_VERSION);
|
|
112 |
|
|
113 |
return result;
|
|
114 |
|
|
115 |
} catch (Exception ex) {
|
|
116 |
// REVISIT. Swallow this or really let
|
|
117 |
// the system shutdown with this Error?
|
|
118 |
|
|
119 |
Error err = new ExceptionInInitializerError(ex);
|
|
120 |
err.initCause( ex ) ;
|
|
121 |
throw err ;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
public static final short kRemoteType = 0;
|
|
126 |
public static final short kAbstractType = 1;
|
|
127 |
public static final short kValueType = 2;
|
|
128 |
|
|
129 |
private Hashtable inputStreamPairs = null;
|
|
130 |
private Hashtable outputStreamPairs = null;
|
|
131 |
private CodeBase codeBase = null;
|
|
132 |
private boolean useHashtables = true;
|
|
133 |
private boolean isInputStream = true;
|
|
134 |
private IIOPOutputStream outputStreamBridge = null;
|
|
135 |
private IIOPInputStream inputStreamBridge = null;
|
|
136 |
private OMGSystemException omgWrapper = OMGSystemException.get(
|
|
137 |
CORBALogDomains.RPC_ENCODING ) ;
|
|
138 |
private UtilSystemException utilWrapper = UtilSystemException.get(
|
|
139 |
CORBALogDomains.RPC_ENCODING ) ;
|
|
140 |
|
|
141 |
// See javax.rmi.CORBA.ValueHandlerMultiFormat
|
|
142 |
public byte getMaximumStreamFormatVersion() {
|
|
143 |
return MAX_STREAM_FORMAT_VERSION;
|
|
144 |
}
|
|
145 |
|
|
146 |
// See javax.rmi.CORBA.ValueHandlerMultiFormat
|
|
147 |
public void writeValue(org.omg.CORBA.portable.OutputStream out,
|
|
148 |
java.io.Serializable value,
|
|
149 |
byte streamFormatVersion) {
|
|
150 |
|
|
151 |
if (streamFormatVersion == 2) {
|
|
152 |
if (!(out instanceof org.omg.CORBA.portable.ValueOutputStream)) {
|
|
153 |
throw omgWrapper.notAValueoutputstream() ;
|
|
154 |
}
|
|
155 |
} else if (streamFormatVersion != 1) {
|
|
156 |
throw omgWrapper.invalidStreamFormatVersion(
|
|
157 |
new Integer(streamFormatVersion) ) ;
|
|
158 |
}
|
|
159 |
|
|
160 |
writeValueWithVersion(out, value, streamFormatVersion);
|
|
161 |
}
|
|
162 |
|
|
163 |
public ValueHandlerImpl(){}
|
|
164 |
|
|
165 |
public ValueHandlerImpl(boolean isInputStream) {
|
|
166 |
this();
|
|
167 |
useHashtables = false;
|
|
168 |
this.isInputStream = isInputStream;
|
|
169 |
}
|
|
170 |
|
|
171 |
/**
|
|
172 |
* Writes the value to the stream using java semantics.
|
|
173 |
* @param out The stream to write the value to
|
|
174 |
* @param value The value to be written to the stream
|
|
175 |
**/
|
|
176 |
public void writeValue(org.omg.CORBA.portable.OutputStream _out,
|
|
177 |
java.io.Serializable value) {
|
|
178 |
writeValueWithVersion(_out, value, STREAM_FORMAT_VERSION_1);
|
|
179 |
}
|
|
180 |
|
|
181 |
private void writeValueWithVersion(org.omg.CORBA.portable.OutputStream _out,
|
|
182 |
java.io.Serializable value,
|
|
183 |
byte streamFormatVersion) {
|
|
184 |
|
|
185 |
org.omg.CORBA_2_3.portable.OutputStream out =
|
|
186 |
(org.omg.CORBA_2_3.portable.OutputStream) _out;
|
|
187 |
|
|
188 |
if (!useHashtables) {
|
|
189 |
if (outputStreamBridge == null) {
|
|
190 |
outputStreamBridge = createOutputStream();
|
|
191 |
outputStreamBridge.setOrbStream(out);
|
|
192 |
}
|
|
193 |
|
|
194 |
try {
|
|
195 |
outputStreamBridge.increaseRecursionDepth();
|
|
196 |
writeValueInternal(outputStreamBridge, out, value, streamFormatVersion);
|
|
197 |
} finally {
|
|
198 |
outputStreamBridge.decreaseRecursionDepth();
|
|
199 |
}
|
|
200 |
|
|
201 |
return;
|
|
202 |
}
|
|
203 |
|
|
204 |
IIOPOutputStream jdkToOrbOutputStreamBridge = null;
|
|
205 |
|
|
206 |
if (outputStreamPairs == null)
|
|
207 |
outputStreamPairs = new Hashtable();
|
|
208 |
|
|
209 |
jdkToOrbOutputStreamBridge = (IIOPOutputStream)outputStreamPairs.get(_out);
|
|
210 |
|
|
211 |
if (jdkToOrbOutputStreamBridge == null) {
|
|
212 |
jdkToOrbOutputStreamBridge = createOutputStream();
|
|
213 |
jdkToOrbOutputStreamBridge.setOrbStream(out);
|
|
214 |
outputStreamPairs.put(_out, jdkToOrbOutputStreamBridge);
|
|
215 |
}
|
|
216 |
|
|
217 |
try {
|
|
218 |
|
|
219 |
jdkToOrbOutputStreamBridge.increaseRecursionDepth();
|
|
220 |
writeValueInternal(jdkToOrbOutputStreamBridge, out, value, streamFormatVersion);
|
|
221 |
} finally {
|
|
222 |
if (jdkToOrbOutputStreamBridge.decreaseRecursionDepth() == 0) {
|
|
223 |
outputStreamPairs.remove(_out);
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
private void writeValueInternal(IIOPOutputStream bridge,
|
|
229 |
org.omg.CORBA_2_3.portable.OutputStream out,
|
|
230 |
java.io.Serializable value,
|
|
231 |
byte streamFormatVersion)
|
|
232 |
{
|
|
233 |
Class clazz = value.getClass();
|
|
234 |
|
|
235 |
if (clazz.isArray())
|
|
236 |
write_Array(out, value, clazz.getComponentType());
|
|
237 |
else
|
|
238 |
bridge.simpleWriteObject(value, streamFormatVersion);
|
|
239 |
}
|
|
240 |
|
|
241 |
/**
|
|
242 |
* Reads a value from the stream using java semantics.
|
|
243 |
* @param in The stream to read the value from
|
|
244 |
* @param clazz The type of the value to be read in
|
|
245 |
* @param sender The sending context runtime
|
|
246 |
**/
|
|
247 |
public java.io.Serializable readValue(org.omg.CORBA.portable.InputStream _in,
|
|
248 |
int offset,
|
|
249 |
java.lang.Class clazz,
|
|
250 |
String repositoryID,
|
|
251 |
org.omg.SendingContext.RunTime _sender)
|
|
252 |
{
|
|
253 |
// Must use narrow rather than a direct cast to a com.sun
|
|
254 |
// class. Fix for bug 4379539.
|
|
255 |
CodeBase sender = CodeBaseHelper.narrow(_sender);
|
|
256 |
|
|
257 |
org.omg.CORBA_2_3.portable.InputStream in =
|
|
258 |
(org.omg.CORBA_2_3.portable.InputStream) _in;
|
|
259 |
|
|
260 |
if (!useHashtables) {
|
|
261 |
if (inputStreamBridge == null) {
|
|
262 |
inputStreamBridge = createInputStream();
|
|
263 |
inputStreamBridge.setOrbStream(in);
|
|
264 |
inputStreamBridge.setSender(sender); //d11638
|
|
265 |
// backward compatability 4365188
|
|
266 |
inputStreamBridge.setValueHandler(this);
|
|
267 |
}
|
|
268 |
|
|
269 |
java.io.Serializable result = null;
|
|
270 |
|
|
271 |
try {
|
|
272 |
|
|
273 |
inputStreamBridge.increaseRecursionDepth();
|
|
274 |
result = (java.io.Serializable) readValueInternal(inputStreamBridge, in, offset, clazz, repositoryID, sender);
|
|
275 |
|
|
276 |
} finally {
|
|
277 |
|
|
278 |
if (inputStreamBridge.decreaseRecursionDepth() == 0) {
|
|
279 |
// Indirections are resolved immediately since
|
|
280 |
// the change to the active recursion manager,
|
|
281 |
// so this will never happen.
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
return result;
|
|
286 |
}
|
|
287 |
|
|
288 |
IIOPInputStream jdkToOrbInputStreamBridge = null;
|
|
289 |
if (inputStreamPairs == null)
|
|
290 |
inputStreamPairs = new Hashtable();
|
|
291 |
|
|
292 |
jdkToOrbInputStreamBridge = (IIOPInputStream)inputStreamPairs.get(_in);
|
|
293 |
|
|
294 |
if (jdkToOrbInputStreamBridge == null) {
|
|
295 |
|
|
296 |
jdkToOrbInputStreamBridge = createInputStream();
|
|
297 |
jdkToOrbInputStreamBridge.setOrbStream(in);
|
|
298 |
jdkToOrbInputStreamBridge.setSender(sender); //d11638
|
|
299 |
// backward compatability 4365188
|
|
300 |
jdkToOrbInputStreamBridge.setValueHandler(this);
|
|
301 |
inputStreamPairs.put(_in, jdkToOrbInputStreamBridge);
|
|
302 |
}
|
|
303 |
|
|
304 |
java.io.Serializable result = null;
|
|
305 |
|
|
306 |
try {
|
|
307 |
|
|
308 |
jdkToOrbInputStreamBridge.increaseRecursionDepth();
|
|
309 |
result = (java.io.Serializable) readValueInternal(jdkToOrbInputStreamBridge, in, offset, clazz, repositoryID, sender);
|
|
310 |
|
|
311 |
} finally {
|
|
312 |
|
|
313 |
if (jdkToOrbInputStreamBridge.decreaseRecursionDepth() == 0) {
|
|
314 |
inputStreamPairs.remove(_in);
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
return result;
|
|
319 |
}
|
|
320 |
|
|
321 |
private java.io.Serializable readValueInternal(IIOPInputStream bridge,
|
|
322 |
org.omg.CORBA_2_3.portable.InputStream in,
|
|
323 |
int offset,
|
|
324 |
java.lang.Class clazz,
|
|
325 |
String repositoryID,
|
|
326 |
com.sun.org.omg.SendingContext.CodeBase sender)
|
|
327 |
{
|
|
328 |
java.io.Serializable result = null;
|
|
329 |
|
|
330 |
if (clazz == null) {
|
|
331 |
// clazz == null indicates an FVD situation for a nonexistant class
|
|
332 |
if (isArray(repositoryID)){
|
|
333 |
read_Array(bridge, in, null, sender, offset);
|
|
334 |
} else {
|
|
335 |
bridge.simpleSkipObject(repositoryID, sender);
|
|
336 |
}
|
|
337 |
return result;
|
|
338 |
}
|
|
339 |
|
|
340 |
if (clazz.isArray()) {
|
|
341 |
result = (java.io.Serializable)read_Array(bridge, in, clazz, sender, offset);
|
|
342 |
} else {
|
|
343 |
result = (java.io.Serializable)bridge.simpleReadObject(clazz, repositoryID, sender, offset);
|
|
344 |
}
|
|
345 |
|
|
346 |
return result;
|
|
347 |
}
|
|
348 |
|
|
349 |
/**
|
|
350 |
* Returns the repository ID for the given RMI value Class.
|
|
351 |
* @param clz The class to return a repository ID for.
|
|
352 |
* @return the repository ID of the Class.
|
|
353 |
**/
|
|
354 |
public java.lang.String getRMIRepositoryID(java.lang.Class clz) {
|
|
355 |
return RepositoryId.createForJavaType(clz);
|
|
356 |
}
|
|
357 |
|
|
358 |
/**
|
|
359 |
* Indicates whether the given Class performs custom or
|
|
360 |
* default marshaling.
|
|
361 |
* @param clz The class to test for custom marshaling.
|
|
362 |
* @return True if the class performs custom marshaling, false
|
|
363 |
* if it does not.
|
|
364 |
**/
|
|
365 |
public boolean isCustomMarshaled(java.lang.Class clz) {
|
|
366 |
return ObjectStreamClass.lookup(clz).isCustomMarshaled();
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
|
370 |
* Returns the CodeBase for this ValueHandler. This is used by
|
|
371 |
* the ORB runtime. The server sends the service context containing
|
|
372 |
* the IOR for this CodeBase on the first GIOP reply. The clients
|
|
373 |
* do the same on the first GIOP request.
|
|
374 |
* @return the SendingContext.CodeBase of this ValueHandler.
|
|
375 |
**/
|
|
376 |
public org.omg.SendingContext.RunTime getRunTimeCodeBase() {
|
|
377 |
if (codeBase != null)
|
|
378 |
return codeBase;
|
|
379 |
else {
|
|
380 |
codeBase = new FVDCodeBaseImpl();
|
|
381 |
|
|
382 |
// backward compatability 4365188
|
|
383 |
// set the valueHandler so that correct/incorrect RepositoryID
|
|
384 |
// calculations can be done based on the ORB version
|
|
385 |
FVDCodeBaseImpl fvdImpl = (FVDCodeBaseImpl) codeBase;
|
|
386 |
fvdImpl.setValueHandler(this);
|
|
387 |
return codeBase;
|
|
388 |
}
|
|
389 |
}
|
|
390 |
|
|
391 |
|
|
392 |
// methods supported for backward compatability so that the appropriate
|
|
393 |
// Rep-id calculations take place based on the ORB version
|
|
394 |
|
|
395 |
/**
|
|
396 |
* Returns a boolean of whether or not RepositoryId indicates
|
|
397 |
* FullValueDescriptor.
|
|
398 |
* used for backward compatability
|
|
399 |
*/
|
|
400 |
|
|
401 |
public boolean useFullValueDescription(Class clazz, String repositoryID)
|
|
402 |
throws IOException
|
|
403 |
{
|
|
404 |
return RepositoryId.useFullValueDescription(clazz, repositoryID);
|
|
405 |
}
|
|
406 |
|
|
407 |
public String getClassName(String id)
|
|
408 |
{
|
|
409 |
RepositoryId repID = RepositoryId.cache.getId(id);
|
|
410 |
return repID.getClassName();
|
|
411 |
}
|
|
412 |
|
|
413 |
public Class getClassFromType(String id)
|
|
414 |
throws ClassNotFoundException
|
|
415 |
{
|
|
416 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
417 |
return repId.getClassFromType();
|
|
418 |
}
|
|
419 |
|
|
420 |
public Class getAnyClassFromType(String id)
|
|
421 |
throws ClassNotFoundException
|
|
422 |
{
|
|
423 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
424 |
return repId.getAnyClassFromType();
|
|
425 |
}
|
|
426 |
|
|
427 |
public String createForAnyType(Class cl)
|
|
428 |
{
|
|
429 |
return RepositoryId.createForAnyType(cl);
|
|
430 |
}
|
|
431 |
|
|
432 |
public String getDefinedInId(String id)
|
|
433 |
{
|
|
434 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
435 |
return repId.getDefinedInId();
|
|
436 |
}
|
|
437 |
|
|
438 |
public String getUnqualifiedName(String id)
|
|
439 |
{
|
|
440 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
441 |
return repId.getUnqualifiedName();
|
|
442 |
}
|
|
443 |
|
|
444 |
public String getSerialVersionUID(String id)
|
|
445 |
{
|
|
446 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
447 |
return repId.getSerialVersionUID();
|
|
448 |
}
|
|
449 |
|
|
450 |
|
|
451 |
public boolean isAbstractBase(Class clazz)
|
|
452 |
{
|
|
453 |
return RepositoryId.isAbstractBase(clazz);
|
|
454 |
}
|
|
455 |
|
|
456 |
public boolean isSequence(String id)
|
|
457 |
{
|
|
458 |
RepositoryId repId = RepositoryId.cache.getId(id);
|
|
459 |
return repId.isSequence();
|
|
460 |
}
|
|
461 |
|
|
462 |
/**
|
|
463 |
* If the value contains a writeReplace method then the result
|
|
464 |
* is returned. Otherwise, the value itself is returned.
|
|
465 |
* @return the true value to marshal on the wire.
|
|
466 |
**/
|
|
467 |
public java.io.Serializable writeReplace(java.io.Serializable value) {
|
|
468 |
return ObjectStreamClass.lookup(value.getClass()).writeReplace(value);
|
|
469 |
}
|
|
470 |
|
|
471 |
/**
|
|
472 |
* Encapsulates writing of Java char arrays so that the 1.3 subclass
|
|
473 |
* can override it without exposing internals across packages. This
|
|
474 |
* is a fix for bug 4367783.
|
|
475 |
*/
|
|
476 |
protected void writeCharArray(org.omg.CORBA_2_3.portable.OutputStream out,
|
|
477 |
char[] array,
|
|
478 |
int offset,
|
|
479 |
int length)
|
|
480 |
{
|
|
481 |
out.write_wchar_array(array, offset, length);
|
|
482 |
}
|
|
483 |
|
|
484 |
private void write_Array(org.omg.CORBA_2_3.portable.OutputStream out, java.io.Serializable obj, Class type) {
|
|
485 |
|
|
486 |
int i, length;
|
|
487 |
|
|
488 |
if (type.isPrimitive()) {
|
|
489 |
if (type == Integer.TYPE) {
|
|
490 |
int[] array = (int[])((Object)obj);
|
|
491 |
length = array.length;
|
|
492 |
out.write_ulong(length);
|
|
493 |
out.write_long_array(array, 0, length);
|
|
494 |
} else if (type == Byte.TYPE) {
|
|
495 |
byte[] array = (byte[])((Object)obj);
|
|
496 |
length = array.length;
|
|
497 |
out.write_ulong(length);
|
|
498 |
out.write_octet_array(array, 0, length);
|
|
499 |
} else if (type == Long.TYPE) {
|
|
500 |
long[] array = (long[])((Object)obj);
|
|
501 |
length = array.length;
|
|
502 |
out.write_ulong(length);
|
|
503 |
out.write_longlong_array(array, 0, length);
|
|
504 |
} else if (type == Float.TYPE) {
|
|
505 |
float[] array = (float[])((Object)obj);
|
|
506 |
length = array.length;
|
|
507 |
out.write_ulong(length);
|
|
508 |
out.write_float_array(array, 0, length);
|
|
509 |
} else if (type == Double.TYPE) {
|
|
510 |
double[] array = (double[])((Object)obj);
|
|
511 |
length = array.length;
|
|
512 |
out.write_ulong(length);
|
|
513 |
out.write_double_array(array, 0, length);
|
|
514 |
} else if (type == Short.TYPE) {
|
|
515 |
short[] array = (short[])((Object)obj);
|
|
516 |
length = array.length;
|
|
517 |
out.write_ulong(length);
|
|
518 |
out.write_short_array(array, 0, length);
|
|
519 |
} else if (type == Character.TYPE) {
|
|
520 |
char[] array = (char[])((Object)obj);
|
|
521 |
length = array.length;
|
|
522 |
out.write_ulong(length);
|
|
523 |
writeCharArray(out, array, 0, length);
|
|
524 |
} else if (type == Boolean.TYPE) {
|
|
525 |
boolean[] array = (boolean[])((Object)obj);
|
|
526 |
length = array.length;
|
|
527 |
out.write_ulong(length);
|
|
528 |
out.write_boolean_array(array, 0, length);
|
|
529 |
} else {
|
|
530 |
// XXX I18N, logging needed.
|
|
531 |
throw new Error("Invalid primitive type : " +
|
|
532 |
obj.getClass().getName());
|
|
533 |
}
|
|
534 |
} else if (type == java.lang.Object.class) {
|
|
535 |
Object[] array = (Object[])((Object)obj);
|
|
536 |
length = array.length;
|
|
537 |
out.write_ulong(length);
|
|
538 |
for (i = 0; i < length; i++) {
|
|
539 |
Util.writeAny(out, array[i]);
|
|
540 |
}
|
|
541 |
} else {
|
|
542 |
Object[] array = (Object[])((Object)obj);
|
|
543 |
length = array.length;
|
|
544 |
out.write_ulong(length);
|
|
545 |
int callType = kValueType;
|
|
546 |
|
|
547 |
if (type.isInterface()) {
|
|
548 |
String className = type.getName();
|
|
549 |
|
|
550 |
if (java.rmi.Remote.class.isAssignableFrom(type)) {
|
|
551 |
// RMI Object reference...
|
|
552 |
callType = kRemoteType;
|
|
553 |
} else if (org.omg.CORBA.Object.class.isAssignableFrom(type)){
|
|
554 |
// IDL Object reference...
|
|
555 |
callType = kRemoteType;
|
|
556 |
} else if (RepositoryId.isAbstractBase(type)) {
|
|
557 |
// IDL Abstract Object reference...
|
|
558 |
callType = kAbstractType;
|
|
559 |
} else if (ObjectStreamClassCorbaExt.isAbstractInterface(type)) {
|
|
560 |
callType = kAbstractType;
|
|
561 |
}
|
|
562 |
}
|
|
563 |
|
|
564 |
for (i = 0; i < length; i++) {
|
|
565 |
switch (callType) {
|
|
566 |
case kRemoteType:
|
|
567 |
Util.writeRemoteObject(out, array[i]);
|
|
568 |
break;
|
|
569 |
case kAbstractType:
|
|
570 |
Util.writeAbstractObject(out,array[i]);
|
|
571 |
break;
|
|
572 |
case kValueType:
|
|
573 |
try{
|
|
574 |
out.write_value((java.io.Serializable)array[i]);
|
|
575 |
} catch(ClassCastException cce){
|
|
576 |
if (array[i] instanceof java.io.Serializable)
|
|
577 |
throw cce;
|
|
578 |
else {
|
|
579 |
Utility.throwNotSerializableForCorba(
|
|
580 |
array[i].getClass().getName());
|
|
581 |
}
|
|
582 |
}
|
|
583 |
break;
|
|
584 |
}
|
|
585 |
}
|
|
586 |
}
|
|
587 |
}
|
|
588 |
|
|
589 |
/**
|
|
590 |
* Encapsulates reading of Java char arrays so that the 1.3 subclass
|
|
591 |
* can override it without exposing internals across packages. This
|
|
592 |
* is a fix for bug 4367783.
|
|
593 |
*/
|
|
594 |
protected void readCharArray(org.omg.CORBA_2_3.portable.InputStream in,
|
|
595 |
char[] array,
|
|
596 |
int offset,
|
|
597 |
int length)
|
|
598 |
{
|
|
599 |
in.read_wchar_array(array, offset, length);
|
|
600 |
}
|
|
601 |
|
|
602 |
private java.lang.Object read_Array(IIOPInputStream bridge,
|
|
603 |
org.omg.CORBA_2_3.portable.InputStream in,
|
|
604 |
Class sequence,
|
|
605 |
com.sun.org.omg.SendingContext.CodeBase sender,
|
|
606 |
int offset)
|
|
607 |
{
|
|
608 |
try {
|
|
609 |
// Read length of coming array
|
|
610 |
int length = in.read_ulong();
|
|
611 |
int i;
|
|
612 |
|
|
613 |
if (sequence == null) {
|
|
614 |
for (i = 0; i < length; i++)
|
|
615 |
in.read_value();
|
|
616 |
|
|
617 |
return null;
|
|
618 |
}
|
|
619 |
|
|
620 |
Class componentType = sequence.getComponentType();
|
|
621 |
Class actualType = componentType;
|
|
622 |
|
|
623 |
|
|
624 |
if (componentType.isPrimitive()) {
|
|
625 |
if (componentType == Integer.TYPE) {
|
|
626 |
int[] array = new int[length];
|
|
627 |
in.read_long_array(array, 0, length);
|
|
628 |
return ((java.io.Serializable)((Object)array));
|
|
629 |
} else if (componentType == Byte.TYPE) {
|
|
630 |
byte[] array = new byte[length];
|
|
631 |
in.read_octet_array(array, 0, length);
|
|
632 |
return ((java.io.Serializable)((Object)array));
|
|
633 |
} else if (componentType == Long.TYPE) {
|
|
634 |
long[] array = new long[length];
|
|
635 |
in.read_longlong_array(array, 0, length);
|
|
636 |
return ((java.io.Serializable)((Object)array));
|
|
637 |
} else if (componentType == Float.TYPE) {
|
|
638 |
float[] array = new float[length];
|
|
639 |
in.read_float_array(array, 0, length);
|
|
640 |
return ((java.io.Serializable)((Object)array));
|
|
641 |
} else if (componentType == Double.TYPE) {
|
|
642 |
double[] array = new double[length];
|
|
643 |
in.read_double_array(array, 0, length);
|
|
644 |
return ((java.io.Serializable)((Object)array));
|
|
645 |
} else if (componentType == Short.TYPE) {
|
|
646 |
short[] array = new short[length];
|
|
647 |
in.read_short_array(array, 0, length);
|
|
648 |
return ((java.io.Serializable)((Object)array));
|
|
649 |
} else if (componentType == Character.TYPE) {
|
|
650 |
char[] array = new char[length];
|
|
651 |
readCharArray(in, array, 0, length);
|
|
652 |
return ((java.io.Serializable)((Object)array));
|
|
653 |
} else if (componentType == Boolean.TYPE) {
|
|
654 |
boolean[] array = new boolean[length];
|
|
655 |
in.read_boolean_array(array, 0, length);
|
|
656 |
return ((java.io.Serializable)((Object)array));
|
|
657 |
} else {
|
|
658 |
// XXX I18N, logging needed.
|
|
659 |
throw new Error("Invalid primitive componentType : " + sequence.getName());
|
|
660 |
}
|
|
661 |
} else if (componentType == java.lang.Object.class) {
|
|
662 |
Object[] array = (Object[])java.lang.reflect.Array.newInstance(
|
|
663 |
componentType, length);
|
|
664 |
|
|
665 |
// Store this object and its beginning position
|
|
666 |
// since there might be indirections to it while
|
|
667 |
// it's been unmarshalled.
|
|
668 |
bridge.activeRecursionMgr.addObject(offset, array);
|
|
669 |
|
|
670 |
for (i = 0; i < length; i++) {
|
|
671 |
Object objectValue = null;
|
|
672 |
try {
|
|
673 |
objectValue = Util.readAny(in);
|
|
674 |
} catch(IndirectionException cdrie) {
|
|
675 |
try {
|
|
676 |
// The CDR stream had never seen the given offset
|
|
677 |
// before, so check the recursion manager (it will
|
|
678 |
// throw an IOException if it doesn't have a
|
|
679 |
// reference, either).
|
|
680 |
objectValue = bridge.activeRecursionMgr.getObject(
|
|
681 |
cdrie.offset);
|
|
682 |
} catch (IOException ie) {
|
|
683 |
// Translate to a MARSHAL exception since
|
|
684 |
// ValueHandlers aren't allowed to throw
|
|
685 |
// IOExceptions
|
|
686 |
throw utilWrapper.invalidIndirection( ie,
|
|
687 |
new Integer( cdrie.offset ) ) ;
|
|
688 |
}
|
|
689 |
}
|
|
690 |
|
|
691 |
array[i] = objectValue;
|
|
692 |
}
|
|
693 |
return ((java.io.Serializable)((Object)array));
|
|
694 |
} else {
|
|
695 |
Object[] array = (Object[])java.lang.reflect.Array.newInstance(
|
|
696 |
componentType, length);
|
|
697 |
// Store this object and its beginning position
|
|
698 |
// since there might be indirections to it while
|
|
699 |
// it's been unmarshalled.
|
|
700 |
bridge.activeRecursionMgr.addObject(offset, array);
|
|
701 |
|
|
702 |
// Decide what method call to make based on the componentType.
|
|
703 |
// If it is a componentType for which we need to load a stub,
|
|
704 |
// convert the componentType to the correct stub type.
|
|
705 |
|
|
706 |
int callType = kValueType;
|
|
707 |
boolean narrow = false;
|
|
708 |
|
|
709 |
if (componentType.isInterface()) {
|
|
710 |
boolean loadStubClass = false;
|
|
711 |
// String className = componentType.getName();
|
|
712 |
|
|
713 |
if (java.rmi.Remote.class.isAssignableFrom(componentType)) {
|
|
714 |
|
|
715 |
// RMI Object reference...
|
|
716 |
callType = kRemoteType;
|
|
717 |
|
|
718 |
// for better performance, load the stub class once
|
|
719 |
// instead of for each element of the array
|
|
720 |
loadStubClass = true;
|
|
721 |
} else if (org.omg.CORBA.Object.class.isAssignableFrom(componentType)){
|
|
722 |
// IDL Object reference...
|
|
723 |
callType = kRemoteType;
|
|
724 |
loadStubClass = true;
|
|
725 |
} else if (RepositoryId.isAbstractBase(componentType)) {
|
|
726 |
// IDL Abstract Object reference...
|
|
727 |
callType = kAbstractType;
|
|
728 |
loadStubClass = true;
|
|
729 |
} else if (ObjectStreamClassCorbaExt.isAbstractInterface(componentType)) {
|
|
730 |
|
|
731 |
// RMI Abstract Object reference...
|
|
732 |
|
|
733 |
// componentType = null;
|
|
734 |
callType = kAbstractType;
|
|
735 |
}
|
|
736 |
|
|
737 |
if (loadStubClass) {
|
|
738 |
try {
|
|
739 |
String codebase = Util.getCodebase(componentType);
|
|
740 |
String repID = RepositoryId.createForAnyType(componentType);
|
|
741 |
Class stubType =
|
|
742 |
Utility.loadStubClass(repID, codebase, componentType);
|
|
743 |
actualType = stubType;
|
|
744 |
} catch (ClassNotFoundException e) {
|
|
745 |
narrow = true;
|
|
746 |
}
|
|
747 |
} else {
|
|
748 |
narrow = true;
|
|
749 |
}
|
|
750 |
}
|
|
751 |
|
|
752 |
for (i = 0; i < length; i++) {
|
|
753 |
|
|
754 |
try {
|
|
755 |
switch (callType) {
|
|
756 |
case kRemoteType:
|
|
757 |
if (!narrow)
|
|
758 |
array[i] = (Object)in.read_Object(actualType);
|
|
759 |
else {
|
|
760 |
array[i] = Utility.readObjectAndNarrow(in, actualType);
|
|
761 |
|
|
762 |
}
|
|
763 |
break;
|
|
764 |
case kAbstractType:
|
|
765 |
if (!narrow)
|
|
766 |
array[i] = (Object)in.read_abstract_interface(actualType);
|
|
767 |
else {
|
|
768 |
array[i] = Utility.readAbstractAndNarrow(in, actualType);
|
|
769 |
}
|
|
770 |
break;
|
|
771 |
case kValueType:
|
|
772 |
array[i] = (Object)in.read_value(actualType);
|
|
773 |
break;
|
|
774 |
}
|
|
775 |
} catch(IndirectionException cdrie) {
|
|
776 |
// The CDR stream had never seen the given offset before,
|
|
777 |
// so check the recursion manager (it will throw an
|
|
778 |
// IOException if it doesn't have a reference, either).
|
|
779 |
try {
|
|
780 |
array[i] = bridge.activeRecursionMgr.getObject(
|
|
781 |
cdrie.offset);
|
|
782 |
} catch (IOException ioe) {
|
|
783 |
// Translate to a MARSHAL exception since
|
|
784 |
// ValueHandlers aren't allowed to throw
|
|
785 |
// IOExceptions
|
|
786 |
throw utilWrapper.invalidIndirection( ioe,
|
|
787 |
new Integer( cdrie.offset ) ) ;
|
|
788 |
}
|
|
789 |
}
|
|
790 |
|
|
791 |
}
|
|
792 |
|
|
793 |
return ((java.io.Serializable)((Object)array));
|
|
794 |
}
|
|
795 |
} finally {
|
|
796 |
// We've completed deserializing this object. Any
|
|
797 |
// future indirections will be handled correctly at the
|
|
798 |
// CDR level. The ActiveRecursionManager only deals with
|
|
799 |
// objects currently being deserialized.
|
|
800 |
bridge.activeRecursionMgr.removeObject(offset);
|
|
801 |
}
|
|
802 |
}
|
|
803 |
|
|
804 |
private boolean isArray(String repId){
|
|
805 |
return RepositoryId.cache.getId(repId).isSequence();
|
|
806 |
}
|
|
807 |
|
|
808 |
protected String getOutputStreamClassName() {
|
|
809 |
return "com.sun.corba.se.impl.io.IIOPOutputStream";
|
|
810 |
}
|
|
811 |
|
|
812 |
private com.sun.corba.se.impl.io.IIOPOutputStream createOutputStream() {
|
|
813 |
return (com.sun.corba.se.impl.io.IIOPOutputStream)AccessController.doPrivileged(
|
|
814 |
new StreamFactory(getOutputStreamClassName()));
|
|
815 |
}
|
|
816 |
|
|
817 |
protected String getInputStreamClassName() {
|
|
818 |
return "com.sun.corba.se.impl.io.IIOPInputStream";
|
|
819 |
}
|
|
820 |
|
|
821 |
private com.sun.corba.se.impl.io.IIOPInputStream createInputStream() {
|
|
822 |
return (com.sun.corba.se.impl.io.IIOPInputStream)AccessController.doPrivileged(
|
|
823 |
new StreamFactory(getInputStreamClassName()));
|
|
824 |
}
|
|
825 |
|
|
826 |
/**
|
|
827 |
* Instantiates a class of the given name using the system ClassLoader
|
|
828 |
* as part of a PrivilegedAction.
|
|
829 |
*
|
|
830 |
* It's private final so hopefully people can't grab it outside of
|
|
831 |
* this class.
|
|
832 |
*
|
|
833 |
* If you're worried that someone could subclass ValueHandlerImpl,
|
|
834 |
* install his own streams, and snoop what's on the wire:
|
|
835 |
* Someone can do that only if he's allowed to use the feature
|
|
836 |
* of installing his own javax.rmi.CORBA.Util delegate (via a
|
|
837 |
* JVM property or orb.properties file, read the first time the
|
|
838 |
* Util class is used). If he can do that, he can snoop
|
|
839 |
* anything on the wire, anyway, without abusing the
|
|
840 |
* StreamFactory class.
|
|
841 |
*/
|
|
842 |
private static final class StreamFactory implements PrivilegedAction {
|
|
843 |
private String className;
|
|
844 |
|
|
845 |
public StreamFactory (String _className) {
|
|
846 |
className = _className;
|
|
847 |
}
|
|
848 |
|
|
849 |
public Object run() {
|
|
850 |
try {
|
|
851 |
// Note: We must use the system ClassLoader here
|
|
852 |
// since we want to load classes outside of the
|
|
853 |
// core JDK when running J2EE Pure ORB and
|
|
854 |
// talking to Kestrel.
|
|
855 |
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
856 |
if (cl == null)
|
|
857 |
cl = ClassLoader.getSystemClassLoader();
|
|
858 |
|
|
859 |
Class streamClass = cl.loadClass(className);
|
|
860 |
|
|
861 |
// Since the ClassLoader should cache the class, this isn't
|
|
862 |
// as expensive as it looks.
|
|
863 |
return streamClass.newInstance();
|
|
864 |
|
|
865 |
} catch(Throwable t) {
|
|
866 |
InternalError ie = new InternalError( "Error loading " + className ) ;
|
|
867 |
ie.initCause( t ) ;
|
|
868 |
throw ie ;
|
|
869 |
}
|
|
870 |
}
|
|
871 |
}
|
|
872 |
|
|
873 |
/**
|
|
874 |
* Our JDK 1.3 and JDK 1.3.1 behavior subclasses override this.
|
|
875 |
* The correct behavior is for a Java char to map to a CORBA wchar,
|
|
876 |
* but our older code mapped it to a CORBA char.
|
|
877 |
*/
|
|
878 |
protected TCKind getJavaCharTCKind() {
|
|
879 |
return TCKind.tk_wchar;
|
|
880 |
}
|
|
881 |
}
|