Posts

XMLBeans - Spare me the parsing and mapping !

I have been using Castor(http://www.castor.org) for a while to translate XML to JavaBeans vice versa. It was ok and reliable but our XML got complicated, it was tedious and cumbersome to maintain the XML Mapping file. Our mapping file keeps growing bigger as our objects gets more complicated. On top of that we have to maintain our XML schemas as well. So we have to maintain the XML mapping file and the XML schema. Then i stumbled upon XMLBeans. XMLBeans got me hooked just by not having to maintain a mapping file. Here are the few easy steps that i followed when i used XMLBeans. 1.) Download and Install XMLBeans (http://xmlbeans.apache.org/). I got version 2.1.0 2.) Create the XML Schema 3.) Do a SCOMP (Please refer to XMLBeans documentation) 4.) Once the XMLBeans jar for my XML Schema was created then it was ready to use. Here is a sample Code: Sample Code processing an XML Message to an Object xmlTest is the XML Message in String InstructorQualification is the root element of the XML

Java Annotations - Simple Explanation

Java 5.0 added a lot of language features to Java. One of the new features is Annotations. Annotations are tags in the source code that can be processed by a tool, compiler etc. (e.g. JavaDoc comments "@author"). The purpose of annotations is to simplify programming by helping programmers avoid boiler-plate code. Annotations are not part of the program itself, they provide data about the program. They have no effect on the code that they annotate. Uses for Annotations: 1. Information for the compiler 2. Deployment time processing 3. Runtime processing How do annotations work? Annotations can be applied to packages, classes, parameters, variables, fields or methods. It is defined using an "@" syntax. Annotations has a corresponding annotation type. The annotation type defines the content of the metadata. There are predefined annotations in Java as well as some API's provide their own annotation library. But to define your own annotation, here is how. Defining a s