Back to Kerala

After a long journey. Now train is in Thrissure station.and its almost vacant.
I got one book[Spiritual Warrrior] with me to read in the train . But i am not able to read the book.
So open my notebook and started surfing… I am going to my home town to celebrate
Onam with my wife and my family.One week i will be there in kerala only. we have planned to visit lots of temples and some places. I wish every one a happy Onam.

ListIterator

java.util.List,the List interface places additional methods, other than those specified in the Collection interface.
On the contracts of the iterator, add, remove.. Some additional methods are added in the List interface. Two of them are here

public abstract java.util.ListIterator listIterator();
public abstract java.util.ListIterator listIterator(int);

The List interface provides a special iterator, called a ListIterator,That allows element insertion and replacement, and bidirectional access, means you can travel through iterator forward and backward while iterating you can add and remove objects from the List implementations.

You can not modify the List directly while iterates through the Iterators

See the following example of ListIterator

import java.util.Arrays;

import java.util.ListIterator;

import java.util.List;

public class ListIteratorTest {

   public static void main(String args[]) {

      List nameList = new ArraysList();
      nameList.add(“one”);
      nameList.add(“two”);
      nameList.add(“three”);

      ListIterator itr = nameList.listIterator();

      while (itr.hasNext()) {

      String name = itr.next();

      System.out.println(name);

      // based on some operation you are adding object to list

      if (name.equals(“three”)) {

      itr.add(“four”);

      }

      }
   
   }

}

Started an Open source project

Hi all.

I have started an open source project for converting pojo to xml and xml to pojo. Project was started while i was consulting a swiss bank product development. There was a requirement for converting POJO to xml. We were using xmlbeans at that time. But Some of the xml are not having the schema or DTD. So the people were just append the tags and values in StringBuffer and produced the output. But i have idea to write simple light weight API  for converting the Transfer Object directly to an xml using reflection API.So the Class name and properties have to declare based on xml element you want. Now i am planning to make that small program to available to every one as an open source project. If any one is interested in contributing the project reply me.

first release will be available on sourceforge.net soon.

Thanks

Hari.

Current Reading

Secret By Rhonda Byrne

Rhonda Byrne

patrick peak and Nick

patrick peak and Nick

Feels Lonely

My love has gone to home town….. Life is again going disorder…………. No proper food. sleeps at late night.

Dear sweety loves you a lot… miss u…. waiting for you.

With Lots of Love Hari.

ISC and Google Ad Sense

Have look on this site
www.indiastudychannel.com

This is an educational site from India.
From here you can earn money from the ISC (India Study Channel ) and Google Ad Sense Revenue.

Hari.

validating xml from xsd using xmlbeans

Late nite I was surfing, sachin’s question stucked in my mind, how to validate xml from xsd using xmlbeans. Sorry dear I was not able to spend time to solve your issues because of my tight schedule. I am here publishing the answer for your doubt to every one and ofcourse you also.

Here i am creating one xsd file with 3 elements and without having any name space :)

sample.xsd

<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema” elementFormDefault=”qualified” attributeFormDefault=”unqualified”>
<xs:element name=”Address”>
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name=”Name” type=”xs:string”  />
<xs:element name=”add1″ type=”xs:string”/>
<xs:element name=”add2″ minOccurs=”0″ type=”xs:string”/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Generating jar from xsd using xmlbeans
scomp -out jars\sample.jar sample.xsd

xml file generated from above schema:

<?xml version=”1.0″ encoding=”UTF-8″?>
<Address xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”sample.xsd”>
<Name>sree</Name>
<add2>city</add2>

</Address>

This file does not contain add1 element and value so it is not a valid xml based on the above schema.
Following program will parse the xml file and validate it from xsd file, if there is any error it will display in console.

SampleValidate.java

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import noNamespace.AddressDocument;

import org.apache.xmlbeans.XmlOptions;

public class SampleValidate {

public static void main(String args[])throws Exception
{
ArrayList validationErrors = new ArrayList();
XmlOptions voptions = new XmlOptions();
voptions.setErrorListener(validationErrors);
AddressDocument addrDoc = AddressDocument.Factory.parse(new File(“sample.xml”));
boolean valid =addrDoc.validate(voptions);
if(valid)
{
System.out.println(“Its valid xml”);
}
else
{
System.out.println(“Not a valid xml file”);
Iterator itr = validationErrors.iterator();
while(itr.hasNext())
{
System.out.println(itr.next().toString());
}
}

}

}

output:

Not a valid xml file
sample.xml:0: error: cvc-complex-type.2.4a: Expected element ‘add1′ instead of ‘add2′ here in element Address
sample.xml:0: error: cvc-complex-type.2.4c: Expected element ‘add1′ before the end of the content in element Address

Thanx
hari

Here My Valentine

Today is valentine day… :) Am @ home only. M going to spend some time with my love.. my life.. my wife :) . I am so much happy.. I got a good girl in my life, Rekha.

dsc051022

We are going to watch a movie today… And going to spend time.. Outside.

and planning to gift something……… :)

Happy valentine day to every one

My Life @ 2008

One more year is going to say by.  I am wishing all of you a happy new year.

Lots of my friends asked that, why there is no new post. Firs I I m saying sorry for that.

 

Look on personal life, Last year I got married, a beautiful girl rekha J comes to my life. I took some times for settling everything.  I took 25 days of  leave.That may be the one reason for this small silence on this blog.  I am happy now .. got a good wife. Loves… you rekha

 

Look on professional view I got opportunity to works on SOA,EAI, JMS,Webservices.

Lots of work I got was interesting and innovative. And I cleared the SCWCD  this year.

But at the year end it was little painful for my professional life. Hope everything will settle faster. Any way I am wishing you a happy new year. My prayers will always with you.

 

Hari.

cleared SCJP and SCWCD

Hi…. :)

i have cleared

SCJP                                
and
SCWCD                          

…………………….. :)