1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47:
48: import ;
49: import ;
50: import ;
51: import ;
52:
53:
58: public class TypeCodeHelper
59: {
60:
67: public static TypeCode read(org.omg.CORBA.portable.InputStream in)
68: throws BadKind, Bounds
69: {
70: TCKind kind = TCKind.from_int(in.read_long());
71: TypeCode rt;
72: GeneralTypeCode g;
73: RecordTypeCode r;
74: RecordTypeCode.Field f;
75: StringTypeCode s;
76: int n;
77:
78: switch (kind.value())
79: {
80: case TCKind._tk_sequence :
81: case TCKind._tk_array :
82:
83: ArrayTypeCode p = new ArrayTypeCode(kind);
84: p.setLength(in.read_long());
85: rt = p;
86: break;
87:
88: case TCKind._tk_string :
89: case TCKind._tk_wstring :
90: s = new StringTypeCode(kind);
91: s.setLength(in.read_long());
92: rt = s;
93: break;
94:
95: case TCKind._tk_fixed :
96:
97: FixedTypeCode fx = new FixedTypeCode();
98: fx.setDigits(in.read_short());
99: fx.setScale(in.read_short());
100: rt = fx;
101: break;
102:
103: case TCKind._tk_objref :
104: case TCKind._tk_native :
105: case TCKind._tk_abstract_interface :
106: g = new GeneralTypeCode(kind);
107: g.setId(in.read_string());
108: g.setName(in.read_string());
109: rt = g;
110: break;
111:
112: case TCKind._tk_alias :
113: case TCKind._tk_value_box :
114: g = new GeneralTypeCode(kind);
115: g.setId(in.read_string());
116: g.setName(in.read_string());
117: g.setContentType(in.read_TypeCode());
118: rt = g;
119: break;
120:
121: case TCKind._tk_struct :
122: case TCKind._tk_except :
123: r = new RecordTypeCode(kind);
124: r.setId(in.read_string());
125: r.setName(in.read_string());
126:
127: n = in.read_long();
128:
129: for (int i = 0; i < n; i++)
130: {
131: f = r.field();
132: f.name = in.read_string();
133: f.type = in.read_TypeCode();
134: }
135: rt = r;
136: break;
137:
138: case TCKind._tk_enum :
139: r = new RecordTypeCode(kind);
140: r.setId(in.read_string());
141: r.setName(in.read_string());
142:
143: n = in.read_long();
144:
145: for (int i = 0; i < n; i++)
146: {
147: f = r.field();
148: f.name = in.read_string();
149: }
150: rt = r;
151: break;
152:
153: case TCKind._tk_union :
154: r = new RecordTypeCode(kind);
155: r.setId(in.read_string());
156: r.setName(in.read_string());
157: r.setDiscriminator_type(in.read_TypeCode());
158: r.setDefaultIndex(in.read_long());
159:
160: n = in.read_long();
161:
162: for (int i = 0; i < n; i++)
163: {
164: f = r.field();
165: f.label = in.read_any();
166: f.name = in.read_string();
167: f.type = in.read_TypeCode();
168: }
169: rt = r;
170:
171: break;
172:
173: case TCKind._tk_value :
174: r = new RecordTypeCode(kind);
175: r.setId(in.read_string());
176: r.setName(in.read_string());
177: r.setTypeModifier(in.read_short());
178: r.setConcreteBase_type(in.read_TypeCode());
179:
180: n = in.read_long();
181:
182: for (int i = 0; i < n; i++)
183: {
184: f = r.field();
185: f.name = in.read_string();
186: f.type = in.read_TypeCode();
187: f.visibility = in.read_short();
188: }
189: rt = r;
190: break;
191:
192: default :
193: rt = new PrimitiveTypeCode(kind);
194: }
195: return rt;
196: }
197:
198:
206: public static void write(org.omg.CORBA.portable.OutputStream out, TypeCode x)
207: throws BadKind, Bounds
208: {
209: out.write_long(x.kind().value());
210:
211: switch (x.kind().value())
212: {
213: case TCKind._tk_string :
214: case TCKind._tk_wstring :
215: out.write_long(x.length());
216: break;
217:
218: case TCKind._tk_sequence :
219: case TCKind._tk_array :
220: write(out, x.content_type());
221: out.write_long(x.length());
222: break;
223:
224: case TCKind._tk_fixed :
225: out.write_short(x.fixed_digits());
226: out.write_short(x.fixed_scale());
227: break;
228:
229: case TCKind._tk_objref :
230: case TCKind._tk_native :
231: case TCKind._tk_abstract_interface :
232: out.write_string(x.id());
233: out.write_string(x.name());
234: break;
235:
236: case TCKind._tk_alias :
237: case TCKind._tk_value_box :
238: out.write_string(x.id());
239: out.write_string(x.name());
240: write(out, x.content_type());
241: break;
242:
243: case TCKind._tk_struct :
244: case TCKind._tk_except :
245: out.write_string(x.id());
246: out.write_string(x.name());
247:
248: out.write_long(x.member_count());
249:
250: for (int i = 0; i < x.member_count(); i++)
251: {
252: out.write_string(x.member_name(i));
253: write(out, x.member_type(i));
254: }
255: break;
256:
257: case TCKind._tk_enum :
258: out.write_string(x.id());
259: out.write_string(x.name());
260:
261: out.write_long(x.member_count());
262:
263: for (int i = 0; i < x.member_count(); i++)
264: {
265: out.write_string(x.member_name(i));
266: }
267: break;
268:
269: case TCKind._tk_union :
270: out.write_string(x.id());
271: out.write_string(x.name());
272:
273: write(out, x.discriminator_type());
274: out.write_long(x.default_index());
275:
276: out.write_long(x.member_count());
277:
278: for (int i = 0; i < x.member_count(); i++)
279: {
280: out.write_any(x.member_label(i));
281: out.write_string(x.member_name(i));
282: write(out, x.member_type(i));
283: }
284: break;
285:
286: case TCKind._tk_value :
287: out.write_string(x.id());
288: out.write_string(x.name());
289: out.write_short(x.type_modifier());
290: write(out, x.concrete_base_type());
291:
292: out.write_long(x.member_count());
293:
294: for (int i = 0; i < x.member_count(); i++)
295: {
296: out.write_string(x.member_name(i));
297: write(out, x.member_type(i));
298: out.write_short(x.member_visibility(i));
299: }
300: break;
301:
302: default :}
303: }
304: }