corba/src/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Helper.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, 2004, 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
// -F46082.51<daz> Remove -stateful feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
// -D57118   <klr> Fix "narrow" in helper for abstract interface
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
// -D58889   <klr> re-Fix "narrow" in helper for abstract interface
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
// -D59383   <klr> 'get_class' in value helper returns value class, not helper.
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
// -D59413   <klr> Remove Helper interface references for non-value types.
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
// -D59435   <klr> Remove read_Object, write_Object completely.
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
// -D59418   <klr> Move read_Value, write_Value to generator's helperRead.
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.io.PrintWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import com.sun.tools.corba.se.idl.GenFileStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.corba.se.idl.InterfaceEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.corba.se.idl.MethodEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.corba.se.idl.ParameterEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.corba.se.idl.SymtabEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.tools.corba.se.idl.ValueEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.tools.corba.se.idl.ValueBoxEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import com.sun.tools.corba.se.idl.TypedefEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import com.sun.tools.corba.se.idl.InterfaceState;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import com.sun.tools.corba.se.idl.PrimitiveEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import com.sun.tools.corba.se.idl.StructEntry;
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 Helper implements AuxGen
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 Helper ()
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
  } // ctor
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
   * Generate the helper class.  Provides general algorithm
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
   * for auxiliary binding generation:
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
   *
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
   * 1.) Initialize symbol table and symbol table entry members,
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
   *     common to all generators.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
   * 2.) Initialize members unique to this generator.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
   * 3.) Open print stream
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
   * 4.) Write class heading: package, prologue, class statement, open curly
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
   * 5.) Write class body: member data and methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
   * 6.) Write class closing: close curly
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
   * 7.) Close the print stream
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
  public void generate (java.util.Hashtable symbolTable, com.sun.tools.corba.se.idl.SymtabEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    this.symbolTable = symbolTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    this.entry       = entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    init ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    openStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    if (stream == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    writeHeading ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    writeBody ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    writeClosing ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    closeStream ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
  } // generate
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
   * Initialize variables unique to this generator.
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
  protected void init ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    helperClass = entry.name () + "Helper";
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    if (entry instanceof ValueBoxEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
      ValueBoxEntry v = (ValueBoxEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
      TypedefEntry member = ((InterfaceState) v.state ().elementAt (0)).entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
      SymtabEntry mType =  member.type ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
      if (mType instanceof PrimitiveEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        helperType = Util.javaName (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
      else
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        helperType = Util.javaName (mType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
      helperType = Util.javaName (entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
  } // init
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
   * Open the print stream for subsequent output.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
  protected void openStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    stream = Util.stream (entry, "Helper.java");
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
  } // openStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
   * Generate the heading, including package, imports, class statements,
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
   * and open curly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
  protected void writeHeading ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    Util.writePackage (stream, entry, Util.HelperFile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    Util.writeProlog (stream, stream.name ());
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    // Transfer comment to target <30jul1997daz>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    if (entry.comment () != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
      entry.comment ().generate ("", stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    stream.print ("public final class " + helperClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    if (entry instanceof ValueEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
      stream.println (" implements org.omg.CORBA.portable.ValueHelper");
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
      stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    stream.println ('{');
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
   * Generate members of this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
  protected void writeBody ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    writeInstVars ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    writeCtors ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    writeInsert ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    writeExtract ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    writeType ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    writeID ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    writeRead ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    writeWrite ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    if (entry instanceof InterfaceEntry && !(entry instanceof ValueEntry)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
      writeNarrow ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
      writeUncheckedNarrow ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    writeHelperInterface ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    if (entry instanceof ValueEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
      writeValueHelperInterface ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
  } // writeBody
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
   * Generate members of the Helper interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
  protected void writeHelperInterface ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
  } // writeHelperInterface
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
   * Generate members of the ValueHelper interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
  protected void writeValueHelperInterface ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    writeGetID ();       // moved for <d59413>
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    writeGetType ();     // moved for <d59413>
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    writeGetInstance (); // not in ValueHelper interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    writeGetClass ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    writeGetSafeBaseIds ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
  } // writeHelperInterface
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
   * Generate the closing statements.
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
  protected void writeClosing ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
  {
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
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
   * Write the stream to file by closing the print stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
  protected void closeStream ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    stream.close ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
   * Generate the instance variables.
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
  protected void writeInstVars ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    stream.println ("  private static String  _id = \"" + Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ()) + "\";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
    if (entry instanceof ValueEntry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
      stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
      stream.println ("  private static " + helperClass + " helper = new " + helperClass + " ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
      stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
      stream.println ("  private static String[] _truncatable_ids = {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
      stream.print   ("    _id");
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
      // Any safe ValueEntry must have a concete value parent.
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
      // The topmost parent cannot be safe since it doesn't have
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
      // a concrete parent.
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
      ValueEntry child = (ValueEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
      while (child.isSafe ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
      {
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        stream.println(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        ValueEntry parent = (ValueEntry)child.derivedFrom ().elementAt (0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        stream.print("    \"" + Util.stripLeadingUnderscoresFromID (parent.repositoryID ().ID ()) + "\"");
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        child = parent;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
      stream.println("   };");
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
  } // writeInstVars
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
   * Generate the constructors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
  protected void writeCtors ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
    stream.println ("  public " + helperClass + "()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
  } // writeCtors
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
   * Generate the insert method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
  protected void writeInsert ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    stream.println ("  public static void insert (org.omg.CORBA.Any a, " + helperType + " that)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    stream.println ("    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    stream.println ("    a.type (type ());");
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    stream.println ("    write (out, that);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    stream.println ("    a.read_value (out.create_input_stream (), type ());");
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
  } // writeInsert
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
   * Generate the extract method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
  protected void writeExtract ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    stream.println ("  public static " + helperType + " extract (org.omg.CORBA.Any a)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    stream.println ("    return read (a.create_input_stream ());");
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
  } // writeExtract
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
   * Generate the typecode variable and type method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
  protected void writeType ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    boolean canRecurse = entry instanceof ValueEntry
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        || entry instanceof ValueBoxEntry
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        || entry instanceof StructEntry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    stream.println ("  private static org.omg.CORBA.TypeCode __typeCode = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    if (canRecurse)
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
      stream.println ("  private static boolean __active = false;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    stream.println ("  synchronized public static org.omg.CORBA.TypeCode type ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    stream.println ("    if (__typeCode == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    stream.println ("    {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    if (canRecurse) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    stream.println ("      synchronized (org.omg.CORBA.TypeCode.class)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    stream.println ("      {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    stream.println ("        if (__typeCode == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    stream.println ("        {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    stream.println ("          if (__active)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    stream.println ("          {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    stream.println ("            return org.omg.CORBA.ORB.init().create_recursive_tc ( _id );");
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    stream.println ("          }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    stream.println ("          __active = true;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    ((JavaGenerator)entry.generator ()).helperType (0, "          ", new TCOffsets (), "__typeCode", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    ((JavaGenerator)entry.generator ()).helperType (0, "      ", new TCOffsets (), "__typeCode", entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    // Generate body of type() method
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    if (canRecurse) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    stream.println ("          __active = false;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    stream.println ("        }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    stream.println ("      }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    stream.println ("    }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    stream.println ("    return __typeCode;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
  } // writeType
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
   * Generate the ID method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
  protected void writeID ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    stream.println ("  public static String id ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    stream.println ("    return _id;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
  } // writeID
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
   * Generate the read method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
  protected void writeRead ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    boolean isLocalInterface = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    if (entry instanceof InterfaceEntry) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        InterfaceEntry ie = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        // for #pragma sun_local or sun_localservant, or actual local
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        // local interface, set the flag by checking on both
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        isLocalInterface = ie.isLocal() | ie.isLocalServant();
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    stream.println ("  public static " + helperType + " read (org.omg.CORBA.portable.InputStream istream)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
    if ( !isLocalInterface ) { // nonLocal Interface and other types
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
      ((JavaGenerator)entry.generator ()).helperRead (helperType, entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    } else { //Local interface should throw exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
      stream.println ("      throw new org.omg.CORBA.MARSHAL ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
  } // writeRead
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
   * Generate the write method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
  protected void writeWrite ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    boolean isLocalInterface = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    if (entry instanceof InterfaceEntry) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        InterfaceEntry ie = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        // for #pragma sun_local or sun_localservant, or actual local
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        // local interface, set the flag by checking on both
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
        isLocalInterface = ie.isLocal() | ie.isLocalServant();
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
    stream.println ("  public static void write (org.omg.CORBA.portable.OutputStream ostream, " + helperType + " value)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
    if ( !isLocalInterface ) { // nonLocal Interface and other types
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
      ((JavaGenerator)entry.generator ()).helperWrite (entry, stream);
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    } else { //Local interface should throw exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
      stream.println ("      throw new org.omg.CORBA.MARSHAL ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
  } // writeWrite
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
   * Generate the narrow method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
  protected void writeNarrow ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
    writeRemoteNarrow ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
   * Write the narrow() method for a remotable object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
  protected void writeRemoteNarrow ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    InterfaceEntry ie = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    // narrow for LocalObject interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
    if (ie.isLocal ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
        writeRemoteNarrowForLocal (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
    // narrow for Abstract interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    if (ie.isAbstract ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
        writeRemoteNarrowForAbstract (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        // Determine if the non-abstract interface has any abstract parents
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        for (int i = 0; i < ie.derivedFrom ().size (); i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
            SymtabEntry parent = (SymtabEntry) ie.derivedFrom ().elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
            if (((InterfaceEntry) parent).isAbstract ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
                writeRemoteNarrowForAbstract (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
    stream.println ("  public static " + helperType + " narrow (org.omg.CORBA.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
    stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
    stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    stream.println ("    else if (!obj._is_a (id ()))");
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
    stream.println ("      throw new org.omg.CORBA.BAD_PARAM ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    stream.println ("    else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
    stream.println ("    {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    stream.println ("      org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
    String stubNameofEntry = stubName ((InterfaceEntry)entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
    stream.println ("      " + stubNameofEntry + " stub = new " + stubNameofEntry + " ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
    stream.println ("      stub._set_delegate(delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
    stream.println ("      return stub;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
    stream.println ("    }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
  } // writeRemoteNarrow
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
   * Write the narrow() method for local interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
  private void writeRemoteNarrowForLocal (boolean hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
    stream.println ("  public static " + helperType + " narrow (org.omg.CORBA.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
    stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    stream.println ("    else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    stream.println ("      throw new org.omg.CORBA.BAD_PARAM ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
  } // writeRemoteNarrowForLocal
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
   * Write the narrow() method for abstract interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
  private void writeRemoteNarrowForAbstract (boolean hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    stream.print ("  public static " + helperType + " narrow (java.lang.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
    if (hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
      stream.println ("    else if (obj instanceof org.omg.CORBA.Object)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
      stream.println ("      return narrow ((org.omg.CORBA.Object) obj);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
      stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
      stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    // If hasAbstractParent is false, then THIS entry must be abstract.
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    // This method is also called in case THIS entry is not abstract, but
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
    // there is an abstract parent.  If this entry is not abstract,
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    // it can never narrow to a CORBA object reference.
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    if (!hasAbstractParent) { // <d58889>
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
      String stubNameofEntry = stubName ((InterfaceEntry)entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
      stream.println ("    else if ((obj instanceof org.omg.CORBA.portable.ObjectImpl) &&");
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
      stream.println ("             (((org.omg.CORBA.Object)obj)._is_a (id ()))) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
      stream.println ("      org.omg.CORBA.portable.ObjectImpl impl = (org.omg.CORBA.portable.ObjectImpl)obj ;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
      stream.println ("      org.omg.CORBA.portable.Delegate delegate = impl._get_delegate() ;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
      stream.println ("      " + stubNameofEntry + " stub = new " + stubNameofEntry + " ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
      stream.println ("      stub._set_delegate(delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
      stream.println ("      return stub;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
      stream.println ("    }" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
    // end <d57118 - check for remotable - klr>
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    stream.println ("    throw new org.omg.CORBA.BAD_PARAM ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
  } // writeRemoteNarrowForAbstract
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
   * Generate the unchecked narrow method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
  protected void writeUncheckedNarrow ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    writeUncheckedRemoteNarrow ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
   * Write the unchecked narrow() method for a remotable object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
  protected void writeUncheckedRemoteNarrow ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
    InterfaceEntry ie = (InterfaceEntry) entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
    // unchecked narrow for LocalObject interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
    if (ie.isLocal ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        writeRemoteUncheckedNarrowForLocal (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
        return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
    // unchecked narrow for Abstract interface
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
    if (ie.isAbstract ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        writeRemoteUncheckedNarrowForAbstract (false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
        return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        // Determine if the non-abstract interface has any abstract parents
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
        for (int i = 0; i < ie.derivedFrom ().size (); i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
            SymtabEntry parent = (SymtabEntry) ie.derivedFrom ().elementAt (i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            if (((InterfaceEntry) parent).isAbstract ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                writeRemoteUncheckedNarrowForAbstract (true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    stream.println ("  public static " + helperType + " unchecked_narrow (org.omg.CORBA.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
    stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    stream.println ("    else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
    stream.println ("    {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    stream.println ("      org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    String stubNameofEntry = stubName ((InterfaceEntry)entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
    stream.println ("      " + stubNameofEntry + " stub = new " + stubNameofEntry + " ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
    stream.println ("      stub._set_delegate(delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
    stream.println ("      return stub;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
    stream.println ("    }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
  } // writeUncheckedRemoteNarrow
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
   * Write the unchecked narrow() method for local interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
  private void writeRemoteUncheckedNarrowForLocal (boolean hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
    stream.println ("  public static " + helperType + " unchecked_narrow (org.omg.CORBA.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
    stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
    stream.println ("    else");
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    stream.println ("      throw new org.omg.CORBA.BAD_PARAM ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
  } // writeRemoteUncheckedNarrowForLocal
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
   * Write the unchecked narrow() method for abstract interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
  private void writeRemoteUncheckedNarrowForAbstract (boolean hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
    stream.print ("  public static " + helperType + " unchecked_narrow (java.lang.Object obj)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
    stream.println ("    if (obj == null)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    stream.println ("      return null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
    if (hasAbstractParent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
      stream.println ("    else if (obj instanceof org.omg.CORBA.Object)");
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
      stream.println ("      return unchecked_narrow ((org.omg.CORBA.Object) obj);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
      stream.println ("    else if (obj instanceof " + helperType + ')');
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
      stream.println ("      return (" + helperType + ")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
    if (!hasAbstractParent) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
      String stubNameofEntry = stubName ((InterfaceEntry)entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
      stream.println ("    else if (obj instanceof org.omg.CORBA.portable.ObjectImpl) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
      stream.println ("      org.omg.CORBA.portable.ObjectImpl impl = (org.omg.CORBA.portable.ObjectImpl)obj ;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
      stream.println ("      org.omg.CORBA.portable.Delegate delegate = impl._get_delegate() ;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
      stream.println ("      " + stubNameofEntry + " stub = new " + stubNameofEntry + " ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
      stream.println ("      stub._set_delegate(delegate);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
      stream.println ("      return stub;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
      stream.println ("    }" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
    stream.println ("    throw new org.omg.CORBA.BAD_PARAM ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
  } // writeRemoteUncheckedNarrowForAbstract
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
   * Generate the GetID method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
  protected void writeGetID ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    if ( !Util.IDLEntity (entry))
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
    stream.println ("  public String get_id ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
    stream.println ("    return _id;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
  } // writeGetID
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
   * Generate the GetType method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
  protected void writeGetType ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
    if ( !Util.IDLEntity (entry))
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
      return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
    stream.println ("  public org.omg.CORBA.TypeCode get_type ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
    stream.println ("    return type ();");
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
  } // writeGetID
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
   * Generate the get_class method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
  protected void writeGetClass ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
    stream.println ("  public Class get_class ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
    stream.println ("    return " + helperType + ".class;"); //<d59383>
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
  } // writeGetClass
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
   * Generate the get_instance method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
  protected void writeGetInstance ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    stream.println ("  public static org.omg.CORBA.portable.ValueHelper get_instance ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    stream.println ("    return helper;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
  } // writeGetInstance
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
   * Generate the GetSafeBaseIds method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
  protected void writeGetSafeBaseIds ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
    stream.println ("  public String[] get_truncatable_base_ids ()");
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
    stream.println ("  {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
    stream.println ("    return _truncatable_ids;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    stream.println ("  }");
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
    stream.println ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
  } // writeGetSafeBaseIds
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
  /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
   * Return the stub name for the interface entry.
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
   **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
  protected String stubName (InterfaceEntry entry)
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
    String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
    if (entry.container ().name ().equals (""))
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
      name =  '_' + entry.name () + "Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
      name = Util.containerFullName (entry.container ()) + "._" + entry.name () + "Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
    return name.replace ('/', '.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
  } // stubName
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
  protected java.util.Hashtable     symbolTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
  protected com.sun.tools.corba.se.idl.SymtabEntry entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
  protected GenFileStream           stream;
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
  // Unique to this generator
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
  protected String helperClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
  protected String helperType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
} // class Helper