aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/tools/rmi
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/javassist/tools/rmi')
-rw-r--r--src/main/javassist/tools/rmi/AppletServer.java47
-rw-r--r--src/main/javassist/tools/rmi/ObjectImporter.java28
-rw-r--r--src/main/javassist/tools/rmi/ObjectNotFoundException.java3
-rw-r--r--src/main/javassist/tools/rmi/RemoteException.java3
-rw-r--r--src/main/javassist/tools/rmi/RemoteRef.java2
-rw-r--r--src/main/javassist/tools/rmi/StubGenerator.java42
6 files changed, 81 insertions, 44 deletions
diff --git a/src/main/javassist/tools/rmi/AppletServer.java b/src/main/javassist/tools/rmi/AppletServer.java
index cc348ac2..e49ed0dc 100644
--- a/src/main/javassist/tools/rmi/AppletServer.java
+++ b/src/main/javassist/tools/rmi/AppletServer.java
@@ -16,16 +16,26 @@
package javassist.tools.rmi;
-import java.io.*;
-
-import javassist.tools.web.*;
-import javassist.CannotCompileException;
-import javassist.NotFoundException;
-import javassist.ClassPool;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidClassException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
import java.util.Vector;
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.NotFoundException;
+import javassist.tools.web.BadHttpRequest;
+import javassist.tools.web.Webserver;
+
/**
* An AppletServer object is a web server that an ObjectImporter
* communicates with. It makes the objects specified by
@@ -37,8 +47,8 @@ import java.util.Vector;
*/
public class AppletServer extends Webserver {
private StubGenerator stubGen;
- private Hashtable exportedNames;
- private Vector exportedObjects;
+ private Map<String,ExportedObject> exportedNames;
+ private List<ExportedObject> exportedObjects;
private static final byte[] okHeader
= "HTTP/1.0 200 OK\r\n\r\n".getBytes();
@@ -81,8 +91,8 @@ public class AppletServer extends Webserver {
throws IOException, NotFoundException, CannotCompileException
{
super(port);
- exportedNames = new Hashtable();
- exportedObjects = new Vector();
+ exportedNames = new Hashtable<String,ExportedObject>();
+ exportedObjects = new Vector<ExportedObject>();
stubGen = gen;
addTranslator(loader, gen);
}
@@ -90,6 +100,7 @@ public class AppletServer extends Webserver {
/**
* Begins the HTTP service.
*/
+ @Override
public void run() {
super.run();
}
@@ -109,11 +120,11 @@ public class AppletServer extends Webserver {
public synchronized int exportObject(String name, Object obj)
throws CannotCompileException
{
- Class clazz = obj.getClass();
+ Class<?> clazz = obj.getClass();
ExportedObject eo = new ExportedObject();
eo.object = obj;
eo.methods = clazz.getMethods();
- exportedObjects.addElement(eo);
+ exportedObjects.add(eo);
eo.identifier = exportedObjects.size() - 1;
if (name != null)
exportedNames.put(name, eo);
@@ -131,6 +142,7 @@ public class AppletServer extends Webserver {
/**
* Processes a request from a web browser (an ObjectImporter).
*/
+ @Override
public void doReply(InputStream in, OutputStream out, String cmd)
throws IOException, BadHttpRequest
{
@@ -152,8 +164,7 @@ public class AppletServer extends Webserver {
Exception err = null;
Object rvalue = null;
try {
- ExportedObject eo
- = (ExportedObject)exportedObjects.elementAt(objectId);
+ ExportedObject eo = exportedObjects.get(objectId);
Object[] args = readParameters(in);
rvalue = convertRvalue(eo.methods[methodId].invoke(eo.object,
args));
@@ -195,8 +206,7 @@ public class AppletServer extends Webserver {
Object a = in.readObject();
if (a instanceof RemoteRef) {
RemoteRef ref = (RemoteRef)a;
- ExportedObject eo
- = (ExportedObject)exportedObjects.elementAt(ref.oid);
+ ExportedObject eo = exportedObjects.get(ref.oid);
a = eo.object;
}
@@ -215,8 +225,7 @@ public class AppletServer extends Webserver {
String classname = rvalue.getClass().getName();
if (stubGen.isProxyClass(classname))
return new RemoteRef(exportObject(null, rvalue), classname);
- else
- return rvalue;
+ return rvalue;
}
private void lookupName(String cmd, InputStream ins, OutputStream outs)
@@ -224,7 +233,7 @@ public class AppletServer extends Webserver {
{
ObjectInputStream in = new ObjectInputStream(ins);
String name = DataInputStream.readUTF(in);
- ExportedObject found = (ExportedObject)exportedNames.get(name);
+ ExportedObject found = exportedNames.get(name);
outs.write(okHeader);
ObjectOutputStream out = new ObjectOutputStream(outs);
if (found == null) {
diff --git a/src/main/javassist/tools/rmi/ObjectImporter.java b/src/main/javassist/tools/rmi/ObjectImporter.java
index 43b62039..798279af 100644
--- a/src/main/javassist/tools/rmi/ObjectImporter.java
+++ b/src/main/javassist/tools/rmi/ObjectImporter.java
@@ -16,10 +16,16 @@
package javassist.tools.rmi;
-import java.io.*;
-import java.net.*;
-import java.applet.Applet;
-import java.lang.reflect.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.net.Socket;
+import java.net.URL;
/**
* The object importer enables applets to call a method on a remote
@@ -73,6 +79,8 @@ import java.lang.reflect.*;
* @see javassist.tools.web.Viewer
*/
public class ObjectImporter implements java.io.Serializable {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private final byte[] endofline = { 0x0d, 0x0a };
private String servername, orgServername;
private int port, orgPort;
@@ -88,7 +96,8 @@ public class ObjectImporter implements java.io.Serializable {
*
* @param applet the applet loaded from the <code>Webserver</code>.
*/
- public ObjectImporter(Applet applet) {
+ public ObjectImporter(@SuppressWarnings("deprecation") java.applet.Applet applet) {
+ @SuppressWarnings("deprecation")
URL codebase = applet.getCodeBase();
orgServername = servername = codebase.getHost();
orgPort = port = codebase.getPort();
@@ -183,12 +192,12 @@ public class ObjectImporter implements java.io.Serializable {
throw new ObjectNotFoundException(name);
}
- private static final Class[] proxyConstructorParamTypes
+ private static final Class<?>[] proxyConstructorParamTypes
= new Class[] { ObjectImporter.class, int.class };
private Object createProxy(int oid, String classname) throws Exception {
- Class c = Class.forName(classname);
- Constructor cons = c.getConstructor(proxyConstructorParamTypes);
+ Class<?> c = Class.forName(classname);
+ Constructor<?> cons = c.getConstructor(proxyConstructorParamTypes);
return cons.newInstance(new Object[] { this, Integer.valueOf(oid) });
}
@@ -267,8 +276,7 @@ public class ObjectImporter implements java.io.Serializable {
if (result)
return rvalue;
- else
- throw new RemoteException(errmsg);
+ throw new RemoteException(errmsg);
}
private void skipHeader(InputStream in) throws IOException {
diff --git a/src/main/javassist/tools/rmi/ObjectNotFoundException.java b/src/main/javassist/tools/rmi/ObjectNotFoundException.java
index 47cfb68e..bd5b27eb 100644
--- a/src/main/javassist/tools/rmi/ObjectNotFoundException.java
+++ b/src/main/javassist/tools/rmi/ObjectNotFoundException.java
@@ -17,6 +17,9 @@
package javassist.tools.rmi;
public class ObjectNotFoundException extends Exception {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public ObjectNotFoundException(String name) {
super(name + " is not exported");
}
diff --git a/src/main/javassist/tools/rmi/RemoteException.java b/src/main/javassist/tools/rmi/RemoteException.java
index e00dff59..6d4612a7 100644
--- a/src/main/javassist/tools/rmi/RemoteException.java
+++ b/src/main/javassist/tools/rmi/RemoteException.java
@@ -21,6 +21,9 @@ package javassist.tools.rmi;
* during remote method invocation.
*/
public class RemoteException extends RuntimeException {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public RemoteException(String msg) {
super(msg);
}
diff --git a/src/main/javassist/tools/rmi/RemoteRef.java b/src/main/javassist/tools/rmi/RemoteRef.java
index 6b604bc5..4537352e 100644
--- a/src/main/javassist/tools/rmi/RemoteRef.java
+++ b/src/main/javassist/tools/rmi/RemoteRef.java
@@ -21,6 +21,8 @@ package javassist.tools.rmi;
* reference through a network stream.
*/
public class RemoteRef implements java.io.Serializable {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
public int oid;
public String classname;
diff --git a/src/main/javassist/tools/rmi/StubGenerator.java b/src/main/javassist/tools/rmi/StubGenerator.java
index 6fc8dbcf..b0817ab5 100644
--- a/src/main/javassist/tools/rmi/StubGenerator.java
+++ b/src/main/javassist/tools/rmi/StubGenerator.java
@@ -16,10 +16,22 @@
package javassist.tools.rmi;
-import javassist.*;
import java.lang.reflect.Method;
import java.util.Hashtable;
+import java.util.Map;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
import javassist.CtMethod.ConstParameter;
+import javassist.CtNewConstructor;
+import javassist.CtNewMethod;
+import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.Translator;
/**
* A stub-code generator. It is used for producing a proxy class.
@@ -47,7 +59,7 @@ public class StubGenerator implements Translator {
private static final String sampleClass = "javassist.tools.rmi.Sample";
private ClassPool classPool;
- private Hashtable proxyClasses;
+ private Map<String,CtClass> proxyClasses;
private CtMethod forwardMethod;
private CtMethod forwardStaticMethod;
@@ -59,7 +71,7 @@ public class StubGenerator implements Translator {
* Constructs a stub-code generator.
*/
public StubGenerator() {
- proxyClasses = new Hashtable();
+ proxyClasses = new Hashtable<String,CtClass>();
}
/**
@@ -68,6 +80,7 @@ public class StubGenerator implements Translator {
*
* @see javassist.Translator#start(ClassPool)
*/
+ @Override
public void start(ClassPool pool) throws NotFoundException {
classPool = pool;
CtClass c = pool.get(sampleClass);
@@ -89,6 +102,7 @@ public class StubGenerator implements Translator {
* This is a method declared in javassist.Translator.
* @see javassist.Translator#onLoad(ClassPool,String)
*/
+ @Override
public void onLoad(ClassPool pool, String classname) {}
/**
@@ -110,22 +124,20 @@ public class StubGenerator implements Translator {
* @return <code>false</code> if the proxy class
* has been already produced.
*/
- public synchronized boolean makeProxyClass(Class clazz)
+ public synchronized boolean makeProxyClass(Class<?> clazz)
throws CannotCompileException, NotFoundException
{
String classname = clazz.getName();
if (proxyClasses.get(classname) != null)
return false;
- else {
- CtClass ctclazz = produceProxyClass(classPool.get(classname),
- clazz);
- proxyClasses.put(classname, ctclazz);
- modifySuperclass(ctclazz);
- return true;
- }
+ CtClass ctclazz = produceProxyClass(classPool.get(classname),
+ clazz);
+ proxyClasses.put(classname, ctclazz);
+ modifySuperclass(ctclazz);
+ return true;
}
- private CtClass produceProxyClass(CtClass orgclass, Class orgRtClass)
+ private CtClass produceProxyClass(CtClass orgclass, Class<?> orgRtClass)
throws CannotCompileException, NotFoundException
{
int modify = orgclass.getModifiers();
@@ -166,7 +178,7 @@ public class StubGenerator implements Translator {
}
}
- private CtClass toCtClass(Class rtclass) throws NotFoundException {
+ private CtClass toCtClass(Class<?> rtclass) throws NotFoundException {
String name;
if (!rtclass.isArray())
name = rtclass.getName();
@@ -179,11 +191,11 @@ public class StubGenerator implements Translator {
sbuf.insert(0, rtclass.getName());
name = sbuf.toString();
}
-
+
return classPool.get(name);
}
- private CtClass[] toCtClass(Class[] rtclasses) throws NotFoundException {
+ private CtClass[] toCtClass(Class<?>[] rtclasses) throws NotFoundException {
int n = rtclasses.length;
CtClass[] ctclasses = new CtClass[n];
for (int i = 0; i < n; ++i)