corba/src/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/InterfaceGen.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
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, 2001, 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
// -The ctor should really throw an exception, but then it must have a
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
//  throws clause. How much of a ripple effect is this?
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
// -F46082.51<daz> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
// -D60929   <klr> Update for RTF2.4 changes
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
// -D61056   <klr> Use Util.helperName
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
// -D62014   <klr> Move const definitions from signature to operations interf.
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
// -D62310   <klr> Fix declaration of interfaces extending abstract intf.
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
// -D62023   <klr> Move const definitions back from operations to signature.
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.io.PrintWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.corba.se.idl.GenFileStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.corba.se.idl.ConstEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.corba.se.idl.InterfaceEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.corba.se.idl.InterfaceState;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.tools.corba.se.idl.MethodEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.tools.corba.se.idl.PrimitiveEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import com.sun.tools.corba.se.idl.SequenceEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import com.sun.tools.corba.se.idl.StringEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import com.sun.tools.corba.se.idl.SymtabEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import com.sun.tools.corba.se.idl.TypedefEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
 **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
public class InterfaceGen implements com.sun.tools.corba.se.idl.InterfaceGen, JavaGenerator
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
   * Public zero-argument constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
  public InterfaceGen ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    //emit = ((Arguments)Compile.compiler.arguments).emit;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    //factories = (Factories)Compile.compiler.factories ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
   * Generate the interface and all the files associated with it.
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
   * Provides general algorithm for binding generation:
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
   * 1.) Initialize symbol table and symbol table entry members, common to all generators.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
   * 2.) Generate the skeleton if required by calling generateSkeletn ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
   * 3.) Generate the holder by calling generateHolder ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
   * 4.) Generate the helper by calling generateHelper ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
   * 5.) Generate the stub if required by calling generateStub ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
   * 6.) Generate the interface by calling generateInterface ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
  public void generate (Hashtable symbolTable, InterfaceEntry i, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    if (!isPseudo(i))
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
      this.symbolTable = symbolTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
      this.i           = i;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
      init ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
      // for sun_local pragma, just generate the signature and operations interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
      // for sun_localservant pragma, generate the Local Stubs, and Skel, should not
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
      // have _invoke defined.
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
      // for local (is_local()) case, generate only Helpers and Holder, where they
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
      // have been modified to throw appropriate exceptions for read and write, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
      // narrow is modified to not invoke _is_a
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
      if (! (i.isLocalSignature())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
          // generate the stubs and skeletons for non-local interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
          if (! (i.isLocal())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
              // for local servant case just generate the skeleton, but
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
              // for others generate the stubs also
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
              generateSkeleton ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
              // _REVISIT_, Whenever there is time restructure the code to
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
              // encapsulate stub and skeleton generation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
              // If the option is -fallTie then generate the Tie class first
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
              // and then generate the ImplBase class to make the generation
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
              // complete for the Hierarchy.
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
              Arguments theArguments = (Arguments)Compile.compiler.arguments;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
              if( (theArguments.TIEServer == true )
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
                &&(theArguments.emit == theArguments.All ) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
              {
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
                  theArguments.TIEServer = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                  // Generate the ImplBase class
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                  generateSkeleton ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
                  // Revert in case file contains multiple interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                  theArguments.TIEServer = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
              }
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
              generateStub ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
          }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
          generateHolder ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
          generateHelper ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
      intfType = SIGNATURE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
      generateInterface ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
      intfType = OPERATIONS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
      generateInterface ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
      intfType = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
  } // generate
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
   * Initialize members unique to this generator.
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
  protected void init ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    emit = ((Arguments)Compile.compiler.arguments).emit;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    factories = (Factories)Compile.compiler.factories ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
  } // init
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
   * Generate a Skeleton when the user does not want just the client-side code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
  protected void generateSkeleton ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    // The Skeleton is generated only when the user doesn't want
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    // JUST the client code OR when the interface is stateful
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    //if (emit != Arguments.Client || i.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    //  factories.skeleton ().generate (symbolTable, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    if (emit != Arguments.Client)
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
      factories.skeleton ().generate (symbolTable, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
  } // generateSkeleton
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
   * Generate a Stub when the user does not want just the server-side code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
  protected void generateStub ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    // <klr> According to Simon on 10/28/98, we should generate stubs for
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    // abstract interfaces too.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    if (emit != Arguments.Server /* && !i.isAbstract () */)
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
      factories.stub ().generate (symbolTable, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
  } // generateStub
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
   * Generate a Helper when the user does not want just the server-side code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
  protected void generateHelper ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    if (emit != Arguments.Server)
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
      factories.helper ().generate (symbolTable, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
  } // generateHelper
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
   * Generate a Holder when the user does not want just the server-side code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
  protected void generateHolder ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    if (emit != Arguments.Server)
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
      factories.holder ().generate (symbolTable, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
  } // generateHolder
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
   * Generate the interface. Provides general algorithm for binding generation:
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
   * 1.) Initialize members unique to this generator. - init ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
   * 2.) Open print stream - openStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
   * 3.) Write class heading (package, prologue, class statement, open curly - writeHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
   * 4.) Write class body (member data and methods) - write*Body ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
   * 5.) Write class closing (close curly) - writeClosing ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
   * 6.) Close the print stream - closeStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
   * For CORBA 2.3, interfaces are mapped to Operations and Signature
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
   * interfaces. The Operations interface contains the method definitions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
   * The Signature interface extends the Operations interface and adds
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
   * CORBA::Object. <klr>
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
  protected void generateInterface ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    init ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    openStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    if (stream == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    writeHeading ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    if (intfType == OPERATIONS)
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
      writeOperationsBody ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    if (intfType == SIGNATURE)
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
      writeSignatureBody ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    writeClosing ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
    closeStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
  } // generateInterface
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
  protected void openStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    if (i.isAbstract () || intfType == SIGNATURE)
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
       stream = Util.stream (i, ".java");
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    else if (intfType == OPERATIONS)
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
       stream = Util.stream (i, "Operations.java");
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
  } // openStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
  protected void writeHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
    Util.writePackage (stream, i, Util.TypeFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    Util.writeProlog (stream, ((GenFileStream)stream).name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    // Transfer interface comment to target <31jul1997>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    if (i.comment () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
      i.comment ().generate ("", stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    String className = i.name ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
//  if (((Arguments)Compile.compiler.arguments).TIEServer)
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
//  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
//    // For the delegate model, don't make interface a subclass of CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
//    stream.print ("public interface " + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
//    boolean firstTime = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
//    for (int ii = 0; ii < i.derivedFrom ().size (); ++ii)
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
//    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
//      SymtabEntry parent = (SymtabEntry)i.derivedFrom ().elementAt (ii);
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
//      if (!parent.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
//      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
//        if (firstTime)
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
//        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
//          firstTime = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
//          stream.print (" extends ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
//        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
//        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
//          stream.print (", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
//        stream.print (Util.javaName (parent));
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
//      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
//    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
//    if (i.derivedFrom ().size () > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
//      stream.print (", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
//    stream.print ("org.omg.CORBA.portable.IDLEntity ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
//  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
//
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
//  else
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
//  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
      if (intfType == SIGNATURE)
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
         writeSignatureHeading ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
      else if (intfType == OPERATIONS)
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
         writeOperationsHeading ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
//  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    stream.println ('{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
  } // writeHeading
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
  protected void writeSignatureHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    String className = i.name ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    stream.print ("public interface " + className + " extends " + className + "Operations, ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    boolean firstTime = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
    boolean hasNonAbstractParent = false; // <d62310-klr>
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    for (int k = 0; k < i.derivedFrom ().size (); ++k)
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
      if (firstTime)
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        firstTime = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
        stream.print (", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
      InterfaceEntry parent = (InterfaceEntry)i.derivedFrom ().elementAt (k);
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
      stream.print (Util.javaName (parent));
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
      if (! parent.isAbstract ()) // <d62310-klr>
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
        hasNonAbstractParent = true; // <d62310-klr>
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    // <d62310-klr> - begin
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    // If this interface extends only abstract interfaces,
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    // it should extend both org.omg.CORBA.Object and IDLEntity.
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    if (!hasNonAbstractParent) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
      stream.print (", org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    // <d62310-klr> - end
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        // extends IDLEntity if there's only one default parent - CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        if (i.derivedFrom ().size () == 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
          stream.print (", org.omg.CORBA.portable.IDLEntity ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
  } // writeSignatureHeading
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
  protected void writeOperationsHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    stream.print ("public interface " + i.name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    if ( !i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
      stream.print ("Operations ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        // <d60929> - base abstract interfaces extend AbstractBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        // changed to IDLEntity by SCN per latest spec...
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        if (i.derivedFrom ().size () == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
          stream.print (" extends org.omg.CORBA.portable.IDLEntity");
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    boolean firstTime = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    for (int k = 0; k < i.derivedFrom ().size (); ++k)
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
      InterfaceEntry parent = (InterfaceEntry) i.derivedFrom ().elementAt (k);
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
      String parentName = Util.javaName (parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
      // ignore the default parent - CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
      if (parentName.equals ("org.omg.CORBA.Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
          continue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
      if (firstTime)
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        firstTime = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        stream.print (" extends ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        stream.print (", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
      // Don't append suffix Operations to the parents of abstract interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
      // or to the abstract parents of regular interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
      if (parent.isAbstract () || i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        stream.print (parentName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        stream.print (parentName + "Operations");
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
  } // writeOperationsHeading
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
  protected void writeOperationsBody ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    // Generate everything but constants
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    Enumeration e = i.contained ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
      SymtabEntry contained = (SymtabEntry)e.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
      if (contained instanceof MethodEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        MethodEntry element = (MethodEntry)contained;
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        ((MethodGen)element.generator ()).interfaceMethod (symbolTable, element, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
        if ( !(contained instanceof ConstEntry))
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
          contained.generate (symbolTable, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
  } // writeOperationsBody
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
  protected void writeSignatureBody ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
    // Generate only constants
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    Enumeration e = i.contained ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
      SymtabEntry contained = (SymtabEntry)e.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
      if (contained instanceof ConstEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
        contained.generate (symbolTable, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
  } // writeSignatureBody
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
  protected void writeClosing ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
    String intfName = i.name ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
    if ( !i.isAbstract () && intfType == OPERATIONS)
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
      intfName = intfName + "Operations";
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
    stream.println ("} // interface " + intfName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
  } // writeClosing
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
  protected void closeStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    stream.close ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
  } // closeStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
  // From JavaGenerator
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
  public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    if (i.state () != null && i.state ().size () > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
      index = structHelperType (index, indent, tcoffsets, name, entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
      tcoffsets.set (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
      if (entry.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        stream.println (indent + name
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
            + " = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_objref);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
        stream.println (indent + name
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
            // <54697>
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
            //+ " = org.omg.CORBA.ORB.init ().create_interface_tc (_id, "
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
            + " = org.omg.CORBA.ORB.init ().create_interface_tc (" + Util.helperName (i, true) + ".id (), " // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
            + '\"' + Util.stripLeadingUnderscores (entry.name ()) + "\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
  } // helperType
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
  public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
    tcoffsets.set (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
    if (entry.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
      stream.println (indent + name
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
          + " = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_objref);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
      stream.println (indent + name
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
          // <54697>
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
          //+ " = org.omg.CORBA.ORB.init ().create_interface_tc (_id, "
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
          + " = org.omg.CORBA.ORB.init ().create_interface_tc (" + Util.helperName (i, true) + ".id (), " // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
          + '\"' + Util.stripLeadingUnderscores (entry.name ()) + "\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
  } // helperType
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
  public int type (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    stream.println (indent + name + " = " + Util.helperName (entry, true) + ".type ();"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
  } // type
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
  public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
    if (i.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
      structHelperRead (entryName, i, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
      if (i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
         stream.println ("    return narrow (((org.omg.CORBA_2_3.portable.InputStream)istream).read_abstract_interface (_" + i.name () + "Stub.class));"); // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
         stream.println ("    return narrow (istream.read_Object (_" + i.name () + "Stub.class));");
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
  } // helperRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
  public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    if (i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
      stream.println ("    return narrow (((org.omg.CORBA_2_3.portable.InputStream)istream).read_abstract_interface (_" + i.name () + "Stub.class));"); // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
      stream.println ("    return narrow (istream.read_Object (_" + i.name () + "Stub.class));");
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
  } // helperRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
  public void helperWrite (SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
    if (i.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
      structHelperWrite (entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
      write (0, "    ", "value", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
  } // helperWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
  public void helperWrite (SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    write (0, "    ", "value", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
  } // helperWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
  public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
    if (i.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
      index = structRead (index, indent, name, i, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
      if (entry.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
        stream.println (indent + name + " = istream.read_Object (_" + i.name () + "Stub.class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        stream.println (indent + name + " = " + Util.helperName (entry, false) + ".narrow (istream.read_Object (_" + i.name () + "Stub.class));"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
  } // read
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
  public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
    if (entry.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
      stream.println (indent + name + " = istream.read_Object (_" + i.name () + "Stub.class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
      stream.println (indent + name + " = " + Util.helperName (entry, false) + ".narrow (istream.read_Object (_" + i.name () + "Stub.class));"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
  } // read
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
  public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
    if (i.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
      index = structWrite (index, indent, name, entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
      if (i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
         stream.println (indent + "((org.omg.CORBA_2_3.portable.OutputStream)ostream).write_abstract_interface ((java.lang.Object) " + name + ");"); // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
         stream.println (indent + "ostream.write_Object ((org.omg.CORBA.Object) " + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
  } // write
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
  public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
    if (i.isAbstract ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
      stream.println (indent + "((org.omg.CORBA_2_3.portable.OutputStream)ostream).write_abstract_interface ((java.lang.Object) " + name + ");"); // <d60929>
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
      stream.println (indent + "ostream.write_Object ((org.omg.CORBA.Object) " + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
  } // write
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
  // <f46082.51> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
  /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
  // These methods are cobbled from StructGen.  Stateful interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
  // are sent across the wire as if they were structs, with the first
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
  // element being a string - the Java name of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
  public int structHelperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
    TCOffsets innerOffsets = new TCOffsets ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
    innerOffsets.set (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    int offsetForStruct = innerOffsets.currentOffset ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
    InterfaceEntry i = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
    String membersName = "_members" + index++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    Vector state = i.state ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
    stream.println (indent + "org.omg.CORBA.StructMember[] " + membersName + " = new org.omg.CORBA.StructMember [" + (state.size () + 1) + "];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    String tcOfMembers = "_tcOf" + membersName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
    stream.println (indent + "org.omg.CORBA.TypeCode " + tcOfMembers + ';');
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    // The name string is the first element of the struct
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
    String memberName = "_name";
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    StringEntry stringEntry = Compile.compiler.factory.stringEntry ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
    index = ((JavaGenerator)stringEntry.generator ()).helperType (index, indent, innerOffsets, tcOfMembers, stringEntry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
    stream.println (indent + membersName + "[0] = new org.omg.CORBA.StructMember (");
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
    stream.println (indent + "  \"" + memberName + "\",");
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
    stream.println (indent + "  " + tcOfMembers + ',');
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
    stream.println (indent + "  null);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
    int offsetSoFar = innerOffsets.currentOffset ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    innerOffsets = new TCOffsets ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
    innerOffsets.set (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
    innerOffsets.bumpCurrentOffset (offsetSoFar - offsetForStruct);
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
    for (int idx = 0; idx < state.size (); ++idx)
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
      TypedefEntry member = ((InterfaceState)state.elementAt (idx)).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
      memberName = member.name ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
      index = ((JavaGenerator)member.generator ()).helperType (index, indent, innerOffsets, tcOfMembers, member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
      stream.println (indent + membersName + '[' + (idx + 1) + "] = new org.omg.CORBA.StructMember (");
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
      stream.println (indent + "  \"" + memberName + "\",");
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
      stream.println (indent + "  " + tcOfMembers + ',');
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
      stream.println (indent + "  null);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
      offsetSoFar = innerOffsets.currentOffset ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
      innerOffsets = new TCOffsets ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
      innerOffsets.set (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
      innerOffsets.bumpCurrentOffset (offsetSoFar - offsetForStruct);
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
    tcoffsets.bumpCurrentOffset (innerOffsets.currentOffset ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    stream.println (indent + name + " = org.omg.CORBA.ORB.init ().create_struct_tc (id (), \"" + entry.name () + "\", " + membersName + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
  } // structHelperType
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
  public void structHelperRead (String entryName, InterfaceEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    String impl = implName ((InterfaceEntry)entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
    stream.println ("      " + Util.javaStatefulName (entry) + " value = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
    structRead (0, "      ", "value", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
    stream.println ("      return value;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
  } // structHelperRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
  private String implName (InterfaceEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
    String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
    if (entry.container ().name ().equals (""))
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
      name =  '_' + entry.name () + "Impl";
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
      name = Util.containerFullName (entry.container ()) + "._" + entry.name () + "Impl";
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
    return name.replace ('/', '.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
  } // implName
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
  public int structRead (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    // The first element will be the name of the Java implementation class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    String stringName = "_name" + index++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
    stream.println (indent + "String " + stringName + " = istream.read_string ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
    stream.println (indent + "try");
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
    stream.println (indent + "{");
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
    stream.println (indent + "  " + name + " = (" + Util.javaStatefulName (entry) + ")com.sun.CORBA.iiop.ORB.getImpl (" + stringName + ".replace ('/', '.'));");
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
    stream.println (indent + "}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
    stream.println (indent + "catch (Exception e)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
    stream.println (indent + "{");
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
    stream.println (indent + "  " + name + " = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
    stream.println (indent + "}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    stream.println (indent + "if (" + name + " == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
    stream.println (indent + "  throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    stream.println (indent + "if (!" + stringName + ".equals (\"" + entry.fullName () + "\"))");
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    stream.println (indent + '{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
    stream.println (indent + "  Class _cls = " + name + ".getClass ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
    stream.println (indent + "  boolean _found = false;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
    stream.println (indent + "  while (!_found && _cls != null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
    stream.println (indent + "  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    stream.println (indent + "    Class[] interfaces = _cls.getInterfaces ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
    stream.println (indent + "    for (int i = 0; i < interfaces.length; ++i)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    stream.println (indent + "      if (interfaces[i].getName ().indexOf (\"State\") > 0)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    stream.println (indent + "      {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
    stream.println (indent + "        _cls = interfaces[i];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    stream.println (indent + "        _found = true;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
    stream.println (indent + "        break;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
    stream.println (indent + "      }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
    stream.println (indent + "    if (!_found)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
    stream.println (indent + "      _cls = _cls.getSuperclass ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
    stream.println (indent + "  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    stream.println (indent + "  if (_cls == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    stream.println (indent + "    throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    stream.println (indent + "  String _className = _cls.getName ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
    stream.println (indent + "  int _index = _className.lastIndexOf ('.');");
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
    stream.println (indent + "  String _helperName = _className.substring (0, _index + 1) + _className.substring (_index + 2, _className.length () - 5) + \"Helper\"; // 5 == \"State\".length");
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    stream.println (indent + "  try");
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
    stream.println (indent + "  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
    stream.println (indent + "    Class _helperClass = Class.forName (_helperName);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
    stream.println (indent + "    Class[] _formalParms = new Class [1];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
    stream.println (indent + "    _formalParms[0] = Class.forName (\"org.omg.CORBA.portable.InputStream\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
    stream.println (indent + "    java.lang.reflect.Method _read = _helperClass.getMethod (\"read\", _formalParms);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
    stream.println (indent + "    Object[] _actualParms = new Object [1];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
    stream.println (indent + "    _actualParms[0] = istream;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
    stream.println (indent + "      " + name + " = (" + Util.javaStatefulName (entry) + ")_read.invoke (null, _actualParms);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    stream.println (indent + "  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
    stream.println (indent + "  catch (Exception e)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
    stream.println (indent + "  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
    stream.println (indent + "    throw new org.omg.CORBA.NO_IMPLEMENT (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
    stream.println (indent + "  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
    stream.println (indent + '}');
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
    // instantiate an implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
    stream.println (indent + "else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
    stream.println (indent + '{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
    // Load the state
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
    readState (index, indent, name, (InterfaceEntry)entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
    stream.println (indent + '}');
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
  } // structRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
  private void readState (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
    // First write the state from all parents
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
    Enumeration e = entry.derivedFrom ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
      InterfaceEntry parent = (InterfaceEntry)e.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
      if (parent.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
        if (parent.state ().size () > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
          readState (index, indent, name, parent, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
    // Now write the state for the local entry
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
    e = entry.state ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
      TypedefEntry member = ((InterfaceState)e.nextElement ()).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
      String tmpName = '_' + member.name () + "Tmp";
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
      Util.writeInitializer (indent + "  ", tmpName, "", member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
      if (!member.arrayInfo ().isEmpty () || member.type () instanceof SequenceEntry || member.type () instanceof PrimitiveEntry || member.type () instanceof StringEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
        index = ((JavaGenerator)member.generator ()).read (index, indent + "  ", tmpName, member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
        stream.println (indent + "  " + tmpName + " = " + Util.helperName (member.type (), true) + ".read (istream);"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
      stream.println (indent + "  " + name + '.' + member.name () + " (" + tmpName + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
  } // readState
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
  public void structHelperWrite (SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    structWrite (0, "      ", "value", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
  } // structHelperWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
  public int structWrite (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
    // The first element of the struct must be the name of the real interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
    stream.println (indent + "Class _cls = " + name + ".getClass ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
    stream.println (indent + "boolean _found = false;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
    stream.println (indent + "while (!_found && _cls != null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
    stream.println (indent + "{");
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
    stream.println (indent + "  Class[] interfaces = _cls.getInterfaces ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
    stream.println (indent + "  for (int i = 0; i < interfaces.length; ++i)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
    stream.println (indent + "    if (interfaces[i].getName ().indexOf (\"State\") > 0)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
    stream.println (indent + "    {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
    stream.println (indent + "      _cls = interfaces[i];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
    stream.println (indent + "      _found = true;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
    stream.println (indent + "      break;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
    stream.println (indent + "    }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
    stream.println (indent + "  if (!_found)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
    stream.println (indent + "    _cls = _cls.getSuperclass ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
    stream.println (indent + '}');
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
    stream.println (indent + "if (_cls == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
    stream.println (indent + "  throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
    stream.println (indent + "String _className = _cls.getName ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
    stream.println (indent + "int _index = _className.lastIndexOf ('.');");
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
    stream.println (indent + "String _interfaceName = _className.substring (0, _index + 1) + _className.substring (_index + 2, _className.length () - 5); // 5 == \"State\".length");
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
    stream.println (indent + "ostream.write_string (_interfaceName.replace ('.', '/'));");
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
    // If _className != Util.javaName (entry), then call that class's helper class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
    stream.println (indent + "if (!_interfaceName.equals (\"" + Util.javaName (entry) + "\"))");
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
    stream.println (indent + '{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
    stream.println (indent + "  try");
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
    stream.println (indent + "  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
    stream.println (indent + "    Class _helperClass = Class.forName (_interfaceName + \"Helper\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
    stream.println (indent + "    Class[] _formalParms = new Class [2];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
    stream.println (indent + "    _formalParms[0] = Class.forName (\"org.omg.CORBA.portable.OutputStream\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    stream.println (indent + "    _formalParms[1] = _cls;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
    stream.println (indent + "    java.lang.reflect.Method _write = _helperClass.getMethod (\"write\", _formalParms);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
    stream.println (indent + "    Object[] _actualParms = new Object [2];");
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
    stream.println (indent + "    _actualParms[0] = ostream;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
    stream.println (indent + "    _actualParms[1] = " + name + ';');
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
    stream.println (indent + "    _write.invoke (null, _actualParms);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
    stream.println (indent + "  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
    stream.println (indent + "  catch (Exception e)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
    stream.println (indent + "  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
    stream.println (indent + "    throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_NO);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
    stream.println (indent + "  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
    stream.println (indent + '}');
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
    stream.println (indent + "else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
    stream.println (indent + '{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
    writeState (index, indent, name, (InterfaceEntry)entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
    stream.println (indent + '}');
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    return index;
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
  } // structWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
  private void writeState (int index, String indent, String name, InterfaceEntry entry, PrintWriter stream)
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    // First write the state from all parents
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
    Enumeration e = entry.derivedFrom ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
      InterfaceEntry parent = (InterfaceEntry)e.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
      if (parent.state () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
        if (parent.state ().size () > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
          writeState (index, indent, name, parent, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
    // Now write the state for the local entry
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
    Vector members = entry.state ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
    for (int i = 0; i < members.size (); ++i)
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
      TypedefEntry member = ((InterfaceState)members.elementAt (i)).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
      if (!member.arrayInfo ().isEmpty () || member.type () instanceof SequenceEntry || member.type () instanceof PrimitiveEntry || member.type () instanceof StringEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        index = ((JavaGenerator)member.generator ()).write (index, indent + "  ", name + '.' + member.name () + "()", member, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        stream.println (indent + "  " + Util.helperName (member.type (), true) + ".write (ostream, " + name + '.' + member.name () + " ());"); // <d61056>
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
  } // writeState
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
  */
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
   * @return true if the entry is for a CORBA pseudo-object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
  private boolean isPseudo(InterfaceEntry i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
    java.lang.String fullname = i.fullName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    if (fullname.equalsIgnoreCase("CORBA/TypeCode"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
    if (fullname.equalsIgnoreCase("CORBA/Principal"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
    if (fullname.equalsIgnoreCase("CORBA/ORB"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
    if (fullname.equalsIgnoreCase("CORBA/Any"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    if (fullname.equalsIgnoreCase("CORBA/Context"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
    if (fullname.equalsIgnoreCase("CORBA/ContextList"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
    if (fullname.equalsIgnoreCase("CORBA/DynamicImplementation"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
    if (fullname.equalsIgnoreCase("CORBA/Environment"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
    if (fullname.equalsIgnoreCase("CORBA/ExceptionList"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
    if (fullname.equalsIgnoreCase("CORBA/NVList"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
    if (fullname.equalsIgnoreCase("CORBA/NamedValue"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
    if (fullname.equalsIgnoreCase("CORBA/Request"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
    if (fullname.equalsIgnoreCase("CORBA/ServerRequest"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
    if (fullname.equalsIgnoreCase("CORBA/UserException"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
    return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
  // From JavaGenerator
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
  ///////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
  protected int            emit        = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
  protected Factories      factories   = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
  protected Hashtable      symbolTable = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
  protected InterfaceEntry i           = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
  protected PrintWriter    stream      = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
  // <f46082.03, f46838.1/.2/.3> Modify access to protected.
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
  protected static final   int SIGNATURE  = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
  protected static final   int OPERATIONS = 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
  protected                int intfType   = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
} // class InterfaceGen