Anyway I've had the exact same idea about jibx, just passing jibx a stream to parse the individual xml fragments. My problem was that I was already using yaja, and yaja handled all the connections, streams and auth and I didn't want to write that all from scratch.
The other (not a big) problem with passing jibx an xml socket InputStream is that jibx would need a way to take that stream and fragment it into little parts. From your last mail I wasn't sure exactly what you'd be doing with jibx, but now I have a pretty good idea. Creating a JibxXmlStream object would be something that would have to be added to jibx internally. Jibx uses the XPP3 pull parser, so you'd have to write a pull parser(ideally with xpp3) that would fragment the xml stream before passing it to the jibx parser(which would then parse it).
Additionally, you would have to map packets to unmarshallers. I've already got this set up in my SAX parser and it looks like this:
public void addPacketType(String type,String factoryType, Class theClass) {
if (!validPacketTypes.contains(type)) {
validPacketTypes.put(type.toString(), type);
if(theClass != null){
try{
IBindingFactory bf = BindingDirectory.getFactory(factoryType,theClass);
IUnmarshallingContext uctx = bf.createUnmarshallingContext();
packetUnmarshallers.put(type.toString(), uctx);
}catch(JiBXException e){
System.out.println("Could not create unmarshaller for :"+type);
}
}
}
}
So you'd put that code into the JibxXmlStream object, and here's how the pseudo-code would work:
//create some sort of raw xml stream
XMLStream xs = new XMLStream();
//create our jibx stream handler
JibxXmlStream jxs = new JibxXmlStream( xs );
//register that we'd like jibx to create java objects out of jabber:iq:agents xml
jxs.addPacketType( "jabber:iq:agents" , "jabber:iq:agents" , JabberIqAgents.class);
//give our stream handler an object that would like to be notified of jabber:iq:agents objects
jxs.addListener("jabber:iq:agents",myListener);
You'd need to create a binding definition for all classes that you want to be transformed, and a java class (see the jibx docs). Then use JibxXmlStream.addPacketType() to add the definitions like above. Then all jabber:iq:agents elements would be automagically converted into java objects, and passed to any listener registered with the stream.
Alas, I'm sad to say that I've had this idea for about 6 months now. I've been working on other aspects of the project, and so this is all just a big long ramble with no real code. I hope it helps you tho, and gives you something to think about! Your goal of creating near zero coding is very realistic with jibx. But I guess it depends on how 'near' to zero you expect to get.
Happy jabbering!
Peace C
Chris Chen wrote:
Thanks for the quick reply.
Funny thing is that what I'm trying to do is parse jabber streams! :) My current implementation works with SAX. However, I was contemplating the fact where I can create a new framework that allows near-zero parsing code. So what I would do is simply create a normal Java object, and something like JiBX could parse the xml stream and fill in the object automatically for me.
I was looking at the IUnmarshallingContext, and it accepts an InputStream or Reader. My guess is that you can pass the jabber connection stream to JiBX to parse the individual xml fragments (ie. jabber:iq:agents). If JiBX doesn't close the stream, then I believe it will work out fine.
My main goal is to find a way to support near-zero coding to support any future messages coming out. near-zero coding or just creating simple model objects.
Thanks, Chris
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
