View Javadoc
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.parser
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  
36  package com.sun.tools.corba.se.idl;
37  
38  // NOTES:
39  
40  import java.io.PrintWriter;
41  import java.util.Enumeration;
42  import java.util.Hashtable;
43  import java.util.Vector;
44  
45  /**
46   * This is the symbol table entry for forward declarations of interfaces.
47   **/
48  public class ForwardEntry extends SymtabEntry implements InterfaceType
49  {
50    protected ForwardEntry ()
51    {
52      super ();
53    } // ctor
54  
55    protected ForwardEntry (ForwardEntry that)
56    {
57      super (that);
58    } // ctor
59  
60    protected ForwardEntry (SymtabEntry that, IDLID clone)
61    {
62      super (that, clone);
63      if (module ().equals (""))
64        module (name ());
65      else if (!name ().equals (""))
66        module (module () + "/" + name ());
67    } // ctor
68  
69    public Object clone ()
70    {
71      return new ForwardEntry (this);
72    } // clone
73  
74    /** Invoke the forward declaration generator.
75        @param symbolTable the symbol table is a hash table whose key is
76         a fully qualified type name and whose value is a SymtabEntry or
77         a subclass of SymtabEntry.
78        @param stream the stream to which the generator should sent its output.
79        @see SymtabEntry */
80    public void generate (Hashtable symbolTable, PrintWriter stream)
81    {
82      forwardGen.generate (symbolTable, this, stream);
83    } // generate
84  
85    /** Access the interface generator.
86        @returns an object which implements the InterfaceGen interface.
87        @see InterfaceGen */
88    public Generator generator ()
89    {
90      return forwardGen;
91    } // generator
92  
93    static boolean replaceForwardDecl (InterfaceEntry interfaceEntry)
94    {
95      boolean result = true;
96      try
97      {
98        ForwardEntry forwardEntry =
99            (ForwardEntry)Parser.symbolTable.get (interfaceEntry.fullName ());
100       if ( forwardEntry != null )
101       {
102         result = (interfaceEntry.getInterfaceType () ==
103             forwardEntry.getInterfaceType ());
104         forwardEntry.type (interfaceEntry);
105 
106         // If this interface has been forward declared, there are probably
107         // other interfaces which derive from a ForwardEntry.  Replace
108         // those ForwardEntry's with this InterfaceEntry:
109         interfaceEntry.forwardedDerivers = forwardEntry.derivers;
110         for ( Enumeration derivers = forwardEntry.derivers.elements();
111               derivers.hasMoreElements(); )
112           ((InterfaceEntry)derivers.nextElement ()).replaceForwardDecl (forwardEntry, interfaceEntry);
113 
114         // Replace the entry's whose types are forward declarations:
115         for ( Enumeration types = forwardEntry.types.elements ();
116               types.hasMoreElements (); )
117           ((SymtabEntry)types.nextElement ()).type (interfaceEntry);
118       }
119     }
120     catch (Exception exception)
121     {}
122     return result;
123   } // replaceForwardDecl
124 
125   ///////////////
126   // Implement interface InterfaceType
127 
128   public int getInterfaceType ()
129   {
130     return _type;
131   }
132 
133   public void setInterfaceType (int type)
134   {
135     _type = type;
136   }
137 
138   static ForwardGen forwardGen;
139   Vector            derivers   = new Vector (); // Vector of InterfaceEntry's.
140   Vector            types      = new Vector (); // Vector of the entry's whose type is a forward declaration.
141   private int   _type  = InterfaceType.NORMAL; // interface type
142 } // class ForwardEntry