Top Description Fields Constructors Methods
javassist.tools.web

public Class Viewer

extends ClassLoader
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, .URLConnection

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

Modifier and TypeField and Description
private int
private String

Constructor Summary

AccessConstructor and Description
public
Viewer(String
server name
host
,
int
port number
p
)

Constructs a viewer.

Method Summary

Modifier and TypeMethod and Description
protected byte[]
fetchClass(String classname)

Fetches the class file of the specified class from the http server.

protected Class<?>
findClass(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.findClass.

Finds the specified class.

public int
getPort()

Returns the port number.

public String
getServer()

Returns the server name.

protected synchronized Class<?>
loadClass(String
The binary name of the class
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Requests the class loader to load a class.

public static void
main(String[] args)

Starts a program.

private byte[]
public void
run(String
executed class
classname
,
String[]
the arguments passed to main().
args
)

Invokes main() in the class specified by classname.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

portback to summary
private int port
serverback to summary
private String server

Constructor Detail

Viewerback to summary
public Viewer(String host, int p)

Constructs a viewer.

Parameters
host:String

server name

p:int

port number

Method Detail

fetchClassback to summary
protected byte[] fetchClass(String classname) throws Exception

Fetches the class file of the specified class from the http server.

findClassback to summary
protected Class<?> findClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

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.

Parameters
name:String

Doc from java.lang.ClassLoader.findClass.

The binary name of the class

Returns:Class<?>

Doc from java.lang.ClassLoader.findClass.

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.findClass.

If the class could not be found

getPortback to summary
public int getPort()

Returns the port number.

getServerback to summary
public String getServer()

Returns the server name.

loadClassback to summary
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Requests the class loader to load a class.

Parameters
name:String

Doc from java.lang.ClassLoader.loadClass.

The binary name of the class

resolve:boolean

Doc from java.lang.ClassLoader.loadClass.

If true then resolve the class

Returns:Class<?>

Doc from java.lang.ClassLoader.loadClass.

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.loadClass.

If the class could not be found

mainback to summary
public static void main(String[] args) throws Throwable

Starts a program.

readStreamback to summary
private byte[] readStream(InputStream fin) throws IOException
runback to summary
public void run(String classname, String[] args) throws Throwable

Invokes main() in the class specified by classname.

Parameters
classname:String

executed class

args:String[]

the arguments passed to main().