Re: [Simple-support] more trouble with convert...
Brought to you by:
niallg
|
From: -=}\\*/{=- <rui...@gm...> - 2011-12-19 00:40:40
|
solved the problem llike this...
not as i expected but nice...
xml in/output...
<handler>
<Downloader ignoresExplicit="true"
package="abc.kis.handler"/>
<KISRemote package="abc.kis.simple"/>
</handler>
// list declaration...
@Element(name = "handler", required = false) // required is true!!!
private Handler.List handlers;
public interface Handler {
// the base class for all handlers...
public static abstract class Base implements Handler {
@Attribute
private String getPackage() {
return this.getClass().getPackage().getName();
}
@Attribute
private void setPackage(String pack) {
}
}
// Array<Handler> replacement to that it is detected by the converter...
public static class List extends ArrayList<Handler> {
// ... its only member, the converter...
public static class Converter extends SimpleConverter<List> {
public static Registry bind(Registry r) {
return bind(r, List.class, Converter.class);
}
@Override
public List read(InputNode in) throws Exception {
List alh = new List();
for (InputNode next = in.getNext(); next != null; next =
in.getNext())
alh.add((Handler)KeepItSimple.CAMEL_CASE_PERSISTER.read(
Class.forName(next.getAttribute("package").getValue().concat(".").
concat(next.getName())), next));
return alh;
}
@Override
public void write(OutputNode on, List alh) throws Exception {
for (Handler h: alh)
KeepItSimple.CAMEL_CASE_PERSISTER.write(h, on);
}
}
}
|