Hi Josh,

What I've been doing so far is putting this into a file called
'valueobject-custom.xdt' in the merge directory:

    public void getXML(org.jdom.Element el) throws
org.dentaku.exception.XMLBeanException {
        try {
          <XDtEjbPersistent:forAllPersistentFields superclasses="false"
valueobject="<XDtEjbValueObj:valueObjectMatch/>">
            addChild(el, "<XDtMethod:methodNameWithoutPrefix/>",
org.apache.commons.beanutils.BeanUtils.getSimpleProperty(this,
"<XDtMethod:propertyName/>"));
          </XDtEjbPersistent:forAllPersistentFields>
        } catch (Exception e) {
            throw new org.dentaku.exception.XMLBeanException("error creating
DOM", e);
        }
    }

This generates code for one of my value objects that looks like:

    public void getXML(org.jdom.Element el) throws
org.dentaku.exception.XMLBeanException {
        try {
            addChild(el, "Remarks",
org.apache.commons.beanutils.BeanUtils.getSimpleProperty(this, "remarks"));
            addChild(el, "BillingStatus",
org.apache.commons.beanutils.BeanUtils.getSimpleProperty(this,
"billingStatus"));
            addChild(el, "Amount",
org.apache.commons.beanutils.BeanUtils.getSimpleProperty(this, "amount"));
            addChild(el, "Id",
org.apache.commons.beanutils.BeanUtils.getSimpleProperty(this, "id"));
        } catch (Exception e) {
            throw new org.dentaku.exception.XMLBeanException("error creating
DOM", e);
        }
    }

You'll notice the call to 'addChild' right away.  This is declared in a base
class that the value object inherits from.  You can do this with a tag such
as:

 @ejb:value-object name="VOBean" extends="org.dentaku.ejb.beans.vo.VOBase"

...and the class itself:

  public abstract class VOBase implements XMLBean {
    protected static void addChild(org.jdom.Element el, String name, Object
prop) {
        org.jdom.Element child = new org.jdom.Element(name);

        if (prop instanceof XMLBean) {
            ((XMLBean)prop).getXML(child);
        }
        else if (prop instanceof java.util.Date) {
            child.addContent(dateFormat.format(prop));
        }
        else {
            child.addContent(prop.toString());
        }

        el.addContent(child);
    }
  }

XMLBean simply allows polymorphic access to the various beans.  You can flesh
out addChild for specific special formatting cases that you need.

Reverse serialization is handled with something like:

    public void setFromNode(Node node) throws IllegalAccessException,
InvocationTargetException {
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            String name = child.getNodeName();
            String value = child.getFirstChild().getNodeValue();
            if (name != null && value != null) {
                setProperty(name, value);
            }
        }
    }

Again, I'd like to get this into the XDoclet source tree sooner than later,
and focused on Hibernate instead of VOs.  Any input/concerns/etc appreciated.

brian

> -----Original Message-----
> From: Josh Rehman [mailto:[EMAIL PROTECTED]
> Sent: Friday, August 08, 2003 11:03 AM
> To: Brian Topping
> Subject: Re: [Hibernate] Moving Hibernate objects with SOAP
> 
> 
> Hi Brain. Comments below.
> 
> Brian Topping wrote:
> > One of the things that I currently do is use XDoclet to 
> generate inline
> > transforms for going back and forth from XML to entity.  
> You end up with
> > hardcoded serializers, which are very fast, but I don't have enough
> > experience with it yet to know what extended maintenance is 
> going to be
> > like.  It would theoretically be possible to generate a 
> schema/dtd that
> > goes with the serializers, and one maintenance process 
> might rename the
> > then-current serializers and schema pair to something new 
> as the system
> > grew (giving the ability to support backwards compatibility).  Some
> > environments won't need all this though.
> 
> This sounds like a neat idea, and may lessen the maintenance headache 
> somewhat. Can you post some example XDoclet code? I'd like to 
> get a feel 
> for how large the serialization code is.
> 
> 
> >  
> > Note that I am currently using it with XDoclet value 
> objects (DTOs, if I
> > understand the two correctly) from entity beans.  So what I 
> have will
> > need a bit of work to make it work with Hibernate POJOs, 
> but not much
> > and I plan on doing that work within the next few days.  As it works
> > today, simply changing your XDoclet tags for your entities 
> rewrites the
> > serializers automagically.  The same thing will happen with 
> the POJOs
> > when I am done.
> 
> I'd like to know how this works out for you.
> 
> Thanks,
> Josh
> 
> 


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to