Package javassist.tools.web
Class Viewer
- java.lang.Object
-
- java.lang.ClassLoader
-
- javassist.tools.web.Viewer
-
public class Viewer extends java.lang.ClassLoaderA sample 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 callsmain()in the main class.To run, you should type:
% java javassist.tools.web.Viewer host port Main arg1, ...
This command calls
Main.main()witharg1,...All classes includingMainare fetched from a server http://host:port. Only the class file forViewermust exist on a local file system at the client side; even otherjavassist.*classes are not needed at the client side.Vieweruses only Java core API classes.Note: since a
Viewerobject is a class loader, a program loaded by this object can call a method inViewer. For example, you can write something like this:Viewer v = (Viewer)this.getClass().getClassLoader(); String port = v.getPort();
-
-
Constructor Summary
Constructors Constructor Description Viewer(java.lang.String host, int p)Constructs a viewer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.intgetPort()Returns the port number.java.lang.StringgetServer()Returns the server name.protected java.lang.Class<?>loadClass(java.lang.String name, boolean resolve)Requests the class loader to load a class.static voidmain(java.lang.String[] args)Starts a program.private byte[]readStream(java.io.InputStream fin)voidrun(java.lang.String classname, java.lang.String[] args)Invokes main() in the class specified byclassname.-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.lang.ThrowableStarts 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.ThrowableInvokes main() in the class specified byclassname.- Parameters:
classname- executed classargs- the arguments passed tomain().- Throws:
java.lang.Throwable
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundExceptionRequests the class loader to load a class.- Overrides:
loadClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
findClass
protected java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundExceptionFinds the specified class. The implementation in this class fetches the class from the http server. If the class is eitherjava.*,javax.*, orViewer, then it is loaded by the parent class loader.This method can be overridden by a subclass of
Viewer.- Overrides:
findClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
fetchClass
protected byte[] fetchClass(java.lang.String classname) throws java.lang.ExceptionFetches the class file of the specified class from the http server.- Throws:
java.lang.Exception
-
readStream
private byte[] readStream(java.io.InputStream fin) throws java.io.IOException- Throws:
java.io.IOException
-
-