Monday, 22 June 2009

JAXB Custom Data Binding

In a previous post I experimented consuming WCF web services using various Java WS frameworks and tools. As pointed out by Alex, the one that I missed out was wsimport which is bundled as part of JSE6.

Like many other tools, it supports both Ant task and command line interface (CLI). The CLI for wsimport is quite simple - in my case I generated the source code and client stub library like so:

D:\Program Files\Java\jdk1.6.0_11\bin>wsimport -d /temp/generated -s /temp/gensrc -keep http://localhost/PromoService.svc?wsdl
parsing WSDL...

generating code...

D:\Program Files\Java\jdk1.6.0_11\bin>
All the rest is similar to the results of IntelliJ shown in my previous post. There are two problems with the generated which is a data/value object:
  1. string fields are generated as JAXBElement<String>
  2. dateTime fields are generated as XMLGregorianCalendar
I want to use core java data types on the data objects so that they can be easily integrated with other frameworks without having to do conversion. Examining my schema (on http://localhost/PromoService.svc?xsd=xsd2) the PromoInfo complex type is defined as


It is obvious that the xs:string and xs:dateTime were not converted into the desired java types. To solve my problems I specified customised JAXB binding rules in an external file - custombinding.xml like so


The attribute generateElementProperty="false" on line 2 tells wsimport not to generate JAXBElement but to generate native java data types instead.

The javaType element on line 3 defines the binding between "xs:dateTime" and "java.util.Date" because by default xml dateTime binds to javax.xml.datatype.XMLGregorianCalendar as shown here.

Once the binding is defined, rerunning the wsimport tool with the -b switch will produce the desired output:
D:\Program Files\Java\jdk1.6.0_11\bin>wsimport -d /temp/generated -s /temp/gensrc -b /temp/custombinding.xml http://localhost/PromoService.svc?wsdl
parsing WSDL...

generating code...
Note: D:\temp\gensrc\org\w3\_2001\xmlschema\ uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

This time the generated looks much better:
public class PromoInfo {

    @XmlElement(name = "PromoDateTime", type = String.class)
    @XmlJavaTypeAdapter(Adapter1 .class)
    @XmlSchemaType(name = "dateTime")
    protected Date promoDateTime;
    @XmlElement(name = "PromoDescription", nillable = true)
    protected String promoDescription;
    @XmlElement(name = "PromoName", nillable = true)
    protected String promoName;
    @XmlElement(name = "PromoVenue", nillable = true)
    protected String promoVenue;

Thursday, 18 June 2009

A Racist Job Market

My friend forwarded me an interesting article today - Ethnic names hinder job seeking: report. I have also seen similar reports on Channel 7 two days in a row.

The result of the research shows that job applicants with Anglo-Saxon names received more calls than those with Indigenous, Chinese, Middle Eastern or Italian names. Whether the business owners/employment agencies/HR people are consciously racist or not is debatable. However, it is proven that collectively the job market in Australia is racist.

The rationale behind this phenomenon is complex and multifaceted. Let's assume people are not intentionally or consciously racist for a while. There could be several reasons behind it:

Typecasting - Once someone sees a 'foreign' name, he/she automatically assign a profile to it. Of course, there could be good and bad aspects of this profile depending on the reviewer's personal experiences and belief. The biggest disadvantage of such profiles for foreign names is perhaps the assumption that they do not speak English well. Hence we see many job ads have requirements like "excellent communication skills" to deter non-English speakers from even applying. True, Australia is a country of immigrants and there are many new immigrants who cannot speak English well. However, majority of them are quick and keen learners, especially those who are actively seeking jobs. And let's not forget the vast number of 2nd-, 3rd-... generations of immigrants who identify themselves as true-blue Aussies.

"Not Made Here" syndrome - People are more comfortable with what they are already familiar with. A foreign name automatically triggers off a level of fear and set off the defense mechanism subconsciously (or unconsciously if you prefer Freudism). Many people tend to prefer interacting with people with similar backgrounds and interests forgetting the advantages of diversity, especially in a work environment. There are a large number of small businesses in Australia which have only a handful of employees in the workplace. Hiring people with the same traits/profile that everyone else is comfortable with becomes an important criterion.

Media - The mass media is the most powerful brainwashing machine in the world and often, by criticising their countries of origin the media cast negative lights on the ethnic minorities who live in Australia.

Although we have been told not to judge a book by its cover, people cannot easily shake off the racial prejudice that have been intrinsically wired into our brain and heart as a result of millions of years of evolution. To break down the racial barrier, we have to actively and consciously broaden our horizon; seek more interactions with all walks of life; treat individuals as individuals; do upon others that which you will have them do onto you.

Thursday, 11 June 2009

One Year On

I started this blog one year ago in June 2008. I have been using Google Analytics to track the site. Here are some visitor (mostly from IT and development communities) trends collected in the last year or so.

Browsers used:

OS used:

Browser + OS used:

Java support:

As of June 2009 the top 5 visited posts on this blog site are:

  1. Consuming WCF Web Service Using Java Client, July 2008
  2. Consuming Web Services from Android, August 2008
  3. IE8 + Outlook Web Access = Problems, May 2009
  4. WPF Splash with ProgressBar, July 2008
  5. How To Add Unicode Fonts to N95, September 2008

There are a couple of trends worth noticing:

  1. Firefox has a bigger market share than IE among the technical users and rightly so. It will be interesting to see how Chrome will measure up against the top two. Chrome has certainly great momentum considering it has only been launched 9 months ago and already in 3rd place.
  2. Java support is not as ubiquitous as I first thought. I wouldn't develop my next RIA business application on JavaFX any time soon. So right now I will stick to ZK (and maybe SmartSWT) and wait for HTML5 to take over.
  3. It only took less than a month for the IE8 + Outlook Web Access = Problems post to claim the no. 3 spot. It just shows how bad IE8 is.
  4. The post on number 5 spot has far more comments than the rest. It proves once again that non-technical people are far more social