A better solution for this type of requirement is to just use an org.jibx.runtime.impl.UnmarshallerContext directly. This internally wraps an XPP3 parser, and provides methods which allow you to access things at the parser level (this is what is done for the org.jibx.extras.DomElementMapper and similar document model handler classes). You can use these methods from your control code, then call the unmarshalObject() method when you've gotten to a tag you want to unmarshal. Since you're in control of the process you can stream these objects.
- Dennis
Chris Hill wrote:
Haha, that is pretty funny! Well, my original implementation used yaja and dom4j, but I ended up spending a lot of time using dom4j to convert my jabber objects into useful bits, and boy was it a waste of time and processing. I gutted yaja's dom4j transformer and created a jibx transformer instead which is like trading in a tank for a porsche. :)
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
------------------------------------------------------- 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
