OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [rmic/] [SourceRmicCompiler.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* SourceRmicCompiler.java -- RMI stub generator for java.rmi.*
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.classpath.tools.rmic;
39
 
40
import java.lang.reflect.Method;
41
import java.io.File;
42
import java.util.Iterator;
43
 
44
import gnu.classpath.tools.rmic.AbstractMethodGenerator;
45
 
46
/**
47
 * RMI stub source code generator, required to support java.rmi.*
48
 *
49
 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
50
 */
51
public class SourceRmicCompiler extends SourceGiopRmicCompiler
52
{
53
  /**
54
   * If true, the zero size object array is declared in the stub to reduce
55
   * garbage generation.
56
   */
57
  public boolean addZeroSizeObjecArray;
58
 
59
  /**
60
   * Generate a RMI stub.
61
   *
62
   * @return the string, containing the text of the generated stub.
63
   */
64
  public String generateStub()
65
  {
66
    String template = getResource("Stub_12.jav");
67
 
68
    // Generate methods.
69
    StringBuilder b = new StringBuilder();
70
    Iterator iter = methods.iterator();
71
    while (iter.hasNext())
72
      {
73
        RmiMethodGenerator m = (RmiMethodGenerator) iter.next();
74
        b.append(m.generateStubMethod());
75
      }
76
 
77
    vars.put("#stub_methods", b.toString());
78
    vars.put("#imports", getImportStatements());
79
    vars.put("#interfaces", getAllInterfaces());
80
    vars.put("#stub_method_declarations", getStubMethodDeclarations());
81
    vars.put("#stub_method_initializations", getStubMethodInitializations());
82
    if (addZeroSizeObjecArray)
83
      {
84
        vars.put("#zeroSizeObjecArray",
85
               "private static final Object[] NO_ARGS = new Object[0];");
86
        vars.put("#zeroSizeClassArray",
87
               "final Class[]  NO_ARGSc = new Class[0];");
88
      }
89
    else
90
      {
91
        vars.put("#zeroSizeObjecArray","");
92
        vars.put("#zeroSizeClassArray","");
93
      }
94
 
95
    String output = replaceAll(template, vars);
96
    return output;
97
  }
98
 
99
  /**
100
   * Create a method generator, applicable for RMI stub methods.
101
   */
102
  protected AbstractMethodGenerator createMethodGenerator(Method m)
103
  {
104
    return new RmiMethodGenerator(m, this);
105
  }
106
 
107
  /**
108
   * Get the stub method declarations.
109
   */
110
  public String getStubMethodDeclarations()
111
  {
112
    StringBuilder b = new StringBuilder();
113
 
114
    Iterator iter = methods.iterator();
115
 
116
    while (iter.hasNext())
117
      {
118
        RmiMethodGenerator method = (RmiMethodGenerator) iter.next();
119
        b.append("    ");
120
        b.append("private static final Method met_");
121
        b.append(method.method.getName());
122
        b.append(';');
123
        if (iter.hasNext())
124
          b.append('\n');
125
      }
126
    return b.toString();
127
  }
128
 
129
  /**
130
   * Get stub method initializations. These must be done in a try-catch
131
   * statement to catch {@link NoSuchMethodException}.
132
   */
133
  public String getStubMethodInitializations()
134
  {
135
    StringBuilder b = new StringBuilder();
136
 
137
    Iterator iter = methods.iterator();
138
 
139
    while (iter.hasNext())
140
      {
141
        RmiMethodGenerator method = (RmiMethodGenerator) iter.next();
142
        b.append("             ");
143
        b.append("met_");
144
        b.append(method.method.getName());
145
        b.append(" =\n               ");
146
        b.append(name(method.method.getDeclaringClass()));
147
        b.append(".class.getMethod(");
148
        b.append('"');
149
        b.append(method.method.getName());
150
        b.append("\", ");
151
        if (method.method.getParameterTypes().length == 0)
152
          b.append("NO_ARGSc);");
153
        else
154
          {
155
            b.append("new Class[]\n                 {\n                   ");
156
            b.append(method.getArgListAsClassArray());
157
            b.append("\n                 }");
158
            b.append(");");
159
          }
160
        b.append('\n');
161
      }
162
    return b.toString();
163
  }
164
 
165
  /**
166
   * Prepare for the compilation of the next class.
167
   */
168
  public void reset()
169
  {
170
    addZeroSizeObjecArray = false;
171
    super.reset();
172
  }
173
 
174
  /**
175
   * Additional processing of the stub name (nothing to do for JRMP stubs).
176
   */
177
  public String convertStubName(String name)
178
  {
179
    return name;
180
  }
181
 
182
  /**
183
   * Override to do nothing.
184
   */
185
  protected boolean outputTie(File fw, Class c)
186
  {
187
    return true;
188
  }
189
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.