This patch adds java.rmi version jdk 1.2+ stub generator to the
classpath tools package.
Unlike rmic from the cp-tools project (that generates classes but cannot
generate the source code) this version generates only source code that must
be compiled with any java compiler. Source code (rather than binary) output
and template system seems providing the easier maintenance.
The deprecated jdk 1.1 classes are not supporte by this compiler (seems low
priority now).
Unlike cp-tools rmic, this compiler is not dependent on any third party
libraries.
The common rmic key -iiop forces to delegate work to the previoslu comitted
grmic.
2006-02-09 Audrius Meskauskas <[EMAIL PROTECTED]>
* tools/Makefile.am: Add tools/gnu/classpath/tools/rmi folder.
* tools/gnu/classpath/tools/giop/GRMIC.txt: Explain it called from RMIC.
* tools/gnu/classpath/tools/giop/grmic/Generator.java (getResource):
Better diagnostic.
* tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java:
Rewritten.
* tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java: Implement
AbstractMethodGenerator.
* tools/gnu/classpath/tools/AbstractMethodGenerator.java,
tools/gnu/classpath/tools/rmi/RMIC.java,
tools/gnu/classpath/tools/rmi/RMIC.txt,
tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java,
tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java,
tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java,
tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav,
tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav,
tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav:
New files.
* NEWS: Corrected entry about the tools.
Index: NEWS
===================================================================
RCS file: /sources/classpath/classpath/NEWS,v
retrieving revision 1.108
diff -u -r1.108 NEWS
--- NEWS 8 Feb 2006 12:14:04 -0000 1.108
+++ NEWS 9 Feb 2006 20:18:15 -0000
@@ -7,9 +7,10 @@
`java.security.' `javax.crypto,' and `javax.net.ssl' packages, and
are service providers implementing the underlying algorithms.
- * The new folder tools now contains GIOP tools, providing necessary support
- for development using org.omg.* and javax.rmi.CORBA.* packages: GIOP
- stub and tie code generator, IOR parser and naming service.
+* The new folder tools now contains GIOP and RMI tools, providing necessary
+ support for development using org.omg.*, javax.rmi.CORBA.* and java.rmi.*
+ packages. The toll set includes GIOP and RMI stub and tie code generators,
+ IOR parser and GIOP naming service.
New in release 0.20 (Jan 13, 2006)
Index: tools/Makefile.am
===================================================================
RCS file: /sources/classpath/classpath/tools/Makefile.am,v
retrieving revision 1.3
diff -u -r1.3 Makefile.am
--- tools/Makefile.am 8 Feb 2006 12:34:19 -0000 1.3
+++ tools/Makefile.am 9 Feb 2006 20:18:48 -0000
@@ -29,8 +29,9 @@
# Extra objects that will not exist until configure-time
BUILT_SOURCES = $(TOOLS_ZIP)
-# the templates that must be included into the generated zip file
-TOOLS_TEMPLATES = $(srcdir)/gnu/classpath/tools/giop/grmic/templates/*.jav
+# The templates that must be included into the generated zip file.
+# This covers both tools/giop/grmic/templates and tools/rmi/rmic/templates:
+TOOLS_TEMPLATES = $(srcdir)/gnu/classpath/tools/*/*/templates/*.jav
TOOLS_HELPS = $(srcdir)/gnu/classpath/tools/giop/*.txt
# The tool specific README files.
@@ -88,7 +89,7 @@
# And copy the template files we use to the classes dir so they get also included.
$(TOOLS_ZIP): $(TOOLS_JAVA_FILES)
mkdir -p classes/gnu/classpath/tools/giop/grmic/templates
- cp $(TOOLS_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates
+ cp $(TOOLS_TEMPLATES) classes/gnu/classpath/tools/*/*/templates
cp $(TOOLS_HELPS) classes/gnu/classpath/tools/giop/
$(JCOMPILER) -d classes $(TOOLS_JAVA_FILES)
(cd classes; \
Index: tools/gnu/classpath/tools/giop/GRMIC.txt
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/giop/GRMIC.txt,v
retrieving revision 1.1
diff -u -r1.1 GRMIC.txt
--- tools/gnu/classpath/tools/giop/GRMIC.txt 8 Feb 2006 07:35:30 -0000 1.1
+++ tools/gnu/classpath/tools/giop/GRMIC.txt 9 Feb 2006 20:18:48 -0000
@@ -1,3 +1,4 @@
+GIOP stub and tie generator source code generator for javax.rmi.*, omg.org.*
Copyright 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
@@ -22,5 +23,6 @@
and <class names> can include one or more non abstract classes that implement
Remote and are accessible via current class path.
-This tool generates the source code that must be compiled with java compiler.
+* This tool generates the source code that must be compiled with java compiler.
+* GRMIC is invoked from RMIC if the -iiop or -giop keys are specified.
Index: tools/gnu/classpath/tools/giop/grmic/Generator.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/giop/grmic/Generator.java,v
retrieving revision 1.1
diff -u -r1.1 Generator.java
--- tools/gnu/classpath/tools/giop/grmic/Generator.java 8 Feb 2006 07:35:30 -0000 1.1
+++ tools/gnu/classpath/tools/giop/grmic/Generator.java 9 Feb 2006 20:18:48 -0000
@@ -56,13 +56,18 @@
/**
* Get resource with the given name, as string.
*
- * @param name
- * the resource name
+ * @param name the resource name
* @return the resourse string (in subfolder /templates).
*/
public String getResource(String name)
{
- InputStream in = getClass().getResourceAsStream("templates/" + name);
+ String resourcePath = "templates/" + name;
+ InputStream in = getClass().getResourceAsStream(resourcePath);
+
+ if (in == null)
+ throw new InternalError(getClass().getName() + ": no resource "
+ + resourcePath);
+
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuffer b = new StringBuffer();
Index: tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java,v
retrieving revision 1.1
diff -u -r1.1 GiopRmicCompiler.java
--- tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java 8 Feb 2006 07:35:30 -0000 1.1
+++ tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java 9 Feb 2006 20:18:49 -0000
@@ -37,6 +37,8 @@
package gnu.classpath.tools.giop.grmic;
+import gnu.classpath.tools.AbstractMethodGenerator;
+
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.RemoteException;
@@ -55,60 +57,60 @@
public class GiopRmicCompiler extends Generator
{
/** The package name. */
- String packag;
+ protected String packag;
/**
* The "basic" name (normally, the interface name, unless several Remote -
* derived interfaces are implemented.
*/
- String name;
+ protected String name;
/**
* The name (without package) of the class, passed as the parameter.
*/
- String implName;
+ protected String implName;
/**
* The proposed name for the stub.
*/
- String stubName;
+ protected String stubName;
/**
* The Remote's, implemented by this class.
*/
- Collection implementedRemotes = new HashSet();
+ protected Collection implementedRemotes = new HashSet();
/**
* The extra classes that must be imported.
*/
- Collection extraImports = new HashSet();
+ protected Collection extraImports = new HashSet();
/**
* The methods we must implement.
*/
- Collection methods = new HashSet();
+ protected Collection methods = new HashSet();
/**
* The map of all code generator variables.
*/
- Properties vars = new Properties();
+ public Properties vars = new Properties();
/**
* If this flag is set (true by default), the compiler generates the Servant
* based classes. If set to false, the compiler generates the old style
* ObjectImpl based classes.
*/
- boolean poaMode = true;
+ protected boolean poaMode = true;
/**
* If this flag is set (true by default), the compiler emits warnings.
*/
- boolean warnings = true;
+ protected boolean warnings = true;
/**
* Verbose output
*/
- boolean verbose = false;
+ protected boolean verbose = false;
/**
* Clear data, preparing for the next compilation.
@@ -206,11 +208,23 @@
+ ", does not throw "
+ RemoteException.class.getName());
}
- MethodGenerator mm = new MethodGenerator(m[i], this);
+ AbstractMethodGenerator mm = createMethodGenerator(m[i]);
methods.add(mm);
}
}
}
+
+ /**
+ * Create the method generator for the given method.
+ *
+ * @param m the method
+ *
+ * @return the created method generator
+ */
+ protected AbstractMethodGenerator createMethodGenerator(Method m)
+ {
+ return new MethodGenerator(m, this);
+ }
/**
* Get the name of the given class. The class is added to imports, if not
@@ -315,7 +329,7 @@
Iterator iter = methods.iterator();
while (iter.hasNext())
{
- MethodGenerator m = (MethodGenerator) iter.next();
+ AbstractMethodGenerator m = (AbstractMethodGenerator) iter.next();
b.append(m.generateStubMethod());
}
@@ -366,7 +380,7 @@
Iterator iter = methods.iterator();
while (iter.hasNext())
{
- MethodGenerator m = (MethodGenerator) iter.next();
+ AbstractMethodGenerator m = (AbstractMethodGenerator) iter.next();
b.append(m.generateTieMethod());
}
Index: tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java
===================================================================
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java,v
retrieving revision 1.1
diff -u -r1.1 MethodGenerator.java
--- tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java 8 Feb 2006 07:35:30 -0000 1.1
+++ tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java 9 Feb 2006 20:18:50 -0000
@@ -37,6 +37,8 @@
package gnu.classpath.tools.giop.grmic;
+import gnu.classpath.tools.AbstractMethodGenerator;
+
import java.lang.reflect.Method;
import java.util.Properties;
@@ -46,7 +48,7 @@
*
* @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
*/
-public class MethodGenerator
+public class MethodGenerator implements AbstractMethodGenerator
{
/**
* The method being defined.
Index: tools/gnu/classpath/tools/AbstractMethodGenerator.java
===================================================================
RCS file: tools/gnu/classpath/tools/AbstractMethodGenerator.java
diff -N tools/gnu/classpath/tools/AbstractMethodGenerator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/AbstractMethodGenerator.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,53 @@
+/* AbstractMethodGenerator.java -- the abstract method generator
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.tools;
+
+public interface AbstractMethodGenerator
+{
+ /**
+ * Generate this method for the Stub (remote caller) class.
+ */
+ String generateStubMethod();
+
+ /**
+ * Generate this method for the Tie (remote servant) class.
+ */
+ String generateTieMethod();
+
+}
Index: tools/gnu/classpath/tools/rmi/RMIC.java
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/RMIC.java
diff -N tools/gnu/classpath/tools/rmi/RMIC.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/RMIC.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,198 @@
+/* RMIC.java -- RMI stub generator.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.tools.rmi;
+
+import gnu.classpath.tools.HelpPrinter;
+import gnu.classpath.tools.giop.GRMIC;
+import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
+import gnu.classpath.tools.rmi.rmic.RmicCompiler;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
+ *
+ * @author Audrius Meskauskas ([EMAIL PROTECTED])
+ */
+public class RMIC
+{
+ /**
+ * The version of the compiler.
+ */
+ public static String VERSION = "0.0 alpha pre";
+
+ /**
+ * The GRMIC compiler methods
+ *
+ * @param args the compiler parameters.
+ */
+ public static void main(String[] args)
+ {
+ // Check for the -iiop or -giop keys. If one of these keys is present,
+ // forward all call to GRMIC.
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].equals("-giop") || args[i].equals("-iiop"))
+ {
+ GRMIC.main(args);
+ return;
+ }
+ }
+
+ boolean noWrite = false;
+ boolean verbose = false;
+
+ String HelpPath = "rmi/RMIC.txt";
+
+ HelpPrinter.checkHelpKey(args, HelpPath);
+
+ File output = new File(".");
+
+ if (args.length == 0)
+ {
+ HelpPrinter.printHelpAndExit(HelpPath);
+ }
+ else
+ {
+ RmicCompiler compiler = new RmicCompiler();
+
+ int cl = - 1;
+
+ Options: for (int i = 0; i < args.length; i++)
+ {
+ String c = args[i];
+ if (c.equals("-v"))
+ {
+ printVersion();
+ System.exit(0);
+ }
+ else if (c.equals("-nowrite"))
+ noWrite = true;
+ else if (c.equals("-nowarn"))
+ compiler.setWarnings(false);
+ else if (c.equals("-verbose"))
+ {
+ verbose = true;
+ compiler.setVerbose(true);
+ }
+ else if (c.equals("-d"))
+ {
+ int f = i + 1;
+ if (f < args.length)
+ {
+ output = new File(args[f]);
+ i++;
+ }
+ else
+ HelpPrinter.printHelpAndExit(HelpPath);
+ }
+ else if (c.charAt(0) != '-')
+ // No more options - start of class list.
+ {
+ cl = i;
+ break Options;
+ }
+ }
+
+ if (cl < 0)
+ HelpPrinter.printHelpAndExit(HelpPath);
+
+ if (verbose)
+ System.out.println("Compiling to " + output.getAbsolutePath());
+
+ // Compile classes
+ Compile: for (int i = cl; i < args.length; i++)
+ {
+ if (args[i].charAt(0) != '-')
+ {
+ compiler.reset();
+ Class c = null;
+ try
+ {
+ c = Thread.currentThread().getContextClassLoader().loadClass(
+ args[i]);
+ }
+ catch (ClassNotFoundException e)
+ {
+ System.err.println(args[i] + " class not found.");
+ System.exit(1);
+ }
+
+ compiler.compile(c);
+ String packag = compiler.getPackageName().replace('.', '/');
+ File fw = new File(output, packag);
+
+ // Generate stub.
+ String stub = compiler.generateStub();
+ String subName = "_" + compiler.getStubName() + "_Stub.java";
+
+ if (noWrite)
+ continue Compile;
+
+ try
+ {
+ fw.mkdirs();
+ OutputStream out = new FileOutputStream(new File(fw,
+ subName));
+ out.write(stub.getBytes());
+ out.close();
+ }
+ catch (IOException ioex)
+ {
+ System.err.println("Output path not accessible");
+ ioex.printStackTrace();
+ System.exit(1);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Print the version information.
+ */
+ public static void printVersion()
+ {
+ System.out.println
+ ("rmic v "+VERSION+" - RMI stub generator for java.rmi.* ");
+ }
+}
Index: tools/gnu/classpath/tools/rmi/RMIC.txt
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/RMIC.txt
diff -N tools/gnu/classpath/tools/rmi/RMIC.txt
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/RMIC.txt 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,39 @@
+RMI stub and tie source code generator for java.rmi.*, javax.rmi.*
+
+Copyright 2006 Free Software Foundation, Inc.
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+Please report bugs at http://www.gnu.org/software/classpath/bugs.html
+
+Usage: rmic <options> <class names>
+
+ where <options> includes:
+ -nowarn Show no warnings
+ -nowrite Do not write any files (check for errors only)
+ -d <folder> Place generated files into the given folder
+
+ -help Print this help text
+ -v Print version
+ -verbose Verbose output
+
+ -1.2 Generate v 1.2 stubs (default)*
+
+ -iiop Generate stubs and ties for the GIOP based RMI package extension,
+ javax.rmi. With this key, the two additional keys are accepted:
+ -poa Generate the Servant based ties (default)
+ -impl Generate the obsoleted ObjectImpl based ties
+ (for backward compatibility)
+ -help Show more details on the giop stub and tie generator options.
+ -giop Same as -iiop*
+
+
+ and <class names> can include one or more non abstract classes that implement
+ Remote and are accessible via current class path.
+
+* This tool generates the source code that must be compiled with java compiler.
+* The deprecated 1.1 version stubs are currently not supported (the v 1.2
+ style stubs are always generated).
+* -iiop is a standard key for this tool, but it is also a registered OMG mark
+ when giop is not.
+
Index: tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java
diff -N tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,302 @@
+/* MethodGenerator.java -- Generates methods for rmi compiler.
+ Copyright (C) 2006 Free Software Foundation
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+
+package gnu.classpath.tools.rmi.rmic;
+
+import gnu.classpath.tools.AbstractMethodGenerator;
+
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.zip.Adler32;
+
+/**
+ * Keeps information about the single method and generates the code fragments,
+ * related to that method.
+ *
+ * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
+ */
+public class RmiMethodGenerator
+ implements AbstractMethodGenerator
+{
+ /**
+ * The method being defined.
+ */
+ Method method;
+
+ /**
+ * The parent code generator.
+ */
+ RmicCompiler rmic;
+
+ /**
+ * Create the new method generator for the given method.
+ *
+ * @param aMethod the related method.
+ * @param aRmic the Rmic generator instance, where more class - related
+ * information is defined.
+ */
+ public RmiMethodGenerator(Method aMethod, RmicCompiler aRmic)
+ {
+ method = aMethod;
+ rmic = aRmic;
+ if (method.getParameterTypes().length == 0)
+ rmic.addZeroSizeObjecArray = true;
+ }
+
+ /**
+ * Get the method parameter declaration.
+ *
+ * @return the string - method parameter declaration.
+ */
+ public String getArgumentList()
+ {
+ StringBuffer b = new StringBuffer();
+
+ Class[] args = method.getParameterTypes();
+
+ for (int i = 0; i < args.length; i++)
+ {
+ b.append(rmic.name(args[i]));
+ b.append(" p" + i);
+ if (i < args.length - 1)
+ b.append(", ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Get the method parameter list only (no type declarations). This is used to
+ * generate the method invocations statement.
+ *
+ * @return the string - method parameter list.
+ */
+ public String getArgumentNames()
+ {
+ StringBuffer b = new StringBuffer();
+
+ Class[] args = method.getParameterTypes();
+
+ for (int i = 0; i < args.length; i++)
+ {
+ b.append(" p" + i);
+ if (i < args.length - 1)
+ b.append(", ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Get the list of exceptions, thrown by this method.
+ *
+ * @return the list of exceptions.
+ */
+ public String getThrows()
+ {
+ StringBuffer b = new StringBuffer();
+
+ Class[] args = method.getExceptionTypes();
+
+ for (int i = 0; i < args.length; i++)
+ {
+ b.append(rmic.name(args[i]));
+ if (i < args.length - 1)
+ b.append(", ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Generate this method for the Stub class.
+ *
+ * @return the method body for the stub class.
+ */
+ public String generateStubMethod()
+ {
+ String templateName;
+
+ Properties vars = new Properties(rmic.vars);
+ vars.put("#return_type", rmic.name(method.getReturnType()));
+ vars.put("#method_name", method.getName());
+ vars.put("#method_hash", getMethodHashCode());
+ vars.put("#argument_list", getArgumentList());
+ vars.put("#object_arg_list", getArgListAsObjectArray());
+ vars.put("#declaring_class", rmic.name(method.getDeclaringClass()));
+ vars.put("#class_arg_list", getArgListAsClassArray());
+
+ String thr = getThrows();
+ if (thr.length() > 0)
+ vars.put("#throws", "\n throws " + thr);
+ else
+ vars.put("#throws", "");
+
+ if (method.getReturnType().equals(void.class))
+ templateName = "Stub_12MethodVoid.jav";
+ else
+ {
+ templateName = "Stub_12Method.jav";
+ vars.put("#return_statement", getReturnStatement());
+ }
+
+ String template = rmic.getResource(templateName);
+ String generated = rmic.replaceAll(template, vars);
+ return generated;
+ }
+
+ /**
+ * Generate sentences for Reading and Defining Arguments.
+ *
+ * @return the sequence of sentences for reading and defining arguments.
+ */
+ public String getStaticMethodDeclarations()
+ {
+ StringBuffer b = new StringBuffer();
+ Class[] args = method.getParameterTypes();
+
+ for (int i = 0; i < args.length; i++)
+ {
+ b.append(" ");
+ b.append(rmic.name(args[i]));
+ b.append(" ");
+ b.append("p" + i);
+ b.append(" = ");
+ if (i < args.length - 1)
+ b.append("\n");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Get the write statement for writing parameters inside the stub.
+ *
+ * @return the write statement.
+ */
+ public String getArgListAsObjectArray()
+ {
+ Class[] args = method.getParameterTypes();
+
+ if (args.length==0)
+ return "NO_ARGS";
+
+ StringBuffer b = new StringBuffer("new Object[] {");
+
+ for (int i = 0; i < args.length; i++)
+ {
+ if (!args[i].isPrimitive())
+ b.append("p"+i);
+ else
+ {
+ b.append("new "+rmic.name(WrapUnWrapper.getWrappingClass(args[i])));
+ b.append("(p"+i+")");
+ }
+ if (i<args.length-1)
+ b.append(", ");
+ }
+ b.append("}");
+ return b.toString();
+ }
+
+ /**
+ * Get the return statement, assuming that the returned object is placed into
+ * the variable "result".
+ */
+ public String getReturnStatement()
+ {
+ Class r = method.getReturnType();
+ if (r.equals(void.class))
+ return "";
+ else
+ {
+ if (r.isPrimitive())
+ {
+ String wcd = rmic.name(WrapUnWrapper.getWrappingClass(r));
+ return "return ((" + wcd + ") result)."
+ + WrapUnWrapper.getUnwrappingMethod(r) + ";";
+ }
+ else
+ return "return (" + rmic.name(r) + ") result;";
+ }
+ }
+
+ /**
+ * Get argument list as class array.
+ */
+ public String getArgListAsClassArray()
+ {
+ StringBuffer b = new StringBuffer();
+ Class[] args = method.getParameterTypes();
+
+ for (int i = 0; i < args.length; i++)
+ {
+ b.append(rmic.name(args[i]));
+ b.append(".class");
+ if (i < args.length - 1)
+ b.append(", ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * RMI ties (previously named Skeletons) are no longer used since v 1.2. This
+ * method should never be called.
+ */
+ public String generateTieMethod()
+ {
+ throw new InternalError();
+ }
+
+ /**
+ * Get the method hash code.
+ */
+ public String getMethodHashCode()
+ {
+ // Using the reliable chechsum method as this is a code generator, as
+ // the code will be generated once, but is likely to be used much more
+ // frequently.
+ Adler32 adler = new Adler32();
+
+ adler.update(method.getDeclaringClass().getName().getBytes());
+ adler.update(method.getName().getBytes());
+
+ Class[] args = method.getParameterTypes();
+ for (int i = 0; i < args.length; i++)
+ {
+ adler.update(args[i].getName().getBytes());
+ }
+ return adler.getValue() + "L";
+ }
+}
Index: tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java
diff -N tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,175 @@
+/* RmicCompiler.java -- RMI stub generator for java.rmi.*
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.tools.rmi.rmic;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+
+import gnu.classpath.tools.AbstractMethodGenerator;
+import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
+
+/**
+ * RMI stub source code generator, required to support java.rmi.*
+ *
+ * @author Audrius Meskauskas ([EMAIL PROTECTED])
+ */
+public class RmicCompiler extends GiopRmicCompiler
+{
+ /**
+ * If true, the zero size object array is declared in the stub to reduce
+ * garbage generation.
+ */
+ public boolean addZeroSizeObjecArray;
+
+ /**
+ * Generate a RMI stub.
+ *
+ * @return the string, containing the text of the generated stub.
+ */
+ public String generateStub()
+ {
+ String template = getResource("Stub_12.jav");
+
+ // Generate methods.
+ StringBuffer b = new StringBuffer();
+ Iterator iter = methods.iterator();
+ while (iter.hasNext())
+ {
+ RmiMethodGenerator m = (RmiMethodGenerator) iter.next();
+ b.append(m.generateStubMethod());
+ }
+
+ vars.put("#stub_methods", b.toString());
+ vars.put("#imports", getImportStatements());
+ vars.put("#interfaces", getAllInterfaces());
+ vars.put("#stub_method_declarations", getStubMethodDeclarations());
+ vars.put("#stub_method_initializations", getStubMethodInitializations());
+ if (addZeroSizeObjecArray)
+ {
+ vars.put("#zeroSizeObjecArray",
+ "private static final Object[] NO_ARGS = new Object[0];");
+ vars.put("#zeroSizeClassArray",
+ "final Class[] NO_ARGSc = new Class[0];");
+ }
+ else
+ {
+ vars.put("#zeroSizeObjecArray","");
+ vars.put("#zeroSizeClassArray","");
+ }
+
+ String output = replaceAll(template, vars);
+ return output;
+ }
+
+ /**
+ * Create a method generator, applicable for RMI stub methods.
+ */
+ protected AbstractMethodGenerator createMethodGenerator(Method m)
+ {
+ return new RmiMethodGenerator(m, this);
+ }
+
+ /**
+ * Get the stub method declarations.
+ */
+ public String getStubMethodDeclarations()
+ {
+ StringBuffer b = new StringBuffer();
+
+ Iterator iter = methods.iterator();
+
+ while (iter.hasNext())
+ {
+ RmiMethodGenerator method = (RmiMethodGenerator) iter.next();
+ b.append(" ");
+ b.append("private static final Method met_");
+ b.append(method.method.getName());
+ b.append(';');
+ if (iter.hasNext())
+ b.append('\n');
+ }
+ return b.toString();
+ }
+
+ /**
+ * Get stub method initializations. These must be done in a try-catch
+ * statement to catch [EMAIL PROTECTED] NoSuchMethodException}.
+ */
+ public String getStubMethodInitializations()
+ {
+ StringBuffer b = new StringBuffer();
+
+ Iterator iter = methods.iterator();
+
+ while (iter.hasNext())
+ {
+ RmiMethodGenerator method = (RmiMethodGenerator) iter.next();
+ b.append(" ");
+ b.append("met_");
+ b.append(method.method.getName());
+ b.append(" =\n ");
+ b.append(name(method.method.getDeclaringClass()));
+ b.append(".class.getMethod(");
+ b.append('"');
+ b.append(method.method.getName());
+ b.append("\", ");
+ if (method.method.getParameterTypes().length == 0)
+ b.append("NO_ARGSc);");
+ else
+ {
+ b.append("new Class[]\n {\n ");
+ b.append(method.getArgListAsClassArray());
+ b.append("\n }");
+ b.append(");");
+ }
+ b.append('\n');
+ }
+ return b.toString();
+ }
+
+ /**
+ * Prepare for the compilation of the next class.
+ */
+ public void reset()
+ {
+ addZeroSizeObjecArray = false;
+ super.reset();
+ }
+
+}
Index: tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java
diff -N tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,100 @@
+/* WrapUnWrapper.java -- Wrapper and unwrapper for primitive types.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.tools.rmi.rmic;
+
+import java.lang.reflect.Method;
+
+public class WrapUnWrapper
+{
+ /**
+ * Get the wrapper class for the primitive type
+ *
+ * @param primitive the class of the primitive type
+ *
+ * @return the wrapper class
+ */
+ public static Class getWrappingClass(Class primitive)
+ {
+ if (primitive.equals(byte.class))
+ return Byte.class;
+ if (primitive.equals(int.class))
+ return Integer.class;
+ if (primitive.equals(long.class))
+ return Long.class;
+ if (primitive.equals(boolean.class))
+ return Boolean.class;
+ if (primitive.equals(double.class))
+ return Double.class;
+ if (primitive.equals(float.class))
+ return Float.class;
+ if (primitive.equals(char.class))
+ return Character.class;
+ else
+ return null;
+ }
+
+ /**
+ * Get the method, invocation of that would return the wrapped value.
+ *
+ * @param primitive the class of the primitive type.
+ *
+ * @return the wrapper method that unwraps the value to the primitive type.
+ */
+ public static String getUnwrappingMethod(Class primitive)
+ {
+ if (primitive.equals(byte.class))
+ return "byteValue()";
+ if (primitive.equals(int.class))
+ return "intValue()";
+ if (primitive.equals(long.class))
+ return "longValue()";
+ if (primitive.equals(boolean.class))
+ return "booleanValue()";
+ if (primitive.equals(double.class))
+ return "doubleValue()";
+ if (primitive.equals(float.class))
+ return "floatValue()";
+ if (primitive.equals(char.class))
+ return "charValue()";
+ else
+ return null;
+ }
+
+
+}
Index: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav
diff -N tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,62 @@
+package #package;
+
+#imports
+import java.lang.reflect.Method;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.RemoteStub;
+import java.rmi.UnexpectedException;
+
+/**
+ * This class delegates its method calls to the remote RMI object, referenced
+ * by [EMAIL PROTECTED] RemoteRef}.
+ *
+ * It is normally generated with rmic.
+ */
+public final class _#name_Stub
+ extends RemoteStub
+ implements #interfaces
+{
+ /**
+ * Use serialVersionUID for interoperability
+ */
+ private static final long serialVersionUID = 2;
+
+ /**
+ * The explaining message for [EMAIL PROTECTED] UnexpectedException}.
+ */
+ private static final String exception_message =
+ "undeclared checked exception";
+
+ /* All remote methods, invoked by this stub: */
+#stub_method_declarations
+ #zeroSizeObjecArray
+ static
+ {
+ #zeroSizeClassArray
+ try
+ {
+#stub_method_initializations
+ }
+ catch (NoSuchMethodException nex)
+ {
+ NoSuchMethodError err = new NoSuchMethodError(
+ "_#name_Stub class initialization failed");
+ err.initCause(nex);
+ throw err;
+ }
+ }
+
+ /**
+ * Create the instance for _#name_Stub that forwards method calls to the
+ * remote object.
+ *
+ * @para the reference to the remote object.
+ */
+ public _#name_Stub(RemoteRef reference)
+ {
+ super(reference);
+ }
+
+ /* Methods */
+#stub_methods
+}
Index: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav
diff -N tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,26 @@
+ /** @inheritDoc */
+ public #return_type #method_name(#argument_list) #throws
+ {
+ try
+ {
+ Object result = ref.invoke(this, met_#method_name,
+ #object_arg_list,
+ #method_hash);
+ #return_statement
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (RemoteException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ UnexpectedException uex = new UnexpectedException(exception_message);
+ uex.initCause(e);
+ throw uex;
+ }
+ }
+
Index: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav
===================================================================
RCS file: tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav
diff -N tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,25 @@
+ /** @inheritDoc */
+ public void #method_name(#argument_list) #throws
+ {
+ try
+ {
+ ref.invoke(this, met_#method_name,
+ #object_arg_list,
+ #method_hash);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (RemoteException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ UnexpectedException uex = new UnexpectedException(exception_message);
+ uex.initCause(e);
+ throw uex;
+ }
+ }
+