1 /* DivideableAny.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.CORBA
.DynAn
;
41 import gnu
.CORBA
.TypeKindNamer
;
43 import org
.omg
.CORBA
.Any
;
44 import org
.omg
.CORBA
.CompletionStatus
;
45 import org
.omg
.CORBA
.ORB
;
46 import org
.omg
.CORBA
.Object
;
47 import org
.omg
.CORBA
.TypeCode
;
48 import org
.omg
.CORBA
.UNKNOWN
;
49 import org
.omg
.DynamicAny
.DynAny
;
50 import org
.omg
.DynamicAny
.DynAnyPackage
.InvalidValue
;
51 import org
.omg
.DynamicAny
.DynAnyPackage
.TypeMismatch
;
52 import org
.omg
.DynamicAny
.DynValueCommon
;
54 import java
.io
.Serializable
;
57 * Provides a base for DynAnys, having multiple components.
59 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
61 public abstract class DivideableAny
63 implements Serializable
66 * Use serialVersionUID for interoperability.
68 private static final long serialVersionUID
= 1;
71 * The array of the components that in general case may have different
74 protected DynAny
[] array
;
77 * The internal pointer.
79 protected int pos
= 0;
81 public DivideableAny(TypeCode oType
, TypeCode aType
,
82 gnuDynAnyFactory aFactory
, ORB anOrb
85 super(oType
, aType
, aFactory
, anOrb
);
94 return array
.length
> pos
;
108 public boolean seek(int p
)
111 return pos
>= 0 && array
.length
> pos
;
115 * Get the insertion point as DynAny. This method may throw exceptions if the
116 * current insertion point does not support reading or insertion of the
119 * @return the focused component, from where the primitve value can be read or
120 * where it can be inserted.
121 * @throws InvalidValue if the primitive value cannot be inserted at the given
124 protected DynAny
focused()
125 throws InvalidValue
, TypeMismatch
127 if (pos
>= 0 && pos
< array
.length
)
129 if (array
[ pos
].component_count() == 0)
130 return array
[ pos
];
132 throw new TypeMismatch("Multiple coponents at " + pos
);
135 throw new InvalidValue("Out of bounds at " + pos
+ " valid 0.." +
141 public int component_count()
147 * Return the second (enclosed any) that is stored in the wrapped Any.
150 throws TypeMismatch
, InvalidValue
152 return focused().get_any();
156 public boolean get_boolean()
157 throws TypeMismatch
, InvalidValue
159 return focused().get_boolean();
163 public char get_char()
164 throws TypeMismatch
, InvalidValue
166 return focused().get_char();
170 public double get_double()
171 throws TypeMismatch
, InvalidValue
173 return focused().get_double();
177 public float get_float()
178 throws TypeMismatch
, InvalidValue
180 return focused().get_float();
184 public int get_long()
185 throws TypeMismatch
, InvalidValue
187 return focused().get_long();
191 public long get_longlong()
192 throws TypeMismatch
, InvalidValue
194 return focused().get_longlong();
198 public byte get_octet()
199 throws TypeMismatch
, InvalidValue
201 return focused().get_octet();
205 public Object
get_reference()
206 throws TypeMismatch
, InvalidValue
208 return focused().get_reference();
212 public short get_short()
213 throws TypeMismatch
, InvalidValue
215 return focused().get_short();
219 public String
get_string()
220 throws TypeMismatch
, InvalidValue
222 return focused().get_string();
226 public TypeCode
get_typecode()
227 throws TypeMismatch
, InvalidValue
229 return focused().get_typecode();
233 public int get_ulong()
234 throws TypeMismatch
, InvalidValue
236 return focused().get_ulong();
240 public long get_ulonglong()
241 throws TypeMismatch
, InvalidValue
243 return focused().get_ulonglong();
247 public short get_ushort()
248 throws TypeMismatch
, InvalidValue
250 return focused().get_ushort();
254 public Serializable
get_val()
255 throws TypeMismatch
, InvalidValue
257 if (pos
>= 0 && pos
< array
.length
)
259 if (array
[ pos
] instanceof DynValueCommon
)
260 return array
[ pos
].get_val();
262 throw new TypeMismatch();
265 throw new InvalidValue("Out of bounds at " + pos
+ " valid 0.." +
271 public char get_wchar()
272 throws TypeMismatch
, InvalidValue
274 return focused().get_wchar();
278 public String
get_wstring()
279 throws TypeMismatch
, InvalidValue
281 return focused().get_wstring();
285 public void insert_any(Any a_x
)
286 throws TypeMismatch
, InvalidValue
288 focused().insert_any(a_x
);
293 public void insert_boolean(boolean a_x
)
294 throws InvalidValue
, TypeMismatch
296 focused().insert_boolean(a_x
);
301 public void insert_char(char a_x
)
302 throws InvalidValue
, TypeMismatch
304 focused().insert_char(a_x
);
309 public void insert_double(double a_x
)
310 throws InvalidValue
, TypeMismatch
312 focused().insert_double(a_x
);
317 public void insert_float(float a_x
)
318 throws InvalidValue
, TypeMismatch
320 focused().insert_float(a_x
);
325 public void insert_long(int a_x
)
326 throws InvalidValue
, TypeMismatch
328 focused().insert_long(a_x
);
333 public void insert_longlong(long a_x
)
334 throws InvalidValue
, TypeMismatch
336 focused().insert_longlong(a_x
);
341 public void insert_octet(byte a_x
)
342 throws InvalidValue
, TypeMismatch
344 focused().insert_octet(a_x
);
349 public void insert_reference(Object a_x
)
350 throws InvalidValue
, TypeMismatch
352 focused().insert_reference(a_x
);
357 public void insert_short(short a_x
)
358 throws InvalidValue
, TypeMismatch
360 focused().insert_short(a_x
);
365 public void insert_string(String a_x
)
366 throws InvalidValue
, TypeMismatch
368 focused().insert_string(a_x
);
373 public void insert_typecode(TypeCode a_x
)
374 throws InvalidValue
, TypeMismatch
376 focused().insert_typecode(a_x
);
381 public void insert_ulong(int a_x
)
382 throws InvalidValue
, TypeMismatch
384 focused().insert_ulong(a_x
);
389 public void insert_ulonglong(long a_x
)
390 throws InvalidValue
, TypeMismatch
392 focused().insert_ulonglong(a_x
);
397 public void insert_ushort(short a_x
)
398 throws InvalidValue
, TypeMismatch
400 focused().insert_ushort(a_x
);
405 public void insert_val(Serializable a_x
)
406 throws InvalidValue
, TypeMismatch
408 if (pos
>= 0 && pos
< array
.length
)
410 if (array
[ pos
] instanceof DynValueCommon
)
411 array
[ pos
].insert_val(a_x
);
413 throw new TypeMismatch();
416 throw new InvalidValue("Out of bounds at " + pos
+ " valid 0.." +
423 public void insert_wchar(char a_x
)
424 throws InvalidValue
, TypeMismatch
426 focused().insert_wchar(a_x
);
431 public void insert_wstring(String a_x
)
432 throws InvalidValue
, TypeMismatch
434 focused().insert_wstring(a_x
);
439 public DynAny
get_dyn_any()
440 throws TypeMismatch
, InvalidValue
442 return focused().get_dyn_any();
446 public void insert_dyn_any(DynAny insert_it
)
447 throws TypeMismatch
, InvalidValue
449 focused().insert_dyn_any(insert_it
);
453 * Get current component.
455 * @return current component or <code>null</code> if the pointer is out of
458 public DynAny
current_component()
461 if (array
.length
== 0)
462 throw new TypeMismatch("empty");
463 return (pos
>= 0 && pos
< array
.length
) ? array
[ pos
] : null;
467 * No action, cleanup is done by garbage collector in java.
469 public void destroy()
474 * Involved in equal(DynAny).
476 public abstract Any
to_any()
480 * Compares with other DynAny for equality. The final_type, array size and
481 * array members must match.
483 public boolean equal(DynAny other
)
487 if (!official_type
.equal(other
.type()))
489 else if (other
instanceof DivideableAny
)
491 DivideableAny x
= (DivideableAny
) other
;
492 if (x
.array
.length
!= array
.length
)
495 for (int i
= 0; i
< array
.length
; i
++)
497 if (!array
[ i
].equal(x
.array
[ i
]))
502 else if (other
== null || other
instanceof AbstractAny
)
505 return other
.to_any().equal(to_any());
507 catch (TypeMismatch e
)
509 UNKNOWN u
= new UNKNOWN(MINOR
, CompletionStatus
.COMPLETED_NO
);