I thought
you said you "didn't really want to have to design a general API for
parsing XML as part of this project" ? :)
Having grown tired of messing with my own solution I tried using commons
Digester with my example XML but ran into issues so I'm back looking at
a custom solution.
I'd still like to keep the parser core reasonably generic (ie
java.lang.Object rather than Query or Filter) because I can see it being
used for instantiating many different types of objects eg requests for
GroupBy , highlighting, indexing, testing etc.
As for your type-safety requirement, one approach I considered which
supports an extensible list of types with type safety was to use a
reflection-based API like this:
class MyObjectBuilder
.....
parser.processChildElements(new Object(){
public void consume(Query query)
{
//do something with query
}
}
);
....
class Parser
public void processChildElements(Object consumer) ...
This is how an ObjectBuilder could hand-off to the parser to get
something nested built eg a BooleanQuery builder wanting to get a
clause's choice of Query built.
The generic parser knows nothing about the "Query" type - it introspects
the supplied consumer and (by convention) sees what type of object the
"consume" method takes. It then ensures that any child elements are
built by a registered ObjectBuilder that supports that type and then
passes the resulting object to the consumer by dynamically invoking the
consume method.
However, I'm not sure that that really buys us a lot more than the
existing approach where java.lang.Object is used in ObjectConsumer and
the calling ObjectBuilder has to explicitly cast a java.lang.Object to
the required type. We still don't find out until runtime that something
doesn't work.
This type-safety requirement and the general-purpose-parser requirement
seem to be at odds with each other.
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]