Posts

Showing posts from January, 2012

Learn XML Schema by Example: 2 Polymorphism

Image
In the previous blog, Learn XML Schema by Example: 1. Complex type , I introduced the very simple idea of ComplexType in Schema. In this blog, I am going to introduce idea of polymorphism which is one of the very important concept in Object orientation. As shown in the above figure, I need Address to be replaced by AUAddress or USAddress in the instance xml file. All the Address, USAddress and AUAddress are complex types in the XML schema. These types are defined in the address.xsd file as shown in the following code. <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.ojitha.org/address" targetNamespace="http://www.ojitha.org/address" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="AUAddress"> <xs:complexContent> <xs:extension base="Address"...

Learn XML Schema by Example: 1. Complex type

Image
XML Schema development is one of the major requirements for the Web services. It is time to get rid of the RPC style and move to DOCUMENT style. First of this series I would like to start with complex type. <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.ojitha.org" targetNamespace="http://www.ojitha.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="process"> <xs:complexType> <xs:sequence> <xs:element name="person" type="personType"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="personType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name=...

SAAJ Unit testing client for JAX-WS web services

Image
JAX-WS is the simplest java web services. In this blog, I would like to use first example explained in the book Java Web Services: Up and Running , by Martin Kalin ( thanks Martin, great book). Here the SEI and SBI created from the above book. SEI package com.ojitha.ws.ex1; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style=Style.RPC) public interface TimeServer { @WebMethod String getTimeAsString(); @WebMethod long getTimeAsElapsed(); } SBI package com.ojitha.ws.ex1; import java.util.Date; import javax.jws.WebService; @WebService(endpointInterface="com.ojitha.ws.ex1.TimeServer") public class TimeSeverImpl implements TimeServer { @Override public String getTimeAsString() { return new Date().toString(); } @Override public long getTimeAsElapsed() { return new Date().getTime(); } } The main objective of this blog is to introduce a SAA...

Tip: Java Instance initialization is critical

One of my previous blogs, I showed how the instances are initiated in the Java, if you wish see the  Java Constructor Loading Tips . In this blog, I will give an example, where developer can confused. For example, the following code compiles but throws the NPE in the runtime. package com.ojitha.green; /** * @author Ojitha * */ public class Child { //singleton public static final Child GIRL = new Child(); private Child() {} private static final Boolean GENDER = true; private Boolean gender = GENDER; public Boolean isMale(){ return gender;} public static void main(String... args){ String gender = Child.GIRL.isMale() ? "Female":"Male"; System.out.println(gender); } } In the line 17, you get the exception. At the time of creating GIRL, initializing the object variable is happen after the constructor is called. At the time of the GIRL singleton instance is created, Boolean type gender variable is already initialized to null, that cause to the N...