|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ClassLoader | +--loader.NetworkClassLoader
Load a class from the local file system or from the network.
When a class is loaded with this loader, this loader becomes the default loader.
So all the other classes that are associated with this classe (super classes, or used classes)
will be loaded with this loader.
First a class is searched in the local cache
(implemented in java.lang.ClassLoader), the in the local file system,
and if it's still not found, it is searched in the net.
In the cache, only classes from the network are added.
If all classes are available locally, no connection is established with the server.
Example:
ClassLoader loader = new NetworkClassLoader(host, port);
Object main = loader.loadClass("myClass").newInstance();
ClassLoader
Constructor Summary | |
NetworkClassLoader()
default constructor |
|
NetworkClassLoader(java.lang.String hostName,
int serverPort)
Costructor. |
Method Summary | |
protected void |
connect()
connect to the ClassServer |
protected java.io.File |
createLocalResourceFile(java.lang.String name,
byte[] bytes)
create the local file for the resource and return the URL. |
protected java.lang.String |
createLocalResourceName(java.lang.String name)
it creates a name for the local file that will store the resource contents. |
protected void |
disconnect()
Close the connection to the ClassServer |
protected java.lang.Class |
findClass(java.lang.String className)
Required method. |
protected java.net.URL |
findResource(java.lang.String name)
|
protected java.net.URL |
getLocalResourceURL(java.io.File file)
open the local file for the resource and return the URL. |
java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Not required. |
protected byte[] |
loadClassFromServer(java.lang.String className)
Read the class from the network and return a byte array. |
protected byte[] |
loadResourceFromServer(java.lang.String resourceName,
java.lang.String type)
Read the class from the network and return a byte array. |
protected void |
Print(java.lang.String s)
Print on the screen with indentation to show the nesting of the calls. |
protected void |
sendRequest(java.lang.String name,
java.lang.String type)
send a request to the server |
Methods inherited from class java.lang.ClassLoader |
defineClass,
defineClass,
defineClass,
definePackage,
findLibrary,
findLoadedClass,
findResources,
findSystemClass,
getPackage,
getPackages,
getParent,
getResource,
getResourceAsStream,
getResources,
getSystemClassLoader,
getSystemResource,
getSystemResourceAsStream,
getSystemResources,
loadClass,
resolveClass,
setSigners |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public NetworkClassLoader()
public NetworkClassLoader(java.lang.String hostName, int serverPort)
hostName
- host to load the classes fromserverPort
- port of the serverMethod Detail |
protected java.lang.Class findClass(java.lang.String className) throws ConnectClassServerException, JavaPackageException, java.lang.ClassNotFoundException, java.lang.ClassFormatError
name
- class nameprotected java.net.URL findResource(java.lang.String name)
protected java.net.URL getLocalResourceURL(java.io.File file) throws java.net.MalformedURLException
file
- the local File for the resourceprotected java.io.File createLocalResourceFile(java.lang.String name, byte[] bytes) throws java.net.MalformedURLException, java.io.FileNotFoundException, java.io.IOException
name
- the name of the resourcebytes
- the binary contents of this resourceprotected java.lang.String createLocalResourceName(java.lang.String name)
name
- the resource namepublic java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
protected void Print(java.lang.String s)
protected void connect() throws java.net.UnknownHostException, java.io.IOException
protected void disconnect()
protected byte[] loadClassFromServer(java.lang.String className) throws java.lang.ClassNotFoundException, java.net.SocketException, java.io.IOException
className
- class nameprotected byte[] loadResourceFromServer(java.lang.String resourceName, java.lang.String type) throws java.io.FileNotFoundException, java.lang.ClassNotFoundException, java.net.SocketException, java.io.IOException
resourceName
- resource nametype
- resource typeprotected void sendRequest(java.lang.String name, java.lang.String type) throws java.io.IOException
name
- the name of the requested resourcetype
- the type of the requested resource
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |