summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/tools/gnu
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2007-01-09 19:58:05 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2007-01-09 19:58:05 +0000
commit65bf3316cf384588453604be6b4f0ed3751a8b0f (patch)
tree996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/tools/gnu
parent8fc56618a84446beccd45b80381cdfe0e94050df (diff)
downloadppe42-gcc-65bf3316cf384588453604be6b4f0ed3751a8b0f.tar.gz
ppe42-gcc-65bf3316cf384588453604be6b4f0ed3751a8b0f.zip
Merged gcj-eclipse branch to trunk.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120621 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/tools/gnu')
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/HelpPrinter.java116
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java3
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java175
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/Main.java123
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java4
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java12
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java4
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java3
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java10
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java33
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java56
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/common/ClasspathToolParser.java (renamed from libjava/classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java)18
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/common/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/common/Persistent.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/Persistent.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/getopt/Messages.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/getopt/Option.java68
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java5
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/getopt/Parser.java99
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/getopt/package.html (renamed from libjava/classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java)43
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.java189
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.txt33
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.java109
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.txt10
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.txt28
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/NamingService.txt21
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/giop/README19
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/jar/Creator.java9
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/jar/Main.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/jarsigner/Main.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/ClassWrapper.java346
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/CniIncludePrinter.java80
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/CniPrintStream.java243
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/CniStubPrinter.java129
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/FieldHelper.java99
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/JniHelper.java120
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/JniIncludePrinter.java158
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/JniPrintStream.java115
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/JniStubPrinter.java106
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/Keywords.java85
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/Main.java441
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/MethodHelper.java130
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/PackageWrapper.java54
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/PathOptionGroup.java135
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/Printer.java138
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/javah/Text.java60
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/CACertCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/Command.java4
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java3
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java3
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/ListCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/Main.java10
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/orbd/Main.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.java)144
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/orbd/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContext.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContext.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContextMap.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContextMap.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentMap.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentMap.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.txt28
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.java186
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.txt45
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.txt30
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java (renamed from libjava/classpath/tools/gnu/classpath/tools/AbstractMethodGenerator.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java1824
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/CompilationError.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/CompilationError.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/Generator.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/Generator.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/GiopIo.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopIo.java)6
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/HashFinder.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/HashFinder.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/Main.java282
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/MethodGenerator.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java)8
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/RMICException.java54
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/RmiMethodGenerator.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java)8
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/RmicBackend.java31
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java)113
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/SourceRmicCompiler.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java)18
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/Variables.java137
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/WrapUnWrapper.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/ImplTie.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/ImplTie.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Stub.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethod.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethod.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethodVoid.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethodVoid.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12Method.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12MethodVoid.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Tie.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Tie.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethod.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethod.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethodVoid.jav (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethodVoid.jav)0
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl.java)5
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl_Stub.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl_Stub.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmid/Main.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.java)152
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmid/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmid/PersistentBidiHashTable.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentBidiHashTable.java)5
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Main.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.java)155
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Messages.java67
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/PersistentHashTable.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentHashTable.java)18
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl.java)13
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Skel.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Skel.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Stub.java (renamed from libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Stub.java)2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java2
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/tnameserv/Main.java (renamed from libjava/classpath/tools/gnu/classpath/tools/giop/NameService.java)76
-rw-r--r--libjava/classpath/tools/gnu/classpath/tools/tnameserv/Messages.java67
111 files changed, 6134 insertions, 1378 deletions
diff --git a/libjava/classpath/tools/gnu/classpath/tools/HelpPrinter.java b/libjava/classpath/tools/gnu/classpath/tools/HelpPrinter.java
deleted file mode 100644
index 89468918a08..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/HelpPrinter.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/* HelpPrinter -- help message printer
- 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;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-/**
- * The shared class to print the help message and exit, when applicable.
- * Support the --help key.
- *
- * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
- */
-public class HelpPrinter
-{
- /**
- * Check for the --help, -help and -? keys. If one is found, print help and
- * exit the program.
- *
- * @param args the program arguments.
- * @param helpResourcePath the path to the help resource, related to the
- * HelpPrinter class.
- */
- public static void checkHelpKey(String[] args, String helpResourcePath)
- {
- for (int i = 0; i < args.length; i++)
- {
- String a = args[i];
- if (a.equals("-?") || a.equalsIgnoreCase("-help")
- || a.equalsIgnoreCase("--help"))
- printHelpAndExit(helpResourcePath);
- }
- }
-
- /**
- * Prints the contents of the resource specified by the designated path.
- *
- * @param helpResourcePath the path to a help resource, related to the
- * HelpPrinter class.
- */
- public static void printHelp(String helpResourcePath)
- {
- InputStream in = HelpPrinter.class.getResourceAsStream(helpResourcePath);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- try
- {
- String s;
- while ((s = br.readLine()) != null)
- System.out.println(s);
- }
- catch (IOException x)
- {
- System.err.print("Resource loading is broken:");
- x.printStackTrace(System.err);
- }
- finally
- {
- try
- {
- br.close();
- }
- catch (IOException ignored)
- {
- }
- }
- }
-
- /**
- * Prints the help message and terminates.
- *
- * @param helpResourcePath the path to the help resource, related to the
- * HelpPrinter class.
- */
- public static void printHelpAndExit(String helpResourcePath)
- {
- printHelp(helpResourcePath);
- System.exit(0);
- }
-}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java
index bc0cc45e128..c41ac1d7c86 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java
@@ -98,7 +98,8 @@ class CommonAppletStub
}
catch (MalformedURLException e)
{
- throw new RuntimeException("unknown codebase");
+ throw new RuntimeException("Attempted to create"
+ + " invalid codebase URL.", e);
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java
deleted file mode 100644
index 9c937cc779d..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/* ConsoleDialog -- a console dialog for applets
- Copyright (C) 2003, 2004, 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.appletviewer;
-
-import java.awt.BorderLayout;
-import java.awt.Button;
-import java.awt.FlowLayout;
-import java.awt.Frame;
-import java.awt.Panel;
-import java.awt.TextArea;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-
-
-/**
- * This class is a little dialog showing standard output and standard error output.
- *
- * @author Michael Koch (konqueror@gmx.de)
- */
-public class ConsoleDialog extends Frame
- implements ActionListener
-{
- static class InternalOutputStream extends OutputStream
- {
- private ConsoleDialog console;
-
- public InternalOutputStream(ConsoleDialog console)
- {
- super();
- this.console = console;
- }
-
- public void write(int data) throws IOException
- {
- console.print(String.valueOf((char) data));
- }
- }
-
- private TextArea textArea;
- private Button buttonClear;
- private Button buttonHide;
- private PrintStream printStream;
-
- /**
- * Creates a console dialog object.
- */
- public ConsoleDialog()
- {
- super(Main.messages.getString("gcjwebplugin.console_title"));
-
- setSize(400, 200);
- setLayout(new BorderLayout());
- addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent event)
- {
- hide();
- }
- });
-
- textArea = new TextArea();
- textArea.setEditable(false);
- add(textArea);
-
- Panel panel = new Panel();
- panel.setLayout(new FlowLayout());
- add(panel, BorderLayout.SOUTH);
-
- buttonClear = new Button(Main.messages.getString("gcjwebplugin.console_clear"));
- buttonClear.addActionListener(this);
- panel.add(buttonClear);
-
- buttonHide = new Button(Main.messages.getString("gcjwebplugin.console_hide"));
- buttonHide.addActionListener(this);
- panel.add(buttonHide);
-
- printStream = new PrintStream(new InternalOutputStream(this));
- clearTextArea();
- }
-
- /**
- * Clears the content of the textarea and inserts the initial text.
- */
- public void clearTextArea()
- {
- textArea.setText("");
-
- println("java.vm.version: " + System.getProperty("java.vm.version"));
- println("java.vm.vendor: " + System.getProperty("java.vm.vendor"));
- }
-
- /**
- * Print a message into the console dialog.
- *
- * @param message the message to print.
- */
- public void print(String message)
- {
- textArea.append(message);
- }
-
- /**
- * Print a line into the console dialog.
- *
- * @param message the line to print.
- */
- public void println(String message)
- {
- print(message + "\n");
- }
-
- /**
- * Perform actions on button clicks inside the console dialog.
- *
- * @param event the event.
- */
- public void actionPerformed(ActionEvent event)
- {
- if (event.getSource() == buttonHide)
- hide(); // Hide console window.
- else if (event.getSource() == buttonClear)
- clearTextArea(); // Clear text area and insert standard messages.
- }
-
- /**
- * Returns a <code>PrintStream</code> object that prints into the
- * console dialog.
- *
- * @return the <code>PrintStream</code> object.
- */
- public PrintStream getPrintStream()
- {
- return printStream;
- }
-}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Main.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Main.java
index 1d9fed2b04d..a10b889bc97 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Main.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Main.java
@@ -37,17 +37,19 @@ exception statement from your version. */
package gnu.classpath.tools.appletviewer;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.applet.Applet;
import java.awt.Dimension;
+import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
@@ -58,12 +60,6 @@ import java.util.ResourceBundle;
class Main
{
- /**
- * The localized strings are kept in a separate file.
- */
- public static final ResourceBundle messages = ResourceBundle.getBundle
- ("gnu.classpath.tools.appletviewer.MessagesBundle");
-
private static HashMap classLoaderCache = new HashMap();
private static ClassLoader getClassLoader(URL codebase, ArrayList archives)
@@ -108,7 +104,7 @@ class Main
}
if (applet == null)
- applet = new ErrorApplet("Error loading applet");
+ applet = new ErrorApplet(Messages.getString ("Main.ErrorApplet"));
return applet;
}
@@ -125,68 +121,72 @@ class Main
public static void main(String[] args) throws IOException
{
parser = new ClasspathToolParser("appletviewer", true);
- parser.setHeader("usage: appletviewer [OPTION] -code CODE | URL...");
+ parser.setHeader(Messages.getString("Main.Usage"));
- OptionGroup attributeGroup = new OptionGroup("Applet tag options");
+ OptionGroup attributeGroup
+ = new OptionGroup(Messages.getString("Main.AppletTagOptions"));
- attributeGroup.add(new Option("code", Main.messages.getString
- ("gcjwebplugin.code_description"),
- "CODE")
+ attributeGroup.add(new Option("code",
+ Messages.getString("Main.CodeDescription"),
+ Messages.getString("Main.CodeArgument"))
{
public void parsed(String argument) throws OptionException
{
code = argument;
}
});
- attributeGroup.add(new Option("codebase", Main.messages.getString
- ("gcjwebplugin.codebase_description"),
- "CODEBASE")
+ attributeGroup.add
+ (new Option("codebase",
+ Messages.getString("Main.CodebaseDescription"),
+ Messages.getString("Main.CodebaseArgument"))
{
public void parsed(String argument) throws OptionException
{
codebase = argument;
}
});
- attributeGroup.add(new Option("archive", Main.messages.getString
- ("gcjwebplugin.archive_description"),
- "ARCHIVE")
+ attributeGroup.add
+ (new Option("archive",
+ Messages.getString("Main.ArchiveDescription"),
+ Messages.getString("Main.ArchiveArgument"))
{
public void parsed(String argument) throws OptionException
{
archive = argument;
}
});
- attributeGroup.add(new Option("width", Main.messages.getString
- ("gcjwebplugin.width_description"),
- "WIDTH")
+ attributeGroup.add(new Option("width",
+ Messages.getString("Main.WidthDescription"),
+ Messages.getString("Main.WidthArgument"))
{
public void parsed(String argument) throws OptionException
{
dimensions.width = Integer.parseInt(argument);
}
});
- attributeGroup.add(new Option("height", Main.messages.getString
- ("gcjwebplugin.height_description"),
- "HEIGHT")
+ attributeGroup.add(new Option("height",
+ Messages.getString("Main.HeightDescription"),
+ Messages.getString("Main.HeightArgument"))
{
public void parsed(String argument) throws OptionException
{
dimensions.height = Integer.parseInt(argument);
}
});
- attributeGroup.add(new Option("param", Main.messages.getString
- ("gcjwebplugin.param_description"),
- "NAME,VALUE")
+ attributeGroup.add(new Option("param",
+ Messages.getString("Main.ParamDescription"),
+ Messages.getString("Main.ParamArgument"))
{
public void parsed(String argument) throws OptionException
{
parameters.add(argument);
}
});
- OptionGroup pluginGroup = new OptionGroup("Plugin option");
- pluginGroup.add(new Option("plugin", Main.messages.getString
- ("gcjwebplugin.plugin_description"),
- "INPUT,OUTPUT")
+ OptionGroup pluginGroup
+ = new OptionGroup(Messages.getString("Main.PluginOption"));
+ pluginGroup.add(new Option("plugin",
+ Messages.getString("Main.PluginDescription"),
+ Messages.getString("Main.PluginArgument"))
{
public void parsed(String argument) throws OptionException
{
@@ -196,29 +196,34 @@ class Main
pipeOutName = argument.substring(comma + 1);
}
});
- OptionGroup debuggingGroup = new OptionGroup("Debugging option");
- debuggingGroup.add(new Option("verbose", Main.messages.getString
- ("gcjwebplugin.verbose_description"),
- (String) null)
+ OptionGroup debuggingGroup
+ = new OptionGroup(Messages.getString("Main.DebuggingOption"));
+ debuggingGroup.add
+ (new Option("verbose",
+ Messages.getString("Main.VerboseDescription"),
+ (String) null)
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
- OptionGroup compatibilityGroup = new OptionGroup("Compatibility options");
- compatibilityGroup.add(new Option("debug", Main.messages.getString
- ("gcjwebplugin.debug_description"),
- (String) null)
+ OptionGroup compatibilityGroup
+ = new OptionGroup(Messages.getString("Main.CompatibilityOptions"));
+ compatibilityGroup.add
+ (new Option("debug",
+ Messages.getString("Main.DebugDescription"),
+ (String) null)
{
public void parsed(String argument) throws OptionException
{
// Currently ignored.
}
});
- compatibilityGroup.add(new Option("encoding", Main.messages.getString
- ("gcjwebplugin.encoding_description"),
- "CHARSET")
+ compatibilityGroup.add
+ (new Option("encoding",
+ Messages.getString("Main.EncodingDescription"),
+ Messages.getString("Main.EncodingArgument"))
{
public void parsed(String argument) throws OptionException
{
@@ -249,6 +254,7 @@ class Main
if (pluginMode)
{
+ // Plugin will warn user about missing security manager.
InputStream in;
OutputStream out;
@@ -259,13 +265,37 @@ class Main
}
else
{
+ // Warn user about missing security manager.
+ System.err.println(Messages.getString("Main.SecurityWarning") + "\n");
+
+ System.err.println(Messages.getString("Main.ContinuationPrompt"));
+
+ BufferedReader stdin
+ = new BufferedReader(new InputStreamReader(System.in));
+ String response = null;
+
+ try
+ {
+ response = stdin.readLine();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to read response"
+ + " to continuation prompt.", e);
+ }
+
+ if (!(response.equals("c") || response.equals("C")))
+ {
+ System.exit(0);
+ }
+
if (code == null)
{
// The --code option wasn't given and there are no URL
// arguments so we have nothing to work with.
if (args.length == 0)
{
- System.err.println(Main.messages.getString("gcjwebplugin.no_input_files"));
+ System.err.println(Messages.getString("Main.NoInputFiles"));
System.exit(1);
}
// Create a standalone appletviewer from a list of URLs.
@@ -275,7 +305,8 @@ class Main
{
// Create a standalone appletviewer from the --code
// option.
- new StandaloneAppletViewer(code, codebase, archive, parameters, dimensions);
+ new StandaloneAppletViewer(code, codebase, archive,
+ parameters, dimensions);
}
}
}
@@ -284,7 +315,7 @@ class Main
{
if (verbose)
{
- System.out.println("raw arguments:");
+ System.out.println(Messages.getString("Main.RawArguments"));
for (int i = 0; i < args.length; i++)
System.out.println(" " + args[i]);
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Messages.java
new file mode 100644
index 00000000000..614a509fd53
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for appletviewer
+ 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.appletviewer;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.appletviewer.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java
index a0e6acd124c..bc445a6b33c 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java
@@ -54,7 +54,7 @@ class PluginAppletContext extends CommonAppletContext
}
catch(IOException e)
{
- System.err.println("showDocument failed: " + e);
+ throw new RuntimeException("showDocument failed.", e);
}
}
@@ -66,7 +66,7 @@ class PluginAppletContext extends CommonAppletContext
}
catch(IOException e)
{
- System.err.println("showDocument failed: " + e);
+ throw new RuntimeException("showStatus failed.", e);
}
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java
index fdb8097b44b..d77aad39223 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java
@@ -141,7 +141,9 @@ class PluginAppletViewer
pluginOutputStream.newLine();
pluginOutputStream.flush();
- System.err.println(" PIPE: applet viewer wrote: " + message);
+ System.err.println
+ (" " + Messages.getString("PluginAppletViewer.AppletViewerWrote")
+ + message);
}
/**
@@ -155,7 +157,9 @@ class PluginAppletViewer
{
String message = pluginInputStream.readLine();
- System.err.println(" PIPE: applet viewer read: " + message);
+ System.err.println
+ (" " + Messages.getString("PluginAppletViewer.AppletViewerRead")
+ + message);
if (message == null || message.equals("shutdown"))
{
@@ -163,7 +167,9 @@ class PluginAppletViewer
pluginInputStream.close();
pluginOutputStream.close();
- System.err.println("appletviewer: exiting plugin applet viewer");
+ System.err.println
+ (Messages.getString("PluginAppletViewer.AppletViewerExiting"));
+
System.exit(0);
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java
index 6d36e1cf0b9..283d547b801 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java
@@ -428,10 +428,6 @@ class PluginAppletWindow
if (contexts.get(tag.getCodeBase()) == null)
contexts.put(tag.getCodeBase(), new PluginAppletContext());
- int result = AppletWarning.show();
- if (result == JOptionPane.NO_OPTION)
- return;
-
add(applet);
AppletContext context = (AppletContext) contexts.get(tag.getCodeBase());
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java
index a779f068ab6..48468f84d67 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java
@@ -58,7 +58,8 @@ class StandaloneAppletContext extends CommonAppletContext
public void showDocument(URL url, String target)
{
- System.err.println("showDocument is not implemented in standalone mode");
+ System.err.println
+ (Messages.getString("StandaloneAppletContext.ShowDocumentError"));
}
// In standalone mode, there are potentially several windows, each
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java
index 2b58f4b87e8..cc3a65cd72c 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java
@@ -79,7 +79,8 @@ class StandaloneAppletViewer extends Main
{
if (!(code.equals("") || code.endsWith(".class")))
{
- System.err.println("appletviewer: option '--code' requires a class filename");
+ System.err.println
+ (Messages.getString("StandaloneAppletViewer.CodeOptionError"));
System.exit(1);
}
@@ -118,13 +119,16 @@ class StandaloneAppletViewer extends Main
{
if (verbose)
{
- System.out.println("parsed applet tags:");
+ System.out.println
+ (Messages.getString("StandaloneAppletViewer.ParsedAppletTags"));
for (int i = 0; i < appletTags.size(); i++)
{
AppletTag tag = (AppletTag) appletTags.get(i);
- System.out.println(" tag " + i + ":");
+ System.out.println
+ (" " + Messages.getString("StandaloneAppletViewer.Tag")
+ + " " + i + ":");
System.out.println(tag);
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java
index fd2a7c0d832..3a0a442825d 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java
@@ -128,57 +128,57 @@ class StandaloneAppletWindow
addHierarchyListener(this);
addHierarchyBoundsListener(this);
- restartItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_restart"));
+ restartItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuRestart"));
restartItem.setEnabled(false);
restartItem.addActionListener(this);
- reloadItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_reload"));
+ reloadItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuReload"));
reloadItem.setEnabled(false);
reloadItem.addActionListener(this);
- cancelItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_cancel"));
+ cancelItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuCancel"));
cancelItem.setEnabled(false);
cancelItem.addActionListener(this);
- saveItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_save"));
+ saveItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuSave"));
saveItem.setEnabled(false);
saveItem.addActionListener(this);
- startItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_start"));
+ startItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuStart"));
startItem.setEnabled(false);
startItem.addActionListener(this);
- cloneItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_clone"));
+ cloneItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuClone"));
cloneItem.setEnabled(false);
cloneItem.addActionListener(this);
- closeItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_close"));
+ closeItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuClose"));
closeItem.setEnabled(false);
closeItem.addActionListener(this);
tagItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_tag"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuTag"));
tagItem.setEnabled(false);
tagItem.addActionListener(this);
infoItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_info"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuInfo"));
infoItem.setEnabled(false);
infoItem.addActionListener(this);
editItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_edit"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuEdit"));
editItem.setEnabled(false);
editItem.addActionListener(this);
editItem.setEnabled(false);
encodingItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_encoding"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuEncoding"));
encodingItem.setEnabled(false);
encodingItem.addActionListener(this);
printItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_print"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuPrint"));
printItem.setEnabled(false);
printItem.addActionListener(this);
propertiesItem =
- new MenuItem(Main.messages.getString("gcjwebplugin.menu_properties"));
+ new MenuItem(Messages.getString("StandaloneAppletWindow.MenuProperties"));
propertiesItem.setEnabled(false);
propertiesItem.addActionListener(this);
- quitItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_quit"));
+ quitItem = new MenuItem(Messages.getString("StandaloneAppletWindow.MenuQuit"));
quitItem.addActionListener(this);
MenuBar menuBar = new MenuBar();
- Menu menuApplet = new Menu(Main.messages.getString("gcjwebplugin.menu_title"));
+ Menu menuApplet = new Menu(Messages.getString("StandaloneAppletWindow.MenuTitle"));
menuBar.add(menuApplet);
menuApplet.add(restartItem);
menuApplet.add(reloadItem);
@@ -199,7 +199,8 @@ class StandaloneAppletWindow
menuApplet.add(closeItem);
menuApplet.add(quitItem);
setMenuBar(menuBar);
- setTitle("GNU Classpath Applet Viewer: " + tag.code);
+ setTitle(Messages.getString("StandaloneAppletWindow.WindowTitle")
+ + " " + tag.code);
AppletContext context = (AppletContext) contexts.get(tag.codebase);
((StandaloneAppletContext) context).addApplet(applet);
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java
index 68dce97e0ba..b5bdca70f9b 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java
@@ -230,12 +230,66 @@ public class TagParser
t.archives = parseArchives(val, t);
val = t.archives.toString();
}
-
+ val = unescapeString(val);
t.parameters.put(key.toLowerCase(), val);
}
}
/**
+ * This method does the same thing as the g_strcompress function in glib.
+ *
+ * @param value
+ * @return value in its original one-byte equivalence.
+ */
+ private static String unescapeString(String value)
+ {
+ String unescVal = "";
+ for (int i = 0; i < value.length(); i++)
+ {
+ if (i == value.length() - 1)
+ {
+ unescVal = unescVal.concat(value.substring(i));
+ break;
+ }
+ if (value.charAt(i) == '\\')
+ {
+ switch (value.charAt(i + 1))
+ {
+ case 'b':
+ unescVal = unescVal.concat("\b");
+ break;
+ case 'f':
+ unescVal = unescVal.concat("\f");
+ break;
+ case 'n':
+ unescVal = unescVal.concat("\n");
+ break;
+ case 'r':
+ unescVal = unescVal.concat("\r");
+ break;
+ case 't':
+ unescVal = unescVal.concat("\t");
+ break;
+ case '\\':
+ unescVal = unescVal.concat("\\");
+ break;
+ case '\"':
+ unescVal = unescVal.concat("\"");
+ break;
+ default:
+ unescVal = unescVal.concat("\\");
+ unescVal = unescVal.concat(value.substring(i + 1, i + 2));
+ break;
+ }
+ i++;
+ }
+ else
+ unescVal = unescVal.concat(value.substring(i, i + 1));
+ }
+ return unescVal;
+ }
+
+ /**
* Parses the archive string and returns a list.
*
* @param the list of archives (comma-separated) in a String.
diff --git a/libjava/classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java b/libjava/classpath/tools/gnu/classpath/tools/common/ClasspathToolParser.java
index e712056ef98..e44b9011cfd 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/common/ClasspathToolParser.java
@@ -36,11 +36,14 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools.getopt;
+package gnu.classpath.tools.common;
import java.text.MessageFormat;
import gnu.classpath.Configuration;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.Parser;
/**
* This is like the Parser class, but is specialized for use by
@@ -63,11 +66,22 @@ public class ClasspathToolParser
public ClasspathToolParser(String programName)
{
- super(programName, getVersionString(programName));
+ this(programName, false);
}
public ClasspathToolParser(String programName, boolean longOnly)
{
super(programName, getVersionString(programName), longOnly);
+ addFinal(new Option('J',
+ Messages.getString("ClasspathToolParser.JArgument"),//$NON-NLS-1$
+ Messages.getString("ClasspathToolParser.JName"), //$NON-NLS-1$
+ true)
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ // -J should be handled by the wrapper binary.
+ // We add it here so that it shows up in the --help output.
+ }
+ });
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/common/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/common/Messages.java
new file mode 100644
index 00000000000..1c92d348d2b
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/common/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- i18n support for tools common code
+ 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.common;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.common.Messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/Persistent.java b/libjava/classpath/tools/gnu/classpath/tools/common/Persistent.java
index 5cd1efe91f7..5a2b48a8ddc 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/Persistent.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/common/Persistent.java
@@ -35,7 +35,7 @@ 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;
+package gnu.classpath.tools.common;
import java.util.Timer;
import java.util.TimerTask;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/getopt/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/getopt/Messages.java
index 3c963d786b3..19f10174332 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/getopt/Messages.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/getopt/Messages.java
@@ -41,7 +41,7 @@ package gnu.classpath.tools.getopt;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-public class Messages
+class Messages
{
private static final String BUNDLE_NAME
= "gnu.classpath.tools.getopt.Messages"; //$NON-NLS-1$
diff --git a/libjava/classpath/tools/gnu/classpath/tools/getopt/Option.java b/libjava/classpath/tools/gnu/classpath/tools/getopt/Option.java
index 6f775e4a105..53255811eb1 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/getopt/Option.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/getopt/Option.java
@@ -44,7 +44,10 @@ package gnu.classpath.tools.getopt;
* like '--verbose'; if the parser is working in "long option only" mode, then a
* long flag has a single dash, like '-verbose'. Both a long and a short form
* may be specified; it is not valid to have neither. A description is mandatory
- * for options; this is used to automatically generate '--help' output.
+ * for options; this is used to automatically generate '--help' output. An option
+ * which takes an argument and which has a short form can also be "joined", in
+ * this case the option's argument can either be separated, like "-I path" or
+ * joined with the short option name, like "-Ipath".
*/
public abstract class Option
{
@@ -56,6 +59,8 @@ public abstract class Option
private String argumentName;
+ private boolean joined;
+
/**
* Create a new option with the given short name and description.
*
@@ -64,6 +69,8 @@ public abstract class Option
*/
protected Option(char shortName, String description)
{
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
this.shortName = shortName;
this.description = description;
}
@@ -78,12 +85,34 @@ public abstract class Option
*/
protected Option(char shortName, String description, String argumentName)
{
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
this.shortName = shortName;
this.description = description;
this.argumentName = argumentName;
}
/**
+ * Create a new option with the given short name and description.
+ *
+ * @param shortName the short name
+ * @param description the description
+ * @param argumentName the descriptive name of the argument, if this option
+ * takes an argument; otherwise null
+ * @param joined true if the short option is joined to its argument
+ */
+ protected Option(char shortName, String description, String argumentName,
+ boolean joined)
+ {
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
+ this.shortName = shortName;
+ this.description = description;
+ this.argumentName = argumentName;
+ this.joined = joined;
+ }
+
+ /**
* Create a new option with the given long name and description. The long name
* should be specified without any leading dashes.
*
@@ -122,6 +151,8 @@ public abstract class Option
*/
protected Option(String longName, char shortName, String description)
{
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
this.shortName = shortName;
this.longName = longName;
this.description = description;
@@ -140,10 +171,35 @@ public abstract class Option
protected Option(String longName, char shortName, String description,
String argumentName)
{
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
+ this.shortName = shortName;
+ this.longName = longName;
+ this.argumentName = argumentName;
+ this.description = description;
+ }
+
+ /**
+ * Create a new option with the given short and long names and description.
+ * The long name should be specified without any leading dashes.
+ *
+ * @param longName the long name
+ * @param shortName the short name
+ * @param description the description
+ * @param argumentName the descriptive name of the argument, if this option
+ * takes an argument; otherwise null
+ * @param joined true if the short option is joined to its argument
+ */
+ protected Option(String longName, char shortName, String description,
+ String argumentName, boolean joined)
+ {
+ if (shortName == 0)
+ throw new IllegalArgumentException("short name must not be \\0");
this.shortName = shortName;
this.longName = longName;
this.argumentName = argumentName;
this.description = description;
+ this.joined = joined;
}
/**
@@ -188,6 +244,16 @@ public abstract class Option
}
/**
+ * Return true if this is a "joined" option, false otherwise.
+ * Only the short form of an option can be joined; this will always
+ * return false for an option which does not have a short form.
+ */
+ public boolean isJoined()
+ {
+ return joined;
+ }
+
+ /**
* This is called by the parser when this option is recognized. It may be
* called multiple times during a single parse. If this option takes an
* argument, the argument will be passed in. Otherwise the argument will be
diff --git a/libjava/classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java b/libjava/classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java
index f7d966d9459..63853b2d0e4 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java
@@ -231,10 +231,7 @@ public class OptionGroup
{
if (argName != null)
{
- // This is a silly hack just for '-J'. We don't
- // support joined options in general, but this option
- // is filtered out before argument processing can see it.
- if (option.getShortName() != 'J')
+ if (! option.isJoined())
{
out.print(' ');
++column;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/getopt/Parser.java b/libjava/classpath/tools/gnu/classpath/tools/getopt/Parser.java
index 3c6cf6f46ac..b142836a5dc 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/getopt/Parser.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/getopt/Parser.java
@@ -72,6 +72,8 @@ public class Parser
private OptionGroup defaultGroup = new OptionGroup();
+ private OptionGroup finalGroup;
+
// These are used while parsing.
private int currentIndex;
@@ -166,7 +168,7 @@ public class Parser
this.longOnly = longOnly;
// Put standard options in their own section near the end.
- OptionGroup finalGroup = new OptionGroup(Messages.getString("Parser.StdOptions")); //$NON-NLS-1$
+ finalGroup = new OptionGroup(Messages.getString("Parser.StdOptions")); //$NON-NLS-1$
finalGroup.add(new Option("help", Messages.getString("Parser.PrintHelp")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
@@ -183,15 +185,6 @@ public class Parser
System.exit(0);
}
});
- finalGroup.add(new Option('J', Messages.getString("Parser.JArgument"), Messages.getString("Parser.JName")) //$NON-NLS-1$ //$NON-NLS-2$
- {
- public void parsed(String argument) throws OptionException
- {
- // -J should be handled by the appletviewer wrapper binary.
- // We add it here so that it shows up in the --help output.
- // Note that there is a special case for this in OptionGroup.
- }
- });
add(finalGroup);
add(defaultGroup);
@@ -230,6 +223,18 @@ public class Parser
}
/**
+ * This is like {@link #add(Option)}, but adds the option to the "final"
+ * group. This should be used sparingly, if at all; it is intended for
+ * other very generic options like --help or --version.
+ * @param opt the option to add
+ */
+ protected synchronized void addFinal(Option opt)
+ {
+ options.add(opt);
+ finalGroup.add(opt);
+ }
+
+ /**
* Add an option group to this parser. All the options in this group will be
* recognized by the parser.
*
@@ -314,11 +319,10 @@ public class Parser
String option = real.substring(index);
String justName = option;
int eq = option.indexOf('=');
- if (eq != - 1)
+ if (eq != -1)
justName = option.substring(0, eq);
- char shortName = 0;
- if (justName.length() == 1)
- shortName = justName.charAt(0);
+ boolean isPlainShort = justName.length() == 1;
+ char shortName = justName.charAt(0);
Option found = null;
for (int i = options.size() - 1; i >= 0; --i)
{
@@ -328,8 +332,14 @@ public class Parser
found = opt;
break;
}
- if (shortName != 0 && opt.getShortName() == shortName)
+ if ((isPlainShort || opt.isJoined())
+ && opt.getShortName() == shortName)
{
+ if (! isPlainShort)
+ {
+ // The rest of the option string is the argument.
+ eq = 0;
+ }
found = opt;
break;
}
@@ -343,7 +353,7 @@ public class Parser
String argument = null;
if (found.getTakesArgument())
{
- if (eq == - 1)
+ if (eq == -1)
argument = getArgument(real);
else
argument = option.substring(eq + 1);
@@ -358,35 +368,42 @@ public class Parser
found.parsed(argument);
}
- private void handleShortOption(char option) throws OptionException
+ private void handleShortOptions(String option) throws OptionException
{
- Option found = null;
- for (int i = options.size() - 1; i >= 0; --i)
+ for (int charIndex = 1; charIndex < option.length(); ++charIndex)
{
- Option opt = (Option) options.get(i);
- if (option == opt.getShortName())
+ char optChar = option.charAt(charIndex);
+ Option found = null;
+ for (int i = options.size() - 1; i >= 0; --i)
{
- found = opt;
- break;
+ Option opt = (Option) options.get(i);
+ if (optChar == opt.getShortName())
+ {
+ found = opt;
+ break;
+ }
}
- }
- if (found == null)
- {
- String msg = MessageFormat.format(Messages.getString("Parser.UnrecDash"), //$NON-NLS-1$
- new Object[] { "" + option }); //$NON-NLS-1$
- throw new OptionException(msg);
- }
- String argument = null;
- if (found.getTakesArgument())
- argument = getArgument("-" + option); //$NON-NLS-1$
- found.parsed(argument);
- }
-
- private void handleShortOptions(String option) throws OptionException
- {
- for (int i = 1; i < option.length(); ++i)
- {
- handleShortOption(option.charAt(i));
+ if (found == null)
+ {
+ String msg = MessageFormat.format(Messages.getString("Parser.UnrecDash"), //$NON-NLS-1$
+ new Object[] { "" + optChar }); //$NON-NLS-1$
+ throw new OptionException(msg);
+ }
+ String argument = null;
+ if (found.getTakesArgument())
+ {
+ // If this is a joined short option, and there are more
+ // characters left in this argument, use those as the
+ // argument.
+ if (found.isJoined() && charIndex + 1 < option.length())
+ {
+ argument = option.substring(charIndex + 1);
+ charIndex = option.length();
+ }
+ else
+ argument = getArgument("-" + optChar); //$NON-NLS-1$
+ }
+ found.parsed(argument);
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java b/libjava/classpath/tools/gnu/classpath/tools/getopt/package.html
index b2376a4cb77..ce6d34a4370 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/getopt/package.html
@@ -1,5 +1,6 @@
-/* AppletWarning -- a security warning message display dialog
- Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.util package.
+ Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -33,34 +34,16 @@ 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. */
+exception statement from your version. -->
-package gnu.classpath.tools.appletviewer;
+<html>
+<head><title>GNU Classpath - gnu.classpath.tools.getopt</title></head>
-import javax.swing.JOptionPane;
+<body>
+<p>This package contains a GNU-style command line option parser. It
+handles short and long options, options with arguments (optionally
+joined to the option text), and a "long option only" mode. It also
+automatically handles <code>--help</code> output. </p>
-/**
- * @author Michael Koch (konqueror@gmx.de)
- */
-public class AppletWarning
-{
- private static String TITLE = "WARNING";
- private static boolean showWarning = false;
-
- private static String MESSAGE =
- "The current version of this applet plugin does not provide\n" +
- "a security manager capable of handling Java (tm) applets. Applets\n" +
- "have UNRESTRICTED access to your computer. This means they can do\n" +
- "anything you can do, like deleting all your important data.\n\n" +
- "Continue ?";
-
- public static int show()
- {
- if (showWarning)
- return JOptionPane.showConfirmDialog(null, MESSAGE, TITLE,
- JOptionPane.YES_NO_OPTION,
- JOptionPane.WARNING_MESSAGE);
- else
- return JOptionPane.YES_OPTION;
- }
-}
+</body>
+</html>
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.java b/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.java
deleted file mode 100644
index c910d7083c7..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/* GRMIC.java -- GIOP support for RMIC.
- 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.
-*/
-
-package gnu.classpath.tools.giop;
-
-import gnu.classpath.tools.HelpPrinter;
-import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * The main class of the GIOP compiler to generate stubs and ties for
- * javax.rmi package.
- *
- * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
- */
-public class GRMIC
-{
- /**
- * 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)
- {
- boolean noWrite = false;
- boolean verbose = false;
-
- String HelpPath = "giop/GRMIC.txt";
-
- HelpPrinter.checkHelpKey(args, HelpPath);
-
- File output = new File(".");
-
- if (args.length == 0)
- {
- HelpPrinter.printHelpAndExit(HelpPath);
- }
- else
- {
- GiopRmicCompiler compiler = new GiopRmicCompiler();
-
- int cl = - 1;
-
- Options: for (int i = 0; i < args.length; i++)
- {
- String c = args[i];
- if (c.equals("-poa"))
- compiler.setPoaMode(true);
- else if (c.equals("-impl"))
- compiler.setPoaMode(false);
- else 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("-force"))
- {
- compiler.setForce(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.equals("-classpath"))
- {
- int f = i + 1;
- if (f < args.length)
- {
- compiler.setClassPath(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 = compiler.loadClass(args[i]);
-
- 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";
-
- compiler.reset();
- compiler.compile(c);
-
- // Generate tie
- String tie = compiler.generateTie();
- String tieName = "_" + compiler.name(c) + "_Tie.java";
-
- if (noWrite)
- continue Compile;
-
- try
- {
- fw.mkdirs();
- OutputStream out = new FileOutputStream(new File(fw,
- subName));
- out.write(stub.getBytes());
- out.close();
-
- out = new FileOutputStream(new File(fw, tieName));
- out.write(tie.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
- ("grmic v "+VERSION+" - GIOP stub and tie generator for javax.rmi.* ");
- }
-}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.txt b/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.txt
deleted file mode 100644
index 875bcdbcf38..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/GRMIC.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-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
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-Please report bugs at http://www.gnu.org/software/classpath/bugs.html
-
-Usage: grmic <options> <class names>
-
- where <options> includes:
- -poa Generate the Servant based ties (default)
- -impl Generate the obsoleted ObjectImpl based ties
- (for backward compatibility)
- -nowarn Show no warnings
- -nowrite Do not write any files (check for errors only)
- -d <folder> Place generated files into the given folder
- -classpath <path> Specifies the path, where to find the classes being
- compiled
-
- -help Print this help text
- -v Print version
- -verbose Verbose output
- -force Try to generate code even if the input classes seem not
- consistent with RMI specification.
-
-
- 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.
-* GRMIC is invoked from RMIC if the -iiop or -giop keys are specified.
-
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.java b/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.java
deleted file mode 100644
index 411b8997d49..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* IorParser.java -- IOR parser.
- 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.
-*/
-
-
-package gnu.classpath.tools.giop;
-
-import gnu.CORBA.IOR;
-import gnu.classpath.tools.HelpPrinter;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.omg.CORBA.BAD_PARAM;
-
-/**
- * Parses the information, encoded in the Interoperable Object References
- * (IORs).
- *
- * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
- */
-public class IorParser
-{
- /**
- * Parse and print IOR reference. The system exit code is 0 if the parsed
- * IOR was correct, 1 if it was invalid or missing.
- *
- * @param args supports -f file to read IOR from the file.
- */
- public static void main(String[] args)
- {
- boolean ok = false;
- String HelpResource = "giop/IorParser.txt";
- HelpPrinter.checkHelpKey(args, HelpResource);
- if (args.length == 0)
- HelpPrinter.printHelpAndExit(HelpResource);
- else if (args[0].equals("-f") && args.length==2)
- {
- File file = new File(args[1]);
- if (!file.exists())
- System.err.println("The file "+file.getAbsolutePath()+" is missing.");
- // Read IOR reference from file.
- String ior = null;
- try
- {
- FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- ior = br.readLine();
- br.close();
- ok = parseAndPrint(ior);
- }
- catch (IOException e)
- {
- System.err.print("Unable to read the file "+file);
- e.printStackTrace();
- }
-
- }
- else if (args.length == 1)
- ok = parseAndPrint(args[0]);
- else
- HelpPrinter.printHelpAndExit(HelpResource);
-
- if (ok)
- System.exit(0);
- else
- System.exit(1);
- }
-
- /**
- * Parse and print IOR.
- *
- * @param ior the IOR string to anlyse.
- * @return true if the passed value is a valid IOR, false otherwise.
- */
- public static boolean parseAndPrint(String ior)
- {
- try
- {
- IOR gior = IOR.parse(ior);
- System.out.println(gior.toStringFormatted());
- return true;
- }
- catch (BAD_PARAM e)
- {
- System.out.println("Invalid ior: "+e.getMessage());
- return false;
- }
- }
-}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.txt b/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.txt
deleted file mode 100644
index 3b04224f126..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/IorParser.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-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
-
-IOR (interoperable GIOP object reference) parser,
- usage: IorParser -f ior_file
- or: IorParser -f ior_string
-
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.txt b/libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.txt
deleted file mode 100644
index 3de15f62a96..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-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
-
-GNU Classpath GIOP persitent naming service.
- usage: NameServicePersistent <options>
-
- where <options> includes:
-* -org.omg.CORBA.ORBInitialPort NNN
- or -ORBInitialPort NNN - specifies the port, on that the
- service must be started. If this key
- is not specified, the service starts
- at the port 900.
-
-* -ior FILE_NAME - store the IOR reference to this naming
- service to the specified file. The
- IOR reference contains enough
- information to locate the service
- on the web.
-* - folder FOLDER - store the persistent information
- to the given folder
-* - reset - discard any previously stored
- persistent information (cold start)
-
-
-
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/NamingService.txt b/libjava/classpath/tools/gnu/classpath/tools/giop/NamingService.txt
deleted file mode 100644
index f57e4ac66a7..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/NamingService.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-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
-
-GNU Classpath GIOP naming service, usage: NameService <options>
-
- where <options> includes:
-* -org.omg.CORBA.ORBInitialPort NNN or
-* -ORBInitialPort NNN - specifies the port, on that the
- service must be started. If this key
- is not specified, the service starts
- at the port 900.
-
-* -ior FILE_NAME - store the IOR reference to this naming
- service to the specified file. The
- IOR reference contains enough
- information to locate the service
- on the web.
-
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/README b/libjava/classpath/tools/gnu/classpath/tools/giop/README
deleted file mode 100644
index 94fc2f15825..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/README
+++ /dev/null
@@ -1,19 +0,0 @@
-This package defines GIOP tools for creating the applications that use this
-protocol. It provides necessary support for org.omg.* and javax.rmi.*
-packages.
-
-All GIOP tools support the --help option.
-
-The list of the currently available tools:
-
-* GRMIC - RMI-IIOP stub and tie generator.
-* NameService - GIOP transient naming service (this tool is called
- tnameserv in Sun's package).
-* NameServicePersistent
- - GIOP persistent naming service (this tool is called
- orbd in Sun's package).
-* IorParser - Parses the stringified form of the interoperable
- object references (IOR's).
-* RMIC - RMI stub and tie source code generator (complements
- the ASM based bytecode generator in the separate
- tools package). \ No newline at end of file
diff --git a/libjava/classpath/tools/gnu/classpath/tools/jar/Creator.java b/libjava/classpath/tools/gnu/classpath/tools/jar/Creator.java
index 55159660d46..294549327a6 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/jar/Creator.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/jar/Creator.java
@@ -142,15 +142,18 @@ public class Creator
throws IOException
{
boolean isDirectory = file.isDirectory();
- InputStream inputStream = null;
if (isDirectory)
{
if (filename.charAt(filename.length() - 1) != '/')
filename += '/';
+ writeFile(isDirectory, null, filename, verbose);
}
else
- inputStream = new FileInputStream(file);
- writeFile(isDirectory, inputStream, filename, verbose);
+ {
+ InputStream inputStream = new FileInputStream(file);
+ writeFile(isDirectory, inputStream, filename, verbose);
+ inputStream.close();
+ }
}
private void addEntries(ArrayList result, Entry entry)
diff --git a/libjava/classpath/tools/gnu/classpath/tools/jar/Main.java b/libjava/classpath/tools/gnu/classpath/tools/jar/Main.java
index 8ea770bb63f..34f637204e7 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/jar/Main.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/jar/Main.java
@@ -38,7 +38,7 @@
package gnu.classpath.tools.jar;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.FileArgumentCallback;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/jarsigner/Main.java b/libjava/classpath/tools/gnu/classpath/tools/jarsigner/Main.java
index b6b50e7417a..0cff2fd856a 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/jarsigner/Main.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/jarsigner/Main.java
@@ -41,8 +41,8 @@ package gnu.classpath.tools.jarsigner;
import gnu.classpath.Configuration;
import gnu.classpath.SystemProperties;
import gnu.classpath.tools.common.CallbackUtil;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.common.ProviderUtil;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.FileArgumentCallback;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/ClassWrapper.java b/libjava/classpath/tools/gnu/classpath/tools/javah/ClassWrapper.java
new file mode 100644
index 00000000000..e238065c2c0
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/ClassWrapper.java
@@ -0,0 +1,346 @@
+/* ClassWrapper.java - wrap ASM class objects
+ 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.javah;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+public class ClassWrapper
+ extends ClassNode
+{
+ Main classpath;
+
+ ClassWrapper superClass;
+
+ ArrayList interfaceClasses;
+
+ // The virtual table for this class.
+ ArrayList vtable;
+
+ // A set of all the bridge method targets we've found.
+ HashSet bridgeTargets;
+
+ // A set of all the method names in this class.
+ HashSet methodNames = new HashSet();
+
+ public ClassWrapper(Main classpath)
+ {
+ this.classpath = classpath;
+ }
+
+ public boolean hasNativeMethod()
+ {
+ Iterator i = methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode method = (MethodNode) i.next();
+ if (Modifier.isNative(method.access))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isThrowable() throws IOException
+ {
+ linkSupers();
+ ClassWrapper self = this;
+ while (self != null)
+ {
+ if (self.name.equals("java/lang/Throwable"))
+ return true;
+ self = self.superClass;
+ }
+ return false;
+ }
+
+ private void linkSupers() throws IOException
+ {
+ if (superName == null)
+ {
+ // Object, do nothing.
+ return;
+ }
+ if (superClass == null)
+ {
+ superClass = classpath.getClass(superName);
+ assert interfaceClasses == null;
+ interfaceClasses = new ArrayList();
+ for (int i = 0; i < interfaces.size(); ++i)
+ {
+ String ifname = (String) interfaces.get(i);
+ ClassWrapper iface = classpath.getClass(ifname);
+ iface.linkSupers();
+ interfaceClasses.add(iface);
+ }
+ }
+ superClass.linkSupers();
+ }
+
+ private int findSlot(MethodNode method)
+ {
+ for (int i = vtable.size() - 1; i >= 0; --i)
+ {
+ MethodNode base = (MethodNode) vtable.get(i);
+ if (MethodHelper.overrides(method, base))
+ return i;
+ }
+ return - 1;
+ }
+
+ private void addInterfaceMethods(ClassWrapper iface)
+ {
+ Iterator i = iface.methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode im = (MethodNode) i.next();
+ int slot = findSlot(im);
+ if (slot == - 1)
+ {
+ vtable.add(im);
+ // Also add it to our local methods.
+ methods.add(im);
+ }
+ }
+ addInterfaces(iface);
+ }
+
+ private void addInterfaces(ClassWrapper base)
+ {
+ if (base.interfaceClasses == null)
+ return;
+ Iterator i = base.interfaceClasses.iterator();
+ while (i.hasNext())
+ {
+ ClassWrapper iface = (ClassWrapper) i.next();
+ addInterfaceMethods(iface);
+ }
+ }
+
+ private void addLocalMethods()
+ {
+ Iterator i = methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode meth = (MethodNode) i.next();
+ methodNames.add(meth.name);
+ if (Modifier.isStatic(meth.access))
+ continue;
+ int slot = findSlot(meth);
+ if (slot == - 1)
+ vtable.add(meth);
+ else
+ vtable.set(slot, meth);
+ }
+ }
+
+ private void makeVtable() throws IOException
+ {
+ if (vtable != null)
+ return;
+ if (superClass != null)
+ {
+ superClass.makeVtable();
+ vtable = new ArrayList(superClass.vtable);
+ bridgeTargets = new HashSet(superClass.bridgeTargets);
+ }
+ else
+ {
+ // Object.
+ vtable = new ArrayList();
+ bridgeTargets = new HashSet();
+ }
+ addLocalMethods();
+ addInterfaces(this);
+
+ // Make a set of all the targets of bridge methods.
+ // We rename bridge methods to avoid problems with C++.
+ Iterator i = methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode m = (MethodNode) i.next();
+ String desc = MethodHelper.getBridgeTarget(m);
+ if (desc != null)
+ bridgeTargets.add(m.name + desc);
+ }
+ }
+
+ private void printFields(CniPrintStream out)
+ {
+ Iterator i = fields.iterator();
+ ClassWrapper self = superClass;
+ while (i.hasNext())
+ {
+ FieldNode f = (FieldNode) i.next();
+ boolean hasMethodName = methodNames.contains(f.name);
+ if (FieldHelper.print(out, f, self, hasMethodName))
+ self = null;
+ }
+ }
+
+ private void printMethods(CniPrintStream out) throws IOException
+ {
+ makeVtable();
+
+ // A given method is either static, overrides a super method, or
+ // is already in vtable order.
+ Iterator i = methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode m = (MethodNode) i.next();
+ boolean isTarget = bridgeTargets.contains(m.name + m.desc);
+ MethodHelper.print(out, m, this, isTarget);
+ }
+ }
+
+ private void printTextList(PrintStream out, int what, ArrayList textList)
+ {
+ if (textList == null)
+ return;
+ Iterator i = textList.iterator();
+ boolean first = true;
+ while (i.hasNext())
+ {
+ Text item = (Text) i.next();
+ if (item.type == what)
+ {
+ if (first)
+ {
+ out.println();
+ first = false;
+ }
+ if (what == Text.FRIEND)
+ out.print(" friend ");
+ out.println(item.text);
+ }
+ }
+ }
+
+ public void print(CniPrintStream out)
+ {
+ out.print("::" + name.replaceAll("/", "::"));
+ }
+
+ // This prints the body of a class to a CxxPrintStream.
+ private void printContents(CniPrintStream out, ArrayList textList)
+ throws IOException
+ {
+ printTextList(out, Text.PREPEND, textList);
+ out.println();
+
+ out.print("class ");
+ // Don't use our print() -- we don't want the leading "::".
+ out.print(name.replaceAll("/", "::"));
+ if (superClass != null)
+ {
+ out.print(" : public ");
+ superClass.print(out);
+ }
+ out.println();
+ out.println("{");
+
+ printTextList(out, Text.ADD, textList);
+ out.println();
+
+ // Note: methods must come first, as we build the list
+ // of method names while printing them.
+ printMethods(out);
+ printFields(out);
+
+ out.setModifiers(Modifier.PUBLIC);
+ out.println(" static ::java::lang::Class class$;");
+
+ printTextList(out, Text.FRIEND, textList);
+
+ out.print("}");
+ if (Modifier.isInterface(access))
+ out.print(" __attribute__ ((java_interface))");
+ out.println(";");
+
+ printTextList(out, Text.APPEND, textList);
+ }
+
+ public void printFully(PrintStream out) throws IOException
+ {
+ linkSupers();
+
+ ArrayList textList = classpath.getClassTextList(name);
+
+ out.println("// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-");
+ out.println();
+ String xname = "__" + name.replaceAll("/", "_") + "__";
+ out.println("#ifndef " + xname);
+ out.println("#define " + xname);
+ out.println();
+ out.println("#pragma interface");
+ out.println();
+
+ if (superClass != null)
+ {
+ out.print("#include <");
+ out.print(superName);
+ out.println(".h>");
+ }
+
+ // Write the body of the stream here. This lets
+ // us emit the namespaces without a second pass.
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ CniPrintStream cxxOut = new CniPrintStream(bytes);
+ cxxOut.addClass(this);
+ printContents(cxxOut, textList);
+ cxxOut.printNamespaces(out);
+ bytes.writeTo(out);
+
+ out.println();
+ out.println("#endif // " + xname);
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/CniIncludePrinter.java b/libjava/classpath/tools/gnu/classpath/tools/javah/CniIncludePrinter.java
new file mode 100644
index 00000000000..fb007b13101
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/CniIncludePrinter.java
@@ -0,0 +1,80 @@
+/* CniIncludePrinter.java - generate CNI header files
+ 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.javah;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class CniIncludePrinter
+ extends Printer
+{
+ protected CniIncludePrinter(Main classpath, File outFile, boolean isDir,
+ boolean force)
+ {
+ super(classpath, outFile, isDir, force);
+ }
+
+ protected void writePreambleImpl(PrintStream ps)
+ {
+ // does nothing
+ }
+
+ protected PrintStream getPrintStreamImpl(FileOutputStream fos,
+ ClassWrapper klass)
+ {
+ return new PrintStream(fos);
+ }
+
+ public void printClass(ClassWrapper klass) throws IOException
+ {
+ // Never write Object or Class. This is a hack, maybe
+ // the user would like to see what they look like...
+ if (klass.name.equals("java/lang/Object")
+ || klass.name.equals("java/lang/Class"))
+ return;
+ PrintStream ps = getPrintStream(klass.name + ".h", klass);
+ if (ps == null)
+ return;
+ ps.println();
+ klass.printFully(ps);
+ ps.close();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/CniPrintStream.java b/libjava/classpath/tools/gnu/classpath/tools/javah/CniPrintStream.java
new file mode 100644
index 00000000000..64ba537d4d3
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/CniPrintStream.java
@@ -0,0 +1,243 @@
+/* CniPrintStream.java - PrintStream that emits CNI declarations
+ 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.javah;
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.objectweb.asm.Type;
+
+public class CniPrintStream
+ extends PrintStream
+{
+ int currentModifiers = Modifier.PRIVATE;
+
+ // True if we saw an array type.
+ boolean sawArray;
+
+ // All the classes referenced by this header.
+ HashSet allClasses = new HashSet();
+
+ String[] previousPackage = new String[0];
+
+ public CniPrintStream(OutputStream out)
+ {
+ super(out);
+ }
+
+ public void addClass(ClassWrapper cw)
+ {
+ allClasses.add(cw.name);
+ }
+
+ public void setModifiers(int newMods)
+ {
+ newMods &= (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE);
+ if (newMods != currentModifiers)
+ {
+ switch (newMods)
+ {
+ case Modifier.PUBLIC:
+ println("public:");
+ break;
+ case Modifier.PROTECTED:
+ println("public: // actually protected");
+ break;
+ case Modifier.PRIVATE:
+ println("private:");
+ break;
+ default:
+ println("public: // actually package-private");
+ break;
+ }
+ currentModifiers = newMods;
+ }
+ }
+
+ private String getName(Type type)
+ {
+ if (type == Type.BOOLEAN_TYPE)
+ return "jboolean";
+ else if (type == Type.BYTE_TYPE)
+ return "jbyte";
+ else if (type == Type.CHAR_TYPE)
+ return "jchar";
+ else if (type == Type.SHORT_TYPE)
+ return "jshort";
+ else if (type == Type.INT_TYPE)
+ return "jint";
+ else if (type == Type.LONG_TYPE)
+ return "jlong";
+ else if (type == Type.FLOAT_TYPE)
+ return "jfloat";
+ else if (type == Type.DOUBLE_TYPE)
+ return "jdouble";
+ else
+ {
+ assert type == Type.VOID_TYPE;
+ return "void";
+ }
+ }
+
+ public String getClassName(Type type)
+ {
+ String name = type.toString();
+ name = name.substring(1, name.length() - 1);
+ // Add the plain class name; we'll handle it when
+ // we process namespaces.
+ allClasses.add(name);
+ return "::" + name.replaceAll("/", "::") + " *";
+ }
+
+ public void print(Type type)
+ {
+ int arrayCount = 0;
+ if (type.getSort() == Type.ARRAY)
+ {
+ arrayCount = type.getDimensions();
+ for (int i = 0; i < arrayCount; ++i)
+ print("JArray< ");
+ type = type.getElementType();
+ sawArray = true;
+ }
+ if (type.getSort() == Type.OBJECT)
+ {
+ print(getClassName(type));
+ }
+ else
+ {
+ print(getName(type));
+ }
+ if (arrayCount > 0)
+ {
+ while (arrayCount-- > 0)
+ {
+ print(" > *");
+ }
+ }
+ }
+
+ private void indent(PrintStream out, int n)
+ {
+ for (int i = 0; i < n; ++i)
+ {
+ out.print(" ");
+ }
+ }
+
+ private void moveToPackage(PrintStream out, String[] pkgParts)
+ {
+ // Find greatest common part.
+ int commonIndex;
+ for (commonIndex = 0; commonIndex < previousPackage.length; ++commonIndex)
+ {
+ if (commonIndex >= pkgParts.length)
+ break;
+ if (! previousPackage[commonIndex].equals(pkgParts[commonIndex]))
+ break;
+ }
+ // Close old parts after the common part.
+ for (int j = previousPackage.length - 1; j >= commonIndex; --j)
+ {
+ indent(out, j + 1);
+ out.println("}");
+ }
+ // Open new parts.
+ for (int j = commonIndex; j < pkgParts.length; ++j)
+ {
+ indent(out, j + 1);
+ out.print("namespace ");
+ out.println(pkgParts[j]);
+ indent(out, j + 1);
+ out.println("{");
+ }
+ previousPackage = pkgParts;
+ }
+
+ private void writeClass(PrintStream out, String klass)
+ {
+ int index = klass.lastIndexOf('/');
+ String pkg = index == -1 ? "" : klass.substring(0, index);
+ String[] pkgParts = index == -1 ? new String[0] : pkg.split("/");
+ String className = index == -1 ? klass : klass.substring(index + 1);
+ moveToPackage(out, pkgParts);
+ indent(out, pkgParts.length + 2);
+ out.print("class ");
+ out.print(className);
+ out.println(";");
+ }
+
+ public void printNamespaces(PrintStream out)
+ {
+ if (sawArray)
+ {
+ out.println("#include <gcj/array.h>");
+ out.println();
+ }
+
+ String[] classes = (String[]) allClasses.toArray(new String[0]);
+ Arrays.sort(classes);
+
+ boolean first = true;
+ boolean seen = false;
+ for (int i = 0; i < classes.length; ++i)
+ {
+ String klass = classes[i];
+ if (klass.startsWith("java/lang/") || klass.startsWith("java/io/")
+ || klass.startsWith("java/util/"))
+ continue;
+ if (first)
+ {
+ out.println("extern \"Java\"");
+ out.println("{");
+ first = false;
+ seen = true;
+ }
+ writeClass(out, klass);
+ }
+ if (seen)
+ {
+ moveToPackage(out, new String[0]);
+ out.println("}");
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/CniStubPrinter.java b/libjava/classpath/tools/gnu/classpath/tools/javah/CniStubPrinter.java
new file mode 100644
index 00000000000..d91f367c45c
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/CniStubPrinter.java
@@ -0,0 +1,129 @@
+/* CniStubPrinter.java - Generate a CNI stub file
+ 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.javah;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.MethodNode;
+
+public class CniStubPrinter
+ extends Printer
+{
+ protected CniStubPrinter(Main classpath, File outFile, boolean isDir,
+ boolean force)
+ {
+ super(classpath, outFile, isDir, force);
+ }
+
+ private void printDecl(CniPrintStream out, String className, MethodNode method)
+ {
+ out.print(className);
+ out.print("::");
+ out.print(method.name);
+ out.print("(");
+ Type[] argTypes = Type.getArgumentTypes(method.desc);
+ for (int j = 0; j < argTypes.length; ++j)
+ {
+ if (j > 0)
+ out.print(", ");
+ out.print(argTypes[j]);
+ }
+ out.print(")");
+ }
+
+ protected void writePreambleImpl(PrintStream out)
+ {
+ out.println("// This file is intended to give you a head start on implementing native");
+ out.println("// methods using CNI.");
+ out.println("// Be aware: running 'gcjh -stubs' once more for this class may");
+ out.println("// overwrite any edits you have made to this file.");
+ out.println();
+ out.println("#include <gcj/cni.h>");
+ out.println("#include <java/lang/UnsupportedOperationException.h>");
+ }
+
+ protected PrintStream getPrintStreamImpl(FileOutputStream fos,
+ ClassWrapper klass)
+ {
+ return new CniPrintStream(fos);
+ }
+
+ public void printClass(ClassWrapper klass) throws IOException
+ {
+ if (! klass.hasNativeMethod())
+ return;
+ String className = klass.name.replaceAll("/", "::");
+ CniPrintStream out = (CniPrintStream) getPrintStream(klass.name + ".cc",
+ klass);
+ if (out == null)
+ return;
+ out.println();
+ out.println("#include <" + klass.name + ".h>");
+ out.println();
+
+ Iterator i = klass.methods.iterator();
+ boolean first = true;
+ while (i.hasNext())
+ {
+ MethodNode method = (MethodNode) i.next();
+ if (! Modifier.isNative(method.access))
+ continue;
+ if (! first)
+ out.println();
+ first = false;
+ out.print(Type.getReturnType(method.desc));
+ out.println();
+ printDecl(out, className, method);
+ out.println();
+ out.println("{");
+ out.print(" throw new ::java::lang::UnsupportedOperationException(");
+ out.print("JvNewStringLatin1 (\"");
+ printDecl(out, className, method);
+ out.println("\"));");
+ out.println("}");
+ }
+ out.close();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/FieldHelper.java b/libjava/classpath/tools/gnu/classpath/tools/javah/FieldHelper.java
new file mode 100644
index 00000000000..a9385e04d33
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/FieldHelper.java
@@ -0,0 +1,99 @@
+/* FieldHelper.java - field helper methods for CNI
+ 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.javah;
+
+import java.lang.reflect.Modifier;
+
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.FieldNode;
+
+public class FieldHelper
+{
+ public static boolean print(CniPrintStream out, FieldNode field,
+ ClassWrapper superType, boolean hasMethodName)
+ {
+ out.setModifiers(field.access);
+ out.print(" ");
+ if (Modifier.isStatic(field.access))
+ out.print("static ");
+ if (Modifier.isVolatile(field.access))
+ out.print("volatile ");
+ if ((field.value instanceof Integer) || (field.value instanceof Long))
+ out.print("const ");
+ out.print(Type.getType(field.desc));
+ out.print(" ");
+ boolean result = false;
+ if (superType != null && ! Modifier.isStatic(field.access))
+ {
+ out.print("__attribute__((aligned(__alignof__( ");
+ superType.print(out);
+ out.print(")))) ");
+ result = true;
+ }
+ out.print(Keywords.getCxxName(field.name));
+ if (hasMethodName)
+ out.print("__");
+ if (Modifier.isStatic(field.access))
+ {
+ if (field.value instanceof Integer)
+ {
+ out.print(" = ");
+ int val = ((Integer) field.value).intValue();
+ if (val == Integer.MIN_VALUE)
+ out.print("-" + Integer.MAX_VALUE + " - 1");
+ else
+ out.print(val);
+ }
+ else if (field.value instanceof Long)
+ {
+ out.print(" = ");
+ long val = ((Long) field.value).longValue();
+ if (val == Long.MIN_VALUE)
+ out.print("-" + Long.MAX_VALUE + "LL - 1");
+ else
+ {
+ out.print(val);
+ out.print("LL");
+ }
+ }
+ }
+ out.println(";");
+ return result;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/JniHelper.java b/libjava/classpath/tools/gnu/classpath/tools/javah/JniHelper.java
new file mode 100644
index 00000000000..7c508997e18
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/JniHelper.java
@@ -0,0 +1,120 @@
+/* JniHelper.java - name mangling and other JNI support
+ 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.javah;
+
+import java.io.IOException;
+
+import org.objectweb.asm.Type;
+
+public class JniHelper
+{
+ public static String getName(Main classpath, Type type) throws IOException
+ {
+ if (type == Type.BOOLEAN_TYPE)
+ return "jboolean";
+ else if (type == Type.BYTE_TYPE)
+ return "jbyte";
+ else if (type == Type.CHAR_TYPE)
+ return "jchar";
+ else if (type == Type.SHORT_TYPE)
+ return "jshort";
+ else if (type == Type.INT_TYPE)
+ return "jint";
+ else if (type == Type.LONG_TYPE)
+ return "jlong";
+ else if (type == Type.FLOAT_TYPE)
+ return "jfloat";
+ else if (type == Type.DOUBLE_TYPE)
+ return "jdouble";
+ else if (type == Type.VOID_TYPE)
+ return "void";
+
+ if (type.getSort() == Type.ARRAY)
+ {
+ Type elt = type.getElementType();
+ int eltSort = elt.getSort();
+ if (type.getDimensions() == 1 && eltSort != Type.OBJECT)
+ return getName(classpath, elt) + "Array";
+ return "jobjectArray";
+ }
+
+ // assert type.getSort() == Type.OBJECT;
+ String className = type.getClassName();
+ // FIXME: is this correct?
+ if (className.equals("java/lang/Class")
+ || className.equals("java.lang.Class"))
+ return "jclass";
+ if (className.equals("java/lang/String")
+ || className.equals("java.lang.String"))
+ return "jstring";
+
+ ClassWrapper klass = classpath.getClass(className);
+ if (klass.isThrowable())
+ return "jthrowable";
+ return "jobject";
+ }
+
+ public static String mangle(String name)
+ {
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < name.length(); ++i)
+ {
+ char c = name.charAt(i);
+ if (c == '_')
+ result.append("_1");
+ else if (c == ';')
+ result.append("_2");
+ else if (c == '[')
+ result.append("_3");
+ else if (c == '/')
+ result.append("_");
+ else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z'))
+ result.append(c);
+ else
+ {
+ result.append("_0");
+ // Sigh.
+ String hex = "0000" + Integer.toHexString(c);
+ result.append(hex.substring(hex.length() - 4));
+ }
+ }
+ return result.toString();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/JniIncludePrinter.java b/libjava/classpath/tools/gnu/classpath/tools/javah/JniIncludePrinter.java
new file mode 100644
index 00000000000..f29bfc30050
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/JniIncludePrinter.java
@@ -0,0 +1,158 @@
+/* JniIncludePrinter.java - Generate a JNI header file
+ 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.javah;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+public class JniIncludePrinter
+ extends Printer
+{
+ protected JniIncludePrinter(Main classpath, File outFile, boolean isDir,
+ boolean force)
+ {
+ super(classpath, outFile, isDir, force);
+ }
+
+ private void writeFields(ClassWrapper klass, JniPrintStream out)
+ {
+ boolean wroteAny = false;
+ for (; klass != null; klass = klass.superClass)
+ {
+ Iterator i = klass.fields.iterator();
+ while (i.hasNext())
+ {
+ FieldNode field = (FieldNode) i.next();
+ if (! Modifier.isStatic(field.access)
+ || ! Modifier.isFinal(field.access))
+ continue;
+ if (! (field.value instanceof Integer)
+ && ! (field.value instanceof Long))
+ continue;
+
+ // Note that we don't want to mangle the field name.
+ String name = (JniHelper.mangle(klass.name) + "_" + field.name);
+ out.print("#undef ");
+ out.println(name);
+ out.print("#define ");
+ out.print(name);
+ out.print(" ");
+ out.print(field.value);
+ if (field.value instanceof Integer)
+ out.print("L");
+ else if (field.value instanceof Long)
+ out.print("LL");
+ out.println();
+ wroteAny = true;
+ }
+ }
+ if (wroteAny)
+ out.println();
+ }
+
+ protected void writePreambleImpl(PrintStream out)
+ {
+ out.println("/* DO NOT EDIT THIS FILE - it is machine generated */");
+ out.println();
+ out.println("#include <jni.h>");
+ }
+
+ protected PrintStream getPrintStreamImpl(FileOutputStream fos,
+ ClassWrapper klass)
+ {
+ return new JniPrintStream(classpath, fos, klass);
+ }
+
+ public void printClass(ClassWrapper klass) throws IOException
+ {
+ if (! klass.hasNativeMethod())
+ return;
+ String xname = JniHelper.mangle(klass.name);
+ JniPrintStream out = (JniPrintStream) getPrintStream(klass.name + ".h", klass);
+ if (out == null)
+ return;
+ out.println();
+ out.print("#ifndef __");
+ out.print(xname);
+ out.println("__");
+ out.print("#define __");
+ out.print(xname);
+ out.println("__");
+ out.println();
+ out.println("#ifdef __cplusplus");
+ out.println("extern \"C\"");
+ out.println("{");
+ out.println("#endif");
+ out.println();
+
+ Iterator i = klass.methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode method = (MethodNode) i.next();
+ if (! Modifier.isNative(method.access))
+ continue;
+ out.print("JNIEXPORT ");
+ out.print(Type.getReturnType(method.desc));
+ out.print(" JNICALL ");
+ out.print(method, xname);
+ out.println(";");
+ }
+
+ out.println();
+
+ writeFields(klass, out);
+
+ out.println("#ifdef __cplusplus");
+ out.println("}");
+ out.println("#endif");
+ out.println();
+ out.print("#endif /* __");
+ out.print(xname);
+ out.println("__ */");
+ out.close();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/JniPrintStream.java b/libjava/classpath/tools/gnu/classpath/tools/javah/JniPrintStream.java
new file mode 100644
index 00000000000..a0461f475fd
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/JniPrintStream.java
@@ -0,0 +1,115 @@
+/* JniPrintStream.java - PrintStream that emits JNI declarations
+ 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.javah;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.MethodNode;
+
+public class JniPrintStream
+ extends PrintStream
+{
+ Main classpath;
+
+ // This is used to determine whether a method has an overload.
+ HashMap methodNameMap = new HashMap();
+
+ public JniPrintStream(Main classpath, OutputStream out, ClassWrapper klass)
+ {
+ super(out);
+ this.classpath = classpath;
+ computeOverloads(klass);
+ }
+
+ private void computeOverloads(ClassWrapper klass)
+ {
+ Iterator i = klass.methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode method = (MethodNode) i.next();
+ if (! Modifier.isNative(method.access))
+ continue;
+ if (methodNameMap.containsKey(method.name))
+ {
+ Integer val = (Integer) methodNameMap.get(method.name);
+ methodNameMap.put(method.name, new Integer(val.intValue() + 1));
+ }
+ else
+ methodNameMap.put(method.name, new Integer(1));
+ }
+ }
+
+ public void print(Type type) throws IOException
+ {
+ print(JniHelper.getName(classpath, type));
+ }
+
+ public void print(MethodNode method, String className) throws IOException
+ {
+ print("Java_");
+ print(className);
+ print("_");
+ print(JniHelper.mangle(method.name));
+ Integer overloadCount = (Integer) methodNameMap.get(method.name);
+ if (overloadCount.intValue() > 1)
+ {
+ print("__");
+ int lastOffset = method.desc.lastIndexOf(')');
+ print(JniHelper.mangle(method.desc.substring(1, lastOffset)));
+ }
+ print(" (JNIEnv *env");
+ if (Modifier.isStatic(method.access))
+ print(", jclass");
+ else
+ print(", jobject");
+ Type[] types = Type.getArgumentTypes(method.desc);
+ for (int i = 0; i < types.length; ++i)
+ {
+ print(", ");
+ print(types[i]);
+ }
+ print(")");
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/JniStubPrinter.java b/libjava/classpath/tools/gnu/classpath/tools/javah/JniStubPrinter.java
new file mode 100644
index 00000000000..4e7871008d7
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/JniStubPrinter.java
@@ -0,0 +1,106 @@
+/* JniStubPrinter.java - Generate JNI stub files
+ 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.javah;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.MethodNode;
+
+public class JniStubPrinter
+ extends Printer
+{
+ protected JniStubPrinter(Main classpath, File outFile, boolean isDir,
+ boolean force)
+ {
+ super(classpath, outFile, isDir, force);
+ }
+
+ protected void writePreambleImpl(PrintStream out)
+ {
+ out.println("/* This file is intended to give you a head start on implementing native");
+ out.println(" methods using JNI.");
+ out.println(" Be aware: running gcjh or compatible tool with '-stubs' option once more");
+ out.println(" for the same input may overwrite any edits you have made to this file. */");
+ }
+
+ protected PrintStream getPrintStreamImpl(FileOutputStream fos,
+ ClassWrapper klass)
+ {
+ return new JniPrintStream(classpath, fos, klass);
+ }
+
+ public void printClass(ClassWrapper klass) throws IOException
+ {
+ if (! klass.hasNativeMethod())
+ return;
+ String xname = JniHelper.mangle(klass.name);
+ JniPrintStream out = (JniPrintStream) getPrintStream(klass.name + ".c", klass);
+ if (out == null)
+ return;
+ out.println();
+ out.print("#include <");
+ out.print(klass.name);
+ out.println(".h>");
+
+ Iterator i = klass.methods.iterator();
+ while (i.hasNext())
+ {
+ MethodNode method = (MethodNode) i.next();
+ if (! Modifier.isNative(method.access))
+ continue;
+ out.println();
+ out.print(Type.getReturnType(method.desc));
+ out.println();
+ out.print(method, xname);
+ out.println();
+ out.println("{");
+ out.print(" (*env)->FatalError (env, \"");
+ out.print(method, xname);
+ out.println(" not implemented\");");
+ out.println("}");
+ }
+ out.close();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/Keywords.java b/libjava/classpath/tools/gnu/classpath/tools/javah/Keywords.java
new file mode 100644
index 00000000000..46543ba45df
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/Keywords.java
@@ -0,0 +1,85 @@
+/* Keywords.java - List of C++ keywords
+ 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.javah;
+
+import java.util.HashSet;
+
+public class Keywords
+{
+ private static final String[] words = { "and", "and_eq", "asm", "auto",
+ "bitand", "bitor", "bool", "break",
+ "case", "catch", "char", "class",
+ "compl", "const", "const_cast",
+ "continue", "default", "delete", "do",
+ "double", "dynamic_cast", "else",
+ "enum", "explicit", "export",
+ "extern", "false", "float", "for",
+ "friend", "goto", "if", "inline",
+ "int", "long", "mutable", "namespace",
+ "new", "not", "not_eq", "operator",
+ "or", "or_eq", "private", "protected",
+ "public", "register",
+ "reinterpret_cast", "return", "short",
+ "signed", "sizeof", "static",
+ "static_cast", "struct", "switch",
+ "template", "this", "throw", "true",
+ "try", "typedef", "typeid",
+ "typename", "typeof", "union",
+ "unsigned", "using", "virtual",
+ "void", "volatile", "wchar_t",
+ "while", "xor", "xor_eq" };
+
+ private static final HashSet keywords;
+ static
+ {
+ keywords = new HashSet();
+ for (int i = 0; i < words.length; ++i)
+ keywords.add(words[i]);
+ }
+
+ public static String getCxxName(String name)
+ {
+ int i;
+ for (i = name.length() - 1; i >= 0 && name.charAt(i) == '$'; --i)
+ ;
+ if (keywords.contains(name.substring(0, i + 1)))
+ return name + "$";
+ return name;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/Main.java b/libjava/classpath/tools/gnu/classpath/tools/javah/Main.java
new file mode 100644
index 00000000000..2cddbaae750
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/Main.java
@@ -0,0 +1,441 @@
+/* Main.java - javah main program
+ 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.javah;
+
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.Parser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.objectweb.asm.ClassReader;
+
+public class Main
+{
+ // This is an option group for classpath-related options,
+ // and also is used for loading classes.
+ PathOptionGroup classpath = new PathOptionGroup();
+
+ // The output directory.
+ String outputDir;
+
+ // The output file name used if/when -o option is used.
+ String outFileName;
+
+ // The loader that we use to load class files.
+ URLClassLoader loader;
+
+ // In -all mode, the name of the directory to scan.
+ String allDirectory;
+
+ // True for verbose mode.
+ boolean verbose;
+
+ // True if we're emitting stubs.
+ boolean stubs;
+
+ // True if we're emitting CNI code.
+ boolean cni;
+
+ // True if output files should always be written.
+ boolean force;
+
+ // Map class names to class wrappers.
+ HashMap classMap = new HashMap();
+
+ // Map class names to lists of Text objects.
+ HashMap textMap = new HashMap();
+
+ void readCommandFile(String textFileName) throws OptionException
+ {
+ FileInputStream fis;
+ try
+ {
+ fis = new FileInputStream(textFileName);
+ }
+ catch (FileNotFoundException ignore)
+ {
+ throw new OptionException("file \"" + textFileName + "\" not found");
+ }
+ BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
+ String currentClass = null;
+ ArrayList currentValues = null;
+ while (true)
+ {
+ String line;
+ try
+ {
+ line = reader.readLine();
+ }
+ catch (IOException _)
+ {
+ break;
+ }
+ if (line == null)
+ break;
+ line = line.trim();
+ if (line.length() == 0 || line.charAt(0) == '#')
+ continue;
+ int index = line.indexOf(' ');
+ String cmd = line.substring(0, index);
+ String value = line.substring(index + 1);
+ int cmdValue;
+ if ("class".equals(cmd))
+ {
+ if (currentClass != null)
+ {
+ textMap.put(currentClass, currentValues);
+ }
+ currentClass = value;
+ currentValues = new ArrayList();
+ continue;
+ }
+ if (currentClass == null)
+ throw new OptionException("no class set");
+ if ("add".equals(cmd))
+ cmdValue = Text.ADD;
+ else if ("append".equals(cmd))
+ cmdValue = Text.APPEND;
+ else if ("prepend".equals(cmd))
+ cmdValue = Text.PREPEND;
+ else if ("friend".equals(cmd))
+ cmdValue = Text.FRIEND;
+ else
+ throw new OptionException("unrecognized command: " + cmd);
+ currentValues.add(new Text(cmdValue, value));
+ }
+ if (currentClass != null)
+ {
+ textMap.put(currentClass, currentValues);
+ }
+ }
+
+ void scanDirectory(File dir, final HashSet results)
+ {
+ File[] files = dir.listFiles(new FileFilter()
+ {
+ public boolean accept(File pathname)
+ {
+ if (pathname.isDirectory())
+ {
+ scanDirectory(pathname, results);
+ return false;
+ }
+ return pathname.getName().endsWith(".class");
+ }
+ });
+ if (files != null)
+ results.addAll(Arrays.asList(files));
+ }
+
+ private Parser getParser()
+ {
+ ClasspathToolParser result = new ClasspathToolParser("javah", true);
+ result.setHeader("usage: javah [OPTIONS] CLASS...");
+ result.add(classpath);
+ result.add(new Option('d', "Set output directory", "DIR")
+ {
+ public void parsed(String dir) throws OptionException
+ {
+ if (outputDir != null)
+ throw new OptionException("-d already seen");
+ if (outFileName != null)
+ throw new OptionException("only one of -d or -o may be used");
+ outputDir = dir;
+ }
+ });
+ result.add(new Option('o',
+ "Set output file (only one of -d or -o may be used)",
+ "FILE")
+ {
+ public void parsed(String fileName) throws OptionException
+ {
+ if (outFileName != null)
+ throw new OptionException("-o already seen");
+ if (outputDir != null)
+ throw new OptionException("only one of -d or -o may be used");
+ outFileName = fileName;
+ }
+ });
+ result.add(new Option("cmdfile", "Read command file", "FILE")
+ {
+ public void parsed(String file) throws OptionException
+ {
+ readCommandFile(file);
+ }
+ });
+ result.add(new Option("all", "Operate on all class files under directory",
+ "DIR")
+ {
+ public void parsed(String arg) throws OptionException
+ {
+ // FIXME: lame restriction...
+ if (allDirectory != null)
+ throw new OptionException("-all already specified");
+ allDirectory = arg;
+ }
+ });
+ result.add(new Option("stubs", "Emit stub implementation")
+ {
+ public void parsed(String arg0) throws OptionException
+ {
+ stubs = true;
+ }
+ });
+ result.add(new Option("jni", "Emit JNI stubs or header (default)")
+ {
+ public void parsed(String arg0) throws OptionException
+ {
+ if (cni)
+ throw new OptionException("only one of -jni or -cni may be used");
+ cni = false;
+ }
+ });
+ result.add(new Option("cni", "Emit CNI stubs or header (default JNI)")
+ {
+ public void parsed(String arg0) throws OptionException
+ {
+ cni = true;
+ }
+ });
+ result.add(new Option("verbose", "Set verbose mode")
+ {
+ public void parsed(String arg0) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(new Option("force", "Output files should always be written")
+ {
+ public void parsed(String arg0) throws OptionException
+ {
+ force = true;
+ }
+ });
+ return result;
+ }
+
+ private File makeOutputDirectory() throws IOException
+ {
+ File outputFile;
+ if (outputDir == null)
+ outputFile = new File(".");
+ else
+ outputFile = new File(outputDir);
+ return outputFile;
+ }
+
+ /**
+ * @return The {@link File} object where the generated code will be written.
+ * Returns <code>null</code> if the option <code>-force</code> was
+ * specified on the command line and the designated file already
+ * exists.
+ * @throws IOException if <code>outFileName</code> is not a writable file.
+ */
+ private File makeOutputFile() throws IOException
+ {
+ File result = new File(outFileName);
+ if (result.exists())
+ {
+ if (! result.isFile())
+ throw new IOException("'" + outFileName + "' is not a file");
+ if (! force)
+ {
+ if (verbose)
+ System.err.println("["+ outFileName
+ + " already exists. Use -force to overwrite]");
+ return null;
+ }
+ if (! result.delete())
+ throw new IOException("Was unable to delete existing file: "
+ + outFileName);
+ }
+ return result;
+ }
+
+ private void writeHeaders(ArrayList klasses, Printer printer)
+ throws IOException
+ {
+ Iterator i = klasses.iterator();
+ while (i.hasNext())
+ {
+ ClassWrapper klass = (ClassWrapper) i.next();
+ if (verbose)
+ System.err.println("[writing " + klass + "]");
+ printer.printClass(klass);
+ }
+ }
+
+ private void run(String[] args) throws IOException
+ {
+ Parser p = getParser();
+ String[] classNames = p.parse(args);
+ loader = classpath.getLoader();
+
+ boolean isDirectory = outFileName == null;
+ File outputFile = isDirectory ? makeOutputDirectory() : makeOutputFile();
+ if (outputFile == null)
+ return;
+
+ Printer printer;
+ if (! cni)
+ {
+ if (stubs)
+ printer = new JniStubPrinter(this, outputFile, isDirectory, force);
+ else
+ printer = new JniIncludePrinter(this, outputFile, isDirectory, force);
+ }
+ else
+ {
+ if (stubs)
+ printer = new CniStubPrinter(this, outputFile, isDirectory, force);
+ else
+ printer = new CniIncludePrinter(this, outputFile, isDirectory, force);
+ }
+
+ // First we load all of the files. That way if
+ // there are references between the files we will
+ // be loading the set that the user asked for.
+ HashSet klasses = new HashSet();
+ if (allDirectory != null)
+ scanDirectory(new File(allDirectory), klasses);
+ // Add the command-line arguments. We use the type of
+ // an item in 'klasses' to decide how to load each class.
+ for (int i = 0; i < classNames.length; ++i)
+ {
+ if (classNames[i].endsWith(".class"))
+ {
+ klasses.add(new File(classNames[i]));
+ }
+ else
+ {
+ klasses.add(classNames[i]);
+ }
+ }
+
+ Iterator i = klasses.iterator();
+ ArrayList results = new ArrayList();
+ while (i.hasNext())
+ {
+ // Let user specify either kind of class name or a
+ // file name.
+ Object item = i.next();
+ ClassWrapper klass;
+ if (item instanceof File)
+ {
+ // Load class from file.
+ if (verbose)
+ System.err.println("[reading file " + item + "]");
+ klass = getClass((File) item);
+ }
+ else
+ {
+ // Load class given the class name.
+ String className = ((String) item).replace('.', '/');
+ if (verbose)
+ System.err.println("[reading class " + className + "]");
+ klass = getClass(className);
+ }
+ results.add(klass);
+ }
+
+ writeHeaders(results, printer);
+ }
+
+ public ArrayList getClassTextList(String name)
+ {
+ return (ArrayList) textMap.get(name);
+ }
+
+ private ClassWrapper readClass(InputStream is) throws IOException
+ {
+ ClassReader r = new ClassReader(is);
+ ClassWrapper result = new ClassWrapper(this);
+ r.accept(result, true);
+ is.close();
+ return result;
+ }
+
+ private ClassWrapper getClass(File fileName) throws IOException
+ {
+ InputStream is = new FileInputStream(fileName);
+ ClassWrapper result = readClass(is);
+ if (classMap.containsKey(result.name))
+ throw new IllegalArgumentException("class " + result.name
+ + " already loaded");
+ classMap.put(result.name, result);
+ return result;
+ }
+
+ public ClassWrapper getClass(String name) throws IOException
+ {
+ if (! classMap.containsKey(name))
+ {
+ String resource = name.replace('.', '/') + ".class";
+ URL url = loader.findResource(resource);
+ if (url == null)
+ throw new IOException("can't find class file " + resource);
+ InputStream is = url.openStream();
+ ClassWrapper result = readClass(is);
+ classMap.put(name, result);
+ }
+ return (ClassWrapper) classMap.get(name);
+ }
+
+ public static void main(String[] args) throws IOException
+ {
+ Main m = new Main();
+ m.run(args);
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/MethodHelper.java b/libjava/classpath/tools/gnu/classpath/tools/javah/MethodHelper.java
new file mode 100644
index 00000000000..6657f115ac4
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/MethodHelper.java
@@ -0,0 +1,130 @@
+/* MethodHelper.java - helper class for manipulating methods
+ 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.javah;
+
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+
+public class MethodHelper
+{
+
+ public static boolean overrides(MethodNode derived, MethodNode base)
+ {
+ if (! derived.name.equals(base.name))
+ return false;
+ if (! derived.desc.equals(base.desc))
+ return false;
+ // FIXME: permission madness?
+ return true;
+ }
+
+ public static String getBridgeTarget(MethodNode meth)
+ {
+ if ((meth.access & Opcodes.ACC_BRIDGE) == 0)
+ return null;
+ Iterator i = meth.instructions.iterator();
+ while (i.hasNext())
+ {
+ AbstractInsnNode insn = (AbstractInsnNode) i.next();
+ if (! (insn instanceof MethodInsnNode))
+ continue;
+ return ((MethodInsnNode) insn).desc;
+ }
+ return null;
+ }
+
+ public static void print(CniPrintStream out, MethodNode meth,
+ ClassWrapper declarer, boolean isBridgeTarget)
+ {
+ if ("<clinit>".equals(meth.name))
+ return;
+ boolean isInit = "<init>".equals(meth.name);
+ out.setModifiers(meth.access);
+ out.print(" ");
+ if (Modifier.isStatic(meth.access))
+ out.print("static ");
+ // If a class is final then we might as well skip 'virtual'.
+ // The reason here is that it is safe in this case for C++
+ // ABI code to generate a direct call. The method does end
+ // up in the vtable (for BC code) but we don't care. Also,
+ // the class can't be derived from anyway.
+ else if (! isInit && ! Modifier.isPrivate(meth.access)
+ && ! Modifier.isFinal(declarer.access))
+ out.print("virtual ");
+ if (! isInit)
+ {
+ out.print(Type.getReturnType(meth.desc));
+ out.print(" ");
+ if (isBridgeTarget)
+ {
+ out.print("target$");
+ out.print(meth.name);
+ }
+ else
+ {
+ out.print(Keywords.getCxxName(meth.name));
+ }
+ }
+ else
+ {
+ String name = declarer.name;
+ int index = name.lastIndexOf('/');
+ name = name.substring(index + 1);
+ out.print(name);
+ }
+ out.print("(");
+ Type[] argTypes = Type.getArgumentTypes(meth.desc);
+ for (int i = 0; i < argTypes.length; ++i)
+ {
+ if (i > 0)
+ out.print(", ");
+ out.print(argTypes[i]);
+ }
+ out.print(")");
+ if (Modifier.isAbstract(meth.access))
+ out.print(" = 0");
+ out.println(";");
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/PackageWrapper.java b/libjava/classpath/tools/gnu/classpath/tools/javah/PackageWrapper.java
new file mode 100644
index 00000000000..11b38b20f96
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/PackageWrapper.java
@@ -0,0 +1,54 @@
+/* PackageWrapper.java - represent a package
+ 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.javah;
+
+public class PackageWrapper
+{
+ // This is null if there is no parent package.
+ PackageWrapper parent;
+
+ // Name of this package relative to its parent's name.
+ String name;
+
+ public PackageWrapper(PackageWrapper parent, String name)
+ {
+ this.parent = parent;
+ this.name = name;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/PathOptionGroup.java b/libjava/classpath/tools/gnu/classpath/tools/javah/PathOptionGroup.java
new file mode 100644
index 00000000000..4287354aed6
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/PathOptionGroup.java
@@ -0,0 +1,135 @@
+/* PathOptionGroup.java - handle classpath-setting options
+ 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.javah;
+
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+public class PathOptionGroup
+ extends OptionGroup
+{
+ ArrayList classpath = new ArrayList();
+
+ ArrayList bootclasspath = new ArrayList();
+
+ void setPath(ArrayList list, String path)
+ {
+ list.clear();
+ StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
+ while (st.hasMoreTokens())
+ {
+ list.add(st.nextToken());
+ }
+ }
+
+ void addExtDirs(ArrayList list, String path)
+ {
+ StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
+ while (tok.hasMoreTokens())
+ {
+ File dir = new File(tok.nextToken());
+ list.addAll(Arrays.asList(dir.list(new FilenameFilter()
+ {
+ public boolean accept(File dir, String name)
+ {
+ return name.endsWith(".zip") || name.endsWith(".jar");
+ }
+ })));
+ }
+ }
+
+ public PathOptionGroup()
+ {
+ super("Class path options");
+
+ add(new Option("classpath", "Set the class path", "PATH")
+ {
+ public void parsed(String path) throws OptionException
+ {
+ setPath(classpath, path);
+ }
+ });
+ add(new Option('I', "Add directory to class path", "DIR", true)
+ {
+ public void parsed(String path) throws OptionException
+ {
+ classpath.add(path);
+ }
+ });
+ add(new Option("bootclasspath", "Set the boot class path", "PATH")
+ {
+ public void parsed(String path) throws OptionException
+ {
+ setPath(bootclasspath, path);
+ }
+ });
+ add(new Option("extdirs", "Set the extension directory path", "PATH")
+ {
+ public void parsed(String path) throws OptionException
+ {
+ addExtDirs(classpath, path);
+ }
+ });
+ }
+
+ public URLClassLoader getLoader() throws MalformedURLException
+ {
+ ArrayList urls = new ArrayList();
+ classpath.addAll(bootclasspath);
+ Iterator i = classpath.iterator();
+ while (i.hasNext())
+ {
+ String f = (String) i.next();
+ urls.add(new File(f).toURL());
+ }
+ URL[] urlArray = (URL[]) urls.toArray(new URL[0]);
+ return new URLClassLoader(urlArray);
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/Printer.java b/libjava/classpath/tools/gnu/classpath/tools/javah/Printer.java
new file mode 100644
index 00000000000..9c4b48d2e5c
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/Printer.java
@@ -0,0 +1,138 @@
+/* Print.java - abstract base class for printing classes
+ 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.javah;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public abstract class Printer
+{
+ protected Main classpath;
+
+ /**
+ * The {@link File} object that denotes either a directory (when the
+ * <code>-d</code> option was used), or a file (when the <code>-o</code>
+ * option was used) on the command line.
+ */
+ protected File outputFileObject;
+
+ /**
+ * Set to <code>true</code> if the field <code>outputFileObject</code> denotes
+ * a directory; i.e. for each input class file, one JNI header file will be
+ * generated in that directory.
+ * <p>
+ * Set to <code>false</code> if the field <code>outputFileObject</code>
+ * denotes a file; i.e. all generated headers will be written to that file.
+ */
+ protected boolean isDirectory;
+
+ /**
+ * Set to <code>true</code> if the output file(s) should always be written.
+ * <p>
+ * When set to <code>false</code>, the contents of the header/stub are only
+ * written to the file if it does not already exist.
+ */
+ protected boolean force;
+
+ /**
+ * Set to <code>true</code> if all output is directed to one file, and the
+ * common preamble text has already been generated.
+ */
+ protected boolean wrotePreamble;
+
+ protected Printer(Main classpath, File outFile, boolean isDir, boolean force)
+ {
+ this.classpath = classpath;
+ if (outFile == null)
+ throw new IllegalArgumentException("File argument MUST NOT be null");
+ outputFileObject = outFile;
+ isDirectory = isDir;
+ if (! isDirectory)
+ {
+ File parent = outputFileObject.getParentFile();
+ if (parent != null)
+ parent.mkdirs();
+ }
+ this.force = force;
+ }
+
+ public abstract void printClass(ClassWrapper klass) throws IOException;
+
+ protected abstract void writePreambleImpl(PrintStream ps);
+
+ protected abstract PrintStream getPrintStreamImpl(FileOutputStream fos,
+ ClassWrapper klass);
+
+ protected PrintStream getPrintStream(String fullName, ClassWrapper klass)
+ throws FileNotFoundException
+ {
+ PrintStream result;
+ FileOutputStream fos;
+ if (isDirectory)
+ {
+ File outFile = new File(outputFileObject, fullName);
+ if (outFile.exists() && ! force)
+ return null;
+ File parent = outFile.getParentFile();
+ if (parent != null)
+ parent.mkdirs();
+ fos = new FileOutputStream(outFile);
+ result = getPrintStreamImpl(fos, klass);
+ writePreamble(result);
+ }
+ else
+ {
+ // the first time we open this file, wrotePreamble is false
+ fos = new FileOutputStream(outputFileObject, wrotePreamble);
+ result = getPrintStreamImpl(fos, klass);
+ if (! wrotePreamble)
+ writePreamble(result);
+ }
+ return result;
+ }
+
+ protected void writePreamble(PrintStream out)
+ {
+ writePreambleImpl(out);
+ wrotePreamble = true;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/javah/Text.java b/libjava/classpath/tools/gnu/classpath/tools/javah/Text.java
new file mode 100644
index 00000000000..37a1ad66906
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/javah/Text.java
@@ -0,0 +1,60 @@
+/* Text.java - convenience class for CNI header text insertions
+ 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.javah;
+
+public class Text
+{
+ public static final int ADD = 0;
+
+ public static final int APPEND = 1;
+
+ public static final int FRIEND = 2;
+
+ public static final int PREPEND = 3;
+
+ public int type;
+
+ public String text;
+
+ public Text(int type, String text)
+ {
+ this.type = type;
+ this.text = text;
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/CACertCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/CACertCmd.java
index 2bf832beee0..a53a8b21ae3 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/CACertCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/CACertCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java
index 692b1f69015..bdf3aac8f9e 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/Command.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/Command.java
index bc5cff2aaba..af91e4a7151 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/Command.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/Command.java
@@ -56,7 +56,6 @@ import gnu.java.security.hash.MD5;
import gnu.java.security.hash.Sha160;
import gnu.java.security.util.Util;
import gnu.java.security.x509.X500DistinguishedName;
-import gnu.javax.security.auth.callback.ConsoleCallbackHandler;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -1203,7 +1202,8 @@ abstract class Command
* <p>
* If no installed providers were found, this method falls back on the GNU
* provider, by-passing the Security search mechanism. The default console
- * callback handler implementation is {@link ConsoleCallbackHandler}.
+ * callback handler implementation is
+ * {@link gnu.javax.security.auth.callback.ConsoleCallbackHandler}.
*
* @return a console-based {@link CallbackHandler}.
*/
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java
index 8107055d02b..53611b21cda 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java
index 75f71801c9a..a07edc6316f 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
index 03a1555a8c6..79d3824af81 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
@@ -217,7 +217,6 @@ class GenKeyCmd extends Command
protected String _providerClassName;
private int keySize;
private X500DistinguishedName distinguishedName;
- private Parser cmdOptionsParser;
// default 0-arguments constructor
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
index d0de589d933..ac0ee1329e9 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java
index 3a6ed872bfb..18a21aa683d 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java
@@ -40,7 +40,7 @@ package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
import gnu.classpath.SystemProperties;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
@@ -207,7 +207,6 @@ class ImportCmd extends Command
protected String _ksPassword;
protected String _providerClassName;
private CertificateFactory x509Factory;
- private boolean imported;
/**
* Pathname to a GKR-type cacerts file to use when trustCACerts is true. This
* is usually a file named "cacerts.gkr" located in lib/security in the folder
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
index 81549864b9e..973ed46ce51 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
index 89e6daa0249..5f91becd973 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
@@ -40,7 +40,7 @@ package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
import gnu.classpath.SystemProperties;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/ListCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/ListCmd.java
index 61cec01a4dc..7579c3f85c0 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/ListCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/ListCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/Main.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/Main.java
index 08d55556efd..2d5234ad0dd 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/Main.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/Main.java
@@ -39,8 +39,8 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.common.ProviderUtil;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
@@ -296,14 +296,6 @@ public class Main
log.exiting(this.getClass().getName(), "teardown"); //$NON-NLS-1$
}
- private void printHelp()
- {
- if (helpPrinted)
- return;
-
- helpPrinted = true;
- }
-
// Inner class(es)
// ==========================================================================
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
index 2c5461b3619..2100a60261b 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
index 75f1e8299ed..f297046c79a 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
@@ -39,7 +39,7 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java b/libjava/classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
index 1313ec6abe7..489ecccb070 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
@@ -40,7 +40,7 @@ package gnu.classpath.tools.keytool;
import gnu.classpath.Configuration;
import gnu.classpath.SystemProperties;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java b/libjava/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
index 9508c103e08..622de6056ce 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
@@ -38,7 +38,7 @@
package gnu.classpath.tools.native2ascii;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.FileArgumentCallback;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.java b/libjava/classpath/tools/gnu/classpath/tools/orbd/Main.java
index df0c9539d6a..91c50d7f8c7 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/NameServicePersistent.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/orbd/Main.java
@@ -35,23 +35,28 @@ 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.giop;
+package gnu.classpath.tools.orbd;
import gnu.CORBA.OrbFunctional;
import gnu.CORBA.IOR;
import gnu.CORBA.NamingService.Ext;
-import gnu.classpath.tools.HelpPrinter;
-import gnu.classpath.tools.giop.nameservice.PersistentContext;
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+import gnu.classpath.tools.getopt.Parser;
import org.omg.CosNaming.NamingContextExt;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
/**
- * The server for the gnu classpath persistent naming service.
+ * The server for the GNU Classpath persistent naming service.
*
* GNU Classpath currently works with this naming service and is also
* interoperable with the Sun Microsystems naming services from releases 1.3 and
@@ -59,7 +64,7 @@ import java.io.UnsupportedEncodingException;
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
-public class NameServicePersistent
+public class Main
{
/**
* The default port (900), on that the naming service starts if no
@@ -67,6 +72,11 @@ public class NameServicePersistent
*/
public static final int PORT = 900;
+ private int port = PORT;
+ private String iorf;
+ private boolean cold;
+ private String directory = "";
+
/**
* Get the object key for the naming service. The default key is the string
* "NameService" in ASCII.
@@ -85,61 +95,74 @@ public class NameServicePersistent
}
}
- /**
- * Start the naming service on the current host at the given port. The
- * parameter -org.omg.CORBA.ORBInitialPort NNN or -ORBInitialPort NNN, if
- * present, specifies the port, on that the service must be started. If this
- * key is not specified, the service starts at the port 900. The parameter
- * -ior FILE_NAME, if present, forces to store the ior string of this naming
- * service to the specified file.
- *
- * @param args the parameter string.
- */
- public static void main(String[] args)
+ private Parser initializeParser()
+ {
+ Parser parser = new ClasspathToolParser("orbd", true); //$NON-NLS-1$
+ parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+ parser.add(new Option("ORBInitialPort", //$NON-NLS-1$
+ Messages.getString("Main.ORBInitialPort"), //$NON-NLS-1$
+ Messages.getString("Main.Port")) //$NON-NLS-1$
+ {
+ public void parsed(String portArgument) throws OptionException
+ {
+ port = Integer.parseInt(portArgument);
+ }
+ });
+
+ parser.add(new Option("ior", //$NON-NLS-1$
+ Messages.getString("Main.IOR"), //$NON-NLS-1$
+ Messages.getString("Main.IORFile")) //$NON-NLS-1$
+ {
+ public void parsed(String fileArgument) throws OptionException
+ {
+ iorf = fileArgument;
+ }
+ });
+ parser.add(new Option("directory", //$NON-NLS-1$
+ Messages.getString("Main.Directory"), //$NON-NLS-1$
+ Messages.getString("Main.DirectoryArgument")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ directory = argument;
+ }
+ });
+ parser.add(new Option("restart", //$NON-NLS-1$
+ Messages.getString("Main.Restart")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ cold = true;
+ }
+ });
+
+ return parser;
+ }
+
+ private void run(String[] args)
{
- HelpPrinter.checkHelpKey(args, "giop/NameServicePersistent.txt");
- System.out.println("Please use --help for options.");
+ Parser parser = initializeParser();
+ parser.parse(args);
- int port = PORT;
- String iorf = null;
- boolean reset = false;
- String folder = "";
try
{
// Create and initialize the ORB
final OrbFunctional orb = new OrbFunctional();
-
- for (int i = 0; i < args.length; i++)
- {
- if (i < args.length - 1)
- {
- if (args[i].endsWith("ORBInitialPort"))
- port = Integer.parseInt(args[i + 1]);
-
- if (args[i].equals("-ior"))
- iorf = args[i + 1];
-
- if (args[i].equals("-folder"))
- folder = args[i + 1];
- }
- if (args[i].equals("-reset"))
- reset = true;
- }
-
OrbFunctional.setPort(port);
// Create the servant and register it with the ORB
- File dataFolder = new File(folder);
+ File dataDirectory = new File(directory);
System.out.println("Persistent data stored at "
- + dataFolder.getAbsolutePath());
- dataFolder.mkdirs();
+ + dataDirectory.getAbsolutePath());
+ dataDirectory.mkdirs();
// / TODO support more starting modes.
NamingContextExt namer = new Ext(
new PersistentContext(
orb,
- dataFolder,
- reset));
+ dataDirectory,
+ cold));
// Case with the key "NameService".
orb.connect(namer, "NameService".getBytes());
@@ -173,14 +196,33 @@ public class NameServicePersistent
}
}.start();
}
- catch (Exception e)
+ catch (FileNotFoundException e)
{
- System.err.println("ERROR: " + e);
- e.printStackTrace(System.out);
+ throw new RuntimeException(e);
}
+ finally
+ {
+ // Restore the default value for allocating ports for the subsequent
+ // objects.
+ OrbFunctional.setPort(OrbFunctional.DEFAULT_INITIAL_PORT);
+ }
+ }
- // Restore the default value for allocating ports for the subsequent
- // objects.
- OrbFunctional.setPort(OrbFunctional.DEFAULT_INITIAL_PORT);
+ /**
+ * The persistent naming service entry point.
+ */
+ public static void main(String[] args)
+ {
+ Main orbdprogram = new Main();
+ try
+ {
+ orbdprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
}
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/orbd/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/orbd/Messages.java
new file mode 100644
index 00000000000..c9bb371ad3b
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/orbd/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for orbd
+ 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.orbd;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.orbd.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContext.java b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContext.java
index 9f0903f0ab8..9b4f27a3d7d 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContext.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContext.java
@@ -36,7 +36,7 @@
exception statement from your version. */
-package gnu.classpath.tools.giop.nameservice;
+package gnu.classpath.tools.orbd;
import gnu.CORBA.NamingService.NameTransformer;
import gnu.CORBA.NamingService.TransientContext;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContextMap.java b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContextMap.java
index ce0188cf2b1..e983ef30f7a 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentContextMap.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentContextMap.java
@@ -36,7 +36,7 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools.giop.nameservice;
+package gnu.classpath.tools.orbd;
import java.io.File;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentMap.java b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentMap.java
index 6939ede17c2..6c6164d21f4 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/nameservice/PersistentMap.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/orbd/PersistentMap.java
@@ -36,7 +36,7 @@
exception statement from your version. */
-package gnu.classpath.tools.giop.nameservice;
+package gnu.classpath.tools.orbd;
import gnu.CORBA.NamingService.NamingMap;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.txt b/libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.txt
deleted file mode 100644
index 7d8e192329f..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-The persistent RMI naming service, required for the remote method invocations
-(packages java.rmi.*, java.rmi.Registry.*).
-
-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: rmiregistry <options>
-
- where <options> includes:
- -port N Start the registry on the given local port. If this key
- is not specified, the service starts on the port 1099.
- -verbose Log binding events to stdout.
- -stop Stop the running naming service at the given port.
-
- -transient Start transient registry service that does not write any
- data to the disk. Such service looses the stored bindings if
- restarted. If this key is not specified, the
- persistent naming service is started.
- -restart "Cold start:, clear the persistent naming database, if any.
- -folder Folder Store the persistent binding file in the given folder. If this
- key is not specified, the file with persistent bindings is
- stored into the current folder.
-
-
-
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.java b/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.java
deleted file mode 100644
index fa4d87c1707..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/* 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.
-*/
-
-
-package gnu.classpath.tools.rmi;
-
-import gnu.classpath.tools.HelpPrinter;
-import gnu.classpath.tools.giop.GRMIC;
-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.01 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("-force"))
- {
- compiler.setForce(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.equals("-classpath"))
- {
- int f = i + 1;
- if (f < args.length)
- {
- compiler.setClassPath(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 = compiler.loadClass(args[i]);
-
- 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/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.txt b/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.txt
deleted file mode 100644
index 882cca5538a..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMIC.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-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
- -classpath <path> Specifies the path, where to find the classes being
- compiled
-
- -help Print this help text
- -v Print version
- -verbose Verbose output
- -force Try to generate code even if the input classes seem not
- consistent with RMI specification.
-
- -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/libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.txt b/libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.txt
deleted file mode 100644
index a62613fd4a2..00000000000
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-The persistent RMI activation daemon, support RMI object activation
-(package java.rmi.activation.*).
-
-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: rmid <options>
-
- where <options> includes:
- -port N Start the service on the given local port. If this key
- is not specified, the service starts on the port 1098.
- -verbose Log registration events to stdout.
- -stop Stop the running activation service at the given port.
-
- -transient Start transient activation service that does not write any
- data to the disk. Such service looses the stored activation
- descriptors, if restarted. If this key is not specified, the
- persistent naming service is started.
- -restart "Cold start:, clear the activation descriptor database, if any.
- -folder Folder Store the persistent descriptor file in the given folder. If this
- key is not specified, the file with persistent activation
- information is stored into the current folder.
-
-All activation groups are activated on the same virtual machine, where the
-daemon is running. For security reasons, all the classes, required for
-activation, must be available in the classpath of that machine.
- \ No newline at end of file
diff --git a/libjava/classpath/tools/gnu/classpath/tools/AbstractMethodGenerator.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java
index d82284988e9..492566a80f6 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/AbstractMethodGenerator.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java
@@ -36,7 +36,7 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools;
+package gnu.classpath.tools.rmic;
public interface AbstractMethodGenerator
{
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
new file mode 100644
index 00000000000..9c50efa8ff9
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
@@ -0,0 +1,1824 @@
+/* ClassRmicCompiler.java --
+ Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
+ 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA. */
+
+package gnu.classpath.tools.rmic;
+
+import gnu.java.rmi.server.RMIHashes;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.rmi.MarshalException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.UnexpectedException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.Operation;
+import java.rmi.server.RemoteCall;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.Skeleton;
+import java.rmi.server.SkeletonMismatchException;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.Type;
+
+public class ClassRmicCompiler
+ implements RmicBackend
+{
+ private String[] args;
+ private int next;
+ private List errors = new ArrayList();
+ private boolean keep = false;
+ private boolean need11Stubs = true;
+ private boolean need12Stubs = true;
+ private boolean compile = true;
+ private boolean verbose;
+ private boolean noWrite;
+ private String destination;
+ private String classpath;
+ private ClassLoader loader;
+ private int errorCount = 0;
+
+ private Class clazz;
+ private String classname;
+ private String classInternalName;
+ private String fullclassname;
+ private MethodRef[] remotemethods;
+ private String stubname;
+ private String skelname;
+ private List mRemoteInterfaces;
+
+ /**
+ * @return true if run was successful
+ */
+ public boolean run(String[] inputFiles)
+ {
+ args = inputFiles;
+
+ if (next >= args.length)
+ return false;
+
+ for (int i = next; i < args.length; i++)
+ {
+ try
+ {
+ if (verbose)
+ System.out.println("[Processing class " + args[i] + ".class]");
+ processClass(args[i].replace(File.separatorChar, '.'));
+ }
+ catch (IOException e)
+ {
+ errors.add(e);
+ }
+ catch (RMICException e)
+ {
+ errors.add(e);
+ }
+ }
+ if (errors.size() > 0)
+ {
+ for (Iterator it = errors.iterator(); it.hasNext(); )
+ {
+ Exception ex = (Exception) it.next();
+ logError(ex);
+ }
+ }
+
+ return errorCount == 0;
+ }
+
+ private void processClass(String cls) throws IOException, RMICException
+ {
+ // reset class specific vars
+ clazz = null;
+ classname = null;
+ classInternalName = null;
+ fullclassname = null;
+ remotemethods = null;
+ stubname = null;
+ skelname = null;
+ mRemoteInterfaces = new ArrayList();
+
+ analyzeClass(cls);
+ generateStub();
+ if (need11Stubs)
+ generateSkel();
+ }
+
+ private void analyzeClass(String cname)
+ throws RMICException
+ {
+ if (verbose)
+ System.out.println("[analyze class " + cname + "]");
+ int p = cname.lastIndexOf('.');
+ if (p != -1)
+ classname = cname.substring(p + 1);
+ else
+ classname = cname;
+ fullclassname = cname;
+
+ findClass();
+ findRemoteMethods();
+ }
+
+ /**
+ * @deprecated
+ */
+ public Exception getException()
+ {
+ return errors.size() == 0 ? null : (Exception) errors.get(0);
+ }
+
+ private void findClass()
+ throws RMICException
+ {
+ ClassLoader cl = (loader == null
+ ? ClassLoader.getSystemClassLoader()
+ : loader);
+ try
+ {
+ clazz = Class.forName(fullclassname, false, cl);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RMICException
+ ("Class " + fullclassname + " not found in classpath", cnfe);
+ }
+
+ if (! Remote.class.isAssignableFrom(clazz))
+ {
+ throw new RMICException
+ ("Class " + clazz.getName()
+ + " does not implement a remote interface.");
+ }
+ }
+
+ private static Type[] typeArray(Class[] cls)
+ {
+ Type[] t = new Type[cls.length];
+ for (int i = 0; i < cls.length; i++)
+ {
+ t[i] = Type.getType(cls[i]);
+ }
+
+ return t;
+ }
+
+ private static String[] internalNameArray(Type[] t)
+ {
+ String[] s = new String[t.length];
+ for (int i = 0; i < t.length; i++)
+ {
+ s[i] = t[i].getInternalName();
+ }
+
+ return s;
+ }
+
+ private static String[] internalNameArray(Class[] c)
+ {
+ return internalNameArray(typeArray(c));
+ }
+
+ private static final String forName = "class$";
+
+ private static Object param(Method m, int argIndex)
+ {
+ List l = new ArrayList();
+ l.add(m);
+ l.add(new Integer(argIndex));
+ return l;
+ }
+
+ private static void generateClassForNamer(ClassVisitor cls)
+ {
+ MethodVisitor cv =
+ cls.visitMethod
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC, forName,
+ Type.getMethodDescriptor
+ (Type.getType(Class.class), new Type[] { Type.getType(String.class) }),
+ null, null);
+
+ Label start = new Label();
+ cv.visitLabel(start);
+ cv.visitVarInsn(Opcodes.ALOAD, 0);
+ cv.visitMethodInsn
+ (Opcodes.INVOKESTATIC,
+ Type.getInternalName(Class.class),
+ "forName",
+ Type.getMethodDescriptor
+ (Type.getType(Class.class), new Type[] { Type.getType(String.class) }));
+ cv.visitInsn(Opcodes.ARETURN);
+
+ Label handler = new Label();
+ cv.visitLabel(handler);
+ cv.visitVarInsn(Opcodes.ASTORE, 1);
+ cv.visitTypeInsn(Opcodes.NEW, typeArg(NoClassDefFoundError.class));
+ cv.visitInsn(Opcodes.DUP);
+ cv.visitVarInsn(Opcodes.ALOAD, 1);
+ cv.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(ClassNotFoundException.class),
+ "getMessage",
+ Type.getMethodDescriptor(Type.getType(String.class), new Type[] {}));
+ cv.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(NoClassDefFoundError.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+ cv.visitInsn(Opcodes.ATHROW);
+ cv.visitTryCatchBlock
+ (start, handler, handler,
+ Type.getInternalName(ClassNotFoundException.class));
+ cv.visitMaxs(-1, -1);
+ }
+
+ private void generateClassConstant(MethodVisitor cv, Class cls) {
+ if (cls.isPrimitive())
+ {
+ Class boxCls;
+ if (cls.equals(Boolean.TYPE))
+ boxCls = Boolean.class;
+ else if (cls.equals(Character.TYPE))
+ boxCls = Character.class;
+ else if (cls.equals(Byte.TYPE))
+ boxCls = Byte.class;
+ else if (cls.equals(Short.TYPE))
+ boxCls = Short.class;
+ else if (cls.equals(Integer.TYPE))
+ boxCls = Integer.class;
+ else if (cls.equals(Long.TYPE))
+ boxCls = Long.class;
+ else if (cls.equals(Float.TYPE))
+ boxCls = Float.class;
+ else if (cls.equals(Double.TYPE))
+ boxCls = Double.class;
+ else if (cls.equals(Void.TYPE))
+ boxCls = Void.class;
+ else
+ throw new IllegalArgumentException("unknown primitive type " + cls);
+
+ cv.visitFieldInsn
+ (Opcodes.GETSTATIC, Type.getInternalName(boxCls), "TYPE",
+ Type.getDescriptor(Class.class));
+ return;
+ }
+ cv.visitLdcInsn(cls.getName());
+ cv.visitMethodInsn
+ (Opcodes.INVOKESTATIC, classInternalName, forName,
+ Type.getMethodDescriptor
+ (Type.getType(Class.class),
+ new Type[] { Type.getType(String.class) }));
+ }
+
+ private void generateClassArray(MethodVisitor code, Class[] classes)
+ {
+ code.visitLdcInsn(new Integer(classes.length));
+ code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Class.class));
+ for (int i = 0; i < classes.length; i++)
+ {
+ code.visitInsn(Opcodes.DUP);
+ code.visitLdcInsn(new Integer(i));
+ generateClassConstant(code, classes[i]);
+ code.visitInsn(Opcodes.AASTORE);
+ }
+ }
+
+ private void fillOperationArray(MethodVisitor clinit)
+ {
+ // Operations array
+ clinit.visitLdcInsn(new Integer(remotemethods.length));
+ clinit.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Operation.class));
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+
+ StringBuffer desc = new StringBuffer();
+ desc.append(getPrettyName(m.getReturnType()) + " ");
+ desc.append(m.getName() + "(");
+
+ // signature
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++)
+ {
+ desc.append(getPrettyName(sig[j]));
+ if (j + 1 < sig.length)
+ desc.append(", ");
+ }
+
+ // push operations array
+ clinit.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+
+ // push array index
+ clinit.visitLdcInsn(new Integer(i));
+
+ // instantiate operation and leave a copy on the stack
+ clinit.visitTypeInsn(Opcodes.NEW, typeArg(Operation.class));
+ clinit.visitInsn(Opcodes.DUP);
+ clinit.visitLdcInsn(desc.toString());
+ clinit.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(Operation.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+
+ // store in operations array
+ clinit.visitInsn(Opcodes.AASTORE);
+ }
+ }
+
+ private void generateStaticMethodObjs(MethodVisitor clinit)
+ {
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+
+ /*
+ * $method_<i>m.getName()</i>_<i>i</i> =
+ * <i>m.getDeclaringClass()</i>.class.getMethod
+ * (m.getName(), m.getParameterType())
+ */
+ String methodVar = "$method_" + m.getName() + "_" + i;
+ generateClassConstant(clinit, m.getDeclaringClass());
+ clinit.visitLdcInsn(m.getName());
+ generateClassArray(clinit, m.getParameterTypes());
+ clinit.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(Class.class),
+ "getMethod",
+ Type.getMethodDescriptor
+ (Type.getType(Method.class),
+ new Type[] { Type.getType(String.class),
+ Type.getType(Class[].class) }));
+
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, methodVar,
+ Type.getDescriptor(Method.class));
+ }
+ }
+
+ private void generateStub()
+ throws IOException
+ {
+ stubname = fullclassname + "_Stub";
+ String stubclassname = classname + "_Stub";
+ File file = new File((destination == null ? "." : destination)
+ + File.separator
+ + stubname.replace('.', File.separatorChar)
+ + ".class");
+
+ if (verbose)
+ System.out.println("[Generating class " + stubname + "]");
+
+ final ClassWriter stub = new ClassWriter(true);
+ classInternalName = stubname.replace('.', '/');
+ final String superInternalName =
+ Type.getType(RemoteStub.class).getInternalName();
+
+ String[] remoteInternalNames =
+ internalNameArray((Class[]) mRemoteInterfaces.toArray(new Class[] {}));
+ stub.visit
+ (Opcodes.V1_2, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, classInternalName,
+ null, superInternalName, remoteInternalNames);
+
+ if (need12Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "serialVersionUID",
+ Type.LONG_TYPE.getDescriptor(), null, new Long(2L));
+ }
+
+ if (need11Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL,
+ "interfaceHash", Type.LONG_TYPE.getDescriptor(), null,
+ new Long(RMIHashes.getInterfaceHash(clazz)));
+
+ if (need12Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor(), null, null);
+ }
+
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL,
+ "operations", Type.getDescriptor(Operation[].class), null, null);
+ }
+
+ // Set of method references.
+ if (need12Stubs)
+ {
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+ String slotName = "$method_" + m.getName() + "_" + i;
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, slotName,
+ Type.getDescriptor(Method.class), null, null);
+ }
+ }
+
+ MethodVisitor clinit = stub.visitMethod
+ (Opcodes.ACC_STATIC, "<clinit>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
+
+ if (need11Stubs)
+ {
+ fillOperationArray(clinit);
+ if (! need12Stubs)
+ clinit.visitInsn(Opcodes.RETURN);
+ }
+
+ if (need12Stubs)
+ {
+ // begin of try
+ Label begin = new Label();
+
+ // beginning of catch
+ Label handler = new Label();
+ clinit.visitLabel(begin);
+
+ // Initialize the methods references.
+ if (need11Stubs)
+ {
+ /*
+ * RemoteRef.class.getMethod("invoke", new Class[] {
+ * Remote.class, Method.class, Object[].class, long.class })
+ */
+ generateClassConstant(clinit, RemoteRef.class);
+ clinit.visitLdcInsn("invoke");
+ generateClassArray
+ (clinit, new Class[] { Remote.class, Method.class,
+ Object[].class, long.class });
+ clinit.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(Class.class),
+ "getMethod",
+ Type.getMethodDescriptor
+ (Type.getType(Method.class),
+ new Type[] { Type.getType(String.class),
+ Type.getType(Class[].class) }));
+
+ // useNewInvoke = true
+ clinit.visitInsn(Opcodes.ICONST_1);
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor());
+ }
+
+ generateStaticMethodObjs(clinit);
+
+ // jump past handler
+ clinit.visitInsn(Opcodes.RETURN);
+ clinit.visitLabel(handler);
+ if (need11Stubs)
+ {
+ // useNewInvoke = false
+ clinit.visitInsn(Opcodes.ICONST_0);
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor());
+ clinit.visitInsn(Opcodes.RETURN);
+ }
+ else
+ {
+ // throw NoSuchMethodError
+ clinit.visitTypeInsn(Opcodes.NEW, typeArg(NoSuchMethodError.class));
+ clinit.visitInsn(Opcodes.DUP);
+ clinit.visitLdcInsn("stub class initialization failed");
+ clinit.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(NoSuchMethodError.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(String.class) }));
+ clinit.visitInsn(Opcodes.ATHROW);
+ }
+
+ clinit.visitTryCatchBlock
+ (begin, handler, handler,
+ Type.getInternalName(NoSuchMethodException.class));
+
+ }
+
+ clinit.visitMaxs(-1, -1);
+
+ generateClassForNamer(stub);
+
+ // Constructors
+ if (need11Stubs)
+ {
+ // no arg public constructor
+ MethodVisitor code = stub.visitMethod
+ (Opcodes.ACC_PUBLIC, "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}),
+ null, null);
+ code.visitVarInsn(Opcodes.ALOAD, 0);
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL, superInternalName, "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
+ code.visitInsn(Opcodes.RETURN);
+
+ code.visitMaxs(-1, -1);
+ }
+
+ // public RemoteRef constructor
+ MethodVisitor constructor = stub.visitMethod
+ (Opcodes.ACC_PUBLIC, "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] {Type.getType(RemoteRef.class)}),
+ null, null);
+ constructor.visitVarInsn(Opcodes.ALOAD, 0);
+ constructor.visitVarInsn(Opcodes.ALOAD, 1);
+ constructor.visitMethodInsn
+ (Opcodes.INVOKESPECIAL, superInternalName, "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] {Type.getType(RemoteRef.class)}));
+ constructor.visitInsn(Opcodes.RETURN);
+ constructor.visitMaxs(-1, -1);
+
+ // Method implementations
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+ Class[] sig = m.getParameterTypes();
+ Class returntype = m.getReturnType();
+ Class[] except = sortExceptions
+ ((Class[]) remotemethods[i].exceptions.toArray(new Class[0]));
+
+ MethodVisitor code = stub.visitMethod
+ (Opcodes.ACC_PUBLIC,
+ m.getName(),
+ Type.getMethodDescriptor(Type.getType(returntype), typeArray(sig)),
+ null,
+ internalNameArray(typeArray(except)));
+
+ final Variables var = new Variables();
+
+ // this and parameters are the declared vars
+ var.declare("this");
+ for (int j = 0; j < sig.length; j++)
+ var.declare(param(m, j), size(sig[j]));
+
+ Label methodTryBegin = new Label();
+ code.visitLabel(methodTryBegin);
+
+ if (need12Stubs)
+ {
+ Label oldInvoke = new Label();
+ if (need11Stubs)
+ {
+ // if not useNewInvoke jump to old invoke
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "useNewInvoke",
+ Type.getDescriptor(boolean.class));
+ code.visitJumpInsn(Opcodes.IFEQ, oldInvoke);
+ }
+
+ // this.ref
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class),
+ "ref", Type.getDescriptor(RemoteRef.class));
+
+ // "this" is first arg to invoke
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+
+ // method object is second arg to invoke
+ String methName = "$method_" + m.getName() + "_" + i;
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, methName,
+ Type.getDescriptor(Method.class));
+
+ // args to remote method are third arg to invoke
+ if (sig.length == 0)
+ code.visitInsn(Opcodes.ACONST_NULL);
+ else
+ {
+ // create arg Object[] (with boxed primitives) and push it
+ code.visitLdcInsn(new Integer(sig.length));
+ code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Object.class));
+
+ var.allocate("argArray");
+ code.visitVarInsn(Opcodes.ASTORE, var.get("argArray"));
+
+ for (int j = 0; j < sig.length; j++)
+ {
+ int size = size(sig[j]);
+ int insn = loadOpcode(sig[j]);
+ Class box = sig[j].isPrimitive() ? box(sig[j]) : null;
+
+ code.visitVarInsn(Opcodes.ALOAD, var.get("argArray"));
+ code.visitLdcInsn(new Integer(j));
+
+ // put argument on stack
+ if (box != null)
+ {
+ code.visitTypeInsn(Opcodes.NEW, typeArg(box));
+ code.visitInsn(Opcodes.DUP);
+ code.visitVarInsn(insn, var.get(param(m, j)));
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(box),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(sig[j]) }));
+ }
+ else
+ code.visitVarInsn(insn, var.get(param(m, j)));
+
+ code.visitInsn(Opcodes.AASTORE);
+ }
+
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("argArray"));
+ }
+
+ // push remote operation opcode
+ code.visitLdcInsn(new Long(remotemethods[i].hash));
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteRef.class),
+ "invoke",
+ Type.getMethodDescriptor
+ (Type.getType(Object.class),
+ new Type[] { Type.getType(Remote.class),
+ Type.getType(Method.class),
+ Type.getType(Object[].class),
+ Type.LONG_TYPE }));
+
+ if (! returntype.equals(Void.TYPE))
+ {
+ int retcode = returnOpcode(returntype);
+ Class boxCls =
+ returntype.isPrimitive() ? box(returntype) : null;
+ code.visitTypeInsn
+ (Opcodes.CHECKCAST, typeArg(boxCls == null ? returntype : boxCls));
+ if (returntype.isPrimitive())
+ {
+ // unbox
+ code.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getType(boxCls).getInternalName(),
+ unboxMethod(returntype),
+ Type.getMethodDescriptor
+ (Type.getType(returntype), new Type[] {}));
+ }
+
+ code.visitInsn(retcode);
+ }
+ else
+ code.visitInsn(Opcodes.RETURN);
+
+
+ if (need11Stubs)
+ code.visitLabel(oldInvoke);
+ }
+
+ if (need11Stubs)
+ {
+
+ // this.ref.newCall(this, operations, index, interfaceHash)
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD,
+ Type.getInternalName(RemoteObject.class),
+ "ref",
+ Type.getDescriptor(RemoteRef.class));
+
+ // "this" is first arg to newCall
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+
+ // operations is second arg to newCall
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+
+ // method index is third arg
+ code.visitLdcInsn(new Integer(i));
+
+ // interface hash is fourth arg
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "interfaceHash",
+ Type.LONG_TYPE.getDescriptor());
+
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteRef.class),
+ "newCall",
+ Type.getMethodDescriptor
+ (Type.getType(RemoteCall.class),
+ new Type[] { Type.getType(RemoteObject.class),
+ Type.getType(Operation[].class),
+ Type.INT_TYPE,
+ Type.LONG_TYPE }));
+
+ // store call object on stack and leave copy on stack
+ var.allocate("call");
+ code.visitInsn(Opcodes.DUP);
+ code.visitVarInsn(Opcodes.ASTORE, var.get("call"));
+
+ Label beginArgumentTryBlock = new Label();
+ code.visitLabel(beginArgumentTryBlock);
+
+ // ObjectOutput out = call.getOutputStream();
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteCall.class),
+ "getOutputStream",
+ Type.getMethodDescriptor
+ (Type.getType(ObjectOutput.class), new Type[] {}));
+
+ for (int j = 0; j < sig.length; j++)
+ {
+ // dup the ObjectOutput
+ code.visitInsn(Opcodes.DUP);
+
+ // get j'th arg to remote method
+ code.visitVarInsn(loadOpcode(sig[j]), var.get(param(m, j)));
+
+ Class argCls =
+ sig[j].isPrimitive() ? sig[j] : Object.class;
+
+ // out.writeFoo
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(ObjectOutput.class),
+ writeMethod(sig[j]),
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(argCls) }));
+ }
+
+ // pop ObjectOutput
+ code.visitInsn(Opcodes.POP);
+
+ Label iohandler = new Label();
+ Label endArgumentTryBlock = new Label();
+ code.visitJumpInsn(Opcodes.GOTO, endArgumentTryBlock);
+ code.visitLabel(iohandler);
+
+ // throw new MarshalException(msg, ioexception);
+ code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
+ code.visitTypeInsn(Opcodes.NEW, typeArg(MarshalException.class));
+ code.visitInsn(Opcodes.DUP);
+ code.visitLdcInsn("error marshalling arguments");
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(MarshalException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(String.class),
+ Type.getType(Exception.class) }));
+ code.visitInsn(Opcodes.ATHROW);
+
+ code.visitLabel(endArgumentTryBlock);
+ code.visitTryCatchBlock
+ (beginArgumentTryBlock, iohandler, iohandler,
+ Type.getInternalName(IOException.class));
+
+ // this.ref.invoke(call)
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class),
+ "ref", Type.getDescriptor(RemoteRef.class));
+ code.visitVarInsn(Opcodes.ALOAD, var.get("call"));
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteRef.class),
+ "invoke",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(RemoteCall.class) }));
+
+ // handle return value
+ boolean needcastcheck = false;
+
+ Label beginReturnTryCatch = new Label();
+ code.visitLabel(beginReturnTryCatch);
+
+ int returncode = returnOpcode(returntype);
+
+ if (! returntype.equals(Void.TYPE))
+ {
+ // call.getInputStream()
+ code.visitVarInsn(Opcodes.ALOAD, var.get("call"));
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteCall.class),
+ "getInputStream",
+ Type.getMethodDescriptor
+ (Type.getType(ObjectInput.class), new Type[] {}));
+
+ Class readCls =
+ returntype.isPrimitive() ? returntype : Object.class;
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(ObjectInput.class),
+ readMethod(returntype),
+ Type.getMethodDescriptor
+ (Type.getType(readCls), new Type[] {}));
+
+ boolean castresult = false;
+
+ if (! returntype.isPrimitive())
+ {
+ if (! returntype.equals(Object.class))
+ castresult = true;
+ else
+ needcastcheck = true;
+ }
+
+ if (castresult)
+ code.visitTypeInsn(Opcodes.CHECKCAST, typeArg(returntype));
+
+ // leave result on stack for return
+ }
+
+ // this.ref.done(call)
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD,
+ Type.getInternalName(RemoteObject.class),
+ "ref",
+ Type.getDescriptor(RemoteRef.class));
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("call"));
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteRef.class),
+ "done",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(RemoteCall.class) }));
+
+ // return; or return result;
+ code.visitInsn(returncode);
+
+ // exception handler
+ Label handler = new Label();
+ code.visitLabel(handler);
+ code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
+
+ // throw new UnmarshalException(msg, e)
+ code.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class));
+ code.visitInsn(Opcodes.DUP);
+ code.visitLdcInsn("error unmarshalling return");
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(UnmarshalException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(String.class),
+ Type.getType(Exception.class) }));
+ code.visitInsn(Opcodes.ATHROW);
+
+ Label endReturnTryCatch = new Label();
+
+ // catch IOException
+ code.visitTryCatchBlock
+ (beginReturnTryCatch, handler, handler,
+ Type.getInternalName(IOException.class));
+
+ if (needcastcheck)
+ {
+ // catch ClassNotFoundException
+ code.visitTryCatchBlock
+ (beginReturnTryCatch, handler, handler,
+ Type.getInternalName(ClassNotFoundException.class));
+ }
+ }
+
+ Label rethrowHandler = new Label();
+ code.visitLabel(rethrowHandler);
+ // rethrow declared exceptions
+ code.visitInsn(Opcodes.ATHROW);
+
+ boolean needgeneral = true;
+ for (int j = 0; j < except.length; j++)
+ {
+ if (except[j] == Exception.class)
+ needgeneral = false;
+ }
+
+ for (int j = 0; j < except.length; j++)
+ {
+ code.visitTryCatchBlock
+ (methodTryBegin, rethrowHandler, rethrowHandler,
+ Type.getInternalName(except[j]));
+ }
+
+ if (needgeneral)
+ {
+ // rethrow unchecked exceptions
+ code.visitTryCatchBlock
+ (methodTryBegin, rethrowHandler, rethrowHandler,
+ Type.getInternalName(RuntimeException.class));
+
+ Label generalHandler = new Label();
+ code.visitLabel(generalHandler);
+ String msg = "undeclared checked exception";
+
+ // throw new java.rmi.UnexpectedException(msg, e)
+ code.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
+ code.visitTypeInsn(Opcodes.NEW, typeArg(UnexpectedException.class));
+ code.visitInsn(Opcodes.DUP);
+ code.visitLdcInsn(msg);
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(UnexpectedException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type [] { Type.getType(String.class),
+ Type.getType(Exception.class) }));
+ code.visitInsn(Opcodes.ATHROW);
+
+ code.visitTryCatchBlock
+ (methodTryBegin, rethrowHandler, generalHandler,
+ Type.getInternalName(Exception.class));
+ }
+
+ code.visitMaxs(-1, -1);
+ }
+
+ stub.visitEnd();
+ byte[] classData = stub.toByteArray();
+ if (!noWrite)
+ {
+ if (file.exists())
+ file.delete();
+ if (file.getParentFile() != null)
+ file.getParentFile().mkdirs();
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(classData);
+ fos.flush();
+ fos.close();
+ }
+ }
+
+ private void generateSkel() throws IOException
+ {
+ skelname = fullclassname + "_Skel";
+ String skelclassname = classname + "_Skel";
+ File file = new File(destination == null ? "" : destination
+ + File.separator
+ + skelname.replace('.', File.separatorChar)
+ + ".class");
+ if (verbose)
+ System.out.println("[Generating class " + skelname + "]");
+
+ final ClassWriter skel = new ClassWriter(true);
+ classInternalName = skelname.replace('.', '/');
+ skel.visit
+ (Opcodes.V1_1, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL,
+ classInternalName, Type.getInternalName(Object.class), null,
+ new String[] { Type.getType(Skeleton.class).getInternalName() });
+
+ skel.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "interfaceHash",
+ Type.LONG_TYPE.getDescriptor(), null,
+ new Long(RMIHashes.getInterfaceHash(clazz)));
+
+ skel.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "operations",
+ Type.getDescriptor(Operation[].class), null, null);
+
+ MethodVisitor clinit = skel.visitMethod
+ (Opcodes.ACC_STATIC, "<clinit>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
+
+ fillOperationArray(clinit);
+ clinit.visitInsn(Opcodes.RETURN);
+
+ clinit.visitMaxs(-1, -1);
+
+ // no arg public constructor
+ MethodVisitor init = skel.visitMethod
+ (Opcodes.ACC_PUBLIC, "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
+ init.visitVarInsn(Opcodes.ALOAD, 0);
+ init.visitMethodInsn
+ (Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
+ init.visitInsn(Opcodes.RETURN);
+ init.visitMaxs(-1, -1);
+
+ /*
+ * public Operation[] getOperations()
+ * returns a clone of the operations array
+ */
+ MethodVisitor getOp = skel.visitMethod
+ (Opcodes.ACC_PUBLIC, "getOperations",
+ Type.getMethodDescriptor
+ (Type.getType(Operation[].class), new Type[] {}),
+ null, null);
+ getOp.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+ getOp.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL, Type.getInternalName(Object.class),
+ "clone", Type.getMethodDescriptor(Type.getType(Object.class),
+ new Type[] {}));
+ getOp.visitTypeInsn(Opcodes.CHECKCAST, typeArg(Operation[].class));
+ getOp.visitInsn(Opcodes.ARETURN);
+ getOp.visitMaxs(-1, -1);
+
+ // public void dispatch(Remote, RemoteCall, int opnum, long hash)
+ MethodVisitor dispatch = skel.visitMethod
+ (Opcodes.ACC_PUBLIC,
+ "dispatch",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(Remote.class),
+ Type.getType(RemoteCall.class),
+ Type.INT_TYPE, Type.LONG_TYPE }), null,
+ new String[] { Type.getInternalName(Exception.class) });
+
+ Variables var = new Variables();
+ var.declare("this");
+ var.declare("remoteobj");
+ var.declare("remotecall");
+ var.declare("opnum");
+ var.declareWide("hash");
+
+ /*
+ * if opnum >= 0
+ * XXX it is unclear why there is handling of negative opnums
+ */
+ dispatch.visitVarInsn(Opcodes.ILOAD, var.get("opnum"));
+ Label nonNegativeOpnum = new Label();
+ Label opnumSet = new Label();
+ dispatch.visitJumpInsn(Opcodes.IFGE, nonNegativeOpnum);
+
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ // assign opnum if hash matches supplied hash
+ dispatch.visitVarInsn(Opcodes.LLOAD, var.get("hash"));
+ dispatch.visitLdcInsn(new Long(remotemethods[i].hash));
+ Label notIt = new Label();
+ dispatch.visitInsn(Opcodes.LCMP);
+ dispatch.visitJumpInsn(Opcodes.IFNE, notIt);
+
+ // opnum = <opnum>
+ dispatch.visitLdcInsn(new Integer(i));
+ dispatch.visitVarInsn(Opcodes.ISTORE, var.get("opnum"));
+ dispatch.visitJumpInsn(Opcodes.GOTO, opnumSet);
+ dispatch.visitLabel(notIt);
+ }
+
+ // throw new SkeletonMismatchException
+ Label mismatch = new Label();
+ dispatch.visitJumpInsn(Opcodes.GOTO, mismatch);
+
+ dispatch.visitLabel(nonNegativeOpnum);
+
+ // if opnum is already set, check that the hash matches the interface
+ dispatch.visitVarInsn(Opcodes.LLOAD, var.get("hash"));
+ dispatch.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName,
+ "interfaceHash", Type.LONG_TYPE.getDescriptor());
+ dispatch.visitInsn(Opcodes.LCMP);
+ dispatch.visitJumpInsn(Opcodes.IFEQ, opnumSet);
+
+ dispatch.visitLabel(mismatch);
+ dispatch.visitTypeInsn
+ (Opcodes.NEW, typeArg(SkeletonMismatchException.class));
+ dispatch.visitInsn(Opcodes.DUP);
+ dispatch.visitLdcInsn("interface hash mismatch");
+ dispatch.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(SkeletonMismatchException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+ dispatch.visitInsn(Opcodes.ATHROW);
+
+ // opnum has been set
+ dispatch.visitLabel(opnumSet);
+
+ dispatch.visitVarInsn(Opcodes.ALOAD, var.get("remoteobj"));
+ dispatch.visitTypeInsn(Opcodes.CHECKCAST, typeArg(clazz));
+ dispatch.visitVarInsn(Opcodes.ASTORE, var.get("remoteobj"));
+
+ Label deflt = new Label();
+ Label[] methLabels = new Label[remotemethods.length];
+ for (int i = 0; i < methLabels.length; i++)
+ methLabels[i] = new Label();
+
+ // switch on opnum
+ dispatch.visitVarInsn(Opcodes.ILOAD, var.get("opnum"));
+ dispatch.visitTableSwitchInsn
+ (0, remotemethods.length - 1, deflt, methLabels);
+
+ // Method dispatch
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ dispatch.visitLabel(methLabels[i]);
+ Method m = remotemethods[i].meth;
+ generateMethodSkel(dispatch, m, var);
+ }
+
+ dispatch.visitLabel(deflt);
+ dispatch.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class));
+ dispatch.visitInsn(Opcodes.DUP);
+ dispatch.visitLdcInsn("invalid method number");
+ dispatch.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(UnmarshalException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+ dispatch.visitInsn(Opcodes.ATHROW);
+
+ dispatch.visitMaxs(-1, -1);
+
+ skel.visitEnd();
+ byte[] classData = skel.toByteArray();
+ if (!noWrite)
+ {
+ if (file.exists())
+ file.delete();
+ if (file.getParentFile() != null)
+ file.getParentFile().mkdirs();
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(classData);
+ fos.flush();
+ fos.close();
+ }
+ }
+
+ private void generateMethodSkel(MethodVisitor cv, Method m, Variables var)
+ {
+ Class[] sig = m.getParameterTypes();
+
+ Label readArgs = new Label();
+ cv.visitLabel(readArgs);
+
+ boolean needcastcheck = false;
+
+ // ObjectInput in = call.getInputStream();
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall"));
+ cv.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteCall.class), "getInputStream",
+ Type.getMethodDescriptor
+ (Type.getType(ObjectInput.class), new Type[] {}));
+ cv.visitVarInsn(Opcodes.ASTORE, var.allocate("objectinput"));
+
+ for (int i = 0; i < sig.length; i++)
+ {
+ // dup input stream
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("objectinput"));
+
+ Class readCls = sig[i].isPrimitive() ? sig[i] : Object.class;
+
+ // in.readFoo()
+ cv.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(ObjectInput.class),
+ readMethod(sig[i]),
+ Type.getMethodDescriptor
+ (Type.getType(readCls), new Type [] {}));
+
+ if (! sig[i].isPrimitive() && ! sig[i].equals(Object.class))
+ {
+ needcastcheck = true;
+ cv.visitTypeInsn(Opcodes.CHECKCAST, typeArg(sig[i]));
+ }
+
+ // store arg in variable
+ cv.visitVarInsn
+ (storeOpcode(sig[i]), var.allocate(param(m, i), size(sig[i])));
+ }
+
+ var.deallocate("objectinput");
+
+ Label doCall = new Label();
+ Label closeInput = new Label();
+
+ cv.visitJumpInsn(Opcodes.JSR, closeInput);
+ cv.visitJumpInsn(Opcodes.GOTO, doCall);
+
+ // throw new UnmarshalException
+ Label handler = new Label();
+ cv.visitLabel(handler);
+ cv.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
+ cv.visitTypeInsn(Opcodes.NEW, typeArg(UnmarshalException.class));
+ cv.visitInsn(Opcodes.DUP);
+ cv.visitLdcInsn("error unmarshalling arguments");
+ cv.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
+ cv.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(UnmarshalException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class),
+ Type.getType(Exception.class) }));
+ cv.visitVarInsn(Opcodes.ASTORE, var.allocate("toThrow"));
+ cv.visitJumpInsn(Opcodes.JSR, closeInput);
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("toThrow"));
+ cv.visitInsn(Opcodes.ATHROW);
+
+ cv.visitTryCatchBlock
+ (readArgs, handler, handler, Type.getInternalName(IOException.class));
+ if (needcastcheck)
+ {
+ cv.visitTryCatchBlock
+ (readArgs, handler, handler,
+ Type.getInternalName(ClassCastException.class));
+ }
+
+ // finally block
+ cv.visitLabel(closeInput);
+ cv.visitVarInsn(Opcodes.ASTORE, var.allocate("retAddress"));
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall"));
+ cv.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteCall.class),
+ "releaseInputStream",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
+ cv.visitVarInsn(Opcodes.RET, var.deallocate("retAddress"));
+ var.deallocate("toThrow");
+
+ // do the call using args stored as variables
+ cv.visitLabel(doCall);
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("remoteobj"));
+ for (int i = 0; i < sig.length; i++)
+ cv.visitVarInsn(loadOpcode(sig[i]), var.deallocate(param(m, i)));
+ cv.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL, Type.getInternalName(clazz), m.getName(),
+ Type.getMethodDescriptor(m));
+
+ Class returntype = m.getReturnType();
+ if (! returntype.equals(Void.TYPE))
+ {
+ cv.visitVarInsn
+ (storeOpcode(returntype), var.allocate("result", size(returntype)));
+ }
+
+ // write result to result stream
+ Label writeResult = new Label();
+ cv.visitLabel(writeResult);
+ cv.visitVarInsn(Opcodes.ALOAD, var.get("remotecall"));
+ cv.visitInsn(Opcodes.ICONST_1);
+ cv.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteCall.class),
+ "getResultStream",
+ Type.getMethodDescriptor
+ (Type.getType(ObjectOutput.class),
+ new Type[] { Type.BOOLEAN_TYPE }));
+
+ if (! returntype.equals(Void.TYPE))
+ {
+ // out.writeFoo(result)
+ cv.visitVarInsn(loadOpcode(returntype), var.deallocate("result"));
+ Class writeCls = returntype.isPrimitive() ? returntype : Object.class;
+ cv.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(ObjectOutput.class),
+ writeMethod(returntype),
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(writeCls) }));
+ }
+
+ cv.visitInsn(Opcodes.RETURN);
+
+ // throw new MarshalException
+ Label marshalHandler = new Label();
+ cv.visitLabel(marshalHandler);
+ cv.visitVarInsn(Opcodes.ASTORE, var.allocate("exception"));
+ cv.visitTypeInsn(Opcodes.NEW, typeArg(MarshalException.class));
+ cv.visitInsn(Opcodes.DUP);
+ cv.visitLdcInsn("error marshalling return");
+ cv.visitVarInsn(Opcodes.ALOAD, var.deallocate("exception"));
+ cv.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(MarshalException.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class),
+ Type.getType(Exception.class) }));
+ cv.visitInsn(Opcodes.ATHROW);
+ cv.visitTryCatchBlock
+ (writeResult, marshalHandler, marshalHandler,
+ Type.getInternalName(IOException.class));
+ }
+
+ private static String typeArg(Class cls)
+ {
+ if (cls.isArray())
+ return Type.getDescriptor(cls);
+
+ return Type.getInternalName(cls);
+ }
+
+ private static String readMethod(Class cls)
+ {
+ if (cls.equals(Void.TYPE))
+ throw new IllegalArgumentException("can not read void");
+
+ String method;
+ if (cls.equals(Boolean.TYPE))
+ method = "readBoolean";
+ else if (cls.equals(Byte.TYPE))
+ method = "readByte";
+ else if (cls.equals(Character.TYPE))
+ method = "readChar";
+ else if (cls.equals(Short.TYPE))
+ method = "readShort";
+ else if (cls.equals(Integer.TYPE))
+ method = "readInt";
+ else if (cls.equals(Long.TYPE))
+ method = "readLong";
+ else if (cls.equals(Float.TYPE))
+ method = "readFloat";
+ else if (cls.equals(Double.TYPE))
+ method = "readDouble";
+ else
+ method = "readObject";
+
+ return method;
+ }
+
+ private static String writeMethod(Class cls)
+ {
+ if (cls.equals(Void.TYPE))
+ throw new IllegalArgumentException("can not read void");
+
+ String method;
+ if (cls.equals(Boolean.TYPE))
+ method = "writeBoolean";
+ else if (cls.equals(Byte.TYPE))
+ method = "writeByte";
+ else if (cls.equals(Character.TYPE))
+ method = "writeChar";
+ else if (cls.equals(Short.TYPE))
+ method = "writeShort";
+ else if (cls.equals(Integer.TYPE))
+ method = "writeInt";
+ else if (cls.equals(Long.TYPE))
+ method = "writeLong";
+ else if (cls.equals(Float.TYPE))
+ method = "writeFloat";
+ else if (cls.equals(Double.TYPE))
+ method = "writeDouble";
+ else
+ method = "writeObject";
+
+ return method;
+ }
+
+ private static int returnOpcode(Class cls)
+ {
+ int returncode;
+ if (cls.equals(Boolean.TYPE))
+ returncode = Opcodes.IRETURN;
+ else if (cls.equals(Byte.TYPE))
+ returncode = Opcodes.IRETURN;
+ else if (cls.equals(Character.TYPE))
+ returncode = Opcodes.IRETURN;
+ else if (cls.equals(Short.TYPE))
+ returncode = Opcodes.IRETURN;
+ else if (cls.equals(Integer.TYPE))
+ returncode = Opcodes.IRETURN;
+ else if (cls.equals(Long.TYPE))
+ returncode = Opcodes.LRETURN;
+ else if (cls.equals(Float.TYPE))
+ returncode = Opcodes.FRETURN;
+ else if (cls.equals(Double.TYPE))
+ returncode = Opcodes.DRETURN;
+ else if (cls.equals(Void.TYPE))
+ returncode = Opcodes.RETURN;
+ else
+ returncode = Opcodes.ARETURN;
+
+ return returncode;
+ }
+
+ private static int loadOpcode(Class cls)
+ {
+ if (cls.equals(Void.TYPE))
+ throw new IllegalArgumentException("can not load void");
+
+ int loadcode;
+ if (cls.equals(Boolean.TYPE))
+ loadcode = Opcodes.ILOAD;
+ else if (cls.equals(Byte.TYPE))
+ loadcode = Opcodes.ILOAD;
+ else if (cls.equals(Character.TYPE))
+ loadcode = Opcodes.ILOAD;
+ else if (cls.equals(Short.TYPE))
+ loadcode = Opcodes.ILOAD;
+ else if (cls.equals(Integer.TYPE))
+ loadcode = Opcodes.ILOAD;
+ else if (cls.equals(Long.TYPE))
+ loadcode = Opcodes.LLOAD;
+ else if (cls.equals(Float.TYPE))
+ loadcode = Opcodes.FLOAD;
+ else if (cls.equals(Double.TYPE))
+ loadcode = Opcodes.DLOAD;
+ else
+ loadcode = Opcodes.ALOAD;
+
+ return loadcode;
+ }
+
+ private static int storeOpcode(Class cls)
+ {
+ if (cls.equals(Void.TYPE))
+ throw new IllegalArgumentException("can not load void");
+
+ int storecode;
+ if (cls.equals(Boolean.TYPE))
+ storecode = Opcodes.ISTORE;
+ else if (cls.equals(Byte.TYPE))
+ storecode = Opcodes.ISTORE;
+ else if (cls.equals(Character.TYPE))
+ storecode = Opcodes.ISTORE;
+ else if (cls.equals(Short.TYPE))
+ storecode = Opcodes.ISTORE;
+ else if (cls.equals(Integer.TYPE))
+ storecode = Opcodes.ISTORE;
+ else if (cls.equals(Long.TYPE))
+ storecode = Opcodes.LSTORE;
+ else if (cls.equals(Float.TYPE))
+ storecode = Opcodes.FSTORE;
+ else if (cls.equals(Double.TYPE))
+ storecode = Opcodes.DSTORE;
+ else
+ storecode = Opcodes.ASTORE;
+
+ return storecode;
+ }
+
+ private static String unboxMethod(Class primitive)
+ {
+ if (! primitive.isPrimitive())
+ throw new IllegalArgumentException("can not unbox nonprimitive");
+
+ String method;
+ if (primitive.equals(Boolean.TYPE))
+ method = "booleanValue";
+ else if (primitive.equals(Byte.TYPE))
+ method = "byteValue";
+ else if (primitive.equals(Character.TYPE))
+ method = "charValue";
+ else if (primitive.equals(Short.TYPE))
+ method = "shortValue";
+ else if (primitive.equals(Integer.TYPE))
+ method = "intValue";
+ else if (primitive.equals(Long.TYPE))
+ method = "longValue";
+ else if (primitive.equals(Float.TYPE))
+ method = "floatValue";
+ else if (primitive.equals(Double.TYPE))
+ method = "doubleValue";
+ else
+ throw new IllegalStateException("unknown primitive class " + primitive);
+
+ return method;
+ }
+
+ public static Class box(Class cls)
+ {
+ if (! cls.isPrimitive())
+ throw new IllegalArgumentException("can only box primitive");
+
+ Class box;
+ if (cls.equals(Boolean.TYPE))
+ box = Boolean.class;
+ else if (cls.equals(Byte.TYPE))
+ box = Byte.class;
+ else if (cls.equals(Character.TYPE))
+ box = Character.class;
+ else if (cls.equals(Short.TYPE))
+ box = Short.class;
+ else if (cls.equals(Integer.TYPE))
+ box = Integer.class;
+ else if (cls.equals(Long.TYPE))
+ box = Long.class;
+ else if (cls.equals(Float.TYPE))
+ box = Float.class;
+ else if (cls.equals(Double.TYPE))
+ box = Double.class;
+ else
+ throw new IllegalStateException("unknown primitive type " + cls);
+
+ return box;
+ }
+
+ private static int size(Class cls) {
+ if (cls.equals(Long.TYPE) || cls.equals(Double.TYPE))
+ return 2;
+ else
+ return 1;
+ }
+
+ /**
+ * Sort exceptions so the most general go last.
+ */
+ private Class[] sortExceptions(Class[] except)
+ {
+ for (int i = 0; i < except.length; i++)
+ {
+ for (int j = i + 1; j < except.length; j++)
+ {
+ if (except[i].isAssignableFrom(except[j]))
+ {
+ Class tmp = except[i];
+ except[i] = except[j];
+ except[j] = tmp;
+ }
+ }
+ }
+ return (except);
+ }
+
+ public void setup(boolean keep, boolean need11Stubs, boolean need12Stubs,
+ boolean iiop, boolean poa, boolean debug, boolean warnings,
+ boolean noWrite, boolean verbose, boolean force, String classpath,
+ String bootclasspath, String extdirs, String outputDirectory)
+ {
+ this.keep = keep;
+ this.need11Stubs = need11Stubs;
+ this.need12Stubs = need12Stubs;
+ this.verbose = verbose;
+ this.noWrite = noWrite;
+
+ // Set up classpath.
+ this.classpath = classpath;
+ StringTokenizer st =
+ new StringTokenizer(classpath, File.pathSeparator);
+ URL[] u = new URL[st.countTokens()];
+ for (int i = 0; i < u.length; i++)
+ {
+ String path = st.nextToken();
+ File f = new File(path);
+ try
+ {
+ u[i] = f.toURL();
+ }
+ catch (java.net.MalformedURLException mue)
+ {
+ logError("malformed classpath component " + path);
+ return;
+ }
+ }
+ loader = new URLClassLoader(u);
+
+ destination = outputDirectory;
+ }
+
+ private void findRemoteMethods()
+ throws RMICException
+ {
+ List rmeths = new ArrayList();
+ for (Class cur = clazz; cur != null; cur = cur.getSuperclass())
+ {
+ Class[] interfaces = cur.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ if (java.rmi.Remote.class.isAssignableFrom(interfaces[i]))
+ {
+ Class remoteInterface = interfaces[i];
+ if (verbose)
+ System.out.println
+ ("[implements " + remoteInterface.getName() + "]");
+
+ // check if the methods declare RemoteExceptions
+ Method[] meths = remoteInterface.getMethods();
+ for (int j = 0; j < meths.length; j++)
+ {
+ Method m = meths[j];
+ Class[] exs = m.getExceptionTypes();
+
+ boolean throwsRemote = false;
+ for (int k = 0; k < exs.length; k++)
+ {
+ if (exs[k].isAssignableFrom(RemoteException.class))
+ throwsRemote = true;
+ }
+
+ if (! throwsRemote)
+ {
+ throw new RMICException
+ ("Method " + m + " in interface " + remoteInterface
+ + " does not throw a RemoteException");
+ }
+
+ rmeths.add(m);
+ }
+
+ mRemoteInterfaces.add(remoteInterface);
+ }
+ }
+ }
+
+ // intersect exceptions for doubly inherited methods
+ boolean[] skip = new boolean[rmeths.size()];
+ for (int i = 0; i < skip.length; i++)
+ skip[i] = false;
+ List methrefs = new ArrayList();
+ for (int i = 0; i < rmeths.size(); i++)
+ {
+ if (skip[i]) continue;
+ Method current = (Method) rmeths.get(i);
+ MethodRef ref = new MethodRef(current);
+ for (int j = i+1; j < rmeths.size(); j++)
+ {
+ Method other = (Method) rmeths.get(j);
+ if (ref.isMatch(other))
+ {
+ ref.intersectExceptions(other);
+ skip[j] = true;
+ }
+ }
+ methrefs.add(ref);
+ }
+
+ // Convert into a MethodRef array and sort them
+ remotemethods = (MethodRef[])
+ methrefs.toArray(new MethodRef[methrefs.size()]);
+ Arrays.sort(remotemethods);
+ }
+
+ /**
+ * Prints an error to System.err and increases the error count.
+ */
+ private void logError(Exception theError)
+ {
+ logError(theError.getMessage());
+ if (verbose)
+ theError.printStackTrace(System.err);
+ }
+
+ /**
+ * Prints an error to System.err and increases the error count.
+ */
+ private void logError(String theError)
+ {
+ errorCount++;
+ System.err.println("error: " + theError);
+ }
+
+ private static String getPrettyName(Class cls)
+ {
+ StringBuffer str = new StringBuffer();
+ for (int count = 0;; count++)
+ {
+ if (! cls.isArray())
+ {
+ str.append(cls.getName());
+ for (; count > 0; count--)
+ str.append("[]");
+ return (str.toString());
+ }
+ cls = cls.getComponentType();
+ }
+ }
+
+ private static class MethodRef
+ implements Comparable
+ {
+ Method meth;
+ long hash;
+ List exceptions;
+ private String sig;
+
+ MethodRef(Method m) {
+ meth = m;
+ sig = Type.getMethodDescriptor(meth);
+ hash = RMIHashes.getMethodHash(m);
+ // add exceptions removing subclasses
+ exceptions = removeSubclasses(m.getExceptionTypes());
+ }
+
+ public int compareTo(Object obj) {
+ MethodRef that = (MethodRef) obj;
+ int name = this.meth.getName().compareTo(that.meth.getName());
+ if (name == 0) {
+ return this.sig.compareTo(that.sig);
+ }
+ return name;
+ }
+
+ public boolean isMatch(Method m)
+ {
+ if (!meth.getName().equals(m.getName()))
+ return false;
+
+ Class[] params1 = meth.getParameterTypes();
+ Class[] params2 = m.getParameterTypes();
+ if (params1.length != params2.length)
+ return false;
+
+ for (int i = 0; i < params1.length; i++)
+ if (!params1[i].equals(params2[i])) return false;
+
+ return true;
+ }
+
+ private static List removeSubclasses(Class[] classes)
+ {
+ List list = new ArrayList();
+ for (int i = 0; i < classes.length; i++)
+ {
+ Class candidate = classes[i];
+ boolean add = true;
+ for (int j = 0; j < classes.length; j++)
+ {
+ if (classes[j].equals(candidate))
+ continue;
+ else if (classes[j].isAssignableFrom(candidate))
+ add = false;
+ }
+ if (add) list.add(candidate);
+ }
+
+ return list;
+ }
+
+ public void intersectExceptions(Method m)
+ {
+ List incoming = removeSubclasses(m.getExceptionTypes());
+
+ List updated = new ArrayList();
+
+ for (int i = 0; i < exceptions.size(); i++)
+ {
+ Class outer = (Class) exceptions.get(i);
+ boolean addOuter = false;
+ for (int j = 0; j < incoming.size(); j++)
+ {
+ Class inner = (Class) incoming.get(j);
+
+ if (inner.equals(outer) || inner.isAssignableFrom(outer))
+ addOuter = true;
+ else if (outer.isAssignableFrom(inner))
+ updated.add(inner);
+ }
+
+ if (addOuter)
+ updated.add(outer);
+ }
+
+ exceptions = updated;
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/CompilationError.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/CompilationError.java
index d1fa814ee38..176a09598d2 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/CompilationError.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/CompilationError.java
@@ -19,7 +19,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
/**
* This error is thrown when the target being compiled has illegal
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/Generator.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/Generator.java
index 17ab821ecc9..64eb2eaf66c 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/Generator.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/Generator.java
@@ -19,7 +19,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopIo.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/GiopIo.java
index 0e0df7bc57a..0d77d1a787e 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopIo.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/GiopIo.java
@@ -19,7 +19,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
import java.rmi.Remote;
@@ -44,7 +44,7 @@ public class GiopIo
* the parent generator, used to name the class
* @return the write statement.
*/
- public static String getWriteStatement(Class c, String variable, GiopRmicCompiler r)
+ public static String getWriteStatement(Class c, String variable, SourceGiopRmicCompiler r)
{
if (c.equals(boolean.class))
return "out.write_boolean(" + variable + ");";
@@ -80,7 +80,7 @@ public class GiopIo
* the parent generator, used to name the class
* @return the right side of the read statement.
*/
- public static String getReadStatement(Class c, GiopRmicCompiler r)
+ public static String getReadStatement(Class c, SourceGiopRmicCompiler r)
{
if (c.equals(boolean.class))
return "in.read_boolean();";
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/HashFinder.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/HashFinder.java
index 2efdb1e76de..cf4d67f0cc0 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/HashFinder.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/HashFinder.java
@@ -20,7 +20,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
import java.util.HashSet;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/Main.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/Main.java
new file mode 100644
index 00000000000..12d1fa20eda
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/Main.java
@@ -0,0 +1,282 @@
+/* Main.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.
+*/
+
+package gnu.classpath.tools.rmic;
+
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+import gnu.classpath.tools.getopt.Parser;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+/**
+ * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class Main
+{
+ private boolean noWrite;
+ private boolean warnings = true;
+ private boolean verbose;
+ private boolean force;
+ private String classpath = ".";
+ private String outputDirectory = ".";
+ private boolean poa;
+ private boolean need11Stubs = false;
+ private boolean need12Stubs = true;
+ private boolean keep;
+ private boolean iiop;
+ /**
+ * Specifies whether or not JRMP mode was explicitly requested.
+ */
+ private boolean jrmp;
+
+ private Parser initializeParser()
+ {
+ Parser parser = new ClasspathToolParser("rmic", true); //$NON-NLS-1$
+ parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+ parser.add(new Option("nowarn", //$NON-NLS-1$
+ Messages.getString("Main.NoWarn")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ warnings = false;
+ }
+ });
+ parser.add(new Option("nowrite", //$NON-NLS-1$
+ Messages.getString("Main.NoWrite")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ noWrite = true;
+ }
+ });
+ parser.add(new Option("verbose", //$NON-NLS-1$
+ Messages.getString("Main.Verbose")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ parser.add(new Option("d", //$NON-NLS-1$
+ Messages.getString("Main.DirOpt"), //$NON-NLS-1$
+ Messages.getString("Main.DirArg")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ outputDirectory = argument;
+ }
+ });
+ parser.add(new Option("classpath", //$NON-NLS-1$
+ Messages.getString("Main.ClasspathOpt"), //$NON-NLS-1$
+ Messages.getString("Main.ClasspathArg")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ classpath = argument;
+ }
+ });
+ parser.add(new Option("bootclasspath", //$NON-NLS-1$
+ Messages.getString("Main.BootclasspathOpt"), //$NON-NLS-1$
+ Messages.getString("Main.BootclasspathArg")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ }
+ });
+ parser.add(new Option("extdirs", //$NON-NLS-1$
+ Messages.getString("Main.ExtdirsOpt"), //$NON-NLS-1$
+ Messages.getString("Main.ExtdirsArg")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ }
+ });
+ parser.add(new Option("iiop", //$NON-NLS-1$
+ Messages.getString("Main.IIOP")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ iiop = true;
+ }
+ });
+ parser.add(new Option("always", //$NON-NLS-1$
+ Messages.getString("Main.Always")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ force = true;
+ }
+ });
+ parser.add(new Option("alwaysgenerate", //$NON-NLS-1$
+ Messages.getString("Main.AlwaysGenerate")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ force = true;
+ }
+ });
+ parser.add(new Option("nolocalstubs", //$NON-NLS-1$
+ Messages.getString("Main.NoLocalStubs")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ }
+ });
+ parser.add(new Option("poa", //$NON-NLS-1$
+ Messages.getString("Main.POA")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ poa = true;
+ }
+ });
+ parser.add(new Option("keep", //$NON-NLS-1$
+ Messages.getString("Main.Keep")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ keep = true;
+ }
+ });
+ parser.add(new Option("keepgenerated", //$NON-NLS-1$
+ Messages.getString("Main.KeepGenerated")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ keep = true;
+ }
+ });
+ parser.add(new Option("v1.1", //$NON-NLS-1$
+ Messages.getString("Main.v11")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ need11Stubs = true;
+ need12Stubs = false;
+ jrmp = true;
+ }
+ });
+ parser.add(new Option("v1.2", //$NON-NLS-1$
+ Messages.getString("Main.v12")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ jrmp = true;
+ }
+ });
+ parser.add(new Option("vcompat", //$NON-NLS-1$
+ Messages.getString("Main.vcompat")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ need11Stubs = true;
+ need12Stubs = true;
+ jrmp = true;
+ }
+ });
+ parser.add(new Option("g", //$NON-NLS-1$
+ Messages.getString("Main.DebugInfo")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ }
+ });
+
+ return parser;
+ }
+
+ private void run(String[] args)
+ {
+ Parser p = initializeParser();
+ String[] files = p.parse(args);
+
+ if (files.length == 0)
+ {
+ p.printHelp();
+ System.exit(1);
+ }
+
+ ArrayList backends = new ArrayList();
+
+ // FIXME: need an IDL RmicBackend
+ // FIXME: need a ClassGiopRmicCompiler RmicBackend
+ if (iiop)
+ {
+ backends.add(new SourceGiopRmicCompiler());
+
+ if (jrmp)
+ {
+ // Both IIOP and JRMP stubs were requested.
+ backends.add(new ClassRmicCompiler());
+ // FIXME: SourceRmicCompiler should support v1.1
+ if (keep)
+ backends.add(new SourceRmicCompiler());
+ }
+ }
+ else
+ {
+ backends.add(new ClassRmicCompiler());
+ if (keep)
+ backends.add(new SourceRmicCompiler());
+ }
+
+ for (int i = 0; i < backends.size(); i++)
+ {
+ RmicBackend b = (RmicBackend) backends.get(i);
+ b.setup(keep, need11Stubs, need12Stubs,
+ iiop, poa, false, warnings,
+ noWrite, verbose, force, classpath,
+ null, null, outputDirectory);
+ if (!b.run(files))
+ System.exit(1);
+ }
+ }
+
+ /**
+ * The RMI compiler entry point.
+ */
+ public static void main(String[] args)
+ {
+ Main rmicprogram = new Main();
+ try
+ {
+ rmicprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
+
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/Messages.java
new file mode 100644
index 00000000000..5e67dd163c4
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for rmic
+ 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.rmic;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.rmic.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/MethodGenerator.java
index 80148d51aff..335a0a65c30 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/MethodGenerator.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/MethodGenerator.java
@@ -19,9 +19,9 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
-import gnu.classpath.tools.AbstractMethodGenerator;
+import gnu.classpath.tools.rmic.AbstractMethodGenerator;
import java.lang.reflect.Method;
import java.util.Properties;
@@ -42,7 +42,7 @@ public class MethodGenerator implements AbstractMethodGenerator
/**
* The parent code generator.
*/
- GiopRmicCompiler rmic;
+ SourceGiopRmicCompiler rmic;
/**
* The previous method in the list, null for the first element.
@@ -64,7 +64,7 @@ public class MethodGenerator implements AbstractMethodGenerator
* the Rmic generator instance, where more class - related
* information is defined.
*/
- public MethodGenerator(Method aMethod, GiopRmicCompiler aRmic)
+ public MethodGenerator(Method aMethod, SourceGiopRmicCompiler aRmic)
{
method = aMethod;
rmic = aRmic;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/RMICException.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/RMICException.java
new file mode 100644
index 00000000000..300d60947d7
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/RMICException.java
@@ -0,0 +1,54 @@
+/* RMICException.java --
+ Copyright (c) 2003, 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA. */
+
+
+package gnu.classpath.tools.rmic;
+
+/**
+ * Thrown by the underlying compiler used by RMIC when it fails to compile a
+ * file.
+ *
+ * @author Dalibor Topic <robilad@kaffe.org>
+ */
+public class RMICException
+ extends Exception
+{
+ /**
+ * Create an exception with a message. The cause remains uninitialized.
+ *
+ * @param message the message string
+ * @see #initCause(Throwable)
+ */
+ public RMICException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Create an exception with a message and a cause.
+ *
+ * @param message the message string
+ * @param cause the cause of this exception
+ */
+ public RMICException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/RmiMethodGenerator.java
index 8da486571ce..48abb8fade9 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmiMethodGenerator.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/RmiMethodGenerator.java
@@ -25,9 +25,9 @@
*/
-package gnu.classpath.tools.rmi.rmic;
+package gnu.classpath.tools.rmic;
-import gnu.classpath.tools.AbstractMethodGenerator;
+import gnu.classpath.tools.rmic.AbstractMethodGenerator;
import gnu.java.rmi.server.RMIHashes;
import java.lang.reflect.Method;
@@ -50,7 +50,7 @@ public class RmiMethodGenerator
/**
* The parent code generator.
*/
- RmicCompiler rmic;
+ SourceRmicCompiler rmic;
/**
* Create the new method generator for the given method.
@@ -59,7 +59,7 @@ public class RmiMethodGenerator
* @param aRmic the Rmic generator instance, where more class - related
* information is defined.
*/
- public RmiMethodGenerator(Method aMethod, RmicCompiler aRmic)
+ public RmiMethodGenerator(Method aMethod, SourceRmicCompiler aRmic)
{
method = aMethod;
rmic = aRmic;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/RmicBackend.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/RmicBackend.java
new file mode 100644
index 00000000000..60eb854ca4c
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/RmicBackend.java
@@ -0,0 +1,31 @@
+/* RmicBackend.java --
+ Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
+ 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA. */
+
+package gnu.classpath.tools.rmic;
+public interface RmicBackend
+{
+ void setup(boolean keep, boolean need11Stubs, boolean need12Stubs,
+ boolean iiop, boolean poa, boolean debug, boolean warnings,
+ boolean noWrite, boolean verbose, boolean force, String classpath,
+ String bootclasspath, String extdirs, String outputDirectory);
+
+ boolean run(String[] inputFiles);
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java
index 6d895a14cd3..e9b7bff0b7e 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java
@@ -1,4 +1,4 @@
-/* GiopRmicCompiler -- Central GIOP-based RMI stub and tie compiler class.
+/* SourceGiopRmicCompiler -- Central GIOP-based RMI stub and tie compiler class.
Copyright (C) 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -19,11 +19,14 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
-package gnu.classpath.tools.giop.grmic;
+package gnu.classpath.tools.rmic;
-import gnu.classpath.tools.AbstractMethodGenerator;
+import gnu.classpath.tools.rmic.AbstractMethodGenerator;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
@@ -46,8 +49,8 @@ import java.util.TreeSet;
*
* @author Audrius Meskauskas, Lithuania (audriusa@Bioinformatics.org)
*/
-public class GiopRmicCompiler
- extends Generator implements Comparator
+public class SourceGiopRmicCompiler
+ extends Generator implements Comparator, RmicBackend
{
/** The package name. */
protected String packag;
@@ -101,6 +104,20 @@ public class GiopRmicCompiler
protected boolean warnings = true;
/**
+ * If this flag is set (false by default), the compiler does not
+ * write output files.
+ */
+ protected boolean noWrite = false;
+
+ /**
+ * If this flag is set (false by default), the compiler keeps source
+ * output files. For SourceGiopRmicCompiler this overrides
+ * -nowrite, since -nowrite doesn't apply to sources kept with
+ * -keep.
+ */
+ protected boolean keep = false;
+
+ /**
* Verbose output
*/
protected boolean verbose = false;
@@ -109,7 +126,12 @@ public class GiopRmicCompiler
* Force mode - do not check the exceptions
*/
protected boolean force = false;
-
+
+ /**
+ * The output directory for generated files.
+ */
+ protected String outputDirectory;
+
/**
* The class loader to load the class being compiled.
*/
@@ -590,4 +612,83 @@ public class GiopRmicCompiler
else
return name;
}
+
+ /**
+ * Assumes that output directory is already created.
+ */
+ protected boolean outputTie(File fw, Class c)
+ {
+ try
+ {
+ String tie = generateTie();
+ String tieName = "_" + name(c) + "_Tie.java";
+
+ OutputStream out = new FileOutputStream(new File(fw, tieName));
+ out.write(tie.getBytes());
+ out.close();
+ }
+ catch (IOException ioex)
+ {
+ System.err.println("Output path not accessible");
+ ioex.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ public void setup(boolean keep, boolean need11Stubs, boolean need12Stubs,
+ boolean iiop, boolean poa, boolean debug, boolean warnings,
+ boolean noWrite, boolean verbose, boolean force, String classpath,
+ String bootclasspath, String extdirs, String outputDirectory)
+ {
+ setWarnings(warnings);
+ setVerbose(verbose);
+ setForce(force);
+ setClassPath(classpath);
+ setPoaMode(poa);
+ this.outputDirectory = outputDirectory;
+ this.noWrite = noWrite;
+ this.keep = keep;
+ }
+
+ public boolean run(String[] inputFiles)
+ {
+ for (int i = 0; i < inputFiles.length; i++)
+ {
+ reset();
+ Class c = loadClass(inputFiles[i]);
+
+ compile(c);
+ String packag = getPackageName().replace('.', '/');
+ File fw = new File(outputDirectory, packag);
+
+ // Generate stub.
+ String stub = generateStub();
+ String subName = getStubName() + "_Stub.java";
+
+ // -keep overrides -nowrite for sources.
+ if (!noWrite || keep)
+ {
+ try
+ {
+ fw.mkdirs();
+ OutputStream out = new FileOutputStream(new File(fw,
+ subName));
+ out.write(stub.getBytes());
+ out.close();
+
+ // Generate tie
+ if (!outputTie(fw, c))
+ return false;
+ }
+ catch (IOException ioex)
+ {
+ System.err.println("Output path not accessible");
+ ioex.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/SourceRmicCompiler.java
index bc51aad38b9..3779c5d28fb 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/RmicCompiler.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/SourceRmicCompiler.java
@@ -1,4 +1,4 @@
-/* RmicCompiler.java -- RMI stub generator for java.rmi.*
+/* SourceRmicCompiler.java -- RMI stub generator for java.rmi.*
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -25,20 +25,20 @@ combination.
*/
-package gnu.classpath.tools.rmi.rmic;
+package gnu.classpath.tools.rmic;
import java.lang.reflect.Method;
+import java.io.File;
import java.util.Iterator;
-import gnu.classpath.tools.AbstractMethodGenerator;
-import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
+import gnu.classpath.tools.rmic.AbstractMethodGenerator;
/**
* RMI stub source code generator, required to support java.rmi.*
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
-public class RmicCompiler extends GiopRmicCompiler
+public class SourceRmicCompiler extends SourceGiopRmicCompiler
{
/**
* If true, the zero size object array is declared in the stub to reduce
@@ -168,4 +168,12 @@ public class RmicCompiler extends GiopRmicCompiler
{
return name;
}
+
+ /**
+ * Override to do nothing.
+ */
+ protected boolean outputTie(File fw, Class c)
+ {
+ return true;
+ }
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmic/Variables.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/Variables.java
new file mode 100644
index 00000000000..bddf5f78377
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/Variables.java
@@ -0,0 +1,137 @@
+/* Variables.java --
+ Copyright (c) 2004, 2005
+ 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA. */
+
+package gnu.classpath.tools.rmic;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
+class Variables
+{
+ private final HashSet free = new HashSet();
+ private final HashMap names = new HashMap();
+ private final HashSet wides = new HashSet();
+ private final HashSet declared = new HashSet();
+ private boolean allocated = false;
+
+ public void declare(Object name)
+ {
+ declare(name, 1);
+ }
+
+ public void declareWide(Object name)
+ {
+ declare(name, 2);
+ }
+
+ public void declare(Object name, int size)
+ {
+ if (allocated)
+ throw new IllegalStateException("cannot declare after allocating");
+ if (size != 1 && size != 2)
+ throw new IllegalArgumentException("size must be 1 or 2");
+ if (names.containsKey(name))
+ throw new IllegalStateException("already allocated " + name);
+
+ allocateNew(name, size);
+ declared.add(name);
+ }
+
+ private int allocateNew(Object name, int size)
+ {
+ // total allocation size is first unallocated slot
+ int i = free.size() + names.size() + wides.size();
+ names.put(name, new Integer(i));
+ if (size == 2) wides.add(name);
+ return i;
+ }
+
+ public int allocate(Object name)
+ {
+ return allocate(name, 1);
+ }
+
+ public int allocateWide(Object name)
+ {
+ return allocate(name, 2);
+ }
+
+ public int allocate(Object name, int size)
+ {
+ allocated = true;
+ if (size != 1 && size != 2)
+ throw new IllegalArgumentException("size must be 1 or 2");
+ if (names.containsKey(name))
+ throw new IllegalStateException("already allocated " + name);
+
+ if (size == 2)
+ {
+ // look for consecutive free slots
+ for (Iterator it = free.iterator(); it.hasNext(); )
+ {
+ Integer i = (Integer) it.next();
+ Integer next = new Integer(i.intValue() + 1);
+ if (free.contains(next))
+ {
+ free.remove(i);
+ free.remove(next);
+ wides.add(name);
+ names.put(name, i);
+ return i.intValue();
+ }
+ }
+ }
+ else if (free.size() > 0)
+ {
+ Integer i = (Integer) free.iterator().next();
+ free.remove(i);
+ names.put(name, i);
+ return i.intValue();
+ }
+
+ return allocateNew(name, size);
+ }
+
+ public int deallocate(Object name)
+ {
+ if (! names.containsKey(name))
+ throw new IllegalArgumentException("no variable " + name);
+
+ if (declared.contains(name))
+ throw new IllegalStateException(name + " can't be deallocated");
+
+ Integer i = (Integer) names.get(name);
+ names.remove(name);
+ free.add(i);
+ if (wides.remove(name))
+ free.add(new Integer(i.intValue() + 1));
+ return i.intValue();
+ }
+
+ public int get(Object name)
+ {
+ if (! names.containsKey(name))
+ throw new IllegalArgumentException("no variable " + name);
+
+ return ((Integer) names.get(name)).intValue();
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java b/libjava/classpath/tools/gnu/classpath/tools/rmic/WrapUnWrapper.java
index 8ee4fa5f26d..c51925fa6b9 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/WrapUnWrapper.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/WrapUnWrapper.java
@@ -20,7 +20,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
*/
-package gnu.classpath.tools.rmi.rmic;
+package gnu.classpath.tools.rmic;
public class WrapUnWrapper
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/ImplTie.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/ImplTie.jav
index aff606b90cc..aff606b90cc 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/ImplTie.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/ImplTie.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Stub.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub.jav
index 371e12d4486..371e12d4486 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Stub.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethod.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethod.jav
index 17636deb670..17636deb670 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethod.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethod.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethodVoid.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethodVoid.jav
index 0125a02b0a3..0125a02b0a3 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/StubMethodVoid.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethodVoid.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12.jav
index 1c55a059799..1c55a059799 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12Method.jav
index 9aaf8f5adc0..9aaf8f5adc0 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12Method.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12Method.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12MethodVoid.jav
index 860a93c8447..860a93c8447 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmic/templates/Stub_12MethodVoid.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12MethodVoid.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Tie.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Tie.jav
index 797ae1401de..797ae1401de 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/Tie.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/Tie.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethod.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethod.jav
index 493f0009b48..493f0009b48 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethod.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethod.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethodVoid.jav b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethodVoid.jav
index 3db17da7c84..3db17da7c84 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/grmic/templates/TieMethodVoid.jav
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethodVoid.jav
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl.java b/libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl.java
index dda40b06c02..390117a0527 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl.java
@@ -35,10 +35,9 @@ 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.rmid;
+package gnu.classpath.tools.rmid;
-import gnu.classpath.tools.rmi.Persistent;
-import gnu.classpath.tools.rmi.PersistentBidiHashTable;
+import gnu.classpath.tools.common.Persistent;
import gnu.java.rmi.activation.ActivationSystemTransient;
import java.io.File;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl_Stub.java b/libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl_Stub.java
index 22fa10e4be2..535f8ab92ac 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/rmid/ActivationSystemImpl_Stub.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmid/ActivationSystemImpl_Stub.java
@@ -36,7 +36,7 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools.rmi.rmid;
+package gnu.classpath.tools.rmid;
import java.rmi.MarshalledObject;
import java.rmi.RemoteException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.java b/libjava/classpath/tools/gnu/classpath/tools/rmid/Main.java
index 81d09671a79..d601b13f178 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/RMID.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmid/Main.java
@@ -1,4 +1,4 @@
-/* RMID.java -- the RMI activation daemon.
+/* Main.java -- the RMI activation daemon.
Copyright (c) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,10 +35,15 @@ 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;
+package gnu.classpath.tools.rmid;
-import gnu.classpath.tools.HelpPrinter;
-import gnu.classpath.tools.rmi.rmid.ActivationSystemImpl;
+import gnu.classpath.tools.rmid.ActivationSystemImpl;
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+import gnu.classpath.tools.getopt.Parser;
import gnu.java.rmi.activation.ActivationSystemTransient;
import gnu.java.rmi.server.UnicastServerRef;
@@ -57,7 +62,7 @@ import java.rmi.server.RMIServerSocketFactory;
*
* @author Audrius Meskauskas (audriusa@bioinformatics.org)
*/
-public class RMID
+public class Main
{
/**
* The RMI server socket factory.
@@ -74,55 +79,102 @@ public class RMID
*/
static String ACTIVATION_SYSTEM_NAME = "java.rmi.activation.ActivationSystem";
- /**
- * The RMI activation daemon entry point.
- */
- public static void main(String[] args)
+ // Parse parameters:
+ private boolean stop = false;
+ private String directory = ".";
+ private boolean cold = false;
+ private boolean persistent = false;
+
+ private Parser initializeParser()
{
- String HelpPath = "rmi/RMID.txt";
- HelpPrinter.checkHelpKey(args, HelpPath);
-
- // Parse parameters:
- boolean stop = false;
- String folder = ".";
- boolean cold = false;
- boolean trans = false;
-
- for (int i = 0; i < args.length; i++)
+ Parser parser = new ClasspathToolParser("rmiregistry", true); //$NON-NLS-1$
+ parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+
+ OptionGroup controlGroup
+ = new OptionGroup(Messages.getString("Main.ControlGroup")); //$NON-NLS-1$
+ controlGroup.add(new Option("port", //$NON-NLS-1$
+ Messages.getString("Main.PortOption"), //$NON-NLS-1$
+ Messages.getString("Main.Port")) //$NON-NLS-1$
{
- String a = args[i];
- if (a.equals("-verbose"))
- ActivationSystemTransient.debug = true;
- else if (a.equals("-stop"))
- stop = true;
- else if (a.equals("-restart"))
+ public void parsed(String portArgument) throws OptionException
+ {
+ ACTIVATION_REGISTRY_PORT = Integer.parseInt(portArgument);
+ }
+ });
+ controlGroup.add(new Option("restart", //$NON-NLS-1$
+ Messages.getString("Main.Restart")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
cold = true;
- else if (a.equals("-transient"))
- trans = true;
- else if (i < args.length - 1)
- {
- // The additional key parameter is possible.
- if (a.equals("-port"))
- ACTIVATION_REGISTRY_PORT = Integer.parseInt(args[++i]);
- else if (a.equals("-folder"))
- folder = args[++i];
- }
- }
+ }
+ });
+ controlGroup.add(new Option("stop", //$NON-NLS-1$
+ Messages.getString("Main.Stop")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ stop = true;
+ }
+ });
+ parser.add(controlGroup);
+
+ OptionGroup persistenceGroup
+ = new OptionGroup(Messages.getString("Main.PersistenceGroup")); //$NON-NLS-1$
+ persistenceGroup.add(new Option("persistent", //$NON-NLS-1$
+ Messages.getString("Main.Persistent")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ persistent = true;
+ }
+ });
+ persistenceGroup.add(new Option("directory", //$NON-NLS-1$
+ Messages.getString("Main.Directory"), //$NON-NLS-1$
+ Messages.getString("Main.DirectoryArgument")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ directory = argument;
+ }
+ });
+ parser.add(persistenceGroup);
+
+ OptionGroup debuggingGroup
+ = new OptionGroup(Messages.getString("Main.DebugGroup")); //$NON-NLS-1$
+ debuggingGroup.add(new Option("verbose", //$NON-NLS-1$
+ Messages.getString ("Main.Verbose")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ ActivationSystemTransient.debug = true;
+ }
+ });
+ parser.add(debuggingGroup);
+
+ return parser;
+ }
+
+ private void run(String[] args)
+ {
+ Parser p = initializeParser();
+ p.parse(args);
try
{
if (!stop)
{
// Start the system.
- File dataFolder = new File(folder);
- if (!dataFolder.exists())
- dataFolder.mkdirs();
+ File dataDirectory = new File(directory);
+ if (!dataDirectory.exists())
+ dataDirectory.mkdirs();
ActivationSystem system;
- if (trans)
+ if (!persistent)
system = ActivationSystemTransient.getInstance();
else
- system = ActivationSystemImpl.getInstance(dataFolder, cold);
+ system = ActivationSystemImpl.getInstance(dataDirectory, cold);
// We must export with the specific activation id that is only
// possible when going into the gnu.java.rmi.activation.
@@ -186,4 +238,22 @@ public class RMID
e.printStackTrace();
}
}
+
+ /**
+ * The activation system entry point.
+ */
+ public static void main(String[] args)
+ {
+ Main rmidprogram = new Main();
+ try
+ {
+ rmidprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmid/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/rmid/Messages.java
new file mode 100644
index 00000000000..4365c6de7ca
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmid/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for rmid
+ 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.rmid;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.rmid.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentBidiHashTable.java b/libjava/classpath/tools/gnu/classpath/tools/rmid/PersistentBidiHashTable.java
index 94b5bcbeeb7..d213373d5ff 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentBidiHashTable.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmid/PersistentBidiHashTable.java
@@ -35,9 +35,10 @@ 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;
+package gnu.classpath.tools.rmid;
-import gnu.classpath.tools.rmi.rmid.ActivationSystemImpl;
+import gnu.classpath.tools.common.Persistent;
+import gnu.classpath.tools.rmid.ActivationSystemImpl;
import gnu.java.rmi.activation.BidiTable;
import java.io.BufferedInputStream;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Main.java
index 63f633f992e..e5c41930de1 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/REGISTRY.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Main.java
@@ -1,4 +1,4 @@
-/* REGISTY.java -- RMI registry starter.
+/* Main.java -- RMI registry starter.
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -36,10 +36,15 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools.rmi;
+package gnu.classpath.tools.rmiregistry;
-import gnu.classpath.tools.HelpPrinter;
-import gnu.classpath.tools.rmi.registry.RegistryImpl;
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+import gnu.classpath.tools.getopt.Parser;
+import gnu.classpath.tools.rmiregistry.RegistryImpl;
import gnu.java.rmi.server.UnicastServerRef;
import java.io.File;
@@ -57,7 +62,7 @@ import java.util.Map;
*
* @author Audrius Meskauskas (audriusa@bioinformatics.org)
*/
-public class REGISTRY
+public class Main
{
/**
* The stop command.
@@ -68,58 +73,102 @@ public class REGISTRY
* If true, the registry prints registration events to console.
*/
public static boolean verbose = false;
-
+
/**
- * The RMI registry implementation entry point.
+ * Parsed parameters.
*/
- public static void main(String[] args)
+ private String directory = ".";
+ private boolean cold = false;
+ private boolean persistent = false;
+ private boolean stop = false;
+ private int port = Registry.REGISTRY_PORT;
+ private RMIServerSocketFactory ssf = null;
+
+ private Parser initializeParser()
{
- String HelpPath = "rmi/REGISTRY.txt";
- HelpPrinter.checkHelpKey(args, HelpPath);
-
- // Parse parameters:
- String folder = ".";
- boolean cold = false;
- boolean trans = false;
- boolean stop = false;
-
- int port = Registry.REGISTRY_PORT;
- RMIServerSocketFactory ssf = null;
-
- for (int i = 0; i < args.length; i++)
+ Parser parser = new ClasspathToolParser("rmiregistry", true); //$NON-NLS-1$
+ parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+ OptionGroup controlGroup
+ = new OptionGroup(Messages.getString("Main.ControlGroup")); //$NON-NLS-1$
+ controlGroup.add(new Option("restart", //$NON-NLS-1$
+ Messages.getString("Main.Restart")) //$NON-NLS-1$
{
- String a = args[i];
- if (a.equals("-restart"))
+ public void parsed(String argument) throws OptionException
+ {
cold = true;
- else if (a.equals("-transient"))
- trans = true;
- else if (a.equals("-verbose"))
- verbose = true;
- else if (a.equals("-stop"))
+ }
+ });
+ controlGroup.add(new Option("stop", //$NON-NLS-1$
+ Messages.getString("Main.Stop")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
stop = true;
- else if (i < args.length - 1)
- {
- // The additional key parameter is possible.
- if (a.equals("-port"))
- port = Integer.parseInt(args[++i]);
- else if (a.equals("-folder"))
- folder = args[++i];
- }
- }
+ }
+ });
+ parser.add(controlGroup);
+
+ OptionGroup persistenceGroup
+ = new OptionGroup(Messages.getString("Main.PersistenceGroup")); //$NON-NLS-1$
+ persistenceGroup.add(new Option("persistent", //$NON-NLS-1$
+ Messages.getString("Main.Persistent")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ persistent = true;
+ }
+ });
+ persistenceGroup.add(new Option("directory", //$NON-NLS-1$
+ Messages.getString("Main.Directory"), //$NON-NLS-1$
+ Messages.getString("Main.DirectoryArgument")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ directory = argument;
+ }
+ });
+ parser.add(persistenceGroup);
+
+ OptionGroup debuggingGroup
+ = new OptionGroup(Messages.getString("Main.DebugGroup")); //$NON-NLS-1$
+ debuggingGroup.add(new Option("verbose", //$NON-NLS-1$
+ Messages.getString ("Main.Verbose")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ parser.add(debuggingGroup);
+
+ return parser;
+ }
+
+ private void run(String[] args)
+ {
+ Parser p = initializeParser();
+ p.parse(args, new FileArgumentCallback()
+ {
+ public void notifyFile(String portArgument)
+ {
+ port = Integer.parseInt(portArgument);
+ }
+ });
if (!stop)
{
Map table;
- if (trans)
+ if (!persistent)
table = new Hashtable();
else
{
// Start the system.
- File dataFolder = new File(folder);
- if (!dataFolder.exists())
- dataFolder.mkdirs();
+ File dataDirectory = new File(directory);
+ if (!dataDirectory.exists())
+ dataDirectory.mkdirs();
table = PersistentHashTable.createInstance(
- new File(dataFolder, "rmiregistry.data"), cold);
+ new File(dataDirectory, "rmiregistry.data"), cold);
}
RegistryImpl system = new RegistryImpl(table);
@@ -157,9 +206,27 @@ public class REGISTRY
}
catch (NotBoundException e)
{
- System.out.println("The naming service at port "+port+" is not a "+
- REGISTRY.class.getName());
+ System.out.println("The naming service at port " + port + " is not a "
+ + Main.class.getName());
}
}
}
+
+ /**
+ * The RMI registry implementation entry point.
+ */
+ public static void main(String[] args)
+ {
+ Main rmiregistryprogram = new Main();
+ try
+ {
+ rmiregistryprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+ }
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Messages.java
new file mode 100644
index 00000000000..05bfcf62d23
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for rmiregistry
+ 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.rmiregistry;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.rmiregistry.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentHashTable.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/PersistentHashTable.java
index 925e829ffd0..89d66ce4ad7 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/PersistentHashTable.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/PersistentHashTable.java
@@ -35,7 +35,9 @@ 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;
+package gnu.classpath.tools.rmiregistry;
+
+import gnu.classpath.tools.common.Persistent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -127,26 +129,40 @@ public class PersistentHashTable
try
{
PersistentHashTable k2v;
+ System.out.println ("Here1");
if (file.exists())
{
+ System.out.println ("Here2");
if (coldStart)
{
+ System.out.println ("Here2.5");
file.delete();
k2v = new PersistentHashTable(file);
}
else
{
+ System.out.println ("Here3");
FileInputStream fi = new FileInputStream(file);
+ System.out.println ("Here3.1");
BufferedInputStream b = new BufferedInputStream(fi);
+ System.out.println ("Here3.2");
ObjectInputStream oin = new ObjectInputStream(b);
+ System.out.println ("Here3.3");
+ System.out.println ("Here4");
k2v = (PersistentHashTable) oin.readObject();
oin.close();
+ System.out.println ("Here5");
}
}
else
+ {
+ System.out.println ("Here6");
k2v = new PersistentHashTable(file);
+ System.out.println ("Here7");
+ }
+ System.out.println ("Here8");
k2v.ready = true;
return k2v;
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl.java
index 90bd3a6bdac..b93d3c1169e 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl.java
@@ -36,10 +36,9 @@ 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.registry;
+package gnu.classpath.tools.rmiregistry;
-import gnu.classpath.tools.rmi.Persistent;
-import gnu.classpath.tools.rmi.REGISTRY;
+import gnu.classpath.tools.common.Persistent;
import java.rmi.AccessException;
import java.rmi.AlreadyBoundException;
@@ -85,7 +84,7 @@ public class RegistryImpl implements Registry
public void bind(String name, Remote obj) throws RemoteException,
AlreadyBoundException, AccessException
{
- if (REGISTRY.verbose)
+ if (Main.verbose)
System.out.println("Bind "+name);
if (bindings.containsKey(name))
throw new AlreadyBoundException(name);
@@ -96,7 +95,7 @@ public class RegistryImpl implements Registry
public void unbind(String name) throws RemoteException, NotBoundException,
AccessException
{
- if (name.equals(REGISTRY.STOP))
+ if (name.equals(Main.STOP))
{
if (bindings instanceof Persistent)
((Persistent) bindings).writeContent();
@@ -106,7 +105,7 @@ public class RegistryImpl implements Registry
}
else
{
- if (REGISTRY.verbose)
+ if (Main.verbose)
System.out.println("Unbind "+name);
if (!bindings.containsKey(name))
@@ -120,7 +119,7 @@ public class RegistryImpl implements Registry
public void rebind(String name, Remote obj) throws RemoteException,
AccessException
{
- if (REGISTRY.verbose)
+ if (Main.verbose)
System.out.println("Rebind "+name);
bindings.put(name, obj);
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Skel.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Skel.java
index 36b7d94a595..5150debd1de 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Skel.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Skel.java
@@ -36,7 +36,7 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package gnu.classpath.tools.rmi.registry;
+package gnu.classpath.tools.rmiregistry;
import java.io.IOException;
import java.io.ObjectInput;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Stub.java b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Stub.java
index d8cac5bfcb3..94d35e92fb3 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/rmi/registry/RegistryImpl_Stub.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/rmiregistry/RegistryImpl_Stub.java
@@ -35,7 +35,7 @@ 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.registry;
+package gnu.classpath.tools.rmiregistry;
import java.rmi.AccessException;
import java.rmi.AlreadyBoundException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java b/libjava/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java
index b5a12ec927b..21e0a805a6f 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java
@@ -21,7 +21,7 @@
package gnu.classpath.tools.serialver;
-import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.common.ClasspathToolParser;
import gnu.classpath.tools.getopt.FileArgumentCallback;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
diff --git a/libjava/classpath/tools/gnu/classpath/tools/giop/NameService.java b/libjava/classpath/tools/gnu/classpath/tools/tnameserv/Main.java
index 7e13185f246..460b7818532 100644
--- a/libjava/classpath/tools/gnu/classpath/tools/giop/NameService.java
+++ b/libjava/classpath/tools/gnu/classpath/tools/tnameserv/Main.java
@@ -1,4 +1,4 @@
-/* NameService.java -- Transient GIOP naming service.
+/* Main.java -- Transient GIOP naming service.
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,10 +35,15 @@ 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.giop;
+package gnu.classpath.tools.tnameserv;
import gnu.CORBA.NamingService.NamingServiceTransient;
-import gnu.classpath.tools.HelpPrinter;
+import gnu.classpath.tools.common.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
+import gnu.classpath.tools.getopt.Parser;
/**
* The implementation of the transient naming service. The naming service
@@ -52,24 +57,61 @@ import gnu.classpath.tools.HelpPrinter;
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
-public class NameService
+public class Main
{
+ private int port = -1;
+ private String iorf;
+
+ private Parser initializeParser()
+ {
+ Parser parser = new ClasspathToolParser("tnameserv", true); //$NON-NLS-1$
+ parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+ parser.add(new Option("ORBInitialPort", //$NON-NLS-1$
+ Messages.getString("Main.ORBInitialPort"), //$NON-NLS-1$
+ Messages.getString("Main.Port")) //$NON-NLS-1$
+ {
+ public void parsed(String portArgument) throws OptionException
+ {
+ port = Integer.parseInt(portArgument);
+ }
+ });
+
+ parser.add(new Option("ior", //$NON-NLS-1$
+ Messages.getString("Main.IOR"), //$NON-NLS-1$
+ Messages.getString("Main.IORFile")) //$NON-NLS-1$
+ {
+ public void parsed(String fileArgument) throws OptionException
+ {
+ iorf = fileArgument;
+ }
+ });
+
+ return parser;
+ }
+
+ private void run(String[] args)
+ {
+ Parser p = initializeParser();
+ p.parse(args);
+ NamingServiceTransient.start(port, iorf);
+ }
+
/**
- * Start the naming service on the current host at the given port. The
- * parameter -org.omg.CORBA.ORBInitialPort NNN or -ORBInitialPort NNN, if
- * present, specifies the port, on that the service must be started. If this
- * key is not specified, the service starts at the port 900.
- *
- * The parameter -ior FILE_NAME, if present, forces to store the ior string of
- * this naming service to the specified file.
- *
- * @param args the parameter string.
+ * The naming service entry point.
*/
public static void main(String[] args)
{
- HelpPrinter.checkHelpKey(args, "giop/NamingService.txt");
- System.out.println("Please use --help for options.");
- NamingServiceTransient.main(args);
+ Main tnameservprogram = new Main();
+ try
+ {
+ tnameservprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
}
-
}
diff --git a/libjava/classpath/tools/gnu/classpath/tools/tnameserv/Messages.java b/libjava/classpath/tools/gnu/classpath/tools/tnameserv/Messages.java
new file mode 100644
index 00000000000..505397302b4
--- /dev/null
+++ b/libjava/classpath/tools/gnu/classpath/tools/tnameserv/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for tnameserv
+ 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.tnameserv;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.tnameserv.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}
OpenPOWER on IntegriCloud