tags:

views:

1591

answers:

3

I was trying to add the xml schema to an existing EJB project. JAXB is used to bind the XML-Schema to java class. As we are going to use the search engine to crawl thru DTO when EJB is in session.

I could not find any direct approach as to map entity class file to XML-Schema.

The only way we could achieve so far is to create the Web Services, generate the WSDL which generates xml-schema(XSD) and then parsing the xsd file thru jaxb(xjc command) to create java class files. Now using mapping-binding.xml file we can map both xml and java class file.

But now again the issue is to how map this to entity class.

\

This is what we want to achieve ::

XML Data Object with XML Schema, (This is already present in the JAXB specification). - Entity Bean then Extends or has an interface to this JAXB object. - All Persistence functions are managed by the Entity Bean... - The Entity Bean would then contain the XML Marshalling and UnMarshalling features found in JAXB.. - A Value Object could be retrieved in binary or XML form from the Entity Bean Object. - A JSP could easily extract the XML Schema and XML Data from the Value Object and perform operations on it such as XSL transformations.

My argument is that the Entity Beans have no standard way for interfacing to JAXB objects.

Castor may be the solution, but then again we have to implement web services or using castor JDO’s.

I found xstream to be pretty useful as it uses a converter class in which you can call the entity bean class objects and generate a xml file. but i was not preferring to use another class but incorporate the functions in existing bean class.

Can you help me in this regard?

Thanks in advance

-Sid

+1  A: 

Tightly coupling your data model (entity beans) to your XML interface might not be the best idea in the world; it prevents you from changing one without changing the other.

I'm not 100% sure I understand what you are trying to do, but I think there is a way to instruct JAXB to extend classes rather than create new ones. You could create your Entity Beans as normal, and have your JAXB-generated beans extend those with the extra information.

I can say that getting Entity beans instances from somewhere other than your persistence layer (such as deserializing them from XML) is going to be a huge problem for you.

Also note that using XML to communicate between Java applications (such as between a JSP/Servlet and EJB layer) is a bad idea; the marshaling and added verbosity of the XML buys you very little; serializing objects via RMI (which is what EJB will do for you) would be much easier to implement, test and maintain.

davetron5000
Thanks for you help and suggesetion dave..Please Review...As ive added more info
Siddharth Gaur
A: 

i will tell you what I am actually trying to achieve. m creating a search engine which will be evoked during the EJB in session and will use crawler thru the DTO's and get the snapshot in XML format. search wil be on diff criteria.

Lucene is one of the search engine tool but then it uses its own properties and files (will act more like standalone)

I already have DTO's which are used by webservices to communicate between PHP & Java application (EJB-layer). I wanted to re-use those DTO's in jaxb as a crawler to get the output from tables in XML which i am not able to do as JAXB uses its own generated classes thru xml-schema. Like u said i have yet not found a way to instruct JAXB to bean classes.

Siddharth Gaur
A: 

EclipseLink JAXB (MOXy) can be used to map JPA entities to XML.

For more information see:

Blaise Doughan