1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75:
76: import ;
77: import ;
78:
79: import ;
80:
81:
87: public class gnuDynAny extends AbstractAny implements DynAny, Serializable
88: {
89:
92: private static final long serialVersionUID = 1;
93:
94:
97: protected Streamable holder;
98:
99:
104: public gnuDynAny(Streamable aHolder, TypeCode oType, TypeCode aType,
105: gnuDynAnyFactory aFactory, ORB anOrb
106: )
107: {
108: super(oType, aType, aFactory, anOrb);
109: holder = aHolder;
110: }
111:
112:
117: public void assign(DynAny from) throws TypeMismatch
118: {
119: checkType(official_type, from.type());
120:
121: if (from instanceof gnuDynAny)
122: holder = ((gnuDynAny) from).holder;
123: else
124: holder = from.to_any().extract_Streamable();
125: valueChanged();
126: }
127:
128:
131: public DynAny copy()
132: {
133: if (holder != null)
134: {
135: BufferedCdrOutput buffer = new BufferedCdrOutput();
136: holder._write(buffer);
137:
138: gnuDynAny other;
139: try
140: {
141: other =
142: new gnuDynAny((Streamable) (holder.getClass().newInstance()),
143: official_type, final_type, factory, orb
144: );
145: }
146: catch (Exception e)
147: {
148:
149: throw new Unexpected(e);
150: }
151: other.holder._read(buffer.create_input_stream());
152: return other;
153: }
154: else
155: {
156: return new gnuDynAny(null, official_type, final_type, factory, orb);
157: }
158: }
159:
160:
165: public DynAny current_component() throws TypeMismatch
166: {
167: throw new TypeMismatch("Not applicable for " +
168: TypeKindNamer.nameIt(final_type)
169: );
170: }
171:
172:
175: public void destroy()
176: {
177: }
178:
179:
187: public void from_any(Any an_any) throws TypeMismatch, InvalidValue
188: {
189: checkType(official_type, an_any.type());
190:
191: Streamable a_holder = an_any.extract_Streamable();
192: if (a_holder == null)
193: {
194: throw new InvalidValue(ISNULL);
195: }
196: else if (a_holder instanceof GeneralHolder)
197: {
198: holder = HolderLocator.createHolder(official_type);
199: if (holder == null)
200: holder = HolderLocator.createHolder(final_type);
201:
202: if (holder == null)
203: holder = ((GeneralHolder) a_holder).Clone();
204: else
205: {
206: InputStream in = an_any.create_input_stream();
207: holder._read(in);
208: try
209: {
210: in.close();
211: }
212: catch (IOException ex)
213: {
214: throw new Unexpected(ex);
215: }
216: }
217: }
218: else
219: {
220: try
221: {
222: InputStream in = an_any.create_input_stream();
223: holder = (Streamable) a_holder.getClass().newInstance();
224: holder._read(in);
225: in.close();
226: }
227: catch (Exception ex)
228: {
229: TypeMismatch t = new TypeMismatch();
230: t.initCause(ex);
231: throw t;
232: }
233: }
234: valueChanged();
235: }
236:
237:
240: public Any get_any() throws TypeMismatch
241: {
242: try
243: {
244: return ((AnyHolder) holder).value;
245: }
246: catch (ClassCastException cex)
247: {
248: TypeMismatch m = new TypeMismatch();
249: m.initCause(cex);
250: throw m;
251: }
252: }
253:
254:
255: public boolean get_boolean() throws TypeMismatch
256: {
257: try
258: {
259: return ((BooleanHolder) holder).value;
260: }
261: catch (ClassCastException cex)
262: {
263: TypeMismatch m = new TypeMismatch();
264: m.initCause(cex);
265: throw m;
266: }
267: }
268:
269:
270: public char get_char() throws TypeMismatch
271: {
272: try
273: {
274: return ((CharHolder) holder).value;
275: }
276: catch (ClassCastException cex)
277: {
278: TypeMismatch m = new TypeMismatch();
279: m.initCause(cex);
280: throw m;
281: }
282: }
283:
284:
285: public double get_double() throws TypeMismatch
286: {
287: try
288: {
289: return ((DoubleHolder) holder).value;
290: }
291: catch (ClassCastException cex)
292: {
293: TypeMismatch m = new TypeMismatch();
294: m.initCause(cex);
295: throw m;
296: }
297: }
298:
299:
300: public float get_float() throws TypeMismatch
301: {
302: try
303: {
304: return ((FloatHolder) holder).value;
305: }
306: catch (ClassCastException cex)
307: {
308: TypeMismatch m = new TypeMismatch();
309: m.initCause(cex);
310: throw m;
311: }
312: }
313:
314:
315: public int get_long() throws TypeMismatch
316: {
317: try
318: {
319: return ((IntHolder) holder).value;
320: }
321: catch (ClassCastException cex)
322: {
323: TypeMismatch m = new TypeMismatch();
324: m.initCause(cex);
325: throw m;
326: }
327: }
328:
329:
330: public long get_longlong() throws TypeMismatch
331: {
332: try
333: {
334: return ((LongHolder) holder).value;
335: }
336: catch (ClassCastException cex)
337: {
338: TypeMismatch m = new TypeMismatch();
339: m.initCause(cex);
340: throw m;
341: }
342: }
343:
344:
345: public byte get_octet() throws TypeMismatch
346: {
347: try
348: {
349: return ((OctetHolder) holder).value;
350: }
351: catch (ClassCastException cex)
352: {
353: TypeMismatch m = new TypeMismatch();
354: m.initCause(cex);
355: throw m;
356: }
357: }
358:
359:
360: public Object get_reference() throws TypeMismatch
361: {
362: try
363: {
364: return ((ObjectHolder) holder).value;
365: }
366: catch (ClassCastException cex)
367: {
368: TypeMismatch m = new TypeMismatch();
369: m.initCause(cex);
370: throw m;
371: }
372: }
373:
374:
375: public short get_short() throws TypeMismatch
376: {
377: try
378: {
379: return ((ShortHolder) holder).value;
380: }
381: catch (ClassCastException cex)
382: {
383: TypeMismatch m = new TypeMismatch();
384: m.initCause(cex);
385: throw m;
386: }
387: }
388:
389:
390: public String get_string() throws TypeMismatch
391: {
392: try
393: {
394: return ((StringHolder) holder).value;
395: }
396: catch (ClassCastException cex)
397: {
398: TypeMismatch m = new TypeMismatch();
399: m.initCause(cex);
400: throw m;
401: }
402: }
403:
404:
405: public TypeCode get_typecode() throws TypeMismatch
406: {
407: try
408: {
409: return ((TypeCodeHolder) holder).value;
410: }
411: catch (ClassCastException cex)
412: {
413: TypeMismatch m = new TypeMismatch();
414: m.initCause(cex);
415: throw m;
416: }
417: }
418:
419:
420: public int get_ulong() throws TypeMismatch
421: {
422: check(TCKind.tk_ulong);
423: return get_long();
424: }
425:
426:
427: public long get_ulonglong() throws TypeMismatch
428: {
429: check(TCKind.tk_ulonglong);
430: return get_longlong();
431: }
432:
433:
434: public short get_ushort() throws TypeMismatch
435: {
436: check(TCKind.tk_ushort);
437: return get_short();
438: }
439:
440:
441: public Serializable get_val() throws TypeMismatch
442: {
443: try
444: {
445: return ((ValueBaseHolder) holder).value;
446: }
447: catch (ClassCastException cex)
448: {
449: TypeMismatch m = new TypeMismatch();
450: m.initCause(cex);
451: throw m;
452: }
453: }
454:
455:
456: public char get_wchar() throws TypeMismatch
457: {
458: try
459: {
460: return ((WCharHolder) holder).value;
461: }
462: catch (ClassCastException cex)
463: {
464: TypeMismatch m = new TypeMismatch();
465: m.initCause(cex);
466: throw m;
467: }
468: }
469:
470:
471: public String get_wstring() throws TypeMismatch
472: {
473: try
474: {
475: return ((WStringHolder) holder).value;
476: }
477: catch (ClassCastException cex)
478: {
479: TypeMismatch m = new TypeMismatch();
480: m.initCause(cex);
481: throw m;
482: }
483: }
484:
485:
486: public void insert_any(Any a_x) throws TypeMismatch, InvalidValue
487: {
488: try
489: {
490: if (a_x.type().kind().value() == TCKind._tk_null)
491: ((AnyHolder) holder).value = a_x;
492: else
493: {
494: OutputStream buf = a_x.create_output_stream();
495: buf.write_any(a_x);
496: holder._read(buf.create_input_stream());
497: buf.close();
498: }
499: valueChanged();
500: }
501: catch (ClassCastException cex)
502: {
503: TypeMismatch t = new TypeMismatch();
504: t.initCause(cex);
505: throw t;
506: }
507: catch (MARSHAL m)
508: {
509: InvalidValue v = new InvalidValue();
510: v.initCause(m);
511: throw v;
512: }
513: catch (IOException ex)
514: {
515: throw new Unexpected(ex);
516: }
517: }
518:
519:
520: public void insert_boolean(boolean a_x) throws InvalidValue, TypeMismatch
521: {
522: try
523: {
524: ((BooleanHolder) holder).value = a_x;
525: valueChanged();
526: }
527: catch (ClassCastException cex)
528: {
529: TypeMismatch t = new TypeMismatch();
530: t.initCause(cex);
531: throw t;
532: }
533: }
534:
535:
536: public void insert_char(char a_x) throws InvalidValue, TypeMismatch
537: {
538: try
539: {
540: ((CharHolder) holder).value = a_x;
541: valueChanged();
542: }
543: catch (ClassCastException cex)
544: {
545: TypeMismatch t = new TypeMismatch();
546: t.initCause(cex);
547: throw t;
548: }
549: }
550:
551:
552: public void insert_double(double a_x) throws InvalidValue, TypeMismatch
553: {
554: try
555: {
556: ((DoubleHolder) holder).value = a_x;
557: valueChanged();
558: }
559: catch (ClassCastException cex)
560: {
561: TypeMismatch t = new TypeMismatch();
562: t.initCause(cex);
563: throw t;
564: }
565: }
566:
567:
568: public void insert_float(float a_x) throws InvalidValue, TypeMismatch
569: {
570: try
571: {
572: ((FloatHolder) holder).value = a_x;
573: valueChanged();
574: }
575: catch (ClassCastException cex)
576: {
577: TypeMismatch t = new TypeMismatch();
578: t.initCause(cex);
579: throw t;
580: }
581: }
582:
583:
584: public void insert_long(int a_x) throws InvalidValue, TypeMismatch
585: {
586: try
587: {
588: ((IntHolder) holder).value = a_x;
589: valueChanged();
590: }
591: catch (ClassCastException cex)
592: {
593: TypeMismatch t = new TypeMismatch();
594: t.initCause(cex);
595: throw t;
596: }
597: }
598:
599:
600: public void insert_longlong(long a_x) throws InvalidValue, TypeMismatch
601: {
602: try
603: {
604: ((LongHolder) holder).value = a_x;
605: valueChanged();
606: }
607: catch (ClassCastException cex)
608: {
609: TypeMismatch t = new TypeMismatch();
610: t.initCause(cex);
611: throw t;
612: }
613: }
614:
615:
616: public void insert_octet(byte a_x) throws InvalidValue, TypeMismatch
617: {
618: try
619: {
620: ((OctetHolder) holder).value = a_x;
621: valueChanged();
622: }
623: catch (ClassCastException cex)
624: {
625: TypeMismatch t = new TypeMismatch();
626: t.initCause(cex);
627: throw t;
628: }
629: }
630:
631:
632: public void insert_reference(Object a_x) throws InvalidValue, TypeMismatch
633: {
634: try
635: {
636: ((ObjectHolder) holder).value = a_x;
637: valueChanged();
638: }
639: catch (ClassCastException cex)
640: {
641: TypeMismatch t = new TypeMismatch();
642: t.initCause(cex);
643: throw t;
644: }
645: }
646:
647:
648: public void insert_short(short a_x) throws InvalidValue, TypeMismatch
649: {
650: try
651: {
652: ((ShortHolder) holder).value = a_x;
653: valueChanged();
654: }
655: catch (ClassCastException cex)
656: {
657: TypeMismatch t = new TypeMismatch();
658: t.initCause(cex);
659: throw t;
660: }
661: }
662:
663:
664: public void insert_string(String a_x) throws InvalidValue, TypeMismatch
665: {
666: try
667: {
668: if (a_x != null &&
669: final_type.length() > 0 &&
670: a_x.length() > final_type.length()
671: )
672: throw new InvalidValue(a_x.length() + " exceeds bound, " +
673: final_type.length()
674: );
675: ((StringHolder) holder).value = a_x;
676: valueChanged();
677: }
678: catch (ClassCastException cex)
679: {
680: TypeMismatch t = new TypeMismatch();
681: t.initCause(cex);
682: throw t;
683: }
684: catch (BadKind e)
685: {
686: TypeMismatch t = new TypeMismatch();
687: t.initCause(e);
688: throw t;
689: }
690: }
691:
692:
693: public void insert_typecode(TypeCode a_x) throws InvalidValue, TypeMismatch
694: {
695: try
696: {
697: ((TypeCodeHolder) holder).value = a_x;
698: valueChanged();
699: }
700: catch (ClassCastException cex)
701: {
702: TypeMismatch t = new TypeMismatch();
703: t.initCause(cex);
704: throw t;
705: }
706: }
707:
708:
709: public void insert_ulong(int a_x) throws InvalidValue, TypeMismatch
710: {
711: try
712: {
713: ((IntHolder) holder).value = a_x;
714: valueChanged();
715: }
716: catch (ClassCastException cex)
717: {
718: TypeMismatch t = new TypeMismatch();
719: t.initCause(cex);
720: throw t;
721: }
722: }
723:
724:
725: public void insert_ulonglong(long a_x) throws InvalidValue, TypeMismatch
726: {
727: try
728: {
729: ((LongHolder) holder).value = a_x;
730: valueChanged();
731: }
732: catch (ClassCastException cex)
733: {
734: TypeMismatch t = new TypeMismatch();
735: t.initCause(cex);
736: throw t;
737: }
738: }
739:
740:
741: public void insert_ushort(short a_x) throws InvalidValue, TypeMismatch
742: {
743: try
744: {
745: ((ShortHolder) holder).value = a_x;
746: valueChanged();
747: }
748: catch (ClassCastException cex)
749: {
750: TypeMismatch t = new TypeMismatch();
751: t.initCause(cex);
752: throw t;
753: }
754: }
755:
756:
757: public void insert_val(Serializable a_x) throws InvalidValue, TypeMismatch
758: {
759: try
760: {
761: ((ValueBaseHolder) holder).value = a_x;
762: valueChanged();
763: }
764: catch (ClassCastException cex)
765: {
766: TypeMismatch t = new TypeMismatch();
767: t.initCause(cex);
768: throw t;
769: }
770: }
771:
772:
773: public void insert_wchar(char a_x) throws InvalidValue, TypeMismatch
774: {
775: try
776: {
777: ((WCharHolder) holder).value = a_x;
778: valueChanged();
779: }
780: catch (ClassCastException cex)
781: {
782: TypeMismatch t = new TypeMismatch();
783: t.initCause(cex);
784: throw t;
785: }
786: }
787:
788:
789: public void insert_wstring(String a_x) throws InvalidValue, TypeMismatch
790: {
791: try
792: {
793: if (a_x != null &&
794: final_type.length() > 0 &&
795: a_x.length() > type().length()
796: )
797: throw new InvalidValue(a_x.length() + " exceeds bound, " +
798: final_type.length()
799: );
800: ((WStringHolder) holder).value = a_x;
801: valueChanged();
802: }
803: catch (ClassCastException cex)
804: {
805: TypeMismatch t = new TypeMismatch();
806: t.initCause(cex);
807: throw t;
808: }
809: catch (BadKind e)
810: {
811: TypeMismatch t = new TypeMismatch();
812: t.initCause(e);
813: throw t;
814: }
815: }
816:
817:
822: public boolean next()
823: {
824: return false;
825: }
826:
827:
830: public void rewind()
831: {
832: }
833:
834:
840: public boolean seek(int p)
841: {
842: return false;
843: }
844:
845:
850: public Any to_any()
851: {
852: Any a = createAny();
853: a.insert_Streamable(holder);
854: a.type(official_type);
855: return a;
856: }
857:
858:
859: public TypeCode type()
860: {
861: return official_type;
862: }
863:
864:
867: protected int getHashCodeSimple(int maximum)
868: {
869: int h = super.hashCode() / 2;
870: if (h < 0)
871: h = -h;
872: return h % maximum;
873: }
874:
875:
879: public void insert_dyn_any(DynAny d) throws TypeMismatch, InvalidValue
880: {
881: check(d.type().kind());
882:
883: Any a = d.to_any();
884: holder = a.extract_Streamable();
885: valueChanged();
886: }
887:
888:
891: public boolean equal(DynAny other)
892: {
893: if (other instanceof AbstractAny)
894: {
895: if (other instanceof gnuDynAny)
896: {
897: gnuDynAny x = (gnuDynAny) other;
898:
899: if (!x.holder.getClass().equals(holder.getClass()))
900: return false;
901:
902: BufferedCdrOutput b1 = new BufferedCdrOutput();
903: x.holder._write(b1);
904:
905: BufferedCdrOutput b2 = new BufferedCdrOutput(b1.buffer.size() + 10);
906: holder._write(b2);
907:
908: return Arrays.equals(b1.buffer.toByteArray(),
909: b2.buffer.toByteArray()
910: );
911: }
912: else
913: return false;
914: }
915: if (other == null)
916: return false;
917: else if (other.component_count() != component_count() ||
918: !official_type.equal(other.type())
919: )
920: return false;
921: else
922: return other.to_any().equal(to_any());
923: }
924:
925:
930: public int component_count()
931: {
932: return 0;
933: }
934:
935: public DynAny get_dyn_any() throws TypeMismatch, InvalidValue
936: {
937: return new gnuDynAny(holder, official_type, final_type, factory, orb);
938: }
939:
940: private void check(TCKind t) throws TypeMismatch
941: {
942: if (t.value() != final_type.kind().value())
943: throw new TypeMismatch(t.value() + "!=" + final_type.kind().value());
944: }
945: }