Source for gnu.CORBA.CDR.HeadlessInput

   1: /* HeadlessInput.java --
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package gnu.CORBA.CDR;
  40: 
  41: import gnu.CORBA.Minor;
  42: 
  43: import org.omg.CORBA.Any;
  44: import org.omg.CORBA.AnySeqHolder;
  45: import org.omg.CORBA.BooleanSeqHolder;
  46: import org.omg.CORBA.CharSeqHolder;
  47: import org.omg.CORBA.Context;
  48: import org.omg.CORBA.DataInputStream;
  49: import org.omg.CORBA.DoubleSeqHolder;
  50: import org.omg.CORBA.FloatSeqHolder;
  51: import org.omg.CORBA.LongLongSeqHolder;
  52: import org.omg.CORBA.LongSeqHolder;
  53: import org.omg.CORBA.MARSHAL;
  54: import org.omg.CORBA.ORB;
  55: import org.omg.CORBA.OctetSeqHolder;
  56: import org.omg.CORBA.Principal;
  57: import org.omg.CORBA.ShortSeqHolder;
  58: import org.omg.CORBA.TypeCode;
  59: import org.omg.CORBA.ULongLongSeqHolder;
  60: import org.omg.CORBA.ULongSeqHolder;
  61: import org.omg.CORBA.UShortSeqHolder;
  62: import org.omg.CORBA.WCharSeqHolder;
  63: import org.omg.CORBA.portable.BoxedValueHelper;
  64: import org.omg.CORBA.portable.InputStream;
  65: 
  66: import java.io.IOException;
  67: import java.io.Serializable;
  68: import java.math.BigDecimal;
  69: 
  70: /**
  71:  * Substitutes the main stream in factories when the header is already behind.
  72:  * Overrides methods that may be invoked from the factory, forcing not to read
  73:  * the header if called first time on this stream.
  74:  *
  75:  * This stream reverts to default behavior if one or more call are made (reading
  76:  * value types that are nested fields of the value type).
  77:  *
  78:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  79:  */
  80: public class HeadlessInput
  81:   extends org.omg.CORBA_2_3.portable.InputStream
  82:   implements DataInputStream, gnuValueStream
  83: {
  84:   /**
  85:    * Use serialVersionUID for interoperability.
  86:    */
  87:   private static final long serialVersionUID = 1;
  88: 
  89:   /**
  90:    * Indicates that no positional information is available.
  91:    */
  92:   static final int NONE = -1;
  93: 
  94:   /**
  95:    * If true, this is not the first call.
  96:    */
  97:   public boolean subsequentCalls;
  98: 
  99:   /**
 100:    * The enclosed stream.
 101:    */
 102:   final BufferredCdrInput stream;
 103: 
 104:   /**
 105:    * Create an instance, reading from the given buffer.
 106:    *
 107:    * @param a_stream a stream from where the data will be read.
 108:    * @param inheritSettings a stream from that endian and other settings are
 109:    * inherited.
 110:    */
 111:   public HeadlessInput(BufferredCdrInput a_stream, InputStream inheritSettings)
 112:   {
 113:     stream = a_stream;
 114: 
 115:     if (inheritSettings instanceof AbstractCdrInput)
 116:       {
 117:         AbstractCdrInput t = (AbstractCdrInput) inheritSettings;
 118:         t.cloneSettings(stream);
 119:       }
 120:     else if (stream.orb() == null)
 121:       stream.setOrb(inheritSettings.orb());
 122: 
 123:     if (inheritSettings instanceof gnuValueStream
 124:       && stream.getRunTime() == null)
 125:       {
 126:         stream.setRunTime(((gnuValueStream) inheritSettings).getRunTime());
 127:       }
 128:   }
 129: 
 130:   /**
 131:    * Tries to read using boxed value helper.
 132:    */
 133:   public Serializable read_value(BoxedValueHelper helper)
 134:   {
 135:     if (subsequentCalls)
 136:       return stream.read_value(helper);
 137:     else
 138:       {
 139:         subsequentCalls = true;
 140:         return helper.read_value(this);
 141:       }
 142:   }
 143: 
 144:   /**
 145:    * Tries to locate a factory using repository id.
 146:    */
 147:   public Serializable read_value(String repository_id)
 148:   {
 149:     if (subsequentCalls)
 150:       return stream.read_value(repository_id);
 151:     else
 152:       {
 153:         subsequentCalls = true;
 154:         Serializable value = Vio.readValue(this, NONE, null,
 155:           null, repository_id, null, null);
 156:         return value;
 157:       }
 158:   }
 159: 
 160:   /**
 161:    * Try to read when having an unitialised value.
 162:    */
 163:   public Serializable read_value(Serializable value)
 164:   {
 165:     if (subsequentCalls)
 166:       return stream.read_value(value);
 167:     else
 168:       {
 169:         subsequentCalls = true;
 170:         value = Vio.readValue(this, NONE, value, null, null,
 171:           null, null);
 172:         return value;
 173:       }
 174:   }
 175: 
 176:   /**
 177:    * Try to read when having an unitialised value.
 178:    */
 179:   public Serializable read_value(Class clz)
 180:   {
 181:     if (subsequentCalls)
 182:       return stream.read_value(clz);
 183:     else
 184:       {
 185:         try
 186:           {
 187:             subsequentCalls = true;
 188:             Serializable value = (Serializable) Vio.instantiateAnyWay(clz);
 189:             value = Vio.readValue(this, NONE, value, null, null,
 190:               null, null);
 191:             return value;
 192:           }
 193:         catch (Exception ex)
 194:           {
 195:             MARSHAL m = new MARSHAL("Can't read an instance of "
 196:               + clz.getName());
 197:             m.minor = Minor.Value;
 198:             m.initCause(ex);
 199:             throw m;
 200:           }
 201:       }
 202:   }
 203: 
 204:   /**
 205:    * Delegates functionality to the underlying stream.
 206:    */
 207:   public int available()
 208:     throws IOException
 209:   {
 210:     return stream.available();
 211:   }
 212: 
 213:   /**
 214:    * Delegates functionality to the underlying stream.
 215:    */
 216:   public void close()
 217:     throws IOException
 218:   {
 219:     stream.close();
 220:   }
 221: 
 222:   /**
 223:    * Delegates functionality to the underlying stream.
 224:    */
 225:   public void mark(int readlimit)
 226:   {
 227:     stream.mark(readlimit);
 228:   }
 229: 
 230:   /**
 231:    * Delegates functionality to the underlying stream.
 232:    */
 233:   public boolean markSupported()
 234:   {
 235:     return stream.markSupported();
 236:   }
 237: 
 238:   /**
 239:    * Delegates functionality to the underlying stream.
 240:    */
 241:   public ORB orb()
 242:   {
 243:     return stream.orb();
 244:   }
 245: 
 246:   /**
 247:    * Delegates functionality to the underlying stream.
 248:    */
 249:   public Object read_abstract_interface()
 250:   {
 251:     return stream.read_abstract_interface();
 252:   }
 253: 
 254:   /**
 255:    * Delegates functionality to the underlying stream.
 256:    */
 257:   public Object read_abstract_interface(Class clz)
 258:   {
 259:     return stream.read_abstract_interface(clz);
 260:   }
 261: 
 262:   /**
 263:    * Delegates functionality to the underlying stream.
 264:    */
 265:   public Any read_any()
 266:   {
 267:     return stream.read_any();
 268:   }
 269: 
 270:   /**
 271:    * Delegates functionality to the underlying stream.
 272:    */
 273:   public void read_boolean_array(boolean[] value, int offset, int length)
 274:   {
 275:     stream.read_boolean_array(value, offset, length);
 276:   }
 277: 
 278:   /**
 279:    * Delegates functionality to the underlying stream.
 280:    */
 281:   public boolean read_boolean()
 282:   {
 283:     return stream.read_boolean();
 284:   }
 285: 
 286:   /**
 287:    * Delegates functionality to the underlying stream.
 288:    */
 289:   public void read_char_array(char[] value, int offset, int length)
 290:   {
 291:     stream.read_char_array(value, offset, length);
 292:   }
 293: 
 294:   /**
 295:    * Delegates functionality to the underlying stream.
 296:    */
 297:   public char read_char()
 298:   {
 299:     return stream.read_char();
 300:   }
 301: 
 302:   /**
 303:    * Delegates functionality to the underlying stream.
 304:    */
 305:   public Context read_Context()
 306:   {
 307:     return stream.read_Context();
 308:   }
 309: 
 310:   /**
 311:    * Delegates functionality to the underlying stream.
 312:    */
 313:   public void read_double_array(double[] value, int offset, int length)
 314:   {
 315:     stream.read_double_array(value, offset, length);
 316:   }
 317: 
 318:   /**
 319:    * Delegates functionality to the underlying stream.
 320:    */
 321:   public double read_double()
 322:   {
 323:     return stream.read_double();
 324:   }
 325: 
 326:   /**
 327:    * Delegates functionality to the underlying stream.
 328:    */
 329:   public BigDecimal read_fixed()
 330:   {
 331:     return stream.read_fixed();
 332:   }
 333: 
 334:   /**
 335:    * Delegates functionality to the underlying stream.
 336:    */
 337:   public void read_float_array(float[] value, int offset, int length)
 338:   {
 339:     stream.read_float_array(value, offset, length);
 340:   }
 341: 
 342:   /**
 343:    * Delegates functionality to the underlying stream.
 344:    */
 345:   public float read_float()
 346:   {
 347:     return stream.read_float();
 348:   }
 349: 
 350:   /**
 351:    * Delegates functionality to the underlying stream.
 352:    */
 353:   public void read_long_array(int[] value, int offset, int length)
 354:   {
 355:     stream.read_long_array(value, offset, length);
 356:   }
 357: 
 358:   /**
 359:    * Delegates functionality to the underlying stream.
 360:    */
 361:   public int read_long()
 362:   {
 363:     return stream.read_long();
 364:   }
 365: 
 366:   /**
 367:    * Delegates functionality to the underlying stream.
 368:    */
 369:   public void read_longlong_array(long[] value, int offset, int length)
 370:   {
 371:     stream.read_longlong_array(value, offset, length);
 372:   }
 373: 
 374:   /**
 375:    * Delegates functionality to the underlying stream.
 376:    */
 377:   public long read_longlong()
 378:   {
 379:     return stream.read_longlong();
 380:   }
 381: 
 382:   /**
 383:    * Delegates functionality to the underlying stream.
 384:    */
 385:   public org.omg.CORBA.Object read_Object()
 386:   {
 387:     return stream.read_Object();
 388:   }
 389: 
 390:   /**
 391:    * Delegates functionality to the underlying stream.
 392:    */
 393:   public org.omg.CORBA.Object read_Object(Class klass)
 394:   {
 395:     return stream.read_Object(klass);
 396:   }
 397: 
 398:   /**
 399:    * Delegates functionality to the underlying stream.
 400:    */
 401:   public void read_octet_array(byte[] value, int offset, int length)
 402:   {
 403:     stream.read_octet_array(value, offset, length);
 404:   }
 405: 
 406:   /**
 407:    * Delegates functionality to the underlying stream.
 408:    */
 409:   public byte read_octet()
 410:   {
 411:     return stream.read_octet();
 412:   }
 413: 
 414:   /**
 415:    * Delegates functionality to the underlying stream.
 416:    */
 417:   public Principal read_Principal()
 418:   {
 419:     return stream.read_Principal();
 420:   }
 421: 
 422:   /**
 423:    * Delegates functionality to the underlying stream.
 424:    */
 425:   public void read_short_array(short[] value, int offset, int length)
 426:   {
 427:     stream.read_short_array(value, offset, length);
 428:   }
 429: 
 430:   /**
 431:    * Delegates functionality to the underlying stream.
 432:    */
 433:   public short read_short()
 434:   {
 435:     return stream.read_short();
 436:   }
 437: 
 438:   /**
 439:    * Delegates functionality to the underlying stream.
 440:    */
 441:   public String read_string()
 442:   {
 443:     return stream.read_string();
 444:   }
 445: 
 446:   /**
 447:    * Delegates functionality to the underlying stream.
 448:    */
 449:   public TypeCode read_TypeCode()
 450:   {
 451:     return stream.read_TypeCode();
 452:   }
 453: 
 454:   /**
 455:    * Delegates functionality to the underlying stream.
 456:    */
 457:   public void read_ulong_array(int[] value, int offset, int length)
 458:   {
 459:     stream.read_ulong_array(value, offset, length);
 460:   }
 461: 
 462:   /**
 463:    * Delegates functionality to the underlying stream.
 464:    */
 465:   public int read_ulong()
 466:   {
 467:     return stream.read_ulong();
 468:   }
 469: 
 470:   /**
 471:    * Delegates functionality to the underlying stream.
 472:    */
 473:   public void read_ulonglong_array(long[] value, int offset, int length)
 474:   {
 475:     stream.read_ulonglong_array(value, offset, length);
 476:   }
 477: 
 478:   /**
 479:    * Delegates functionality to the underlying stream.
 480:    */
 481:   public long read_ulonglong()
 482:   {
 483:     return stream.read_ulonglong();
 484:   }
 485: 
 486:   /**
 487:    * Delegates functionality to the underlying stream.
 488:    */
 489:   public void read_ushort_array(short[] value, int offset, int length)
 490:   {
 491:     stream.read_ushort_array(value, offset, length);
 492:   }
 493: 
 494:   /**
 495:    * Delegates functionality to the underlying stream.
 496:    */
 497:   public short read_ushort()
 498:   {
 499:     return stream.read_ushort();
 500:   }
 501: 
 502:   /**
 503:    * Delegates functionality to the underlying stream.
 504:    */
 505:   public Serializable read_value()
 506:   {
 507:     return read_value((Serializable) null);
 508:   }
 509: 
 510:   /**
 511:    * Delegates functionality to the underlying stream.
 512:    */
 513:   public void read_wchar_array(char[] value, int offset, int length)
 514:   {
 515:     stream.read_wchar_array(value, offset, length);
 516:   }
 517: 
 518:   /**
 519:    * Delegates functionality to the underlying stream.
 520:    */
 521:   public char read_wchar()
 522:   {
 523:     return stream.read_wchar();
 524:   }
 525: 
 526:   /**
 527:    * Delegates functionality to the underlying stream.
 528:    */
 529:   public String read_wstring()
 530:   {
 531:     return stream.read_wstring();
 532:   }
 533: 
 534:   /**
 535:    * Delegates functionality to the underlying stream.
 536:    */
 537:   public int read()
 538:     throws IOException
 539:   {
 540:     return stream.read();
 541:   }
 542: 
 543:   /**
 544:    * Delegates functionality to the underlying stream.
 545:    */
 546:   public int read(byte[] b, int off, int len)
 547:     throws IOException
 548:   {
 549:     return stream.read(b, off, len);
 550:   }
 551: 
 552:   /**
 553:    * Delegates functionality to the underlying stream.
 554:    */
 555:   public int read(byte[] b)
 556:     throws IOException
 557:   {
 558:     return stream.read(b);
 559:   }
 560: 
 561:   /**
 562:    * Delegates functionality to the underlying stream.
 563:    */
 564:   public void reset()
 565:     throws IOException
 566:   {
 567:     stream.reset();
 568:   }
 569: 
 570:   /**
 571:    * Delegates functionality to the underlying stream.
 572:    */
 573:   public long skip(long n)
 574:     throws IOException
 575:   {
 576:     return stream.skip(n);
 577:   }
 578: 
 579:   /**
 580:    * Get a string representation.
 581:    */
 582:   public String toString()
 583:   {
 584:     return "HeadlessInput+" + stream.toString();
 585:   }
 586: 
 587:   /**
 588:    * Delegates functionality to the underlying stream.
 589:    */
 590:   public String[] _truncatable_ids()
 591:   {
 592:     return stream._truncatable_ids();
 593:   }
 594: 
 595:   /**
 596:    * Delegates functionality to the underlying stream.
 597:    */
 598:   public Object read_Abstract()
 599:   {
 600:     return stream.read_Abstract();
 601:   }
 602: 
 603:   /**
 604:    * Delegates functionality to the underlying stream.
 605:    */
 606:   public void read_any_array(AnySeqHolder holder, int offset, int length)
 607:   {
 608:     stream.read_any_array(holder, offset, length);
 609:   }
 610: 
 611:   /**
 612:    * Delegates functionality to the underlying stream.
 613:    */
 614:   public void read_boolean_array(BooleanSeqHolder holder, int offset, int length)
 615:   {
 616:     stream.read_boolean_array(holder, offset, length);
 617:   }
 618: 
 619:   /**
 620:    * Delegates functionality to the underlying stream.
 621:    */
 622:   public void read_char_array(CharSeqHolder holder, int offset, int length)
 623:   {
 624:     stream.read_char_array(holder, offset, length);
 625:   }
 626: 
 627:   /**
 628:    * Delegates functionality to the underlying stream.
 629:    */
 630:   public void read_double_array(DoubleSeqHolder holder, int offset, int length)
 631:   {
 632:     stream.read_double_array(holder, offset, length);
 633:   }
 634: 
 635:   /**
 636:    * Delegates functionality to the underlying stream.
 637:    */
 638:   public void read_float_array(FloatSeqHolder holder, int offset, int length)
 639:   {
 640:     stream.read_float_array(holder, offset, length);
 641:   }
 642: 
 643:   /**
 644:    * Delegates functionality to the underlying stream.
 645:    */
 646:   public void read_long_array(LongSeqHolder holder, int offset, int length)
 647:   {
 648:     stream.read_long_array(holder, offset, length);
 649:   }
 650: 
 651:   /**
 652:    * Delegates functionality to the underlying stream.
 653:    */
 654:   public void read_longlong_array(LongLongSeqHolder holder, int offset,
 655:     int length)
 656:   {
 657:     stream.read_longlong_array(holder, offset, length);
 658:   }
 659: 
 660:   /**
 661:    * Delegates functionality to the underlying stream.
 662:    */
 663:   public void read_octet_array(OctetSeqHolder holder, int offset, int length)
 664:   {
 665:     stream.read_octet_array(holder, offset, length);
 666:   }
 667: 
 668:   /**
 669:    * Delegates functionality to the underlying stream.
 670:    */
 671:   public void read_short_array(ShortSeqHolder holder, int offset, int length)
 672:   {
 673:     stream.read_short_array(holder, offset, length);
 674:   }
 675: 
 676:   /**
 677:    * Delegates functionality to the underlying stream.
 678:    */
 679:   public void read_ulong_array(ULongSeqHolder holder, int offset, int length)
 680:   {
 681:     stream.read_ulong_array(holder, offset, length);
 682:   }
 683: 
 684:   /**
 685:    * Delegates functionality to the underlying stream.
 686:    */
 687:   public void read_ulonglong_array(ULongLongSeqHolder holder, int offset,
 688:     int length)
 689:   {
 690:     stream.read_ulonglong_array(holder, offset, length);
 691:   }
 692: 
 693:   /**
 694:    * Delegates functionality to the underlying stream.
 695:    */
 696:   public void read_ushort_array(UShortSeqHolder holder, int offset, int length)
 697:   {
 698:     stream.read_ushort_array(holder, offset, length);
 699:   }
 700: 
 701:   /**
 702:    * Delegates functionality to read_value.
 703:    */
 704:   public Serializable read_Value()
 705:   {
 706:     return read_value();
 707:   }
 708: 
 709:   /**
 710:    * Delegates functionality to the underlying stream.
 711:    */
 712:   public void read_wchar_array(WCharSeqHolder holder, int offset, int length)
 713:   {
 714:     stream.read_wchar_array(holder, offset, length);
 715:   }
 716: 
 717:   /**
 718:    * Delegates functionality to the underlying stream.
 719:    */
 720:   public int getPosition()
 721:   {
 722:     return stream.getPosition();
 723:   }
 724: 
 725:   /**
 726:    * Delegates functionality to the underlying stream.
 727:    */
 728:   public gnuRuntime getRunTime()
 729:   {
 730:     return stream.runtime;
 731:   }
 732: 
 733:   /**
 734:    * Replace the instance of RunTime.
 735:    */
 736:   public void setRunTime(gnuRuntime a_runtime)
 737:   {
 738:     stream.runtime = a_runtime;
 739:   }
 740: 
 741:   /**
 742:    * Delegates functionality to the underlying stream.
 743:    */
 744:   public void seek(int position)
 745:   {
 746:     stream.seek(position);
 747:   }
 748: 
 749: }