License     Codehaus     OpenEJB     OpenJMS     OpenORB     Tyrex     
 

Main
  Home
  About
  Features
  Download
  Maven 2 support
  API
  DTD & Schemas
  Recent changes
  RSS news feed

Development/Support
  Mailing Lists
  SVN/JIRA
  Contributing
  Support
  Prof. services

Related projects
  Spring ORM support
  Spring XML factories

XML
  Using XML
  XML Mapping
  XML FAQ
  XML HOW-TOs
  Custom Handlers
  Best practice

XML Code Generator
  Code Generator
  Properties
  Custom bindings
  Ant task
  Schema Support
  Example

JDO
  Introduction
  Using JDO
  JDO Config
  Types
  JDO Mapping
  JDO FAQ
  JDO Examples
  JDO HOW-TOs
  Other Features
  JDO sample JAR

Advanced JDO
  Caching
  OQL
  Trans. & Locks
  Design
  KeyGen
  Long Trans.
  Nested Attrs.
  Pooling Examples
  LOBs
  Best practice

More
  Presentations
  The Examples
  3rd Party Tools
  JDO Tests
  XML Tests
  Configuration
  Tips & Tricks
  Full JavaDoc
  CastorWiki
 
 

About
  License
  Contributors
  Marketplace
  Status, Todo
  Changelog
  Library
  Contact
  Project Name

  



Integrating Castor with other (open source) projects


Apache Cocoon
    A scenario
    Sitemap configuration
        Component definition
        Usage within a pipeline
        Gotchas
    References


Apache Cocoon

Project home

Apache Cocoon is a web publishing framework built around the concepts of separation of concerns and component-based web development.

As part of this framework, Cocoon provides a component, the CastorTransformer, that marshalls an object hierarchy (for which a mapping file or a class descriptor hierarchy exists) to XML and inserts it as a stream of SAX events into a Cocoon pipeline.

Further information on the integration of Apche Cocoon and Castor can be found here.

A scenario

Let's imagine the listed derivative department of an investment bank wants to display details of a derivative holding to the client. With the use of some 'magic', the information required to render this information is already stored in the (Http)Request object, where it is bound to an attribute with the name 'position'.

The following code fragment (stored in a separate XML file named position.xml)

  <root xmlns:castor="http://apache.org/cocoon/castor/1.0">
    <castor:marshall name="position" scope="request" />
  </root>

will instruct the CastorTransformer to look for an object (hierarchy) bound to a (Http)Request attribute with the name 'position', and marshall its current state to XML.

Sitemap configuration

Component definition

As with all components in Cocoon, before the CastorTransformer can be used, it needs to be defined, i.e. its existence needs to be communicated to Cocoon. This is generally achieved by adding the relevant entries to the <component> section of the sitemap.

As with all transformers, the CastorTransformer definition needs to go into the section as follows:

  <map:transformers>
    <map:transformer name="castor"                                       
                     src="org.apache.cocoon.transformation.CastorTransformer">
      <mapping>castor/mapping.xml</mapping>
    </map:transformer>
  </map:transformers>

This definition registers the CastorTransformer with Cocoon under the logical name 'castor', which will be used in pipeline declarations to specify that this very transformer shall be used.

Usage within a pipeline

To use the CastorTransformer within a pipeline to insert the XML representation of an arbitrary object hierarchy into the pipeline, please specify a pipeline entry similar to the following pipeline definition:

  <map:pipeline>
    <map:match pattern="castor/show/position">
      <map:generate type="file" src="docs/position.xml" />
      <map:transform type="castor" />
      <map:serialize type="xml" />
    </map:match>
  </map:pipeline>

This instructs Cocoon to

  1. read the content of the file 'docs/position.xml'
  2. use the CastorTransformer to replace these instructions with the XML-ized state of the object found
  3. send the result back to the client as a stream with content-type text/xml

Gotchas

-With Cocoon being at release 2.1.5 at the moment of this writing, the CastorTransformer is still part of the scratchpad block. In order to be able to use the samples provided as part of this page, please make sure that you do not exclude the scratchpad block when building Cocoon. Please consult with the manuals for instructions about the Cocoon build process in general and blocks in particular.
-At the time of this writing, the CastorTransformer internally seems to be relying on the use of SAX 1 API. This had the not well documented side-effect that the following property needs to be specified at the JVM level when trying to use the CastorTransformer:
TBD
When deploying Cocoon onto e.g. Tomcat 4.1.x, this is best done through the use of the JAVA_OPTS environment variable, which is used by Catalina to configure its hosting JVM.

References

-Project home
-Javadocs (CastorTransformer)
 
   
  
   
 


Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved.
 
Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners.