Helper24.java revision 672:2bb058ce572e
1246122Shselasky/*
2184610Salfred * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3184610Salfred * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4184610Salfred *
5184610Salfred * This code is free software; you can redistribute it and/or modify it
6184610Salfred * under the terms of the GNU General Public License version 2 only, as
7184610Salfred * published by the Free Software Foundation.  Oracle designates this
8184610Salfred * particular file as subject to the "Classpath" exception as provided
9184610Salfred * by Oracle in the LICENSE file that accompanied this code.
10184610Salfred *
11184610Salfred * This code is distributed in the hope that it will be useful, but WITHOUT
12184610Salfred * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13184610Salfred * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14184610Salfred * version 2 for more details (a copy is included in the LICENSE file that
15184610Salfred * accompanied this code).
16184610Salfred *
17184610Salfred * You should have received a copy of the GNU General Public License version
18184610Salfred * 2 along with this work; if not, write to the Free Software Foundation,
19184610Salfred * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20184610Salfred *
21184610Salfred * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22184610Salfred * or visit www.oracle.com if you need additional information or have any
23184610Salfred * questions.
24184610Salfred */
25184610Salfred/*
26184610Salfred * COMPONENT_NAME: idl.toJava
27184610Salfred *
28184610Salfred * ORIGINS: 27
29184610Salfred *
30184610Salfred * Licensed Materials - Property of IBM
31184610Salfred * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32184610Salfred * RMI-IIOP v1.0
33190754Sthompsa *
34184610Salfred */
35184610Salfred
36246122Shselaskypackage com.sun.tools.corba.se.idl.toJavaPortable;
37246122Shselasky
38246122Shselasky// NOTES:
39194677Sthompsa// -D62023   <klr> New file to implement CORBA 2.4 RTF
40194677Sthompsa
41194677Sthompsaimport java.io.PrintWriter;
42194677Sthompsa
43194677Sthompsaimport java.util.Enumeration;
44194677Sthompsaimport java.util.Vector;
45194677Sthompsa
46194677Sthompsaimport com.sun.tools.corba.se.idl.GenFileStream;
47194677Sthompsaimport com.sun.tools.corba.se.idl.InterfaceEntry;
48194677Sthompsaimport com.sun.tools.corba.se.idl.MethodEntry;
49194677Sthompsaimport com.sun.tools.corba.se.idl.ParameterEntry;
50194677Sthompsaimport com.sun.tools.corba.se.idl.SymtabEntry;
51194677Sthompsaimport com.sun.tools.corba.se.idl.ValueEntry;
52194677Sthompsaimport com.sun.tools.corba.se.idl.ValueBoxEntry;
53194677Sthompsaimport com.sun.tools.corba.se.idl.TypedefEntry;
54194677Sthompsaimport com.sun.tools.corba.se.idl.InterfaceState;
55194677Sthompsaimport com.sun.tools.corba.se.idl.PrimitiveEntry;
56194677Sthompsaimport com.sun.tools.corba.se.idl.StructEntry;
57194677Sthompsa
58188942Sthompsa/**
59194677Sthompsa *
60184610Salfred **/
61184610Salfredpublic class Helper24 extends Helper
62184610Salfred{
63188942Sthompsa  /**
64188942Sthompsa   * Public zero-argument constructor.
65188942Sthompsa   **/
66188942Sthompsa  public Helper24 ()
67188942Sthompsa  {
68188942Sthompsa  } // ctor
69188942Sthompsa
70188942Sthompsa  /**
71184610Salfred   * Generate the heading, including package, imports, class statements,
72188942Sthompsa   * and open curly.
73188942Sthompsa   * d62023 - don't implement ValueHelper, make non-boxed helpers abstract
74246122Shselasky   **/
75246122Shselasky  protected void writeHeading ()
76188942Sthompsa  {
77198151Sthompsa    Util.writePackage (stream, entry, Util.HelperFile);
78184610Salfred    Util.writeProlog (stream, stream.name ());
79190181Sthompsa
80190181Sthompsa    // Transfer comment to target <30jul1997daz>.
81190181Sthompsa    if (entry.comment () != null)
82184610Salfred      entry.comment ().generate ("", stream);
83194677Sthompsa
84184610Salfred    if (entry instanceof ValueBoxEntry) {
85184610Salfred        stream.print   ("public final class " + helperClass);
86227309Sed        stream.println (" implements org.omg.CORBA.portable.BoxedValueHelper");
87242126Shselasky    }
88184610Salfred    else
89199675Sthompsa        stream.println ("abstract public class " + helperClass);
90199675Sthompsa    stream.println ('{');
91184610Salfred  }
92184610Salfred
93184610Salfred  /**
94184610Salfred   * Generate the instance variables.
95184610Salfred   * <pre>
96184610Salfred   * d62023 - no helper instance except for boxed valuetypes;
97184610Salfred   *        - move truncatable_ids to mapped class.
98184610Salfred   * </pre>
99184610Salfred   **/
100184610Salfred  protected void writeInstVars ()
101184610Salfred  {
102184610Salfred    stream.println ("  private static String  _id = \"" + Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ()) + "\";");
103184610Salfred    if (entry instanceof ValueEntry)
104184610Salfred    {
105184610Salfred      stream.println ();
106184610Salfred      if (entry instanceof ValueBoxEntry) {
107184610Salfred          stream.println ("  private static " + helperClass + " _instance = new " + helperClass + " ();");
108184610Salfred          stream.println ();
109184610Salfred      }
110184610Salfred    }
111184610Salfred    stream.println ();
112184610Salfred  } // writeInstVars
113184610Salfred
114192984Sthompsa  /**
115192984Sthompsa   * d62023 - generate members of BoxedValueHelper interface if boxed
116192984Sthompsa   *
117192984Sthompsa   * d62023 - hook in here to write factory methods for non-boxed ValueTypes
118192984Sthompsa   *          into Helper.
119184610Salfred   **/
120192984Sthompsa  protected void writeValueHelperInterface ()
121193045Sthompsa  {
122184610Salfred    if (entry instanceof ValueBoxEntry) {
123192984Sthompsa        writeGetID ();
124190735Sthompsa    } else if (entry instanceof ValueEntry) {
125184610Salfred        writeHelperFactories ();
126184610Salfred    }
127192984Sthompsa  } // writeValueHelperInterface
128184610Salfred
129184610Salfred  /**
130184610Salfred   *
131184610Salfred   **/
132184610Salfred  protected void writeHelperFactories ()
133184610Salfred  {
134184610Salfred    Vector init = ((ValueEntry)entry).initializers ();
135184610Salfred    if (init != null)
136190183Sthompsa    {
137184610Salfred      stream.println ();
138184610Salfred      for (int i = 0; i < init.size (); i++)
139184610Salfred      {
140184610Salfred        MethodEntry element = (MethodEntry) init.elementAt (i);
141184610Salfred        element.valueMethod (true); //tag value method if not tagged previously
142194228Sthompsa        ((MethodGen24) element.generator ()). helperFactoryMethod (symbolTable, element, entry, stream);
143184610Salfred      }
144184610Salfred    }
145184610Salfred  } // writeHelperFactories
146184610Salfred
147193045Sthompsa  /**
148184610Salfred   * d62023 - generate constructors only for boxed valuetype helpers.
149184610Salfred   *          All other helpers are abstract.
150184610Salfred   **/
151184610Salfred  protected void writeCtors ()
152184610Salfred  {
153184610Salfred    if (entry instanceof ValueBoxEntry) {
154184610Salfred        stream.println ("  public " + helperClass + "()");
155184610Salfred        stream.println ("  {");
156184610Salfred        stream.println ("  }");
157184610Salfred        stream.println ();
158184610Salfred    }
159184610Salfred  } // writeCtors
160184610Salfred}
161184610Salfred