Package javassist.tools.web
Class Viewer
java.lang.Object
java.lang.ClassLoader
javassist.tools.web.Viewer
A 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 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();
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
fetchClass
(String classname) Fetches the class file of the specified class from the http server.protected Class
<?> Finds the specified class.int
getPort()
Returns the port number.Returns the server name.protected Class
<?> Requests the class loader to load a class.static void
Starts a program.private byte[]
readStream
(InputStream fin) void
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
-
Field Details
-
server
-
port
private int port
-
-
Constructor Details
-
Viewer
Constructs a viewer.- Parameters:
host
- server namep
- port number
-
-
Method Details
-
main
Starts a program.- Throws:
Throwable
-
getServer
Returns the server name. -
getPort
public int getPort()Returns the port number. -
run
Invokes main() in the class specified byclassname
.- Parameters:
classname
- executed classargs
- the arguments passed tomain()
.- Throws:
Throwable
-
loadClass
Requests the class loader to load a class.- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
findClass
Finds 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:
findClass
in classClassLoader
- Throws:
ClassNotFoundException
-
fetchClass
Fetches the class file of the specified class from the http server.- Throws:
Exception
-
readStream
- Throws:
IOException
-