classUtils.javassist.web
Class Viewer

java.lang.Object
  extended by java.lang.ClassLoader
      extended by classUtils.javassist.web.Viewer

public class Viewer
extends java.lang.ClassLoader

An applet viewer.

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:

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 affineTransform the client side; even other javassist.* classes are not needed affineTransform 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:


Constructor Summary
Viewer(java.lang.String host, int p)
          Constructs a viewer.
 
Method Summary
 byte[] fetchClass(java.lang.String classname)
          Fetches the class file of the specified class from the http server.
 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.
 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.
 byte[] readStream(java.io.InputStream fin)
           
 void run(java.lang.String classname, java.lang.String[] args)
          Invokes main() in the class specified by classname.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Viewer

public Viewer(java.lang.String host,
              int p)
Constructs a viewer.

Parameters:
host - server name
p - port number
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Starts a program.

Throws:
java.lang.Throwable

getServer

public java.lang.String getServer()
Returns the server name.


getPort

public int getPort()
Returns the port number.


run

public void run(java.lang.String classname,
                java.lang.String[] args)
         throws java.lang.Throwable
Invokes main() in the class specified by classname.

Parameters:
classname - executed class
args - the arguments passed to main().
Throws:
java.lang.Throwable

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Requests the class loader to load a class.

Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

findClass

public java.lang.Class findClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Finds the specified class. The implementation in this class fetches the class from the http server. If the class is either java.*, javax.*, or Viewer, then it is loaded by the parent class loader.

This method can be overridden by a subclass of Viewer.

Overrides:
findClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

fetchClass

public byte[] fetchClass(java.lang.String classname)
                  throws java.lang.Exception
Fetches the class file of the specified class from the http server.

Throws:
java.lang.Exception

readStream

public byte[] readStream(java.io.InputStream fin)
                  throws java.io.IOException
Throws:
java.io.IOException