Sunday, September 14, 2008

Creating jaxb files from the opentravel schema

Probably the easiest way to deal with complicated xml documents is to use the jaxb tool from java. jaxb converts a schema definition from .xsd format to java classes. If you are trying to use jaxb on the opentravel.org schema there are a few gotchas:
  • First, since the schema is so large, there are a few places where there are duplicate element names.
  • Second, since the schema was not developed with jaxb in mind, there are a few element names (such as 'class') that are not legal in java.
Luckily, I wrote a utility that makes it a lot easier to use jaxb, called ota-schema-tools. This is part of the open source ota-tools project. You can download these tools at the sourceforge project page. After you have downloaded the tools, unzip them into a directory.

After a few quick steps, the schema tool is ready to go:
1. Download the sch
ema(s) that you want to use from opentravel.org and drop it in the ota-schema-zip-files directory:

2. Edit the ota.xsd file in the ota-schema-tools/config/2008A directory to include only the schema you will need (or leave it alone to compile all the schema). For example, here I only want to use the OTA_Ping messages:

3. Run the schema tool:
If jaxb is not in your classpath, you will need to tell ant where it is wi
th the -Djaxb.home=/location-of-jaxb-home flag. Also, if you are compiling a lot of schemas, you will have to set the ANT_OPTS=javac-options property. Here is what I type:
ota-schema-tools> export ANT_OPTS=-Xmx512m ota-schema-tools> ant -Djaxb.home=/usr/local/java/web/glassfish/ dist

When I run this command I get the error: OTA_TourInformation.xsd and OTA_RailAvailRS.xsd is not a part of this compilation.
No problem. The jaxb configuration file is set up to fix problems in the entire schema. Just remove these lines from the ota-schema-tools/config/2008A/jaxb/binding.xjb file:

I deleted these highlighted lines. Now run this line again from your command prompt:
ant -Djaxb.home=/usr/local/java/web/glassfish/ dist
Voila! Your schema are compiled and neatly packaged in a opentravel2008a.jar file.

Now that wasn't that hard, was it!

25 comments:

Jonathan Vila said...

Hello.

I've tried to download the OTA tools project but in sourceforge there is no file uploaded.

Do you know where I can find that software to download ?

Thanks a lot.

Don Corley said...

Johnathan,
For now, you will have to go to http://ota-tools.svn.sourceforge.net/viewvc/ota-tools/

and click on 'Download GNU tarball'.

If you are using linux, you probably know how to untar an archive, if you are using windows, just google 'untar windows' for a list of utilities that can 'unzip' the archive.

I will try to get the ota-tools project admin to post a zip file.

Thanks

Don

lsri8088 said...

Hello,
I'm trying to create the schema api 2005B. I've also tested with the 2006A and 2008A (your example), but they always give me errors.

Can you help?

These are, after following your instructions, errors 2008A scheme:

[echo] /usr/java/jaxb"
[mkdir] Created dir: /home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/src
[echo] Compiling the schema...
[xjc] Compiling file:/home/arfernandez/Documents/incidencias/138%20[Evento%20Tools,%20nuevo%20api%20OTA]/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/ota.xsd
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1011 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_SimpleTypes.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 489 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_RailAvailRS.xsd
[xjc]
[xjc] [ERROR] Property "Duration" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 165 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_TourInformation.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 355 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details

BUILD FAILED
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:87: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:37: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:24: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/buildspec.xml:190: unable to parse the schema. Error messages should have been provided

lsri8088 said...

Hello,
I'm trying to create the schema api 2005B. I've also tested with the 2006A and 2008A (your example), but they always give me errors.

Can you help?

These are, after following your instructions, errors 2008A scheme:

[echo] /usr/java/jaxb"
[mkdir] Created dir: /home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/src
[echo] Compiling the schema...
[xjc] Compiling file:/home/arfernandez/Documents/incidencias/138%20[Evento%20Tools,%20nuevo%20api%20OTA]/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/ota.xsd
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1011 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_SimpleTypes.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 489 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_RailAvailRS.xsd
[xjc]
[xjc] [ERROR] Property "Duration" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 165 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_TourInformation.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 355 of file:/home/arfernandez/Documents/incidencias/138%20%5BEvento%20Tools,%20nuevo%20api%20OTA%5D/ota-tools/trunk/java/ota-schema-tools/build/2008A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details

BUILD FAILED
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:87: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:37: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/build.xml:24: The following error occurred while executing this line:
/home/arfernandez/Documents/incidencias/138 [Evento Tools, nuevo api OTA]/ota-tools/trunk/java/ota-schema-tools/buildspec.xml:190: unable to parse the schema. Error messages should have been provided

Don Corley said...

lsri8088,
The error you are getting is due to a problem in the design of the open travel schema. You should not get an error if you build the schema using the ant script in the ota-tools site. The ant script does an xsl transformation that fixes this problem before running the jaxb tool.
Don

lsri8088 said...

Hello,

True, I have solved it as you indicate.
Another mistake I had was related to the jaxb-api.jar version. I had to use the version of May 2005, for more recent versions XmlElementRef indicated that the method was not "required".

Thank you very much for your reply. Your post I have been helpful.

Greetings from Spain :)

Kyrto Gyz said...

Hi, I don't see build.xml from which to run the tool.

Kyrto Gyz said...

Hi, I don't see build.xml from which to run the tool.

Kyrto Gyz said...

Hi, I don't see build.xml from which to run the tool.

Don Corley said...

Kyrto,

The build.xml file is in the git repository on sourceforge. You can clone the repository by typing:
git clone git://ota-tools.git.sourceforge.net/gitroot/ota-tools/ota-tools

If you are looking for java bindings for the opentravel schema, I would recommend using the bindings in the jibx schema library, here:
http://jibx.sourceforge.net/schema-library/opentravel/index.html

Hope this helps!

Don

amalEspoire said...

hi, i followed your steps but instead of glassfish i put tomcat then t got Build successful,
but i don't know where can i find the generated jar file

Don Corley said...

Amal,
Try to use jaxb instead of glassfish. Download jaxb and enter the path to your jaxb installation:
ant -Djaxb.home=/path/to/jaxb/ dist
I hope this helps!
Don

Vinit Prajapati said...

dist:

unzip:
[unzip] Expanding: /home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/ota-schema-zip-files/OTA2013A_Publication.zip into /home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/unzip

moveschema:

moveotherschema:

movecodetable:

movetest:

moveflatschema:

movedocs:

copyall:

copybindings:
[xslt] Transforming into /home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema

fixall:

copycodetable:

jaxbschema:
[echo] Compiling the schema...
[xjc] Compiling file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/ota.xsd
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1830 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_Lists.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 6790 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1846 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_Lists.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 7590 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1846 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_Lists.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 5818 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 1846 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_Lists.xsd
[xjc]
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 5727 of file:/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build/2013A/temp/jaxb/schema/OTA_CommonTypes.xsd
[xjc]
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details

BUILD FAILED
/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build.xml:92: The following error occurred while executing this line:
/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build.xml:33: The following error occurred while executing this line:
/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/build.xml:24: The following error occurred while executing this line:
/home/vinit/Docs/Hotel/ota-xsd/ota-schema-tools/buildspec.xml:190: unable to parse the schema. Error messages should have been provided

config/binding.xjb for 2013A





















ota.xsd



Kindly help me

Thank you.

D Entertainment said...

Đấu Tôn cũng sắc mặt trầm xuống, chờ đợi Nhạc Thành phân phó.

- Các huynh đệ, mọi người xông lên đi, nhất định phải giết Cuồng Sư môn, Vạn Kim Môn, nữ nhân của Hồ Điệp cốc, Tuyệt Tình cốc sẽ là của chúng ta

- Ta nhìn thấy ở trong Hồ Điệp cốc và Tuyệt Tình cốc có rất nhiều người rất đẹp, mọi người mau tiến lê thanh âm nhơ lớp dongtam
mu moi ra hom nay
tim phong tro
http://nhatroso.com/
nhạc sàn
tổng đài tư vấn luật
văn phòng luật hà nội
tổng đài tư vấn luật
thành lập công ty trọn gói
http://we-cooking.com/
chém gió
trung tâm tiếng anhsong truyền tới, U Minh tông, Luyện Dược sư công hội những cường giả Đấu Tôn, còn có Đấu Hoàng Đấu Vương đều điên dại lao đến Hạo Đặc thành.

- Đại Song, Tiểu Song chuẩn bị bố trận.

Nhạc Thành cất tiếng nói, trên khuôn mặt của hắn nở ra một nụ cười.

- Nhạc Thành, chúng ta chuẩn bị nghênh địch sao?

Nhìn mảng khí tức bốc lên, Lê Giang Nam không khỏi lo lắng mà nói.

- Chờ một chút là được rồi, vẫn còn sớm.

Nhạc Thành mỉm cười nói.

U Minh tông và Luyện Dược sư công hội mấy vạn người liên tiếp gào thét, nhân số đã trở nên đông nghịt.

Diana Azura said...

This was so useful to read and learn from this blog.
primary school web design

Steve Smith said...

Great and Useful Article.

Online Java Training

Online Java Training from India

Online Java Training

Online Java Training From India

Java Training Institutes in Chennai

Java Training in Chennai

Arjun Rishi said...

Very useful post. Thanks for sharing.

html course in chennai

mary Brown said...

Java Articles | IT Technical Articles | Dot Net Framework Articles |
JavaScript Articles | Java Training Institutes | Single Page Application Development

Best Multimedia (Dilsukhnagar Arena) said...

good course to learn..web design course

John Alert said...

I have read your blog its very attractive and impressive. I like it your blog.


JavaEE Training in Chennai JavaEE Training in Chennai

Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai

John Alert said...

Online JSF Training JSF Training Institutes in Chennai Java Training Institutes Java Training Institutes Struts2 Training Institutes in Chennai Struts2 Training Institutes in Chennai EJB Training Institutes in Chennai EJB Training Institutes in Chennai

Anu Sri said...

I read your post. Very nice. Thanks for sharing.

web design course in chennai

حسام داود said...

شركة تسليك مجاري بالرياض
شركة تسليك مجارى بالرياض
level تسليك المجاري بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
شركة تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مجالس بالرياض
تنظيف فلل بالرياض
ابى شركة تنظيف بالرياض

hassan emad said...

شركه عزل اسطح
شركه عزل مائى
شركه عزل الاسطح
شركه عزل اسطح
شركه عزل مائى
عزل خزانات
شركه عزل خزانات
شركة عازل خزانات بالرياض
شركه عزل مسابح
شركة عزل خزانات
شركه عزل بالرياض
عزل فوم
شركة عزل فوم
شركة عزل فوم بالرياض
شركة عزل الفوم
كشف تسربات المياه
تسربات المياه
شركة تسربات بالرياض
شركه كشف تسربات بالرياض
شركة رش مبيدات
شركة رش مبيدات بالرياض
رش مبيدات
رش مبيدات بالرياض

for IT the said...

Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

Hibernate Online Training Hibernate Online Training Spring Online Training Spring Online Training Spring Batch Training Online Spring Batch Training Online