Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / CORBA / DynAn / DivideableAny.java
blobc96cbedc73bc22fa4fc0d0e2c253c6092532bfce
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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;
56 /**
57 * Provides a base for DynAnys, having multiple components.
59 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
61 public abstract class DivideableAny
62 extends AbstractAny
63 implements Serializable
65 /**
66 * Use serialVersionUID for interoperability.
68 private static final long serialVersionUID = 1;
70 /**
71 * The array of the components that in general case may have different
72 * final_type.
74 protected DynAny[] array;
76 /**
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);
88 /**
89 * Advance forward.
91 public boolean next()
93 pos++;
94 return array.length > pos;
97 /**
98 * Set zero position.
100 public void rewind()
102 pos = 0;
106 * Set a position.
108 public boolean seek(int p)
110 pos = 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
117 * primitive types.
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
122 * point.
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 ];
131 else
132 throw new TypeMismatch("Multiple coponents at " + pos);
134 else
135 throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
136 (array.length - 1)
140 /** {@inheritDoc} */
141 public int component_count()
143 return array.length;
147 * Return the second (enclosed any) that is stored in the wrapped Any.
149 public Any get_any()
150 throws TypeMismatch, InvalidValue
152 return focused().get_any();
155 /** {@inheritDoc} */
156 public boolean get_boolean()
157 throws TypeMismatch, InvalidValue
159 return focused().get_boolean();
162 /** {@inheritDoc} */
163 public char get_char()
164 throws TypeMismatch, InvalidValue
166 return focused().get_char();
169 /** {@inheritDoc} */
170 public double get_double()
171 throws TypeMismatch, InvalidValue
173 return focused().get_double();
176 /** {@inheritDoc} */
177 public float get_float()
178 throws TypeMismatch, InvalidValue
180 return focused().get_float();
183 /** {@inheritDoc} */
184 public int get_long()
185 throws TypeMismatch, InvalidValue
187 return focused().get_long();
190 /** {@inheritDoc} */
191 public long get_longlong()
192 throws TypeMismatch, InvalidValue
194 return focused().get_longlong();
197 /** {@inheritDoc} */
198 public byte get_octet()
199 throws TypeMismatch, InvalidValue
201 return focused().get_octet();
204 /** {@inheritDoc} */
205 public Object get_reference()
206 throws TypeMismatch, InvalidValue
208 return focused().get_reference();
211 /** {@inheritDoc} */
212 public short get_short()
213 throws TypeMismatch, InvalidValue
215 return focused().get_short();
218 /** {@inheritDoc} */
219 public String get_string()
220 throws TypeMismatch, InvalidValue
222 return focused().get_string();
225 /** {@inheritDoc} */
226 public TypeCode get_typecode()
227 throws TypeMismatch, InvalidValue
229 return focused().get_typecode();
232 /** {@inheritDoc} */
233 public int get_ulong()
234 throws TypeMismatch, InvalidValue
236 return focused().get_ulong();
239 /** {@inheritDoc} */
240 public long get_ulonglong()
241 throws TypeMismatch, InvalidValue
243 return focused().get_ulonglong();
246 /** {@inheritDoc} */
247 public short get_ushort()
248 throws TypeMismatch, InvalidValue
250 return focused().get_ushort();
253 /** {@inheritDoc} */
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();
261 else
262 throw new TypeMismatch();
264 else
265 throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
266 (array.length - 1)
270 /** {@inheritDoc} */
271 public char get_wchar()
272 throws TypeMismatch, InvalidValue
274 return focused().get_wchar();
277 /** {@inheritDoc} */
278 public String get_wstring()
279 throws TypeMismatch, InvalidValue
281 return focused().get_wstring();
284 /** {@inheritDoc} */
285 public void insert_any(Any a_x)
286 throws TypeMismatch, InvalidValue
288 focused().insert_any(a_x);
289 valueChanged();
292 /** {@inheritDoc} */
293 public void insert_boolean(boolean a_x)
294 throws InvalidValue, TypeMismatch
296 focused().insert_boolean(a_x);
297 valueChanged();
300 /** {@inheritDoc} */
301 public void insert_char(char a_x)
302 throws InvalidValue, TypeMismatch
304 focused().insert_char(a_x);
305 valueChanged();
308 /** {@inheritDoc} */
309 public void insert_double(double a_x)
310 throws InvalidValue, TypeMismatch
312 focused().insert_double(a_x);
313 valueChanged();
316 /** {@inheritDoc} */
317 public void insert_float(float a_x)
318 throws InvalidValue, TypeMismatch
320 focused().insert_float(a_x);
321 valueChanged();
324 /** {@inheritDoc} */
325 public void insert_long(int a_x)
326 throws InvalidValue, TypeMismatch
328 focused().insert_long(a_x);
329 valueChanged();
332 /** {@inheritDoc} */
333 public void insert_longlong(long a_x)
334 throws InvalidValue, TypeMismatch
336 focused().insert_longlong(a_x);
337 valueChanged();
340 /** {@inheritDoc} */
341 public void insert_octet(byte a_x)
342 throws InvalidValue, TypeMismatch
344 focused().insert_octet(a_x);
345 valueChanged();
348 /** {@inheritDoc} */
349 public void insert_reference(Object a_x)
350 throws InvalidValue, TypeMismatch
352 focused().insert_reference(a_x);
353 valueChanged();
356 /** {@inheritDoc} */
357 public void insert_short(short a_x)
358 throws InvalidValue, TypeMismatch
360 focused().insert_short(a_x);
361 valueChanged();
364 /** {@inheritDoc} */
365 public void insert_string(String a_x)
366 throws InvalidValue, TypeMismatch
368 focused().insert_string(a_x);
369 valueChanged();
372 /** {@inheritDoc} */
373 public void insert_typecode(TypeCode a_x)
374 throws InvalidValue, TypeMismatch
376 focused().insert_typecode(a_x);
377 valueChanged();
380 /** {@inheritDoc} */
381 public void insert_ulong(int a_x)
382 throws InvalidValue, TypeMismatch
384 focused().insert_ulong(a_x);
385 valueChanged();
388 /** {@inheritDoc} */
389 public void insert_ulonglong(long a_x)
390 throws InvalidValue, TypeMismatch
392 focused().insert_ulonglong(a_x);
393 valueChanged();
396 /** {@inheritDoc} */
397 public void insert_ushort(short a_x)
398 throws InvalidValue, TypeMismatch
400 focused().insert_ushort(a_x);
401 valueChanged();
404 /** {@inheritDoc} */
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);
412 else
413 throw new TypeMismatch();
415 else
416 throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
417 (array.length - 1)
419 valueChanged();
422 /** {@inheritDoc} */
423 public void insert_wchar(char a_x)
424 throws InvalidValue, TypeMismatch
426 focused().insert_wchar(a_x);
427 valueChanged();
430 /** {@inheritDoc} */
431 public void insert_wstring(String a_x)
432 throws InvalidValue, TypeMismatch
434 focused().insert_wstring(a_x);
435 valueChanged();
438 /** {@inheritDoc} */
439 public DynAny get_dyn_any()
440 throws TypeMismatch, InvalidValue
442 return focused().get_dyn_any();
445 /** {@inheritDoc} */
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
456 * bounds.
458 public DynAny current_component()
459 throws TypeMismatch
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()
477 throws TypeMismatch;
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()))
488 return false;
489 else if (other instanceof DivideableAny)
491 DivideableAny x = (DivideableAny) other;
492 if (x.array.length != array.length)
493 return false;
495 for (int i = 0; i < array.length; i++)
497 if (!array [ i ].equal(x.array [ i ]))
498 return false;
500 return true;
502 else if (other == null || other instanceof AbstractAny)
503 return false;
504 else
505 return other.to_any().equal(to_any());
507 catch (TypeMismatch e)
509 UNKNOWN u = new UNKNOWN(MINOR, CompletionStatus.COMPLETED_NO);
510 u.initCause(e);
511 throw u;