cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piroumian, Konstantin" <KPiroum...@flagship.ru>
Subject XML to JavaBean mapping (was: Cocoon, XForms, etc.)
Date Mon, 18 Feb 2002 13:04:15 GMT
Hi, all!

Concluding our discussion on Cocoon/XForms/Struts, I can state that we
definitely need a good XML to JavaBeans mapping/binding framework. What are
the options:

1. Castor (or something like that)
Yes, Castor can do that job and it's fine, but has limits, as it is said at
Castor web site, that for some complicated cases additional XSL
transformation will be required. Also, it seems to me that Castor moves
forward too slowly - 1.5 year ago it was  version 0.8, now it's only
0.9.3... What is the reason: conceptual problems or the version numbering
style?

2. XSLT (especially, using Xalan extensions)
XML to JavaBean mapping and vice versa can can be achieved using XSLT and
scripting. It looks like this:

<?xml version="1.0"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:mbean="my.MyBean"
    extension-element-prefixes="mbean"
    version="1.0"
>

  <lxslt:component prefix="mbean">
    <lxslt:script lang="javaclass" src="my.MyBean"/>
  </lxslt:component>

  <xsl:template match="server">
    <xsl:value-of select="mbean:server(string(@domain))"/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="mbean">
    <xsl:value-of select="mbean:create(string(@code),string(@name))"/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="mbean/attribute">
    <xsl:value-of select="mbea7n:attribute(string(@name),text())"/>
  </xsl:template>

  <xsl:template match="mbean/operation">
    <xsl:for-each select="parameter">
      <xsl:value-of select="mbean:parameter(text())"/>
    </xsl:for-each>
    <xsl:value-of select="mbean:operation(string(@name))"/>
  </xsl:template>

</xsl:stylesheet>

So, I think that every complicated case can be handled this way. More over,
it seems that JavaBeans can be instantiated on fly even if they have no
default contructor. The problems I see are perfomance and dependency on a
specific XSLT processor.

3. Something self implemented
As I remember, ExFormula had some Mapper that performs mapping XML data to
JavaBeans. Is there a need for a self implemented framework if ready
solutions can meet the needs?

So, I'd prefer to use the 2nd way - XSLT for data binding. Can anybody
please comment on this? Is there anything that I did not take into account?

Best regards,

Konstantin Piroumian
Leading Software Developer

Protek Flagship LLC
Phone: + 7 095 795 0520 (add. 1288)
Fax: + 7 095 795 0525
E-mail: kpiroumian@flagship.ru
http://www.protek.com

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message