commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cheong Chung Onn <>
Subject Re: How does using Interface for mapping object-to-xml works in Betwixt?
Date Thu, 29 Jan 2004 12:43:36 GMT
Hi Robert,

After tweaking my code, the xml output is some how broken again. I have 
spend a few hours on it but cant decipher it. Essentially i have two 
problems here.

Problem 1, which is the one you been trying to help me earlier ie.  if 
I would to use an Interface class, Betwixt doesn't seems to dump out 
the Superclass attributes (PersonName is superclass of Person) even 
though i have declared an interface dot.betwixt  file for both 
PersonIntf and PersonNameIntf

Problem 2,  A Custom Creator is the only way to update a member object 
(Person.address), is this true? If this is not true then, is it 
possible for me to map the <address> attribute to a method in 
Person.setAddress(String street1, int postalcode) so as to avoid the 
use of a CustomCreator class? This is to avoid breaking the 
encapsulation by re-implementing the  private member class (Address) 
again in the Custom creator class.

I have created a AddressCreator but i can't figure out how to extract 
the values for the <address> element ie. both postalcode and street1 
from the mapping element. I used many combinations of  
mappingElement.getAttributes() but all return a null value, pls refer 

Below are the output and my test case.

Thanks once again.


PS: I am using the nightly built version, downloaded about 2 days ago.

Output from my test
Result:  //without interface

Result with interface: //with interface, superclass (PersonName) 
attributes namely <first> & <last> are missing

=== PersonNameIntf.betwixt
<?xml version="1.0" ?>
<info primitiveTypes="element">
         <element name="person-name">
             <element name="first" property="first"/>
             <element name="last" property="last"/>

<?xml version="1.0" ?>
<info primitiveTypes="element">
     <element name="person">
public interface PersonNameIntf {

     public String getFirst();
     public void setFirst(String first);

     public String getLast();
     public void setLast(String last);

     public void setPersonName(String firstname, String lastname);

public interface PersonIntf extends PersonNameIntf{

     public int getAge();
     public void setAge(int age);
     public AddressIntf getAddress();

public interface AddressIntf {
     public String getStreet1();
     public int getPostalcode();
     public void setStreet1(String st);
     public void setPostalcode(int pc);

     //convenience method
     public void setAddress(String st, int pc);

public class PersonName implements PersonNameIntf {

     private String first;
     private String last;

     public PersonName() {}

     public PersonName(String first, String last){
         this.first = first;
         this.last = last;

     public String getFirst() {return this.first;}
     public void setFirst(String first) {this.first = first;}

     public String getLast() {return this.last;}
     public void setLast(String last) {this.last = last;}

     public void setPersonName(String firstname, String lastname) {
         this.first = firstname;
         this.last = lastname;

     public String toString() { return last + ", " + first;}



public class AddressCreator implements {

     /** Creates a new instance of ServiceTicketCreator */
     public AddressCreator() {

     public Object 
beanCreationChain) {

         dumpInfo(elementMapping, readContext, beanCreationChain);

             System.out.println("Creating a new Address");
             System.out.println("    address:" + 
             System.out.println("    street:" + 
             System.out.println("    postalcode:" + 

             return new Address("new street", 111111);

         return beanCreationChain.create(elementMapping, readContext);

     private void 
         System.out.println("===Begin dump===");
         System.out.println("Element mapping info...");
         System.out.println("first value=" + 
         System.out.println("last value=" + 
         System.out.println("age value=" + 
         System.out.println("street1 value=" + 
         System.out.println("postal value=" + 

         System.out.println("Mapping type:"+ elementMapping.getType());
         int l = elementMapping.getAttributes().getLength();
         System.out.println("number of attr " + l);
         for (int i=0; i < l; i++){
             System.out.println("name=" + 
elementMapping.getAttributes().getQName(i) +
                              ", type=" + 
elementMapping.getAttributes().getType(i) +
                              ", value=" + 

         System.out.println("\nReadContext Info...");
         Object bean = readContext.getBean();
         System.out.println("Bean class:" + ((bean == null)?null: 
         java.util.Map vars = readContext.getVariables();
         System.out.println("Variables..." + vars);
         System.out.println("Classname Attrs..." + 
readContext.getClassNameAttribute() );
         System.out.println("==end dump== \n\n");

     private class Address implements AddressIntf {
         private String street1;
         private int postalcode;

         /** Creates a new instance of Name */
         public Address() {}

         public Address(String street1, int postalcode){

         public String getStreet1() {return street1;}
         public void setStreet1(String street1) {this.street1 = street1;}

         public int getPostalcode() {return postalcode;}
         public void setPostalcode(int postalcode) {this.postalcode = 

         public void setAddress(String street1, int postalcode){

         public String toString(){return "street1="+street1+", 


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message