org.apache.cocoon.transformation
Class CastorTransformer

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.xml.AbstractXMLPipe
              extended byorg.apache.cocoon.transformation.AbstractTransformer
                  extended byorg.apache.cocoon.transformation.CastorTransformer
All Implemented Interfaces:
Configurable, ContentHandler, LexicalHandler, LogEnabled, Poolable, Recyclable, SitemapModelComponent, Transformer, XMLConsumer, XMLConsumer, XMLPipe, XMLProducer

public class CastorTransformer
extends AbstractTransformer
implements Configurable

Castor transformer marshals a object from the Sitemap, Session, Request or the Conext into a series of SAX events.

Configuation

The CastorTransformer needs to be configured with a default mapping. This mapping is used as long as no other mapping is specified as the element.

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

Sample usage:

   <root xmlns:castor="http://apache.org/cocoon/castor/1.0">
     <castor:marshal name="invoice"/>
     <castor:unmarshal name="product" scope="sitemap" mapping="castor/specicalmapping.xml"/>
   </root>
 

The CastorTransfomer supports two elements castor:unmarshal and castor:marshal.

The marshal element is replaced with the marshaled object. The Object given through the attrbute name will be searched in the sitemap, request, session and at least in application If the scope is explicitly given, e.g , the object will ge located only here. The Attribute mapping specifys the mapping to be used. The attribute command specifies a class that implements CastorMarshalCommand and will be called before and after marshaling.

The elements within the unmarshal element will be sent to the castor unmarshaller the resulting java object with be placed in the object specified by name and scope (see also marshal element). The command attribute specifies the class that implements CastorUnmarshalCommand and will be called before and after unmarshaling.

Version:
CVS $Id: CastorTransformer.java 57441 2004-11-11 15:15:58Z vgritsenko $
Author:
Thorsten Mauch, Vadim Gritsenko, Michael Homeijer

Field Summary
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
CastorTransformer()
           
 
Method Summary
 void characters(char[] ch, int start, int len)
          Receive notification of character data.
 void configure(Configuration conf)
           
 void endElement(String uri, String name, String raw)
          Receive notification of the end of an element.
 void recycle()
          Recycle the producer by removing references, and resetting handlers to null (empty) implementations.
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
          The Sitemap will call the setup() method to prepare the component for use.
 void startElement(String uri, String name, String raw, Attributes attr)
          Receive notification of the beginning of an element.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Constructor Detail

CastorTransformer

public CastorTransformer()
Method Detail

configure

public void configure(Configuration conf)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters params)
           throws ProcessingException,
                  SAXException,
                  IOException
Description copied from interface: SitemapModelComponent
The Sitemap will call the setup() method to prepare the component for use. This is where you start the process of getting your information ready to generate your results. See ObjectModelHelper for help with the objectModel.

Specified by:
setup in interface SitemapModelComponent
Parameters:
resolver - The SourceResolver to find resources within your context.
objectModel - A java.util.Map that contains the request and session information.
src - The value of the "src" attribute in the sitemap.
params - The sitemap parameters passed into your component.
Throws:
ProcessingException - if there is any other unexpected problem.
IOException - if there is a problem reading files.
SAXException - if there is a problem reading a SAX stream.

recycle

public void recycle()
Description copied from class: AbstractXMLProducer
Recycle the producer by removing references, and resetting handlers to null (empty) implementations.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractXMLProducer

endElement

public void endElement(String uri,
                       String name,
                       String raw)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
name - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException

startElement

public void startElement(String uri,
                         String name,
                         String raw,
                         Attributes attr)
                  throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
name - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
attr - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int len)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.