KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > dynamicany > DynArrayImpl


1 /*
2  * @(#)DynArrayImpl.java 1.7 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.dynamicany;
9
10 import org.omg.CORBA.TypeCode JavaDoc;
11 import org.omg.CORBA.Any JavaDoc;
12 import org.omg.CORBA.BAD_OPERATION JavaDoc;
13 import org.omg.CORBA.TypeCodePackage.BadKind JavaDoc;
14 import org.omg.CORBA.TypeCodePackage.Bounds JavaDoc;
15 import org.omg.CORBA.portable.InputStream JavaDoc;
16 import org.omg.DynamicAny.*;
17 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc;
18 import org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc;
19 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode JavaDoc;
20
21 import com.sun.corba.se.spi.orb.ORB ;
22 import com.sun.corba.se.spi.logging.CORBALogDomains ;
23 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
24
25 public class DynArrayImpl extends DynAnyCollectionImpl implements DynArray
26 {
27     //
28
// Constructors
29
//
30

31     private DynArrayImpl() {
32         this(null, (Any JavaDoc)null, false);
33     }
34
35     protected DynArrayImpl(ORB orb, Any JavaDoc any, boolean copyValue) {
36         super(orb, any, copyValue);
37     }
38
39     protected DynArrayImpl(ORB orb, TypeCode JavaDoc typeCode) {
40         super(orb, typeCode);
41     }
42
43     // Initializes components and anys representation
44
// from the Any representation
45
protected boolean initializeComponentsFromAny() {
46         // This typeCode is of kind tk_array.
47
TypeCode JavaDoc typeCode = any.type();
48         int length = getBound();
49         TypeCode JavaDoc contentType = getContentType();
50         InputStream JavaDoc input;
51
52         try {
53             input = any.create_input_stream();
54         } catch (BAD_OPERATION JavaDoc e) {
55             return false;
56         }
57
58         components = new DynAny[length];
59         anys = new Any JavaDoc[length];
60
61         for (int i=0; i<length; i++) {
62             // _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
63
// but only for primitive types
64
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
65             try {
66                 // Creates the appropriate subtype without copying the Any
67
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
68             } catch (InconsistentTypeCode JavaDoc itc) { // impossible
69
}
70         }
71         return true;
72     }
73
74     // Initializes components and anys representation
75
// from the internal TypeCode information with default values.
76
// This is not done recursively, only one level.
77
// More levels are initialized lazily, on demand.
78
protected boolean initializeComponentsFromTypeCode() {
79         // This typeCode is of kind tk_array.
80
TypeCode JavaDoc typeCode = any.type();
81         int length = getBound();
82         TypeCode JavaDoc contentType = getContentType();
83
84         components = new DynAny[length];
85         anys = new Any JavaDoc[length];
86
87         for (int i=0; i<length; i++) {
88             createDefaultComponentAt(i, contentType);
89         }
90         return true;
91     }
92
93     //
94
// DynArray interface methods
95
//
96

97     // Initializes the elements of the array.
98
// If value does not contain the same number of elements as the array dimension,
99
// the operation raises InvalidValue.
100
// If one or more elements have a type that is inconsistent with the DynArrays TypeCode,
101
// the operation raises TypeMismatch.
102
// This operation does not change the current position.
103
/*
104     public void set_elements (org.omg.CORBA.Any[] value)
105         throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
106                org.omg.DynamicAny.DynAnyPackage.InvalidValue;
107 */

108
109     //
110
// Utility methods
111
//
112

113     protected void checkValue(Object JavaDoc[] value)
114         throws org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc
115     {
116         if (value == null || value.length != getBound()) {
117             throw new InvalidValue JavaDoc();
118         }
119     }
120 }
121
Popular Tags