net.sourceforge.esw.service
Class ClassServer

java.lang.Object
  |
  +--net.sourceforge.esw.service.ClassServer
All Implemented Interfaces:
java.lang.Runnable

public class ClassServer
extends java.lang.Object
implements java.lang.Runnable


Field Summary
protected static java.lang.String CLASS_NOT_FOUND
           
protected  java.lang.String codebase
           
protected static java.lang.String CODEBASE_PROPERTY
           
protected static java.lang.String COLON
           
protected static java.lang.String CONTENT_LENGTH
           
protected static java.lang.String CONTENT_TYPE
           
protected static java.lang.String CONTENT_TYPE2
           
protected static java.lang.String CR
           
protected static java.lang.String DOT_CLASS
           
protected static java.lang.String END_CONTENT_LENGTH
           
protected static java.lang.String GET
           
protected static java.lang.String HTTP
           
protected static java.lang.String HTTP_START
           
protected  java.net.URLClassLoader loader
           
protected  int port
           
protected  java.net.ServerSocket server
           
protected static java.lang.String SLASH
           
protected static java.lang.String SPACE
           
 
Constructor Summary
ClassServer()
          Creates a new ClassServer utilizing any availiable port.
ClassServer(int aPort)
          Creates a new ClassServer utilizing the specified port.
 
Method Summary
protected  void establishCodebase()
          This adds the codebase for this exporter to the list of codebases stored under the java.rmi.server.codebase property.
protected  byte[] getByteArrayFromInputStream(java.io.InputStream inputstream, int i)
          Gets a byte array from an inputStream, one byte at a time.
protected  byte[] getByteArrayFromInputStream(java.io.InputStream inputstream, int i, int bufferSize)
          Gets a byte array from an inputStream, one byte at a time.
protected  byte[] getByteCodes(java.lang.String aClassname)
          Return the bytecodes for the named class.
protected  byte[] getClassFromJarURLs(java.lang.String s)
          Attempts to retrieve the requested resource from a jar that's part of the loader list
protected  java.lang.String getCodebase()
          Return the codebase URL that identifies this exporter.
protected  boolean isJarFile(java.lang.String s)
          Checks to see if this string indicates a jar file
 void run()
          Services a socket returned by the server socket
 void shutdown()
          Shuts down the server socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected java.net.ServerSocket server

codebase

protected java.lang.String codebase

port

protected int port

loader

protected java.net.URLClassLoader loader

CODEBASE_PROPERTY

protected static final java.lang.String CODEBASE_PROPERTY

HTTP

protected static final java.lang.String HTTP

COLON

protected static final java.lang.String COLON

SLASH

protected static final java.lang.String SLASH

SPACE

protected static final java.lang.String SPACE

HTTP_START

protected static final java.lang.String HTTP_START

CONTENT_LENGTH

protected static final java.lang.String CONTENT_LENGTH

END_CONTENT_LENGTH

protected static final java.lang.String END_CONTENT_LENGTH

CONTENT_TYPE

protected static final java.lang.String CONTENT_TYPE

CLASS_NOT_FOUND

protected static final java.lang.String CLASS_NOT_FOUND

CR

protected static final java.lang.String CR

CONTENT_TYPE2

protected static final java.lang.String CONTENT_TYPE2

GET

protected static final java.lang.String GET

DOT_CLASS

protected static final java.lang.String DOT_CLASS
Constructor Detail

ClassServer

public ClassServer()
            throws java.io.IOException
Creates a new ClassServer utilizing any availiable port.
Throws:
java.io.IOException - If there was a problem initializing the server socket.

ClassServer

public ClassServer(int aPort)
            throws java.io.IOException,
                   java.net.UnknownHostException
Creates a new ClassServer utilizing the specified port.
Parameters:
aPort - The port on which to run the server. Passing in 0 states that any open port may be utilized.
Throws:
java.io.IOException - If there was a problem initializing the server socket.
java.net.UnknownHostException - If the current hostname could not be determined (required for setting the codebase).
Method Detail

shutdown

public void shutdown()
Shuts down the server socket. This is done in a separate thread, as it may take a while...

run

public void run()
Services a socket returned by the server socket
Specified by:
run in interface java.lang.Runnable

getByteCodes

protected byte[] getByteCodes(java.lang.String aClassname)
                       throws java.lang.ClassNotFoundException
Return the bytecodes for the named class. This implementation attempts to find the class as a resource from the class loader specified at construction time (which is usually the context class loader from the thread that constructed the instance).
Parameters:
aClassname - The class to fetch the bytecodes for.
Throws:
java.lang.ClassNotFoundException - If the named class cannot be found.

getCodebase

protected java.lang.String getCodebase()
                                throws java.net.UnknownHostException
Return the codebase URL that identifies this exporter.
Returns:
The codebase of the exporter.
Throws:
java.net.UnknownHostException - If the local hostname could not be determined.

establishCodebase

protected void establishCodebase()
                          throws java.net.UnknownHostException
This adds the codebase for this exporter to the list of codebases stored under the java.rmi.server.codebase property. It will not remove any preexisting codebases.
Throws:
java.net.UnknownHostException - If the local hostname could not be determined.

getClassFromJarURLs

protected byte[] getClassFromJarURLs(java.lang.String s)
Attempts to retrieve the requested resource from a jar that's part of the loader list
Parameters:
String - The path descriptor of the resource
Returns:
the byte array that is this resource, or null if the resource isn't found

isJarFile

protected boolean isJarFile(java.lang.String s)
Checks to see if this string indicates a jar file
Parameters:
String - the name of the resource
Returns:
if this is a jar resource or not

getByteArrayFromInputStream

protected byte[] getByteArrayFromInputStream(java.io.InputStream inputstream,
                                             int i)
                                      throws java.io.IOException
Gets a byte array from an inputStream, one byte at a time. Uses a buffer of the 4096, with an initial size requested
Parameters:
InputStream - the stream to be read from
int - the initial size of the buffered output stream
Returns:
the byte array from this stream
Throws:
java.io.IOException - If there is a problem reading from the stream

getByteArrayFromInputStream

protected byte[] getByteArrayFromInputStream(java.io.InputStream inputstream,
                                             int i,
                                             int bufferSize)
                                      throws java.io.IOException
Gets a byte array from an inputStream, one byte at a time. Uses a buffer of the requested size, with an initial size requested
Parameters:
InputStream - the stream to be read from
int - the initial size of the buffered output stream
int - the number of bytes to read at each pass
Returns:
the byte array from this stream
Throws:
java.io.IOException - If there is a problem reading from the stream


Copyright 2002 Free Software Foundation. All Rights Reserved.