Phong Vu wrote:
> 
> Thanks for your reply Keith,
> 
> I can modify PathAssociation to what you recommended. But how does that
> help me map the element <aspect name="pathAssociation" sequence="1">
> to the PathAssociation class?
> 

Do you only have one type of aspect?

<class name="com.acme.PathAssociation">
  <map-to xml="aspect"/>
  <field name="property" type="com.acme.Property"
set-method="addProperty"/>
</class>

If you have other types of aspects...such as:

<aspect name="someOtherType" ...>

Then...no you'll need XSLT...we don't currently have built-in support
for choosing
a class based on attributes. It would be a nice and powerful feature
though.

To solve this problem many people use a wrapper class, such as:

public class Aspect {

   public static final String PATH_ASSOCIATION = "pathAssociation";

   private String _name = null;

   private Aspect _instance = null;

   public void setName(String name) {
      _name = name;
      getInstance();
   }

   public Aspect getInstance() {

      if (_instance != null) 
         return _instance;

      if (_name == null) return null;
      if (_name.equals(PATH_ASSOCIATION)) {
         _instance = new PathAssociation();
      }
      return _instance;
   }

   public void addProperty(Property property) {
      if (_instance != null) {
          _instance.addProperty(property);
      }
   }
} 


You can make your wrappers as fancy or as simple as you need. It's a bit
more work, but it gives you quite a bit of control. 

And of course your XSLT solution will also work nicely.

Thanks,

--Keith

> Can you show me how the mapping.xml would look like?
> 
> Thanks again.
> Phong
> 
> --
> Phong Vu
> [EMAIL PROTECTED] - email
> (604) 974-0996 ext. 2380 - voicemail/fax
> 
> ---- Keith Visco <[EMAIL PROTECTED]> wrote:
> >
> >
> > Hi Phong...
> >
> > Currently our mapping framework cannot directly handle your situation.
> >
> > Can you modify PathAssociation such that is has an addProperty method:
> >
> > something like:
> >
> > addProptery(Property property) {
> >    if ("pathAssociationId".equals(property.getName())) {
> >       setPathAssociationId(property);
> >    }
> >    else if (...) {
> >      ...
> >    }
> > }
> >
> > I know it's not ideal, but it would actually be more efficient than
> > using XSLT.
> >
> > --Keith
> >
> > Phong Vu wrote:
> > >
> > > Hi,
> > >
> > > I have an existing project where xml <-> java object conversion would
> > > be very helpful.
> > >
> > > The problem that I am having is that  some legacy XML files that
> > I have
> > > appear difficult for Castor to map into java objects. At least the
> > XML
> > > formats are different from the examples given.
> > >
> > > I'm just wondering if the mapping can be specified in Castor or else
> > > I have do to some XSLT translation  on the XML file before Castor
> > can
> > > use it?
> > >
> > > Below is a simplified description of my problem.
> > >
> > > I would like the element with the attribute name "pathAssociation"
> > to
> > > map to the class PathAssociation.
> > >
> > > Is this possible? If so what would the mapping.xml file look like?
> > >
> > > Any feedback would be greatly appreciated.
> > >
> > > /*listing for pathAssociation.xml**********************************/
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > >    <aspect name="pathAssociation" sequence="1">
> > >       <property name="pathAssociationId" type="string">1853</property>
> > >       <property name="componentAgreementTypeId"
> > >                 type="string">652</property>
> > >    </aspect>
> > >
> > > /**listing for PathAssociation.java *********************/
> > >    class PathAssociation{
> > >         Property pathAssociationId;
> > >         Property componentAgreementTypeId;
> > >
> > >         public void setPathAssociationId(Property value){
> > >           ...
> > >         }
> > >         public void setComponentAgreementTypeId(Property value){
> > >           ...
> > >         }
> > >
> > >         public Property getPathAssociationId(){
> > >           ...
> > >         }
> > >         public Property getComponentAgreementTypeId(){
> > >           ...
> > >         }
> > >
> > >    }
> > >
> > > /**************listing for Property.java *****************************/
> > >    class Property{
> > >         String name;
> > >         String type;
> > >
> > >         public void setName(String value){
> > >           ...
> > >         }
> > >         public void setType(String value){
> > >           ...
> > >         }
> > >
> > >         public String getName(){
> > >           ...
> > >         }
> > >         public String getType(){
> > >           ...
> > >         }
> > >
> > >    }
> > >
> > >
> > > ___________________________________________________________
> > > FREE voicemail, email and fax, all in one place.  Sign Up Now! 
>http://www.mybc.com
> > >
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > >         unsubscribe castor-dev
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >       unsubscribe castor-dev
> >
> >
> 
> ___________________________________________________________
> FREE voicemail, email and fax, all in one place.  Sign Up Now! http://www.mybc.com
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to