commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io AbstractBeanWriter.java SAXBeanWriter.java
Date Fri, 19 Jul 2002 00:52:41 GMT
mvdb        2002/07/18 17:52:41

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        AbstractBeanWriter.java SAXBeanWriter.java
  Log:
  Added endDocument and startDocument calls. Needs a lot of tweaking and a usable testcase.

  The changes didn't break any of the tests..
  
  Revision  Changes    Path
  1.2       +30 -7     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java
  
  Index: AbstractBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractBeanWriter.java	18 Jul 2002 23:19:07 -0000	1.1
  +++ AbstractBeanWriter.java	19 Jul 2002 00:52:41 -0000	1.2
  @@ -128,11 +128,34 @@
       public void write(Object bean) throws IOException, SAXException, IntrospectionException
 {
           log.debug( "Writing bean graph..." );
           log.debug( bean );
  -        
  +        start();
           write( null, bean );
  -
  +        end();
           log.debug( "Finished writing bean graph." );
       }
  +    
  +    /**
  +     * Marks the start of the bean writing.
  +     * By default doesn't do anything, but can be used
  +     * to do extra start processing 
  +     * @throws IOException
  +     * @throws SAXException
  +     */
  +    public void start() throws IOException, SAXException {
  +    }
  +    
  +    /**
  +     * Marks the start of the bean writing.
  +     * By default doesn't do anything, but can be used
  +     * to do extra end processing 
  +     * @throws IOExcpetion
  +     * @throws SAXException
  +     */
  +    
  +    public void end() throws IOException, SAXException {
  +    }
  +        
  +    
       
       /** 
        * <p>Writes the given bean to the current stream using the given <code>qualifiedName</code>.</p>
  
  
  
  1.2       +40 -8     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/SAXBeanWriter.java
  
  Index: SAXBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/SAXBeanWriter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAXBeanWriter.java	18 Jul 2002 23:19:07 -0000	1.1
  +++ SAXBeanWriter.java	19 Jul 2002 00:52:41 -0000	1.2
  @@ -89,9 +89,13 @@
   // At the moment, namespaces are NOT supported!
   
   /**
  -  * 
  -  */
  -public class SAXBeanWriter {
  + * The SAXBeanwriter will send events to a ContentHandler
  + * 
  + * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
  + * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
  + * @version $Id$ 
  + */
  +public class SAXBeanWriter extends AbstractBeanWriter {
   
       /** Where the output goes */
       private ContentHandler contentHandler;    
  @@ -104,6 +108,8 @@
       
       private boolean elementWaiting = false;
       
  +    private boolean isDocumentStarted = false;
  +    
       /**
        * <p> Constructor sets writer used for output.</p>
        *
  @@ -140,7 +146,7 @@
           // make sure any previous elements have been sent
           sendElementStart();
           // ok prepare for new one
  -	elementWaiting = true;
  +	    elementWaiting = true;
           attributes = new AttributesImpl();
           lastElementName = qualifiedName;
       }
  @@ -189,9 +195,35 @@
       //-------------------------------------------------------------------------    
       
       private void sendElementStart() throws SAXException {
  +        if (!this.isDocumentStarted)
  +        {
  +            contentHandler.startDocument();
  +            this.isDocumentStarted = true;
  +        }
           if (elementWaiting) {
               contentHandler.startElement("","",lastElementName,attributes);
               elementWaiting = false;
           }
       }
  +    /**
  +     * This will announce the start of the document
  +     * to the contenthandler.
  +     * 
  +     * @see org.apache.commons.betwixt.io.AbstractBeanWriter#end()
  +     */
  +    
  +    public void start() throws SAXException {
  +        contentHandler.startDocument();
  +    }
  +
  +    /**
  +     * This method will announce the end of the document to
  +     * the contenthandler.
  +     * 
  +     * @see org.apache.commons.betwixt.io.AbstractBeanWriter#start()
  +     */
  +    public void end() throws SAXException {
  +        contentHandler.endDocument();
  +    }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message