corba/src/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Stub.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 7580 4b09cf866b32
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, 2002, 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
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.io.PrintWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.tools.corba.se.idl.AttributeEntry;
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.MethodEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.tools.corba.se.idl.SymtabEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
public class Stub implements AuxGen
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
   * Public zero-argument constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
  public Stub ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
  } // ctor
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 void generate (Hashtable symbolTable, SymtabEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    this.symbolTable = symbolTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    this.i           = (InterfaceEntry)entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    this.localStub   = i.isLocalServant();
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    this.isAbstract  = i.isAbstract( );
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    init ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    openStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    if (stream == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    writeHeading ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    writeBody ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    writeClosing ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    closeStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
  } // generate
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
   * Initialize unique members of this generator.
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
  protected void init ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    classSuffix = "Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
  } // init
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
  protected void openStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    String name = '_' + i.name () + classSuffix;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    String pkg = Util.containerFullName (i.container ());
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    if (pkg != null && !pkg.equals (""))
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
      Util.mkdir (pkg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
      name = pkg + '/' + name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    stream = Util.getStream (name.replace ('/', File.separatorChar) + ".java", i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
  } // openStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
  protected void writeHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    Util.writePackage (stream, i, Util.StubFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    Util.writeProlog (stream, ((GenFileStream)stream).name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    // Transfer interface comment to target <31jul1997>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    if (i.comment () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
      i.comment ().generate ("", stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    writeClassDeclaration ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    stream.println ('{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
  } // writeHeading
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
  protected void writeClassDeclaration ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    stream.print ("public class _" + i.name () + classSuffix + " extends org.omg.CORBA.portable.ObjectImpl");
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    stream.println (" implements " + Util.javaName (i));
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
  } // writeClassDeclaration
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
   * Steps done within writeBody include:
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
   * 1.)  makeCtors ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
   * 2.)  buildMethodList ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
   * 3.)  makeMethods ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
   * 4.)  makeCORBAObjectMethods ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
  protected void writeBody ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    writeCtors ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    buildMethodList ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    writeMethods ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    writeCORBAObjectMethods ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    writeSerializationMethods ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
  } // writeBody
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
  protected void writeClosing ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    stream.println ("} // class _" + i.name () + classSuffix);
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
  } // writeClosing
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
  protected void closeStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    stream.close ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
  } // closeStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
  protected void writeCtors ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    String name = i.name ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    /***  the constructors are not generated as per ptc/00-01-08.pdf
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
     *    since these are non-standard APIs, and same can be accomplished
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
     *    programatically, we need to comment this out, in order to
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     *    be able to generate standard stubs
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    /*************
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    stream.println ("  // Constructors");
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    stream.println ("  // NOTE:  If the default constructor is used, the");
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    stream.println ("  //        object is useless until _set_delegate (...)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    stream.println ("  //        is called.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    stream.println ("  public _" + name + classSuffix + " ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    stream.println ("    super ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    stream.println ("  public _" + name + classSuffix + " (org.omg.CORBA.portable.Delegate delegate)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    stream.println ("    super ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    stream.println ("    _set_delegate (delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    ***************/
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    // This is confusing since we have localOptimization flag as well.
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    // We have left this code because JCK team filed a P1 bug for changing
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    // _opsClass to $opsClass. Will clean it up in Tiger
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    // _REVISIT_ (Hemanth 03/05/2002)
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    if (localStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        stream.println ("  final public static java.lang.Class _opsClass = " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            name + "Operations.class;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
        stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
  } // writeCtors
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
   * Build a list of all of the methods, keeping out duplicates.
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
  protected void buildMethodList ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    // Start from scratch
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    methodList = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    buildMethodList (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
  } // buildMethodList
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
  private void buildMethodList (InterfaceEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    // Add the local methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    Enumeration locals = entry.methods ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
    while (locals.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
      addMethod ((MethodEntry)locals.nextElement ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    // Add the inherited methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    Enumeration parents = entry.derivedFrom ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    while (parents.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
      InterfaceEntry parent = (InterfaceEntry)parents.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
      if (!parent.name ().equals ("Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        buildMethodList (parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
  } // buildMethodList
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
  private void addMethod (MethodEntry method)
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    if (!methodList.contains (method))
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
      methodList.addElement (method);
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
  } // addMethod
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
  protected void writeMethods ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    // Count the methods, attributes which are not readonly are
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    // counted as 2 methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    int count = methodList.size ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    Enumeration e = methodList.elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
      Object method = e.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
      if (method instanceof AttributeEntry && !((AttributeEntry)method).readOnly ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        ++count;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    if( (((Arguments)Compile.compiler.arguments).LocalOptimization )
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
      && !isAbstract )
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
        stream.println( "    final public static java.lang.Class _opsClass =" );
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        stream.println( "        " + this.i.name() + "Operations.class;" );
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    // Write the methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    int realI = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    for (int i = 0; i < methodList.size (); ++i)
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
      MethodEntry method = (MethodEntry)methodList.elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
      if (!localStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
      ((MethodGen)method.generator ()).stub (this.i.name(), isAbstract, symbolTable, method, stream, realI);
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
      } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
      ((MethodGen)method.generator ()).localstub (symbolTable, method, stream, realI, this.i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
      if (method instanceof AttributeEntry && !((AttributeEntry)method).readOnly ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        realI += 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        ++realI;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
  } // writeMethods
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
  private void buildIDList (InterfaceEntry entry, Vector list)
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    if (!entry.fullName ().equals ("org/omg/CORBA/Object"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
      String id = Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
      if (!list.contains (id))
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        list.addElement (id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
      Enumeration e = entry.derivedFrom ().elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
      while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        buildIDList ((InterfaceEntry)e.nextElement (), list);
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
  } // buildIDList
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
  private void writeIDs ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    Vector list = new Vector ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    buildIDList (i, list);
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    Enumeration e = list.elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    boolean first = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    while (e.hasMoreElements ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
      if (first)
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        first = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        stream.println (", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
      stream.print ("    \"" + (String)e.nextElement () + '"');
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
  } // writeIDs
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
  protected void writeCORBAObjectMethods ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    stream.println ("  // Type-specific CORBA::Object operations");
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    stream.println ("  private static String[] __ids = {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    writeIDs ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    stream.println ("};");
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    stream.println ("  public String[] _ids ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    stream.println ("    return (String[])__ids.clone ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
  } // writeCORBAObjectMethods
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
  protected void writeSerializationMethods ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    stream.println ("  private void readObject (java.io.ObjectInputStream s) throws java.io.IOException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
    stream.println ("     String str = s.readUTF ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    stream.println ("     String[] args = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    stream.println ("     java.util.Properties props = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    stream.println ("     org.omg.CORBA.Object obj = org.omg.CORBA.ORB.init (args, props).string_to_object (str);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    stream.println ("     org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
    stream.println ("     _set_delegate (delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
    stream.println ("  private void writeObject (java.io.ObjectOutputStream s) throws java.io.IOException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    stream.println ("     String[] args = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
    stream.println ("     java.util.Properties props = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    stream.println ("     String str = org.omg.CORBA.ORB.init (args, props).object_to_string (this);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    stream.println ("     s.writeUTF (str);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    stream.println ("  }");
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 Hashtable      symbolTable = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
  protected InterfaceEntry i           = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
  protected PrintWriter    stream      = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
  // Unique to this generator
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
  protected Vector         methodList  = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
  protected String         classSuffix = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
  protected boolean        localStub = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
  private   boolean        isAbstract = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
} // class Stub