Thursday, November 20, 2014

Doodle Jump



Download Doodle Jump for Windows

Doodle Jump is a game developed specially for Android platform. May be you are a keen player of it by now.

Are you searching for Doodle Jump for your Windows PC? If so, you have come to the correct place this time.


 Believe me, the Doodle Jump is now available for your Windows PC. Download from here.


  • No waiting time
  • Absolutely free
  • No Advertisements
  • Direct download

Download Now





How to use Doodle Jump in your PC.


  1. Go to http://doodlejumpdownload.info/
  2. Click on the download button and save the file into your desktop.
  3. Double click on the file and then your game will load.
  4. Enjoy the game on your PC.

Sunday, July 20, 2014

AXIOM

Introduction to AXIOM

Hi,


Today I am going to discuss the basic concepts of AXIOM. First of all we will look at what AXIOM is.

What is AXIOM?

AXIOM stands for AXIs2 Object Model. This is the XML object model used  by Apache AXIS2 web services.


What is the difference from other models?

For processing XML, we usually use Object Models (OM). There are a lot of different kinds of  them to use with Java. AXIS2 uses AXIOM to process XML documents. AXIOM uses pull parsing method (with StAX standard API), while others using push parsing. In pull parsing, the user can handle the process and can control which events to store or delete.


Let's start the journey...

Hope you have read my post on 'XML basics'. Let's use the same XML document for this purpose.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<mobilephones>
    <mobilephone>
        <model>D6563</model>
        <name>Xperia Z2a</name>
        <brand>Sony</brand>
        <released-year>2014</released-year>
        <dimensions>
            <height>137mm</height>
            <width>72mm</width>
            <depth>11mm</depth>
        </dimensions>
        <weight>163</weight>
    </mobilephone>

    <mobilephone>
        <model>VS876</model>
        <name>Lucid 3</name>
        <brand>LG</brand>
        <released-year>2013</released-year>
        <dimensions>
            <height>131.6mm</height>
            <width>66mm</width>
            <depth>9.9mm</depth>
        </dimensions>
        <weight>123.9</weight>
    </mobilephone>
</mobilephones>

  • Start creating a maven project (I hope you are familiar with maven) and create the above XML document (or else you can use your own XML document).
  • Add the following dependencies for the pom.xml file.

<dependency>
 <groupId>org.apache.ws.commons.axiom</groupId>
     <artifactId>axiom-api</artifactId>
     <version>1.2.14</version>
</dependency>
<dependency>
    <groupId>org.apache.ws.commons.axiom</groupId>
    <artifactId>axiom-impl</artifactId>
    <version>1.2.14</version>
</dependency>

  • Then we will create OMElement for the given XML document

Create a java file and build the OMElement using your path to the XML file.

OMElement documentElement= OMElementBuilder(filePath);


Creating the SOAP envelope

SOAPEnvelope envelope = buildSOAP12Envelope(documentElement);


Create AXIOM paths to access elements in the object

OMElement rootElement=documentElement;

System.out.println("\n\n ----------------------- AXIOM Path for selecting the brand of first mobile phone -----------------------");
AXIOMXPath xpath1 = new AXIOMXPath("//mobilephones/mobilephone[1]/model[1]");
OMElement selectedNode1 = (OMElement) xpath1.selectSingleNode(rootElement);  

System.out.println(selectedNode1.getText());

System.out.println("\n\n-----------------------AXIOM Path for selecting names of mobile phones with weight less than 150g-----------------------");
AXIOMXPath xpath2 = new AXIOMXPath("//mobilephones/mobilephone[weight<150]/name");
List<OMElement> list=xpath2.selectNodes(rootElement);
for(OMElement o:list){
   System.out.println(o.getText());
}
System.out.println("\n\n-----------------------AXIOM Path for selecting brand of mobile phones which starts with \'Xperia\'-----------------------");
AXIOMXPath xpath3 = new AXIOMXPath("//mobilephones/mobilephone[starts-with(name, 'Xperia')]/brand");
List<OMElement> list2=xpath3.selectNodes(rootElement);

for(OMElement o:list2){                 
   System.out.println(o.getText());
}


This will be the output generated by the above file.


AXIOM Path for selecting the brand of first mobile phone
D6563

AXIOM Path for selecting names of mobile phones with weight less than 150g
Lucid 3
Galaxy S Duos 2

AXIOM Path for selecting brand of mobile phones which starts with 'Xperia'

Sony

You can check with any XPath expressions. Check my post on XPath for more details abount XPAth.
See you again with another session soon.

Saturday, July 19, 2014

JAXB Introduction

Learn JAXB

What is JAXB?

JAXB stands for Java Architecture for XML Binding. To work with JAXB you do not need to know about XML parses. You can get either XML document from Java object or vice versa. 

There are two mechanisms in JAXB.

  • Marshalling

Marshalling is converting Java object to XML.

  • Unmarshalling

Unmarshalling is converting XML to Java Object.



Convert Java Object to XML (Marshalling)

Conversion of Java to XML is not a big task with JAXB. We will go in to this step by step.

First of all, we need to create a Java bean. That bean class is the class which we are going to convert. 

Today I am going to write a simple Java bean for Employee. I am going to convert it in to an XML document.

Let's start work. 


import javax.xml.bind.annotation.*;

import java.util.List;

/**
 * Created by dinithi on 7/18/14.
 */

public class Employee {

    private int id;
    private String name;
    private int age;
    private double salary;

    private List<Dependency> dependencies;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public List<Dependency> getDependencies() {
        return dependencies;
    }

    public void setDependencies(List<Dependency> dependencies) {
        this.dependencies = dependencies;
    }
}

For the above bean class, I need the id of the employee to be a attribute and name,age and salary to be elements. So how can the JAXB understand whether this is an attribute or element, or else what is the root element?
For the above purpose, JAXB uses annotations. There are several annotations used by JAXB. We will discuss them one by one.


JAXB Annotations

@XmlRootElement
Defines the root of the XML document which needs to be created. The class name will be the name of the root.
@XmlElement
Defines the property must be an element of the XML document
@XmlAttribute
Defines the property must be an attribute of the XML document
@XmlTransient
Defines the property should not be included in to the XML document
@XmlType
Defines the order of the elements in the XML document
@XmlSeeAlso
Includes another Java bean to the XML document
@XmlElementWrapper(name='<name'>)
Wraps existing set of elements with a tag specified by the name
@XmlID
Specifies a unique identity element or attribute


Let's modify our example bean class with annotations.


import javax.xml.bind.annotation.*;

import java.util.List;

/**
 * Created by dinithi on 7/18/14.
 */
@XmlRootElement
@XmlType(propOrder = { "id", "name", "age","salary","dependencies"})
public class Employee {

    private int id;
    private String name;
    private int age;
    private double salary;

    private List<Dependency> dependencies;

    public int getId() {
        return id;
    }

    @XmlAttribute
    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    @XmlElement
    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    @XmlTransient
    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    @XmlElement
    public void setSalary(double salary) {
        this.salary = salary;
    }

    public List<Dependency> getDependencies() {
        return dependencies;
    }

    @XmlElementWrapper(name="dependencies")
    @XmlElement(name = "dependency")
    public void setDependencies(List<Dependency> dependencies) {
        this.dependencies = dependencies;
    }
}


I think you can understand what happened. We have included some annotations to the Java bean. Look at the places where I add them.If you have declared your properties as private, you need to annotate them with the help of getters or setters. Or else, if you have public modifier you can annotate just in front of the property as follows.


@XmlAttribute public int id;

I think you can assume the output of this. What will be the output of the wrapper element? Can you guess?

It will create a tag with name dependencies and inside it there will be a list of dependency tags. So you may be thinking how the XML document will create a list of dependencies without knowing the values it need.

For that we need to create a bean class for dependency.


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

/**
 * Created by dinithi on 7/18/14.
 */
public class Dependency {

    private int id;
    private String name;
    private int age;


    Dependency(){}

    Dependency(int id, String name, int age){
        this.id=id;
        this.name=name;
        this.age=age;
    }

    public int getId() {
        return id;
    }

    @XmlAttribute
    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    @XmlElement
    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    @XmlElement
    public void setAge(int age) {
        this.age = age;
    }
}

This Dependency class will provide necessary details for the dependencies list in the Employee class.

Up to now, we have completed our bean classes which we need to convert to XML document.

Let's write a Java class to convert this bean classes to XML.


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

/**
 * Created by dinithi on 7/18/14.
 */
public class JAXBJavaToXml {

    public static void main(String[] args) {
        Employee employee1=new Employee();
        employee1.setName("Mathan");
        employee1.setAge(45);
        employee1.setId(1);
        employee1.setSalary(75000.00);

        ArrayList<Dependency> dependencyArrayList=new ArrayList<Dependency>();
        Dependency dependency1=new Dependency(1,"Mirasha",7);
        dependencyArrayList.add(dependency1);

        Dependency dependency2=new Dependency(2,"Albian",3);
        dependencyArrayList.add(dependency2);

        employee1.setDependencies(dependencyArrayList);

        try {
            JAXBContext  jaxbContext=JAXBContext.newInstance(Employee.class);
            Marshaller marshaller=jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

            File xmlFile=new File("outputXML.xml");

            marshaller.marshal(employee1,xmlFile);
            marshaller.marshal(employee1,System.out);


        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
}


When you compile and run this class it will create an XML document with the relevant details. 

This is the output generated form the above bean classes.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee id="1">
    <name>Mathan</name>
    <salary>75000.0</salary>
    <dependencies>
        <dependency id="1">
            <age>7</age>
            <name>Mirasha</name>
        </dependency>
        <dependency id="2">
            <age>3</age>
            <name>Albian</name>
        </dependency>
    </dependencies>
</employee>



Convert XML to Java Object (Unmarshalling)

And also we can convert an XML into a Java object.


Let's talk about unmarshalling with my next session. See you soon...

Friday, July 18, 2014

Learning XPath

Hi all...

Today we are going to learn about XPath.

XPath introduction

First of all we will try to understand, what is XPath. 

XML has a hierarchical structure with parent and child nodes. So we should have a mechanism to navigate through these tags to get their values. XPath is used to do this task. XPath is a major component of XSLT and you must have a good knowledge about it to write XSLT documents.

Let's see how XPath is going to work.

XPath path expressions

The top most element in an XML document is called the root node. The root node is expressed in XPath as '/'.

Let's go to deep with an example. I am going to choose my old favorite example XML document.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/home/dinithi/workspace/PhoneShop/src/StyleSheetXML.xsl"?>
<mobilephones>
 <mobilephone id="1">
  <model>D6563</model>
  <name>Xperia Z2a</name>
  <brand>Sony</brand>
  <released-year>2014</released-year>
  <dimensions>
   <height>137mm</height>
   <width>72mm</width>
   <depth>11mm</depth>
  </dimensions>
  <weight>163g</weight>
  <feature>
   <os>Android v4.4.2</os>
   <CPU>Quad-core 2.3 GHz</CPU>
   <browser>HTML 5</browser>
  </feature>
 </mobilephone>

 <mobilephone id="2">
  <model>VS876</model>
  <name>Lucid 3</name>
  <brand>LG</brand>
  <released-year>2012</released-year>
  <dimensions>
   <height>131.6mm</height>
   <width>66mm</width>
   <depth>9.9mm</depth>
  </dimensions>
  <weight>123.9g</weight>
  <feature>
   <os>Android v4.4.2</os>
   <CPU>Quad-core 1.2 GHz</CPU>
   <browser>HTML</browser>
  </feature>
 </mobilephone>


 <mobilephone id="3">
  <model>S7582</model>
  <name>Galaxy S Duos 2</name>
  <brand>Samsung</brand>
  <released-year>2013</released-year>
  <dimensions>
   <height>121.5mm</height>
   <width>63.1mm</width>
   <depth>10.6mm</depth>
  </dimensions>
  <weight>118g</weight>
  <feature>
   <os>Android v4.2</os>
   <CPU>Dual-core 1.2 GHz</CPU>
   <browser>HTML</browser>
  </feature>
 </mobilephone>
</mobilephones>


You can use /mobilephones or /mobilephones/mobilephone/model to select from the root node.
Or you can select as model and it will search for all the nodes with model tags. This way is not good for large XML documents.
If you select as //model if you really do not know the root node or you know only a part of your XML.

To select attributes, we can use @ symbol. For example if you need to get the id attribute you can use @id or for all attributes @* .

A dot '.' can represent current node and '..' can represent the parent node.

I know it is a mess for the beginners. You can understand clearly with the following examples. Try them in your own.

Ex 1:

Get the model of the first mobile phone. So we can write the path as follows.

//mobilephone[1]/model/text()

This will give the result as Text='D6563' .

Let's examine this syntax.
First it goes to the mobilephone tag and get the list of mobilephones. We have used [1] here. So it will check for the first mobilephone tag. Then /model is going inside the model tag and text() is getting the output value.

Ex 2:

Get the brand of mobiles phones which were released before 2014.

//mobilephone[released-year<2014]/brand/text()

This will give the result as Text='Samsung'.

Ex 3:

Get the brands of all phones which have 'Xperia' as a part of its name.

//mobilephones/mobilephone[starts-with(name, 'Xperia')]/brand

This will give the result as Element='<brand>Sony</brand>' .

Ex 4:

Get the count of available mobile phone nodes.


count(//mobilephones/mobilephone/brand)

This will give the output as Double='3.0' .

Ex 5:

Get the name of the mobile phone which has the id as 1.


//mobilephone[@id='1']/name/text()

This will give the output as Text='Xperia Z2a' .


Hope you can understand what is done by XPath. There are more functions available to work with XPath. Try to get sum, sort like expressions...

See you again...

Tuesday, July 15, 2014

Validating XML

Hi...

Today, we will discuss further more about XML.

Validating XML

We can use either schemas or DTD (Document Type Definition) to validate an XML file. DTD is an obsolete way of validating XML. Schema is widely used now and has better features than in DTD and they are more powerful in may ways.
  • The strongest point of schema is, it supports data types. Therefore the inputs of the XML document can be validated against the data types.
  • Also schema can have restrictions to input data. Therefore it is secured to use schema.


Writing XSD (XML Schema Definition)

First we need to write an XML schema to validate the XML document.

We will create an XSD for the following XML document.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/home/dinithi/workspace/PhoneShop/src/StyleSheetXML.xsl"?>
<mobilephones>
 <mobilephone IMEI="78909875433455">
  <model>D6563</model>
  <name>Xperia Z2a</name>
  <brand>Sony</brand>
  <dimensions>
   <height>137mm</height>
   <width>72mm</width>
   <depth>11mm</depth>
  </dimensions>
  <weight>163</weight>
  <feature>
   <os>Android v4.4.2</os>
   <CPU>Quad-core 2.3 GHz</CPU>
   <browser>HTML 5</browser>
  </feature>
 </mobilephone>

 <mobilephone IMEI="0876666339988">
  <model>VS876</model>
  <name>Lucid 3</name>
  <brand>LG</brand>
  <dimensions>
   <height>131.6mm</height>
   <width>66mm</width>
   <depth>9.9mm</depth>
  </dimensions>
  <weight>123.9</weight>
  <feature>
   <os>Android v4.4.2</os>
   <CPU>Quad-core 1.2 GHz</CPU>
   <browser>HTML</browser>
  </feature>
 </mobilephone>
</mobilephones>

Let's start writing XSD.

XSD elements

There are two types of element types.

  • Simple elements

Simple element is an element with no child elements and it does not have attributes. It can be defined in XSD as follows.

<xs:element name="model" type="xs:string"/>

The available data types in XSD are,
  • xs:string
  • xs:integer
  • xs:boolean
  • xs:decimal
  • xs:date
  • xs:time
Simple elements can have default values or fixed values.

<xs:element name="model" type="xs:string" fixed="D6563"/>

<xs:element name="model" type="xs:string" default="D6563"/>

  • Complex elements

XSD complex types can have child elements and attribute values.
In our XML example, <dimensions> tag has its child elements. So it is a complex element.


<xs:element name="dimensions">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="width" type="xs:string"/>
      <xs:element name="height" type="xs:string"/>
      <xs:element name="depth" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

XSD attributes

XSD attributes syntax is similar to simple type.

<xs:attribute name="IMEI" type="integer"/>

Additionally it can have a value for required field. If the attribute is mandatory required field must contain the value 'yes'.

<xs:attribute name="IMEI" type="integer" required="yes"/>

Restrictions for elements

Now, you can write an XML schema with simple and complex elements. Let's see how we can add restrictions for elements.

We can use <xs: restriction > tag to restrict our element. We can have minimum value, maximum value


<xs:element name="weight">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="50"/>
      <xs:maxInclusive value="500"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>


Also you can use the following restriction methods.


<xs:pattern value="[a-zA-Z]"/>

<xs:minLength value="5"/>
<xs:maxLength value="8"/>


Hope you got an idea about writing XML schema for a given small XML document.


See you with more in the next post....

Wednesday, July 9, 2014

XML Basics

XML

Basic XML

Hi,
I would like to represent you about the basics of XML which I came across by Googling and participating the WSO2 Boot Camp.

Let's start with the most important question.

What is XML?

  • XML stands for eXtensible Markup Language.
  • Unlike HTML(Hyper Text Markup Language), XML is for carrying data and not for displaying data.
  • XML is not a database, but it can store data.
A good definition I found from w3schools about XML is, XML is a software- and hardware-independent tool for carrying information.

XML does not have any predefined tags. Users can define their own tags. If you just double click on a XML document, your browser just display the text. 

Sample XML code


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<mobilephones>
    <mobilephone>
        <model>D6563</model>
        <name>Xperia Z2a</name>
        <brand>Sony</brand>
        <released-year>2014</released-year>
        <dimensions>
            <height>137mm</height>
            <width>72mm</width>
            <depth>11mm</depth>
        </dimensions>
        <weight>163</weight>
    </mobilephone>

    <mobilephone>
        <model>VS876</model>
        <name>Lucid 3</name>
        <brand>LG</brand>
        <released-year>2013</released-year>
        <dimensions>
            <height>131.6mm</height>
            <width>66mm</width>
            <depth>9.9mm</depth>
        </dimensions>
        <weight>123.9</weight>
    </mobilephone>
</mobilephones>


You can notice the first line of this document. Actually the XML document itself does not need it. That line is for the XML parser to identify this document as an XML file. We will discuss about 'parser' in the next post.

A well formatted XML document

  • Every staring must have a matching ending tag.
  • The elements must be properly nested. (The last opened tag must close first.)
  • None of the special characters such as '<' and '&' must not be in the values.
  • A single root element must contain all the elements.
  • Tags are case sensitive, so we need to use correct format for all starting and ending tags.
  • The attribute values must be quoted. 

Comments in XML

The syntax is similar to HTML comments.

<!-- This is a comment -->

Empty elements in XML

<empty_tag></empty_tag> can be replaced by <empty_tag/>

Attributes 

Elements can have attributes. Mostly they are for representing meta data.

Eg: 



<student name="Anne" age="29" mobile="071xxxxxxx">
</student>

Bur it is encouraged to avoid using attributes. Because,

  • it gives a flat structure 
  • cannot have multiple values for a single attribute.
  • hard to expand. 

Assume we need to insert another mobile number for the student 'Anne'. Using attributes it is not possible. Here is the solution for that.



1
2
3
4
5
6
7
8
<student>
 <name>Anne</name>
 <age>29</age>
 <mobiles>
  <mobile>071xxxxxxx</mobile>
  <mobile>078xxxxxxx</mobile>
 </mobiles>
</student>

In this example you can see '<mobiles>' tag has been introduced. In XML those elements must be wrapped with a single sub root element.


Namespaces in XML

XML namespaces are used to provide uniquely identified names and attributes in an XML document.


1
<e:element xmlns:e="http://www.element.org/element">

And also we can use default namespace to avoid using the prefix every time in sub elements.



1
2
<element xmlns="http://www.w3.org/TR/html4/">
</element>



Hope to see you with the next XML session...