You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jozsa Kristof <dy...@kami.vein.hu> on 2001/11/20 19:52:00 UTC

OT: Transforming EJB data to XML for Cocoon

Sorry for being slightly offtopic. I'm developing a J2EE application (my
diplom work, not a commercial project), and I'm using Cocoon for web/wap
output. 

I'm using the JBoss application server, and looking for a suitable way for
converting business data coming from my CMP entity beans into XML to be able
to pass it to Cocoon. I'm trying to use Castor XML directly on my entity
beans at the moment, but without any success so far. Is there any other,
maybe easier / more natural solution for doing that work? Maybe anyone has
did such successfully in the past, and can show me any piece of example code
for that?

I can post my tries and failures with Castor privately if someone's familiar
with that topic..

Thanks much,

Christopher
-- 
.Digital.Yearning.for.Networked.Assassination.and.Xenocide

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: OT: Transforming EJB data to XML for Cocoon

Posted by Werner Guttmann <We...@morganstanley.com>.
Josza,

as with EJBs in general, you always have some freedom in the way you implement
your solution, i.e. whether you use session beans only, session and bean-managed
entity beans, session and container-managed entity beans, session beans and
castor, value objects, etc. In other words, there's no single correct solution.

If there's anything that applies in all the cases, it's the use of a session
bean as an entry point, i.e. a facade. In your particular case, you could for
example use a business delegate that would call the session bean to source some
data you want to display. That business delegate (we called them transformers in
our team here) would implement the XMLFragment interface. In the code of the
transformers toSAX() method you could e.g.

1) invoke a method of your session bean, which returns some value objects (e.g.
a a List)
2) insert the start tag of some outer xml element into your SAX stream
3) iterate through your List of value objects, and invoke each value object's
toSAX() method.
4) insert the end tag of some outer xml element into your SAX stream.

Each of the value objects will - on invocation - insert its state to the SAX
stream as a series of SAX events executed through the ContentHandler passed as
an argument.

Hope this helps.
Werner

Jozsa Kristof wrote:

> Dear Werner,
>
>   I do use entity beans to store my data. Now, if I get it right, you
> suggest writing a Cocoon Transformer, which calls my entity beans' toSAX()
> methods by hand, while implementing the XMLFragment or XMLizable interface
> in the entity beans? (I'm using Cocoon 2.0rc2).
>
>   So far I wrote some session beans to handle a couple of entity beans - I'm
> using joined tables and difficult queries on many tables, so I
> shouldn't/cannot use the enitity beans directly from Cocoon. Can I implement
> the XMLizable interface in my session bean then?
>
> Is that the right way of outputting xml data from entity beans and from
> complex searches for Cocoon?
>
> Best regards,
> Christopher Jozsa
> --
> .Digital.Yearning.for.Networked.Assassination.and.Xenocide


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: OT: Transforming EJB data to XML for Cocoon

Posted by Jozsa Kristof <dy...@kami.vein.hu>.
Dear Werner,

  I do use entity beans to store my data. Now, if I get it right, you
suggest writing a Cocoon Transformer, which calls my entity beans' toSAX()
methods by hand, while implementing the XMLFragment or XMLizable interface
in the entity beans? (I'm using Cocoon 2.0rc2). 

  So far I wrote some session beans to handle a couple of entity beans - I'm
using joined tables and difficult queries on many tables, so I
shouldn't/cannot use the enitity beans directly from Cocoon. Can I implement
the XMLizable interface in my session bean then? 

Is that the right way of outputting xml data from entity beans and from
complex searches for Cocoon?

Best regards,
Christopher Jozsa
-- 
.Digital.Yearning.for.Networked.Assassination.and.Xenocide

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: OT: Transforming EJB data to XML for Cocoon

Posted by Werner Guttmann <We...@morganstanley.com>.
Josza,

youmight want to have a look at the XMLFragment interface (available both for
Cocoon 1.8 and 2.0) which facilitates the creation of SAX events (in the case of
Cocoon 2.0) for your EJBs.

One idea might be to have the entity bean (in case you are using any) or the
value objects (if you are relying on session beans) implement the relevant
method in this interface

void toSAX(ContentHandler handler)    for Cocoon 2.0

and include the output of this method via a standard <xsp:expr< tag in your XSP
page(s).

<xsp:page ...>
   <page>

     <xsl:logic>
       SomeDataTransformer transformer = new SomeDataTransformer(...);
     </xsp:logic>
     <...>
     <xsp:expr>transformer</xsp:expr>
   </page>
</xsp:page>

The contract in the above sample is that SomeDataTransformer implements the
XMLFragment interface and Cocoon 2.0 will calll the toSAX() method on your
<transformer>. In your toSAX() method, simply use the ContentHanlder instance
provided to generate the SAX events as required.

SomeDataTransformer could be a class that uses a business delegate to go to your
session bean which returns a list of domain objects. In its toSAX() method, you
could simply iterate over the list of domain objects returned and invoke the
toSAX() method recursively.

Hope this helps.

Werner

Jozsa Kristof wrote:

> Sorry for being slightly offtopic. I'm developing a J2EE application (my
> diplom work, not a commercial project), and I'm using Cocoon for web/wap
> output.
>
> I'm using the JBoss application server, and looking for a suitable way for
> converting business data coming from my CMP entity beans into XML to be able
> to pass it to Cocoon. I'm trying to use Castor XML directly on my entity
> beans at the moment, but without any success so far. Is there any other,
> maybe easier / more natural solution for doing that work? Maybe anyone has
> did such successfully in the past, and can show me any piece of example code
> for that?
>
> I can post my tries and failures with Castor privately if someone's familiar
> with that topic..
>
> Thanks much,
>
> Christopher
> --
> .Digital.Yearning.for.Networked.Assassination.and.Xenocide
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: OT: Transforming EJB data to XML for Cocoon

Posted by Aurelien <au...@fractals.be>.
I know you've asked this for some time, but I found your post just 
recently.

Well, I am using JBoss/tomcat (catalina)/cocoon2 also, and I've used a 
very simple scheme so far, but it works great, and could be generalized 
very easily.

Regarding J2EE, I'm akin to using the façade pattern when it comes to 
querying the data, and CMP Beans only when I really need to. That's 
because, as you know, CMP Beans use RMI to set/get their values and 
that's of course very, very, very, slow. The façade pattern is a session 
bean that provides value objects to get access the J2EE-managed data; 
there I'm using plain SQL to get things even faster. A façade can also 
have some data storing methods, but that's not their main purpose.

Now, the EJB->XML conversion takes place in a logic sheet where I'm 
using the standard xsp mechanisms to create the XML, eg:

Data [] myData = facade.getData ( request.getParameter ( "foo" ) );

<data>
<xsp:logic>
   for ( int i=0; i &lt; myData.length; i++ ) {
     <entry>
       <xsp:attribute name="att1"><xsp:expr>myData[i].getAtt1 
()</xsp:expr></xsp:attribute>
       <xsp:attribute name="att2"><xsp:expr>myData[i].getAtt2 
()</xsp:expr></xsp:attribute>
     </entry>
   }
</xsp:logic>
</data>

In fact, the <xsp:logic> part could be automatized with introspection, 
and embedded in the logicsheet with a custom tag (though I've not done 
that, I'm pretty sure it's feasible).

The xsp-generated code is very efficient, and this solution has the 
advantage of being simple, cocoon-only and rather flexible.

Well anyway, I think this comes all a little too late, doesn't it ?

Candide

Le mardi 20 novembre 2001, à 07:52 PM, Jozsa Kristof a écrit :

> Sorry for being slightly offtopic. I'm developing a J2EE application (my
> diplom work, not a commercial project), and I'm using Cocoon for web/wap
> output.
>
> I'm using the JBoss application server, and looking for a suitable way 
> for
> converting business data coming from my CMP entity beans into XML to be 
> able
> to pass it to Cocoon. I'm trying to use Castor XML directly on my entity
> beans at the moment, but without any success so far. Is there any other,
> maybe easier / more natural solution for doing that work? Maybe anyone 
> has
> did such successfully in the past, and can show me any piece of example 
> code
> for that?
>
> I can post my tries and failures with Castor privately if someone's 
> familiar
> with that topic..
>
> Thanks much,
>
> Christopher
> --
> .Digital.Yearning.for.Networked.Assassination.and.Xenocide
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>