[4232] in java-interest
Re: (Fwd) More class loader info.
daemon@ATHENA.MIT.EDU (neudeck.arthur@ch.swissbank.com)
Thu Dec 14 04:18:20 1995
From: neudeck.arthur@ch.swissbank.com
Date: Thu, 14 Dec 1995 08:20:49 +0100
To: bolthole@best.com, java-interest@java.sun.com
Cc: neudeca@ch.swissbank.com
Hoi Philip and all other Javaties ...
> Thanks for the posting on a class loader.
> However... could you also post an example on how to CALL it?
> I would really like to see a concrete section of code, that is known
> successful.
> I'm having really lousy luck getting mine to actually USE the class loaded.
Hey, you're absolutely right. I'll keep that in mind for the next posting :)
So here is a use of the own cloass loader. But be aware of the following things:
1. This method is just partly cut out from an existing class. For that reason
it just shows how you can _generally_ invoke your own class loader. There
definitely can be mistakes causing this method not to run in your
project.
2. Pay attention to the comments that are in the source code. I think
they are useful :)
3. If you do have any comments: Just reply!
4. I hope this positing did help all of you 8^)
********************************************************************************
Example of how to use the own class loader
********************************************************************************
public void loadObject( String inObjectName){
// ---------------- -
// local attributes -
// ---------------- -
// transform object name to the class name (class name is part of object name)
String className = persistenceServer.getClassName(inObjectName);
Class newClass = null;
// special interface for using the new object: it's a kind of contract. The
// object promises to provide these certain methods
TOInterface newObject = null;
// -------------- -
// load the class -
// -------------- -
// invokes your own class loader
newClass = classLoader.loadClass(className,true);
// ---------------------- -
// instantiate the object -
// ---------------------- -
try{
newObject = (TOInterface) newClass.newInstance();
// no instantiation possible -
// ------------------------- -
} catch (InstantiationException noInstance){
loggingManager.logError(this,noInstance.toString());
// no access to the given class -
// ---------------------------- -
// occurs whenever a method is called that is not provided by the class
} catch (IllegalAccessException noAccess){
loggingManager.logError(this,noAccess.toString());
}
}
********************************************************************************
Thanx again for this useful request...
Have a nice day,
Arthy
.---------------------------------------------------------------------.
| Arthur Neudeck Tel: +41-61-288 94 44 |
| SYSTOR AG Fax: +41-61-288 42 24 |
| Applications - ARS Email: neudeck.arthur@ch.swissbank.com |
| Hochstrasse 16 X.400: C=CH A=400NET P=SWISSBANK S=NEUDECK |
| CH-4002 Basel G=ARTHUR DDA=ID=T019535 |
| Switzerland WWW: http://www.systor.ch/systor/ |
|---------------------------------------------------------------------|
| Current Project: Thesis about Travelling Objects |
`---------------------------------------------------------------------'
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com