Helper24.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25/*
26 * COMPONENT_NAME: idl.toJava
27 *
28 * ORIGINS: 27
29 *
30 * Licensed Materials - Property of IBM
31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32 * RMI-IIOP v1.0
33 *
34 */
35
36package com.sun.tools.corba.se.idl.toJavaPortable;
37
38// NOTES:
39// -D62023   <klr> New file to implement CORBA 2.4 RTF
40
41import java.io.PrintWriter;
42
43import java.util.Enumeration;
44import java.util.Vector;
45
46import com.sun.tools.corba.se.idl.GenFileStream;
47import com.sun.tools.corba.se.idl.InterfaceEntry;
48import com.sun.tools.corba.se.idl.MethodEntry;
49import com.sun.tools.corba.se.idl.ParameterEntry;
50import com.sun.tools.corba.se.idl.SymtabEntry;
51import com.sun.tools.corba.se.idl.ValueEntry;
52import com.sun.tools.corba.se.idl.ValueBoxEntry;
53import com.sun.tools.corba.se.idl.TypedefEntry;
54import com.sun.tools.corba.se.idl.InterfaceState;
55import com.sun.tools.corba.se.idl.PrimitiveEntry;
56import com.sun.tools.corba.se.idl.StructEntry;
57
58/**
59 *
60 **/
61public class Helper24 extends Helper
62{
63  /**
64   * Public zero-argument constructor.
65   **/
66  public Helper24 ()
67  {
68  } // ctor
69
70  /**
71   * Generate the heading, including package, imports, class statements,
72   * and open curly.
73   * <d62023> - don't implement ValueHelper, make non-boxed helpers abstract
74   **/
75  protected void writeHeading ()
76  {
77    Util.writePackage (stream, entry, Util.HelperFile);
78    Util.writeProlog (stream, stream.name ());
79
80    // Transfer comment to target <30jul1997daz>.
81    if (entry.comment () != null)
82      entry.comment ().generate ("", stream);
83
84    if (entry instanceof ValueBoxEntry) {
85        stream.print   ("public final class " + helperClass);
86        stream.println (" implements org.omg.CORBA.portable.BoxedValueHelper");
87    }
88    else
89        stream.println ("abstract public class " + helperClass);
90    stream.println ('{');
91  }
92
93  /**
94   * Generate the instance variables.
95   * <d62023> - no helper instance except for boxed valuetypes.
96   *          - move truncatable_ids to mapped class.
97   **/
98  protected void writeInstVars ()
99  {
100    stream.println ("  private static String  _id = \"" + Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ()) + "\";");
101    if (entry instanceof ValueEntry)
102    {
103      stream.println ();
104      if (entry instanceof ValueBoxEntry) {
105          stream.println ("  private static " + helperClass + " _instance = new " + helperClass + " ();");
106          stream.println ();
107      }
108    }
109    stream.println ();
110  } // writeInstVars
111
112  /**
113   * <d62023> generate members of BoxedValueHelper interface if boxed
114   *
115   * <d62023> Hook in here to write factory methods for non-boxed ValueTypes
116   *          into Helper.
117   **/
118  protected void writeValueHelperInterface ()
119  {
120    if (entry instanceof ValueBoxEntry) {
121        writeGetID ();
122    } else if (entry instanceof ValueEntry) {
123        writeHelperFactories ();
124    }
125  } // writeValueHelperInterface
126
127  /**
128   *
129   **/
130  protected void writeHelperFactories ()
131  {
132    Vector init = ((ValueEntry)entry).initializers ();
133    if (init != null)
134    {
135      stream.println ();
136      for (int i = 0; i < init.size (); i++)
137      {
138        MethodEntry element = (MethodEntry) init.elementAt (i);
139        element.valueMethod (true); //tag value method if not tagged previously
140        ((MethodGen24) element.generator ()). helperFactoryMethod (symbolTable, element, entry, stream);
141      }
142    }
143  } // writeHelperFactories
144
145  /**
146   * <d62023> Generate constructors only for boxed valuetype helpers
147   *            All other helpers are abstract.
148   **/
149  protected void writeCtors ()
150  {
151    if (entry instanceof ValueBoxEntry) {
152        stream.println ("  public " + helperClass + "()");
153        stream.println ("  {");
154        stream.println ("  }");
155        stream.println ();
156    }
157  } // writeCtors
158}
159