[
Lists Home |
Date Index |
Thread Index
]
- From: Stefan Haustein <haustein@ls8.cs.uni-dortmund.de>
- Date: Wed, 26 Jul 2000 11:04:36 +0200
Michael Brennan wrote:
>
> My more recent approach is to have an "addChild" method on what you are
> calling the ParserListener (which I called "ElementHandler" in my
> implementation). Then, I use a simple Hashtable (loaded from a Java
> Properties file) to map element names to a class that is loaded via
> reflection (just as Stefan Haustein noted in another post). The BaseHandler
> that is maintaining the stack of current ElementHandlers invokes "addChild"
> on the parent ElementHandler after instantiating a new ElementHandler.
BTW: In my most recent approach I got rid of the Hashtable by adding
a prefix to the element name and then use the reflection capabilities
for resolving the element name to a full classified class name.
Advantage: I do just need to create the corresponding classes in the
right package(s), no more ugly registering startup code for tons of
elements. The following code is simplified to show the principle.
Actually it can handle classes from more than one package. My next
step is to link that to xml namespaces somehow....
public synchronized Element createElement (String name) {
try {
Class elementClass = ClassLoader.getSystemClassLoader ()
.loadClass ("de.unido.ai.infolayer.templates.TemplateElement_" +
name);
Class [] ctype = {String.class};
Object [] cargs = {name};
return (TemplateElement) elementClass.getConstructor (ctype)
.newInstance (cargs);
}
catch (Exception e) {
throw new ChainedRuntimeException (e);
}
}
Best,
Stefan
--
Stefan Haustein
Univ. Dortmund, FB 4, LS 8 tel: +49 231 755 2499
Baroper Str. 301 fax: +49 231 755 5105
D-44221 Dortmund (Germany) www-ai.cs.uni-dortmund.de
|