You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alexander Berezhnoy <al...@splc.ru> on 2005/07/12 07:18:35 UTC

Pipeline model generalization

Hi!
Recently I've realized, that the main feature of the Cocoon is the 
pipelines, not XML.
In Cocoon components generate and process events, and those are SAX events.

Why not to try generalize this model in order to support any custom 
event? That could be Java Beans, for example.
In my opinion, that would be a great powering for Cocoon.

Alexander.

-- 
Alexander Berezhnoy,
Chief Architect
SmartPhone Labs, LLC
http://www.smartphonelabs.com


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


Re: Pipeline model generalization

Posted by Ralph Goers <Ra...@dslextreme.com>.
Not a bad idea, but the pipeline is really a bunch of chained 
org.xml.sax.ContentHandler objects.  Whatever custom events you have 
would have to extend that. If you look at the methods they are very XML 
centric.  In practice, what you are suggesting has been implemented by 
using tools like Betwixt or Castor to convert the JavaBeans into SAX 
events, achieving the same effect.  To do this with betwixt simply requires:

/**
 * Generates an XML representation of a bean using Betwixt.
 * The object to be serialized is retrieved from a request attribute
 *
 * @version $Revision: 1.2 $
 * @created August 2003
 */
public class BeanGenerator extends AbstractGenerator
{
    protected ServiceManager manager;
    private Object           bean;
 
    /**
     * Sets up the BeanGenerator. Parameters will be read and the bean 
will be
     * generated by calling the get method of the configured class.
     *
     * @param resolver the source resolver
     * @param objectModel the Cocoon object model
     * @param src ignored by the BeanGenerator
     * @param par parameters to the get method
     * @throws ProcessingException
     * @throws SAXException
     * @throws IOException
     */
    public final void setup(SourceResolver resolver, Map objectModel, 
String src,
                      Parameters par)
        throws ProcessingException, SAXException, IOException
    {
        super.setup(resolver, objectModel, src, par);
 
        Request request = 
(Request)objectModel.get(ObjectModelHelper.REQUEST_OBJECT);
        this.bean = 
request.getAttribute(BusinessDelegate.DATA_TRANSFER_OBJECT);
        if (this.bean == null)
        {
            throw new ProcessingException("No object was provided to 
serialize");
        }
    }
 
    /**
     * Generate XML data.
     * @throws SAXException
     */
    public final void generate()
        throws SAXException
    {
        try
        {
            SAXBeanWriter beanWriter = new 
SAXBeanWriter(this.contentHandler);
            beanWriter.setWriteEmptyElements(false);
            beanWriter.setWriteIDs(false);
            beanWriter.getXMLIntrospector().setElementNameMapper(new 
CapitalizeNameMapper());
            
beanWriter.getXMLIntrospector().setAttributesForPrimitives(true);
            beanWriter.write(this.bean);
        }
        catch (Exception e)
        {
            getLogger().error("Cannot generate XML for " + bean, e);
            SAXException saxException = new SAXException(e.getMessage());
            throw saxException;
        }
    }
}


Ralph

Alexander Berezhnoy wrote:

> Hi!
> Recently I've realized, that the main feature of the Cocoon is the 
> pipelines, not XML.
> In Cocoon components generate and process events, and those are SAX 
> events.
>
> Why not to try generalize this model in order to support any custom 
> event? That could be Java Beans, for example.
> In my opinion, that would be a great powering for Cocoon.
>
> Alexander.
>


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