Code I/O

A topnotch WordPress.com site


Leave a comment

5 Minutes on Java – Playing with XML and Java

Marshelling/unmarshelling of XML is very common.  JAXB and XStream come to my mind when ever I need to work with XML and Java.

Recently I had an interesting conversation with my colleague, he preferred JAXB over others for the following reasons

  • He wanted to use something that is as good as intrinsic of the language.
  • He did not mind the over head of using annotations.
  • nor did he want the dependency on a vendor or get into sustainability issues.

After having thought for a while, I realized software and bugs go hand in hand.  When it comes to delivering projects on schedule, reducing the coding time/complexity is good.  Thirdly, when a vendor has already done a good job of validating the concepts, why not use it in the given constraints.

XStream is equally powerful, in my experience (perhaps I’ve over simplified it), but for the purposes of the tasks I’ve used it for, it has really proven its metal.

The selling points from my point of view is:

  • I really don’t have to care about the XML schema/schema generation tools to work with.
  • When POJO’s are involved, I can marshall/unmarshall it as XML document using a single API call.
  • Once the Java objects are constructed, it can used as ever before.

Everything is good, except for the sustainability part, however, knowing the way Java has touched the lives of billions, sustainability is not a concern as of today.  Perhaps there is more of a organizational standard that forbids you from using XStream.

Check out the tutorial from http://xstream.codehaus.org/tutorial.html

Here is how I’ve used it to convert an XML stream to a Java object

@POST
@Consumes ("application/xml")
@Produces ("application/xml")
public Response postHandler(InputStream input){
String object = input.toString();

URI uri = uriInfo.getAbsolutePathBuilder().path(object).build();
logger.debug("Received Object: " + object);

StringBuffer buff = new StringBuffer();

XStream xstream = new XStream(new DomDriver());
xstream.alias("data", MyData.class);

MyData data = (MyData) xstream.fromXML(input);

...

...

}

Now sending a XML stream to user is as simple as creating it.

class MyData {

String toXML(){

XStream xstream = new XStream(new DomDriver());
xstream.alias("data", MyData.class);

return xstream.toXML(this);

}

}

Learning: if something can be done in few steps, let’s do in just those few steps 🙂

If there is something that you feel is better, please let me know.

Advertisements


Leave a comment

HISTORIC AUDIT ANALYSIS

Looking back in time can give us clues on things that were overlooked or neglected.  However, looking back in time is tough when there are no facilities to do so.

Imagine a scenario where you’re an escalations manager.  The bugs database records all information about incidents and records its intermittent states.

Having the transactional information, as a manager you wanted a root cause analysis done.  This process involves going back in time and finding out how much time was spent in each phase of an escalation process.

However, this posses a challenge when such a trace back mechanism does not exist in the system.  However, most systems will have audit trail recorded somewhere, which can be used to build a time travel to the past.

To fill this gap, a prototype from SAP Business Objects Innovation centre, Dublin can be used.  The tool is handy in scenario where you do not have a mechanism to go back in time, but want to use audit trail to look back.

You can find out more about this from our web-site – http://www.sdn.sap.com/irj/boc/innovation-center?rid=/webcontent/uuid/f00641ea-8ab2-2c10-d092-b9472eef434c

Please do give your feedback and let us know how useful this was for you.


Leave a comment

5 Minutes on Linux: eclipse 3.5.1 on Ubuntu

Buying into the hype of ubuntu, recently I moved away from openSUSE 11.1 to ubuntu (on a urge to use Empathy as my default IM client).  Migrated most of the data and things seem to be going well so far.

What I liked?

  • gwibber client (can finally work in one console for twitter and Facebook)
  • Empathy (need not switch to Skype for voice chat, I can now talk to my Gmail contacts).   This was a failure on OpenSUSE, didn’t work as expected.  Hopefully this is fixed in 11.2 and I can move back soon.
  • SBackup (works well, so far data has not got corrupted)
  • Evolution (works fine as before)
  • VirtualBox (the latest release is very stable, the performance is good.  So far the virtual image works like a charm).

What needed to be added explictly?

Thinkpad fingerprint reader was not enabled, had to install libpam-thinkfinger (used synaptic package manager).  OpenSUSE is been good at this, the integration of fingerprint reader with authentication is a seamless experience.

Refer http://www.thinkwiki.org/wiki/Installing_Ubuntu_9.10_%28Karmic_Koala%29_on_a_ThinkPad_T61 to enable fingerprint reader.

What’s buggy and annoying?

The major glitch I found is with Eclipse, the buttons in most of the dialog boxes became unresponsive and was unable to find out what was going on for a while.  Did few experiments and then found that using open jdk messed up things a little – some of the contextual menu items seemed to be missing (for importing the projects and few of the import sources missed), and this prompted me to move to SUN JDK, which got back the lost context menu and import source items.  However, the glitch continued with buttons in most of the dialog boxes.

Solution:

  • Focus the button with a mouse and then hit the good old keyboards “Return/Enter Key”
  • Launch eclipse with GTK+ client side windows enabled.  This flag when set, will let GDK create all windows as native windows. This can help applications that make assumptions about 1-1 correspondence between GDK windows and X11 windows.  (This is better than the first proposal)
export GDK_NATIVE_WINDOWS=true
eclipse&

Eclipse installed from ubuntu repo and eclipse downloads has been tried with these solutions.

Configuration: IBM Thinkpad T60p, Dual Core, 3GB RAM, Ubuntu lucid lynx