Hi,

I have checked in the first cut under http://svn.apache.org/viewvc?rev=601501&view=rev. With these changes, we now use JAXB databinding to deal with POJOs (including simple and complex types). By the JAXB Java to XML default mapping, POJOs are supported in line with the JavaBeans patterns with the flowing rules.

1) There is a protected or public no-arg constructor
2) A property is either a public field or public setter & getter. Even for Collection type, the setter is required.
3) The property can not be an interface
4) Circular object reference is not supported
5) References to the same object are flattened

One caveat is that it brings the jaxb-api and jaxb-impl as core dependencies (about 1MB). We could try to implement the default Java/XML mapping by ourselves if that's desirable.

There are also other things we need to improve, for example, how to render a JAXB object as XMLStreamReader. The quick and dirty way is to marshal the JAXB object into a byte array and create XMLStreamReader out of it. We could even use the fast-infoset to help the performance of the round trip.

Thanks,
Raymond

----- Original Message ----- From: "Jean-Sebastien Delfino" <[EMAIL PROTECTED]>
To: <tuscany-dev@ws.apache.org>
Sent: Tuesday, November 27, 2007 1:18 PM
Subject: Re: Data transformation from/to POJO


Raymond Feng wrote:
I think there are two options:

1) Make the JAXB databinding as the default databinding for POJOs (simple and complex types).

What about doing that? any drawback?


2) Keep the POJO databindings and implement the POJO<-->XML transformers using JAXB-impl

Thanks,
Raymond

----- Original Message ----- From: "Jean-Sebastien Delfino" <[EMAIL PROTECTED]>
To: <tuscany-dev@ws.apache.org>
Sent: Monday, November 26, 2007 3:26 PM
Subject: Re: Data transformation from/to POJO


Raymond Feng wrote:
Hi,

I just did a test to see how JAXB-RI handles the POJO without any annotations. The result seems to be promising.

I started with a POJO:

public class MyBean {
   private int age;
   private String name;
   private List<String> notes = new ArrayList<String>();

   public int getAge() {
       return age;
   }
   public void setAge(int age) {
       this.age = age;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public List<String> getNotes() {
       return notes;
   }
   public void setNotes(List<String> notes) {
       this.notes = notes;
   }
}

The following test case is then successful.

public void testPOJO() throws Exception {
   JAXBContext context = JAXBContext.newInstance(MyBean.class);
   StringWriter writer = new StringWriter();
   MyBean bean = new MyBean();
   bean.setName("Test");
   bean.setAge(20);
   bean.getNotes().add("1");
   bean.getNotes().add("2");
JAXBElement<Object> element = new JAXBElement<Object>(new QName("http://ns1";, "bean"), Object.class, bean);
   context.createMarshaller().marshal(element, writer);
   System.out.println(writer.toString());
Object result = context.createUnmarshaller().unmarshal(new StringReader(writer.toString()));
   assertTrue(result instanceof JAXBElement);
   JAXBElement e2 = (JAXBElement)result;
   assertTrue(e2.getValue() instanceof MyBean);
}

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:bean xsi:type="myBean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:ns2="http://ns1";><age>20</age><name>Test</name></ns2:bean>



Good that it seems promising :) what do I need to do to get the JaxB to XML transformer to pick up the Item bean in the store tutorial?

--
Jean-Sebastien

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
Jean-Sebastien

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to