Thursday, January 24, 2013

Working with iCal4j

Recently, I started working on ical4j. So, thought will post some of the my initial learnings. I will keep updating this as I learn more.

I created a project with maven. Here is how my pom.xml looks


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.sunilpk</groupId>
    <artifactId>Ical4jProto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Ical4jProto</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.mnode.ical4j</groupId>
            <artifactId>ical4j</artifactId>
            <version>1.0.4</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
  
</project>


Once that is done, now its times to learn some basics. Like creating a Calendar.


package com.sunilpk.ical4jproto;

import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.Version;
import net.fortuna.ical4j.model.property.CalScale;

/**
 *
 */
public class CreateCalendar {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Calendar calendar = new Calendar();
        calendar.getProperties().add(new ProdId("-//CALENDAR//iCal4j 1.4.0//EN"));
        calendar.getProperties().add(Version.VERSION_2_0);
        calendar.getProperties().add(CalScale.GREGORIAN);
        System.out.println("The Calendar is: " + calendar);
    }
}

The output of the program:



The Calendar is: BEGIN:VCALENDAR
PRODID:-//CALENDAR//iCal4j 1.4.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
END:VCALENDAR



Similarly, an .ics file can be read


package com.sunilpk.ical4jproto;

import java.io.FileInputStream;
import java.io.IOException;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.util.CompatibilityHints;

/**
 *
 */
public class ReadCalendar {

    public static void main(String[] args) {
        try {
            FileInputStream fin = new FileInputStream("src/main/java/com/sunilpk/ical4jproto/invite.ics");

            CalendarBuilder builder = new CalendarBuilder();

            Calendar calendar = builder.build(fin);
            System.out.println("Product Id: " + calendar.getProductId());
            System.out.println("Method Id: " + calendar.getMethod());
        } catch (IOException e) {
            System.out.println("IO Exception.. " + e);
        } catch (ParserException pe) {
            System.out.println("Parse Exception. " + pe);
        }
    }
}



The output of the above program could be similar to following.


Product Id: PRODID: Calendar-Provider

Method Id: METHOD:CANCEL


Thursday, November 8, 2012

Trip to "Malaya Maruta", "Dharmasthala" and Manjarabad fort, Sakleshpur

This is about one more journey towards Western Ghats, which has many trekking places. This time (October 27th and 28th weekend) we planned for Charmadi Ghat. Almost 10 years ago, I had been to a place called "Malaya Maruta" in the Charmadi Ghat. Now, again wanted to visit the same place and do the trekking for a day and visit "Dharmasthala" the next day.

"Malaya Maruta" is a place on the way to "Dharmasthala" via "Mudigere". The route to this place from Bangalore is: Bangalore -> Hassan -> Belur -> Mudigere (need not enter into Mudigere) -> Kottigehara -> Malaya Maruta.

Few of our friends decided to do trekking near "Malaya Maruta" and visit some water falls, in that region. The plan was to leave Bangalore early in the morning. Reach the place which is about 270 KMs from Bangalore. However, few of the friends opted out on Friday. So, only 3 of us were ready. We discussed instead of driving whole 270 KMs in one stretch, we shall drive on Friday night and reach Hassan in the night and stay. Drive early morning to "Malaya Maruta" which is another 90 KMs. So, we started Bangalore in the night 8:30 PM and reached Hassan around 11:30 PM with break for dinner in some dhaba on the way. Found a decent room for 3 of us and checked-in.

Got up early and were out of Hassan by 6:30 AM. Road was good most part of the journey. As we reach "Mudigere", we should take a diversion towards "Dharmasthala" and should not enter into Mudigere, however we did not knew this. We entered "Mudigere" and had breakfast in a small canteen. The breakfast was good. Upon checking the place, the localities informed us that we should have taken diversion before 3 KMs. We went back to the place which has many diversions. We took the route to "Dharmasthala". On the way we get a place called "Kottige hara". This is the place where "Charmadi Ghat" starts. To enter "Malaya Maruta" you need to drive straight. There is diversion towards right which takes you to "Kalasa" and "Horanadu", which are other most famous religious places.

There is a small check-post as you drive straight towards "Dharmasthala", where they note down your details like your name, vehicle number. As you start your journey, you will start observing the forest ranges and excitement begins.

From this place if you drive approximately 3 KMs, you will find a guest house aptly named "Malaya Maruta". Just next to this place there is a small stream where you can get in if the water level is less. As we went after monsoon and this time monsoon was bad, hence the water level was pretty low. You need to get permission to enter "Malaya Maruta" guest house. You need to get in advance from the forest office in "Mudigere". You can see panoramic view of the "Charmadi Ghat" from this place.
If you drive further approximately 1 KM from this place, you would get a small bridge build over a stream. There is an estate named "Alekan Estate". There are few streams flows on the either side of the bridge. You can see "Alekan falls" on the left side (if you are coming from "Kottige hara"). To see this falls, you need to get down by the muddy road just next to the bridge (just take care as it would be slippery in monsoon).
As you drive further you would see place called "Jenukal". There is a small temple dedicated to Lord "Annappa". Later, we got to know that one can trek from this place to one of highest point in "Charmadi Ghat", however you need 'expert advice' to enter this trekking. Since it was not a good monsoon this year, the place was little dry compared to good monsoon years. We decided to drive futher and see what we get. We got a place called "Charmadi". This is small village. We parked our car and then had a tea in small canteen. When checked with locals about the trekking. He informed few places where we can trek. There are few local people whom we can take as guide. However to reach one of the peak "Kodekallu", we have to start early in the morning so that can reach back early. Hence we decided not to trek this route. To keep our excitement, we were told that there is a small power station, we can trek to this place. Hence, we decided to trek this place. It was nice route
in the forest. You get small stream
as we cross the entry gate for this power generation station. There is security room. But no one was there at the entrance. We decided to go ahead and after some time we saw a power station. This is a simple power generation station built across stream. They have built a small dam like thing, which holds water to certain level and sends water across a huge pipes to generate current. The engineer working at this station showed us how the power gets generated. I think it generates 1.4 MW of power, which is connected to main grid to supply power. We spent some time and returned to village. We got fresh and decided to drive to "Dharmasthala" on the same day.

We freshened in the river "Netravati" then went to the temple. However, the temple "darshan" time was over and they said it would start at 7:00 PM. Hence decided to roam around, we had some snacks and tea. Our friends took nap in the car. Around 6:00 PM we went to check the queue. It was very crowded. Being holiday season/weekend it had piled up. There is another option to get "darshan". We need to pay Rs. 200/- per person. This queue was also crowded. We decided to stand in this queue. Then slowly the queue started moving and as we move to a certain place, there is a common passage for all types of queues. Here its gets messy, as people starts moving hurriedly. Some how I do not like people just push each other without any reason. Some people go to extreem, by carelessly moving ahead without noticing others. All this said, this is part and parcel of visiting any religious places. We got "Darshan". Another best thing about "Dharmasthala" is food. I like it very much. You will see thousands of people have food simultaneously. It is quick and fast. This is not place for slow eaters. They serve nice rice and "sambar" / "saru" ("rasam") and butter milk.

We finished our dinner and it was 8:30 PM when we came out. That was good when considered the queue length. Now, the big question ... what next?. We were sure that we won't get rooms to stay, not even in private lodges. Hence our good friend suggested to drive to "Sakleshpur" which is around 80 KMs from "Dharmasthala". The pain point was driving through "Shiradi Ghat" road, which is always bad. But we did not had any choice. My friend was very cautious while driving through this section of ghat road that too in the night. We reached "Sakleshpur" around 11:00 PM... you can imagine the time took us to drive this road. Again we got a decent room and slept for the night. Actually we had planned to do trek on day 1 and visit "Dharmasthala" on day 2. However, everything happened on day 1. With nothing much left for day 2.

As we went to bed, we discussed and decided that next day morning we shall visit some near by place and go back to Bagnalore.

As planned we all got up 6:00 AM in the morning and were ready by 7:30 AM. We had our break fast. Then we decided to visit the place called "Manjarabad fort", which is around 5 KMs from Sakleshpur again towards the "Dharmasthala" road. There is no information about this place. As you drive, you shall see some small canteens / tea shops. We parked our car. The fort is not visible from this place. There is a small muddy road which takes you to the top and as we move we shall see steps. That will take you to the fort. It is a star shaped fort. (one can search for it.). History says that it was built by "Tippu Sulatna", the famous king who ruled the "Srirangapattana". As we entered no one was there. It was very cool and calm.

 
View of western ghat from fort Fort viewed from top
 We spent some time there and got down. Then our friend drived non-stop to Bangalore.

We reached Bangalore around 1:00 PM and had lunch... and then slept and slept... and just slept to get up only in the next day morning.

Tuesday, October 16, 2012

Trip to Jog Falls, Sakrebailu and Kemmannu gundi

Recently I had been to Jog falls along with my family. This was my third visit to Jog falls. First two have been with friends. This was first time with my family. The trip was planned for two days. So plan was to see Jog falls, Sakrebailu, Mandagadde and other surrounding places of Shimoga.

So, we started early morning on Saturday, filled-up the car tank and started to Shimoga. The route we had planned was Bangalore -> Tumkur -> Tiptur -> Arasikere -> Kadur -> Birur -> Tarikere -> Bhadravati -> Shimoga.

One of my friend had suggested to have a breakfast at "Preeti Canteen" in Birur. He had informed that it is small canteen as you enter Birur. But we did not find it and hence moved on to have breakfast at Tarikere. It was pretty ordinary. Moved to Shimoga after having breakfast. I had already booked rooms for a day. The hotel was "Jewel Rock". I heard that it was good, hence I had just booked it. We checked-in hotel and rooms were okay. We took much needed rest.

Now, the plan was to visit "Tavarekoppa Lion and Tiger Safari" and then Jog Falls in the evening. The plan to visit Jog falls in the evening was prompted by the news about the newly introduced musical fountain. Hence, we started to "Tavarekoppa" after having lunch. At the entrance, the guard said the Safari would start only at 2:30 PM. We calculated that if we spend an hour in Zoo and Safari, it would be 3:30 PM and it would take approximately 1 hr : 30 mins to travel to Jog falls from there (the Jog falls is 90 KMs from Shimoga) and we would be there by 5:00 PM and we can enjoy at least 2 hours and see the musical fountain. It was good Safari, except that there are very few animals to see. We could see few tigers very closely. There are 3 lions in a cage. But there activities seems to be limited. And there are lots of Deers, Black bucks.
Tigers at Tavarekoppa Lion and Tiger Safari

As planned, we reached Jog falls around 5:00 PM. It was raining all the way. When we reached Jog, the falls was fully covered with fog not even single falls of the four was visible. After some time everything was clear and was able to see the falls.
We can climb down till the water falls and initially I did not had plan go down. As I had been till down and also at the top of Raja in my earlier visits. However, this was first time I had visited Jog after steps were made till down. So, climbed down few steps and I was fully wet. Slowly I was inspired (or tempted) by few people who were enjoying their trip down to Jog falls on top it was raining. So, I too decided get down. It was easy walk down and knew it would be difficult to get to the top again.
Jog falls
It was nice experience to get down in the rain and watching the jog falls and surroundings. I took some snaps at the down even though it was raining.
It was nice to see the whole of the water falling..., spent some time and returned to top. As we reached at top it was very satisfying.
 
Me at the down of Jog falls Water falling at the down of Jog falls.
In the evening around 7:30 PM and the musical fountain started. It was nice, however, since it was still under construction, the area is not covered with sheets and there were no seating arrangements and on top of it, it was raining. Also, there were lots of mosquitoes and it was getting difficult to stand. So, we decided to return back to Shimoga.
Musical fountain at Jog falls Musical fountain at Jog falls

We reached back to hotel around 9:30 PM and hotel restaurant was closed. Hence, we were forced to eat in Bar / Restaurant. He took hell of time to serve the simplest order you can order. So, advice is not eat at that place. We went to bed with lot of tiredness and with fulfillment of achieving what was planned. Next day plan was to getup early, fresh'n up and start to Sakrebailu Elephant Camp. I had read that there we can see the elephants bathing, eating and we too can try our hand. So, I was expecting some fun, particularly for my 4 year old daughter.

Got up early, checked-out hotel, settled the bill and we were out of the hotel by 8:00 AM.

Sakrebailu is around 14 KMs from Shimoga, hence we knew that this can be reached early. Hence, we decided to have breakfast. Visited a small hotel (if I am correct, its name is "Woodlands") and tiffin was good.
We asked localities for the route and they provided all the information. We drived soon to the Sakrebailu Elephant Camp. They charged around Rs. 30/- per adult and free for children. As I had read, already few of the elephants were getting bath. I too tried my hands at the elephant bathing.

Elephant at the camp
Elephants at the Sakrebailu Elephant campMe washing an elephant

Then we visited a place called "Mandgadde", it is small bird sanctuary, which is another 10 KMs from Sakrebailu. When we went it was 10:00 AM and there very few birds and that too we have to see them from a quite distance. Hence, we did not spend much time and decided to drive back to Bangalore.
On the way back we spent some time at "Gajanur Dam", its small dam build across river "Tunga".
Birds at Mandagadde Bird Sanctuary
Later, on the way back we reached Tarikeri and we had enough time and we just checked if we can make the trip to Kemmannugundi. We wanted to check the route to Kemmannu Gundi, which is a nice hill station. In my previous visit, the road was bad and hence it was not in my list. But localities informed the road is good enough to drive. So, first we decided to visit "Kalhatti falls" (also known as Kallatha Giri falls). It is a small falls and there is a temple dedicated to lord Veerabhadreshwar. We took the blessings and headed towards Kemmadnnugundi. The road from this falls was bad and was getting worst. We could see some cement and sand. Expecting that they would be going to repair this road.

Veerbhadreshwar temple at Kallatha GiriKallatha Giri or Kallhatti falls

But once we reached at the top, it was really nice and very cold. There is a small garden and there are guest houses for the people who wants to make a stay. Also, there is falls called "Hebbe" falls. It is around 8 KMs from Kemmannu Gundi. One can trek to this place or there are local Jeeps available. However, we did not had plan to visit any of these, we decided to return to Bangalore.

 
Kemmanna Gundi Scene from a view point

On the way back we stopped for a dinner and then reached our home around 10:00 PM and just wanted to sleep...
Overall, it was a very nice trip and enjoyed.

Tuesday, September 25, 2012

Custom JAXBContextResolver


JSON representation for single record element which is declared as a java array or a collection, using jersey would display it as a single element rather than JSON array.

For example:


For single record:

"employee":
         {
           "id": "16",
           "name": "Sunil"
         }

Where as it is expected to display it as:

"employee":
      [ 
         {
           "id": "16",
           "name": "Sunil"
         }
      ]



If you need to handle JSON produced by Jersey for a single element collection, then we need to customize the JAXBContext Resolver. A provider class annotated with @provider needs to extend the ContextResolver of javax.ws.rs.ext package.


/**
 * This helps in configuring the JSON output format.
 */
@Provider
public class JAXBContextResolver extends ContextResolver {

    /**
     * The JAXBContext object.
     */
    private JAXBContext context;
    /**
     * The class types.
     */
    private final Class[] types = {Employee.class};

    /**
     * Constructs the JSON output format for the specified class types.
     *
     * @throws Exception the exception
     */
    public JAXBContextResolver() throws Exception {
        this.context = new JSONJAXBContext(JSONConfiguration.mapped().arrays("employee").build(), types);
    }

    /**
     * Returns the current context for the given class.
     *     
     * @param objectType the JAXBContext for the given class object.
     * @return the JAXBContext.
     */
    @Override
    public JAXBContext getContext(final Class objectType) {
        for (Class type : types) {
            if (type == objectType) {
                return context;
            }
        }
        return null;
    }
}


In the above class, the Employee.java is a simple Java Bean class which has 'employee' attribute which is a Java arrays or a collection. If that element contains multiple values then JSON conversion would be displayed:

For single record:


"employee":
      [ 
         {
           "id": "16",
           "name": "Sunil"
         }
      ]

  For Multiple Records

  "employee":
       [
           {
               "id": "16",
               "name": "Sunil"
           },
           {
               "id": "17",
               "name": "Ajeesh"
           },
           {
               "id": "18",
               "name": "Sanjay"
           }
       ]



One issue with this implementation is one need to maintain the affected classes/items manually in their implementation. So, you need to add as many as classes that have Java collection to the above class and get the configuration 'mapped' to JSON array.


private final Class[] types = {Employee.class, Company.class};

and

this.context = new JSONJAXBContext(JSONConfiguration.mapped().arrays("employee", "company").build(), types);

JAXB with an example

JAXB with an example.

What is JAXB?
JAXB stands for Java Architecture for XML Binding. It can be used to convert Java Object to XML and XML back to Java Objects.

With JDK Annotation, it is very simple for implementation. Lets directly jump into implementation.

First, Let us define a Address.java class with basic fields.

package baseproject.jaxb;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlType;


/**
 *
 * @author
 */

@XmlType

public class Address {

    private String street;

    private String lane;
    private String city;
    private String state;

    /**

     * Get the value of street
     *
     * @return the value of street
     */
    @XmlElement
    public String getStreet() {
        return street;
    }

    /**

     * Set the value of street
     *
     * @param street new value of street
     */
    public void setStreet(String street) {
        this.street = street;
    }

    /**

     * Get the value of lane
     *
     * @return the value of lane
     */
    @XmlElement
    public String getLane() {
        return lane;
    }

    /**

     * Set the value of lane
     *
     * @param lane new value of lane
     */
    public void setLane(String lane) {
        this.lane = lane;
    }

    /**

     * Get the value of city
     *
     * @return the value of city
     */
    @XmlElement
    public String getCity() {
        return city;
    }

    /**

     * Set the value of city
     *
     * @param city new value of city
     */
    public void setCity(String city) {
        this.city = city;
    }

    /**

     * Get the value of state
     *
     * @return the value of state
     */
    @XmlElement
    public String getState() {
        return state;
    }

    /**

     * Set the value of state
     *
     * @param state new value of state
     */
    public void setState(String state) {
        this.state = state;
    }

    @Override

    public String toString() {
        return "Address: {" + "street=" + street + ", lane=" + lane + ", city=" + city + ", state=" + state + '}';
    }
}

Now, let us define a new Class Employee.java with basic fields and also the 'Address' object.

package baseproject.jaxb;

import javax.xml.bind.annotation.XmlAttribute;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**

 *
 * @author
 */
@XmlRootElement
public class Employee {

    private String id;

    private String name;
    private String company;
    private Address address;

    /**

     * Get the value of id
     *
     * @return the value of id
     */
    @XmlElement
    public String getId() {
        return id;
    }

    /**

     * Set the value of id
     *
     * @param id new value of id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**

     * Get the value of name
     *
     * @return the value of name
     */
    @XmlElement
    public String getName() {
        return name;
    }

    /**

     * Set the value of name
     *
     * @param name new value of name
     */
    public void setName(String name) {
        this.name = name;
    }

    @XmlAttribute

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {

        this.company = company;
    }

    @XmlElement

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {

        this.address = address;
    }

    @Override

    public String toString() {
        return "Employee: {" + "id=" + id + ", name=" + name + ", company="
                + company + ", address=" + address + '}';
    }
}

Now, define the class which converts an Object to XML. For that first we create an object 'Employee' class and set the attributes for the same.

package baseproject.jaxb;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

/**
 *
 * @author
 */
public class JAXBObjectToXML {

    public static void main(String args[]) {
   
        // First define the address of the employee.
        Address address = new Address();
        address.setStreet("Main Street");
        address.setLane("Main Lane");
        address.setCity("Bangalore");
        address.setState("Karnataka");

        // Define the employee object
        Employee e = new Employee();
        e.setId("1");
        e.setName("Sunil");
        e.setCompany("Sunil Systems.");
        e.setAddress(address);  // Setting employee address object.
        try {
            File file = new File("src/baseproject/jaxb/emp.xml");

            // Now the JAXB
            JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(e, file);
            marshaller.marshal(e, System.out); // displays the output on screen for System.out
        } catch (JAXBException ex) {
            System.out.println("JAXB Exception: " + ex);
        }
    }
}

Once you run the JAXBObjectToXML, we see the following output.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee company="Sunil Systems.">
    <address>
        <city>Bangalore</city>
        <lane>Main Lane</lane>
        <state>Karnataka</state>
        <street>Main Street</street>
    </address>
    <id>1</id>
    <name>Sunil</name>
</employee>

Similarly,  It is very easy to convert an XML to an object. 

Now, we shall define a JAXBXmlToObject.java class which constructs an object from an XML file. In the following class, we are reading 'emp.xml' file and converting it to 'Employee' object.

package baseproject.jaxb;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author
 */
public class JAXBXmlToObject {
    public static void main(String args[]) {
        try {
            File file = new File("src/baseproject/jaxb/emp.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
            Unmarshaller unmarhsaller = jaxbContext.createUnmarshaller();
            Employee e = (Employee) unmarhsaller.unmarshal(file);
            System.out.println(e);
        } catch (JAXBException ex) {
            System.out.println("Jaxb Exception... " + ex);
        }
    } 
}


For the same, we shall define XML file similar to one we want for our objects.

Input XML file: emp.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee company="Sunil Systems.">
    <address>
        <city>Bangalore</city>
        <lane>2nd lane</lane>
        <state>Karnataka</state>
        <street>2nd Street</street>
    </address>
    <id>2</id>
    <name>Sunil</name>
</employee>


Upon successful run, we shall have 'Employee' lobject being constructed with values in the XML file. Following output confirms the same.

Employee: {id=2, name=Sunil, company=Sunil Systems., address=Address: {street=2nd Street, lane=2nd lane, city=Bangalore, state=Karnataka}}

Please note the output of address object.

Even if the XML contains additional elements for which the attributes does not exists in the class, they would be simply ignored.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee company="Sunil Systems.">
    <address>
        <city>Bangalore</city>
        <lane>2nd lane</lane>
        <state>Karnataka</state>
        <street>2nd Street</street>
        <cross>2nd cross</cross>  <!-- Will be ignored -->
    </address>
    <id>2</id>
    <name>Sunil</name>
    <dummy>Dummy, will not be used</dummy>   <!-- Will be ignored -->
</employee>


The output would still look the same as above.

Employee: {id=2, name=Sunil, company=Sunil Systems., address=Address: {street=2nd Street, lane=2nd lane, city=Bangalore, state=Karnataka}}

Similarly, if the elements are missing for the attribute in the class, then their default values would be used.

Input XML: emp.xml. (Please see that the element <name/> and <street /> are missing.)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee company="Sunil Systems.">
    <address>
        <city>Bangalore</city>
        <lane>2nd lane</lane>
        <state>Karnataka</state>
    </address>
    <id>2</id>
</employee>

and the output would be:

Employee: {id=2, name=null, company=Sunil Systems., address=Address: {street=null, lane=2nd lane, city=Bangalore, state=Karnataka}}

From the output, we can see that both 'name' and 'street' values are 'null' which are their default values.

Monday, August 23, 2010

My trip to Udupi

My weekends were just passing... without much happening anything in life... and I got tired of watching TV at home.. so decided to travel to Udupi (Karnataka) where my cousin stays.. and he had invited me several times but could not manage to visit. So just decided to make this time and called him to check whether he is available over the weekend and got a positive reply from him. Booked KSRTC volvo bus from Bangalore to Udupi and back. So, after office work on Friday directly left to Kempegouda bus stop in Majestic. Bus was on right time and was standing at the said platform. Just got in the bus after verifying the ticket with bus conductor. Bus started moving just 10 minutes late than said time which is quite okay. I put-in my ipod and started the journey and do not know when I had slept. Got up some time in the night and my ipod was still playing. Removed it and kept in the bag and again slept back. Got up in the early morning and got to know that bus has just passed Mangalore and would be reaching Udupi in an hour. I called my cousin and asked him to reach the Udupi bus stop. He came in and picked up me to his house.

Since it was a unplanned journey, we decided to visit few places around Udupi and cover as much as possible in two days. So morning we visited the famous Krishna temple in Udupi.



Then moved on to visit other temples around this Krishna temple. Then we went to hotel and had breakfast and tea. It was getting hot and decided to visit some places in the evening, so came back to home and took some rest. However, again watching TV was never on my mind.. so asked him where to go. So, my cousin suggested to watch a movie. I said no, but he convinced me and I somehow agreed to watching a new movie than watching TV. So, we left home to a near by theater, where 3 idiots was running. After that we had lunch then went to famous Malpe beach.

I took some Sun set photos.

Sun set at Malpe beach


















Came back to house after having dinner. That was our end of day one. We went to bed discussing about next day's plan and places to visit (we both knew it would change).

Got up early morning, after having breakfast, went to Light house in Koppa. Spent some time there and moved to some hotel had lunch. In the evening we decided to go to St. Mary's island. To go to this island, we have to go by a boat near by a Malpe port. As we were waiting for the boat to come and pick us, I took some snaps of a new ship being built.






St. Mary's island is special in kind where see different kinds of stones. Looks like some pillars rocks.
and here are some more photos of the same stones.


Once back to Udupi, evening we had some snacks and moved to Manipal end point. Manipal is near by town to Udupi famous for some educational institute. Manipal end point a very well maintained garden in the background of river flowing.














and nature scenes like this one!!!















It was all fun and enjoyed my trip to Udupi. Got into the return bus to Bangalore to reach the Bangalore early morning..... again life started as usual and was preparing to go to office...