4
|
1 |
/*
|
5555
|
2 |
* Copyright (c) 2000, 2003, 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 |
package com.sun.corba.se.impl.dynamicany;
|
|
27 |
|
|
28 |
import org.omg.CORBA.TypeCode;
|
|
29 |
import org.omg.CORBA.Any;
|
|
30 |
import org.omg.CORBA.BAD_OPERATION;
|
|
31 |
import org.omg.CORBA.TypeCodePackage.BadKind;
|
|
32 |
import org.omg.CORBA.TypeCodePackage.Bounds;
|
|
33 |
import org.omg.CORBA.portable.InputStream;
|
|
34 |
import org.omg.DynamicAny.*;
|
|
35 |
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
|
36 |
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
|
37 |
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
|
38 |
|
|
39 |
import com.sun.corba.se.spi.orb.ORB ;
|
|
40 |
import com.sun.corba.se.spi.logging.CORBALogDomains ;
|
|
41 |
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
|
|
42 |
|
|
43 |
public class DynArrayImpl extends DynAnyCollectionImpl implements DynArray
|
|
44 |
{
|
|
45 |
//
|
|
46 |
// Constructors
|
|
47 |
//
|
|
48 |
|
|
49 |
private DynArrayImpl() {
|
|
50 |
this(null, (Any)null, false);
|
|
51 |
}
|
|
52 |
|
|
53 |
protected DynArrayImpl(ORB orb, Any any, boolean copyValue) {
|
|
54 |
super(orb, any, copyValue);
|
|
55 |
}
|
|
56 |
|
|
57 |
protected DynArrayImpl(ORB orb, TypeCode typeCode) {
|
|
58 |
super(orb, typeCode);
|
|
59 |
}
|
|
60 |
|
|
61 |
// Initializes components and anys representation
|
|
62 |
// from the Any representation
|
|
63 |
protected boolean initializeComponentsFromAny() {
|
|
64 |
// This typeCode is of kind tk_array.
|
|
65 |
TypeCode typeCode = any.type();
|
|
66 |
int length = getBound();
|
|
67 |
TypeCode contentType = getContentType();
|
|
68 |
InputStream input;
|
|
69 |
|
|
70 |
try {
|
|
71 |
input = any.create_input_stream();
|
|
72 |
} catch (BAD_OPERATION e) {
|
|
73 |
return false;
|
|
74 |
}
|
|
75 |
|
|
76 |
components = new DynAny[length];
|
|
77 |
anys = new Any[length];
|
|
78 |
|
|
79 |
for (int i=0; i<length; i++) {
|
|
80 |
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
|
|
81 |
// but only for primitive types
|
|
82 |
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
|
|
83 |
try {
|
|
84 |
// Creates the appropriate subtype without copying the Any
|
|
85 |
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
|
|
86 |
} catch (InconsistentTypeCode itc) { // impossible
|
|
87 |
}
|
|
88 |
}
|
|
89 |
return true;
|
|
90 |
}
|
|
91 |
|
|
92 |
// Initializes components and anys representation
|
|
93 |
// from the internal TypeCode information with default values.
|
|
94 |
// This is not done recursively, only one level.
|
|
95 |
// More levels are initialized lazily, on demand.
|
|
96 |
protected boolean initializeComponentsFromTypeCode() {
|
|
97 |
// This typeCode is of kind tk_array.
|
|
98 |
TypeCode typeCode = any.type();
|
|
99 |
int length = getBound();
|
|
100 |
TypeCode contentType = getContentType();
|
|
101 |
|
|
102 |
components = new DynAny[length];
|
|
103 |
anys = new Any[length];
|
|
104 |
|
|
105 |
for (int i=0; i<length; i++) {
|
|
106 |
createDefaultComponentAt(i, contentType);
|
|
107 |
}
|
|
108 |
return true;
|
|
109 |
}
|
|
110 |
|
|
111 |
//
|
|
112 |
// DynArray interface methods
|
|
113 |
//
|
|
114 |
|
|
115 |
// Initializes the elements of the array.
|
|
116 |
// If value does not contain the same number of elements as the array dimension,
|
|
117 |
// the operation raises InvalidValue.
|
|
118 |
// If one or more elements have a type that is inconsistent with the DynArrays TypeCode,
|
|
119 |
// the operation raises TypeMismatch.
|
|
120 |
// This operation does not change the current position.
|
|
121 |
/*
|
|
122 |
public void set_elements (org.omg.CORBA.Any[] value)
|
|
123 |
throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
|
|
124 |
org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
|
125 |
*/
|
|
126 |
|
|
127 |
//
|
|
128 |
// Utility methods
|
|
129 |
//
|
|
130 |
|
|
131 |
protected void checkValue(Object[] value)
|
|
132 |
throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
|
|
133 |
{
|
|
134 |
if (value == null || value.length != getBound()) {
|
|
135 |
throw new InvalidValue();
|
|
136 |
}
|
|
137 |
}
|
|
138 |
}
|