rdonkin     02/01/17 14:50:07

  Modified:    betwixt/src/java/org/apache/commons/betwixt
                        XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/io
                        BeanWriter.java
               betwixt/src/test/org/apache/commons/betwixt
                        TestBeanWriter.java
  Log:
  Corrected logging code to reflect revised commons-logging Log interface
  
  Revision  Changes    Path
  1.12      +7 -7      
jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XMLIntrospector.java      5 Jan 2002 15:52:00 -0000       1.11
  +++ XMLIntrospector.java      17 Jan 2002 22:50:07 -0000      1.12
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: XMLIntrospector.java,v 1.11 2002/01/05 15:52:00 rdonkin Exp $
  + * $Id: XMLIntrospector.java,v 1.12 2002/01/17 22:50:07 rdonkin Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -38,14 +38,14 @@
   /** <p><code>XMLIntrospector</code> an introspector of beans to create a 
XMLBeanInfo instance.</p>
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.11 $
  +  * @version $Revision: 1.12 $
     */
   public class XMLIntrospector {
   
       /** should attributes or elements be used for primitive types */
       private boolean attributesForPrimitives = true;
       /** Log used for logging (Doh!) */
  -    protected final Log log = 
LogSource.makeNewLogInstance("org.apache.commons.betwixt.XMLIntrospector");
  +    protected Log log = 
LogSource.makeNewLogInstance("org.apache.commons.betwixt.XMLIntrospector");
   
       
       /** Base constructor */
  @@ -57,8 +57,8 @@
        *
        * @return a <code>org.apache.commons.logging.Log</code> level constant
        */ 
  -    public int getLogLevel() {
  -        return log.getLevel();
  +    public Log getLog() {
  +        return log;
       }
   
       /**
  @@ -66,8 +66,8 @@
        *
        * @param level a <code>org.apache.commons.logging.Log</code> level constant
        */ 
  -    public void setLogLevel(int level) {
  -        log.setLevel(level);
  +    public void setLog(Log log) {
  +        this.log = log;
       }
       
       
  
  
  
  1.11      +37 -27    
jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java
  
  Index: BeanWriter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BeanWriter.java   5 Jan 2002 15:52:00 -0000       1.10
  +++ BeanWriter.java   17 Jan 2002 22:50:07 -0000      1.11
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: BeanWriter.java,v 1.10 2002/01/05 15:52:00 rdonkin Exp $
  + * $Id: BeanWriter.java,v 1.11 2002/01/17 22:50:07 rdonkin Exp $
    */
   package org.apache.commons.betwixt.io;
   
  @@ -46,7 +46,7 @@
     * The indent string used is set by {@link #setIndent}.
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.10 $
  +  * @version $Revision: 1.11 $
     */
   public class BeanWriter {
   
  @@ -63,7 +63,7 @@
       /** should we flush after writing bean */
       private boolean autoFlush;
       /** Log used for logging (Doh!) */
  -    private final Log log = 
LogSource.makeNewLogInstance("org.apache.commons.betwixt.BeanWriter");
  +    private Log log = 
LogSource.makeNewLogInstance("org.apache.commons.betwixt.BeanWriter");
       
       /**
        * <p> Constructor uses <code>System.out</code> for output.</p>
  @@ -115,6 +115,34 @@
           log.debug("Finished writing bean graph.");
       }
       
  +    /** Writes the given bean to the current stream using the given 
<code>qualifiedName</code> */
  +    public void write(
  +                String qualifiedName, 
  +                Object bean) 
  +                    throws 
  +                        IOException, 
  +                        IntrospectionException {
  +        if (log.isDebugEnabled())
  +        {
  +            log.debug("Writing bean graph (qualified name '" + qualifiedName + 
"'");
  +        }
  +        
  +        // introspect to obtain bean info
  +        XMLBeanInfo beanInfo = introspector.introspect( bean );
  +        if ( beanInfo != null ) {
  +            ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
  +            if ( elementDescriptor != null ) {
  +                Context context = new Context( bean, log );
  +                if ( qualifiedName == null ) {
  +                    qualifiedName = elementDescriptor.getQualifiedName();
  +                }
  +                write( qualifiedName, elementDescriptor, context );
  +            }
  +        }
  +        
  +        log.debug("Finished writing bean graph.");
  +    }
  +
       /**
        * <p> Switch on formatted output.
        * This sets the end of line and the indent.
  @@ -173,8 +201,8 @@
        *
        * @return a <code>org.apache.commons.logging.Log</code> level constant
        */ 
  -    public int getLogLevel() {
  -        return log.getLevel();
  +    public Log getLog() {
  +        return log;
       }
   
       /**
  @@ -182,33 +210,13 @@
        *
        * @param level a <code>org.apache.commons.logging.Log</code> level constant
        */ 
  -    public void setLogLevel(int level) {
  -        log.setLevel(level);
  +    public void setLog(Log log) {
  +        this.log = log;
       }
           
       // Implementation methods
       //-------------------------------------------------------------------------    
       
  -    /** Writes the given bean to the current stream using the given 
<code>qualifiedName</code> */
  -    public void write(
  -                String qualifiedName, 
  -                Object bean) 
  -                    throws 
  -                        IOException, 
  -                        IntrospectionException {
  -        XMLBeanInfo beanInfo = introspector.introspect( bean );
  -        if ( beanInfo != null ) {
  -            ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
  -            if ( elementDescriptor != null ) {
  -                Context context = new Context( bean, log );
  -                if ( qualifiedName == null ) {
  -                    qualifiedName = elementDescriptor.getQualifiedName();
  -                }
  -                write( qualifiedName, elementDescriptor, context );
  -            }
  -        }
  -    }
  -    
   
       /** Writes the given element */
       protected void write( 
  @@ -247,6 +255,7 @@
           boolean answer = false;
           ElementDescriptor[] childDescriptors = 
elementDescriptor.getElementDescriptors();
           if ( childDescriptors != null && childDescriptors.length > 0 ) {
  +            // process child elements
               writer.write( ">" );
               ++indentLevel;
               for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
  @@ -278,6 +287,7 @@
               answer = true;
           }
           else {
  +            // evaluate the body text 
               Expression expression = elementDescriptor.getTextExpression();
               if ( expression != null ) {
                   Object value = expression.evaluate( context );
  
  
  
  1.5       +3 -3      
jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java
  
  Index: TestBeanWriter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBeanWriter.java       5 Jan 2002 15:52:00 -0000       1.4
  +++ TestBeanWriter.java       17 Jan 2002 22:50:07 -0000      1.5
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: TestBeanWriter.java,v 1.4 2002/01/05 15:52:00 rdonkin Exp $
  + * $Id: TestBeanWriter.java,v 1.5 2002/01/17 22:50:07 rdonkin Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -23,7 +23,7 @@
   /** Test harness for the BeanWriter
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
     */
   public class TestBeanWriter extends AbstractTestCase {
       
  @@ -67,7 +67,7 @@
           BeanWriter writer = new BeanWriter( buffer );
           //BeanWriter writer = new BeanWriter();
           
  -        //writer.setLogLevel(Log.ERROR);
  +        //writer.setLogLevel(Log.DEBUG);
   
           // set up a cyclic reference
           LoopBean alpha = new LoopBean("alpha");
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to