diff options
author | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-02-09 20:22:07 +0000 |
---|---|---|
committer | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-02-09 20:22:07 +0000 |
commit | eb9aa9ad4129ac88dd0c053c9a87b836deea3ab2 (patch) | |
tree | 67cc83a51a175c23de86892399844e1f71efc48f | |
parent | 7b3d0a185c34dd45b4a3d410e3cf10b6f42732d0 (diff) | |
download | classpath-eb9aa9ad4129ac88dd0c053c9a87b836deea3ab2.tar.gz |
2006-02-09 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* 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.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rwxr-xr-x | tools/Makefile.am | 7 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/AbstractMethodGenerator.java | 53 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/GRMIC.txt | 4 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/grmic/Generator.java | 11 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java | 42 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java | 4 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/RMIC.java | 198 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/RMIC.txt | 39 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java | 302 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java | 175 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java | 100 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav | 62 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav | 26 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav | 25 |
16 files changed, 1052 insertions, 25 deletions
@@ -1,3 +1,25 @@ +2006-02-09 Audrius Meskauskas <AudriusA@Bioinformatics.org> + + * 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. + 2006-02-09 Lillian Angel <langel@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -7,9 +7,10 @@ New in release 0.21 (to be released) `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) diff --git a/tools/Makefile.am b/tools/Makefile.am index 128a299d6..3d9a49d26 100755 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -29,8 +29,9 @@ TOOLS_ZIP = tools.zip # 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 @@ dist-hook: # 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; \ diff --git a/tools/gnu/classpath/tools/AbstractMethodGenerator.java b/tools/gnu/classpath/tools/AbstractMethodGenerator.java new file mode 100644 index 000000000..d82284988 --- /dev/null +++ b/tools/gnu/classpath/tools/AbstractMethodGenerator.java @@ -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(); + +} diff --git a/tools/gnu/classpath/tools/giop/GRMIC.txt b/tools/gnu/classpath/tools/giop/GRMIC.txt index 9471fafe9..fcde83895 100644 --- a/tools/gnu/classpath/tools/giop/GRMIC.txt +++ b/tools/gnu/classpath/tools/giop/GRMIC.txt @@ -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 @@ Usage: grmic <options> <class names> 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. diff --git a/tools/gnu/classpath/tools/giop/grmic/Generator.java b/tools/gnu/classpath/tools/giop/grmic/Generator.java index 90bb21500..a45e8d398 100644 --- a/tools/gnu/classpath/tools/giop/grmic/Generator.java +++ b/tools/gnu/classpath/tools/giop/grmic/Generator.java @@ -56,13 +56,18 @@ public class Generator /** * 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(); diff --git a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java index 7d0c97d55..9ad7249f3 100644 --- a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java +++ b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java @@ -37,6 +37,8 @@ exception statement from your version. */ 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 @@ import java.util.TreeSet; 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 @@ public class GiopRmicCompiler extends Generator + ", 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 @@ public class GiopRmicCompiler extends Generator 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 @@ public class GiopRmicCompiler extends Generator Iterator iter = methods.iterator(); while (iter.hasNext()) { - MethodGenerator m = (MethodGenerator) iter.next(); + AbstractMethodGenerator m = (AbstractMethodGenerator) iter.next(); b.append(m.generateTieMethod()); } diff --git a/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java b/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java index 0000dd5b3..9a2649359 100644 --- a/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java +++ b/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java @@ -37,6 +37,8 @@ exception statement from your version. */ package gnu.classpath.tools.giop.grmic; +import gnu.classpath.tools.AbstractMethodGenerator; + import java.lang.reflect.Method; import java.util.Properties; @@ -46,7 +48,7 @@ import java.util.Properties; * * @author Audrius Meskauskas, Lithuania (audriusa@Bioinformatics.org) */ -public class MethodGenerator +public class MethodGenerator implements AbstractMethodGenerator { /** * The method being defined. diff --git a/tools/gnu/classpath/tools/rmi/RMIC.java b/tools/gnu/classpath/tools/rmi/RMIC.java new file mode 100644 index 000000000..e16e08507 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/RMIC.java @@ -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 (AudriusA@Bioinformatics.org) + */ +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.* "); + } +} diff --git a/tools/gnu/classpath/tools/rmi/RMIC.txt b/tools/gnu/classpath/tools/rmi/RMIC.txt new file mode 100644 index 000000000..df1de9ea6 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/RMIC.txt @@ -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. + diff --git a/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java b/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java new file mode 100644 index 000000000..209d1cca4 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java @@ -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 (audriusa@Bioinformatics.org) + */ +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"; + } +} diff --git a/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java b/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java new file mode 100644 index 000000000..28e78ba97 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java @@ -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 (AudriusA@Bioinformatics.org) + */ +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 {@link 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(); + } + +} diff --git a/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java b/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java new file mode 100644 index 000000000..6451a7074 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java @@ -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; + } + + +} diff --git a/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav new file mode 100644 index 000000000..7ed27d19d --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav @@ -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 {@link 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 {@ling 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 +} diff --git a/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav new file mode 100644 index 000000000..1069884b9 --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav @@ -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; + } + } +
\ No newline at end of file diff --git a/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav new file mode 100644 index 000000000..f67098a4f --- /dev/null +++ b/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav @@ -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; + } + } +
\ No newline at end of file |