Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 22741 invoked from network); 12 Feb 2005 13:52:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Feb 2005 13:52:27 -0000 Received: (qmail 15521 invoked by uid 500); 12 Feb 2005 13:52:25 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 15489 invoked by uid 500); 12 Feb 2005 13:52:25 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 15474 invoked by uid 99); 12 Feb 2005 13:52:25 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from essemtepe.nada.kth.se (HELO smtp.nada.kth.se) (130.237.222.115) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 12 Feb 2005 05:52:23 -0800 X-Authentication-Info: The sender was authenticated as danielf using PLAIN at smtp.nada.kth.se Received: from [83.226.251.175] (localhost [127.0.0.1]) (authenticated bits=0) by smtp.nada.kth.se (8.12.10/8.12.11) with ESMTP id j1CDqJon002101; Sat, 12 Feb 2005 14:52:19 +0100 (MET) Message-ID: <420E0A39.4070101@nada.kth.se> Date: Sat, 12 Feb 2005 14:52:57 +0100 From: Daniel Fagerstrom User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: XMLBeans and request attributes References: <8b8d97d205021111567cee763d@mail.gmail.com> In-Reply-To: <8b8d97d205021111567cee763d@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Irv Salisbury wrote: > This is really a follow up to some questions I asked earlier about XML > in request attributes. I wanted to show how I went about solving what > I needed, and to get feedback if there is a better way. > > To recap, my basic problem was that I wanted to call internal > pipelines and pass them XML. The cocoon: protocol does not support > POST, so the easiest way I was told to use request attributes. I > decided to incorporate XMLBeans into the mix to make my life easier. > > So, all of my business objects in the system are XMLBeans that have > been generated from a set of XMLSchema files. I have a series of > internal pipelines that can generate XML of these schemas. To "pass" > the objects around, I use a combination of flowscript and a generator > I wrote that generates XML from a request attribute that happens to be > an XMLObject. (Borrowing from the RequestAttributeGenerator) > > So, here is a simple flow snippet: > > var sessionInfo = getSessionInfo(); > cocoon.request.setAttribute( "sessionInfo", sessionInfo ); > cocoon.sendPage( "internal/style/catalog" ); > > So, the goal of the getSessionInfo call is to create a SessionInfo > object, which happens to be an XMLBeans object. Here is the > getSessionInfo method: > > function getSessionInfo() { > var pipelineUtil = cocoon.createObject( PipelineUtil ); > var xmlSaxHandler = > XmlBeans.getContextTypeLoader().newXmlSaxHandler( > > SessionInfoDocument.type, null ); > pipelineUtil.processToSAX( > "internal/sessionInfo/getSessionInfo", > null, > xmlSaxHandler.getContentHandler() ); > var sessionInfo = xmlSaxHandler.getObject(); > return sessionInfo; > } > > Then, my generator for internal/style/catalog is such: > > > > > > This really seems to work great. Has anyone had experience with doing > this before? Does this seem like a good idea? Anything I am missing > here? Seem like a reasonable approach. You can simplify things a little bit by embeding the XMLBean in an object that implements org.apache.excalibur.xml.sax.XMLizable, http://svn.apache.org/viewcvs.cgi/excalibur/trunk/components/xmlutil/src/java/org/apache/excalibur/xml/sax/XMLizable.java?view=markup The toSAX method could be implemented in terms of the XMLObject.save method. Both JXTG and the XModuleSource http://wiki.apache.org/cocoon/XModuleSource are XMlizable aware, so you don't need any specialized generator. Also, if you are using trunk, it might be interesting to know that Rhino 1.6, (that is used for flowscripts) has extensive XMLBean support: http://marc.theaimsgroup.com/?t=110009028500003&r=1&w=2. > The main reason for choosing XMLBeans was the ability to go back and > forth from Java - XML easily. Boy, if this was merged with Hibernate, > that would be something! They are at least discussing it: http://wiki.apache.org/xmlbeans/V2Features. /Daniel