corba/src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/ValueBoxGen24.java
author avstepan
Tue, 05 May 2015 15:17:13 +0400
changeset 30383 45960fdbe465
parent 25862 a5e25d68f971
child 30384 ff19c1d6f92a
permissions -rw-r--r--
8079075: some docs cleanup for CORBA - part 1 Summary: some fix for CORBA docs Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * COMPONENT_NAME: idl.toJava
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * ORIGINS: 27
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
package com.sun.tools.corba.se.idl.toJavaPortable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
// NOTES:
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
// -D62023  <klr> Update for Java 2.4 RTF
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.io.PrintWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import com.sun.tools.corba.se.idl.GenFileStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import com.sun.tools.corba.se.idl.InterfaceEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import com.sun.tools.corba.se.idl.SymtabEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.tools.corba.se.idl.TypedefEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import com.sun.tools.corba.se.idl.ValueEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import com.sun.tools.corba.se.idl.ValueBoxEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.corba.se.idl.InterfaceState;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.corba.se.idl.MethodEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.corba.se.idl.PrimitiveEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.corba.se.idl.SequenceEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.tools.corba.se.idl.StringEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
public class ValueBoxGen24 extends ValueBoxGen
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
   * Public zero-argument constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
  public ValueBoxGen24 ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
  /**
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
    72
   * d62023 - Move from helper to mapped class
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
  protected void writeTruncatable () // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
      stream.print   ("  private static String[] _truncatable_ids = {");
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
      stream.println (Util.helperName(v, true) + ".id ()};");
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
      stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
      stream.println ("  public String[] _truncatable_ids() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
      stream.println ("    return _truncatable_ids;");
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
      stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
      stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
  } // writeTruncatable
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
  /**
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
    87
   * d62023
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
  public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    stream.println ("    if (!(istream instanceof org.omg.CORBA_2_3.portable.InputStream)) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    stream.println ("      throw new org.omg.CORBA.BAD_PARAM(); }");
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    stream.println ("    return (" + entryName +") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (_instance);");
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    // done with "read", now do "read_value with real marshalling code.
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    stream.println ("  public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    String indent = "    ";
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    Vector vMembers = ((ValueBoxEntry) entry).state ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    SymtabEntry mType = member.type ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    if (mType instanceof PrimitiveEntry ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        mType instanceof SequenceEntry ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        mType instanceof TypedefEntry ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        mType instanceof StringEntry ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        !member.arrayInfo ().isEmpty ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
      stream.println (indent + Util.javaName (mType) + " tmp;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
      ((JavaGenerator)member.generator ()).read (0, indent, "tmp", member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
      stream.println (indent + Util.javaName (mType) + " tmp = " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
                      Util.helperName ( mType, true ) + ".read (istream);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    if (mType instanceof PrimitiveEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
      stream.println (indent + "return new " + entryName + " (tmp);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
      stream.println (indent + "return (java.io.Serializable) tmp;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
  } // helperRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
   * <d62023>
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
  public void helperWrite (SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    stream.println ("    if (!(ostream instanceof org.omg.CORBA_2_3.portable.OutputStream)) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    stream.println ("      throw new org.omg.CORBA.BAD_PARAM(); }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    stream.println ("    ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, _instance);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    // done with "write", now do "write_value with real marshalling code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    stream.println ("  public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable value)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    String entryName = Util.javaName(entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    stream.println ("    if (!(value instanceof " + entryName + ")) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    stream.println ("      throw new org.omg.CORBA.MARSHAL(); }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    stream.println ("    " + entryName + " valueType = (" + entryName + ") value;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    write (0, "    ", "valueType", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
  } // helperWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
  /**
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
   147
   * d62023
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
  public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    Vector vMembers = ( (ValueEntry) entry ).state ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    SymtabEntry mType = member.type ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    if (mType instanceof PrimitiveEntry || !member.arrayInfo ().isEmpty ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
      index = ((JavaGenerator)member.generator ()).write (index, indent, name + ".value", member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    else if (mType instanceof SequenceEntry || mType instanceof StringEntry || mType instanceof TypedefEntry || !member.arrayInfo ().isEmpty ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
      index = ((JavaGenerator)member.generator ()).write (index, indent, name, member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
      stream.println (indent + Util.helperName (mType, true) + ".write (ostream, " + name + ");"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
  } // write
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
}