public class Viewer
extends java.lang.ClassLoader
This is a sort of applet viewer that can run any program even if
the main class is not a subclass of Applet
.
This viewwer first calls main()
in the main class.
To run, you should type:
% java javassist.tools.web.Viewer host port Main arg1, ...
This command calls Main.main()
with arg1,...
All classes including Main
are fetched from
a server http://host:port.
Only the class file for Viewer
must exist
on a local file system at the client side; even other
javassist.*
classes are not needed at the client side.
Viewer
uses only Java core API classes.
Note: since a Viewer
object is a class loader,
a program loaded by this object can call a method in Viewer
.
For example, you can write something like this:
Viewer v = (Viewer)this.getClass().getClassLoader(); String port = v.getPort();
Modifier and Type | Field and Description |
---|---|
private int |
port |
private java.lang.String |
server |
Constructor and Description |
---|
Viewer(java.lang.String host,
int p)
Constructs a viewer.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
fetchClass(java.lang.String classname)
Fetches the class file of the specified class from the http
server.
|
protected java.lang.Class |
findClass(java.lang.String name)
Finds the specified class.
|
int |
getPort()
Returns the port number.
|
java.lang.String |
getServer()
Returns the server name.
|
protected java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Requests the class loader to load a class.
|
static void |
main(java.lang.String[] args)
Starts a program.
|
private byte[] |
readStream(java.io.InputStream fin) |
void |
run(java.lang.String classname,
java.lang.String[] args)
Invokes main() in the class specified by
classname . |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public Viewer(java.lang.String host, int p)
host
- server namep
- port numberpublic static void main(java.lang.String[] args) throws java.lang.Throwable
java.lang.Throwable
public java.lang.String getServer()
public int getPort()
public void run(java.lang.String classname, java.lang.String[] args) throws java.lang.Throwable
classname
.classname
- executed classargs
- the arguments passed to main()
.java.lang.Throwable
protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.*
, javax.*
, or
Viewer
, then it is loaded by the parent class
loader.
This method can be overridden by a subclass of
Viewer
.
findClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected byte[] fetchClass(java.lang.String classname) throws java.lang.Exception
java.lang.Exception
private byte[] readStream(java.io.InputStream fin) throws java.io.IOException
java.io.IOException