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:

vilojona 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.

Unknown 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

Unknown 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.

Unknown 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

Unknown 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

Unknown 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.

Unknown 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.

Unknown said...

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

Unknown said...

Very useful post. Thanks for sharing.

html course in chennai

Best Multimedia said...

good course to learn..web design course

Unknown said...

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

web design course in chennai

Unknown said...

Excellant Article...Really Helpful....
SEO Experts in Bangalore
Top SEO Company in Bangalore
low cost seo packages

Unknown said...


Nice article . Thank you for this beautiful content, Keep it up. Techavera is the best Institute in Noida for all these main Courses below:-
Python training in noida
SAP HANA Training in Noida.
Angular JS Training in Noida.
PLC SCADA Training in Noida.
Embedded Systems training in noida
Tally ERP 9 Training Institute in Noida.
java training center in noida


Visit us For Quality Learning.Thank you

ramesh said...

I simply want to mention I am just all new to blogging and site-building and truly loved you’re web page. Almost certainly I’m planning to bookmark your site . You really have outstanding stories. Many thanks for revealing your webpage.…

Azure Training in Chennai

Azure Training in Bangalore

Azure Training in Hyderabad

Azure Training in Pune

Azure Training | microsoft azure certification | Azure Online Training Course

Azure Online Training

Technogeekscs said...

Thanks for Sharing a Very Informative Post & I read Your Article & I must say that is very helpful post for us.
Data Science Course in Pune
Python Classes in Pune
AWS Training in Pune
Best RPA Training in Pune

varchasasunny said...

Thank you for this article because it’s really informative, I love reading your article and I hope that I will read some more about this stuff, it’s really informative and very entertaining. Thanks a lot and have a great day. >.Looking for best visual effects training in Hyderabad? For courses in VFX film making, Digital advertising, Web Design, Graphic Design, 2D & 3D Animation & Visual Effects visit Arenadilshuknagar.

gracemila said...

Thanks for sharing this amazing piece of content and this post helps me a lot and I really like it. Its amazing thing. Looking for best vfx training in Hyderabad? For courses in VFX film making, Digital advertising, Web Design, Graphic Design, 2D & 3D Animation & Visual Effects visit Maacdilsukhnagar.

jeetuTh said...

great blog, keep posting valuable information. Full Stack Course In Pune