commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt TestXMLBeanInfoDigester.java TestAll.java
Date Thu, 07 Feb 2002 19:17:27 GMT
jstrachan    02/02/07 11:17:27

  Modified:    betwixt  build.xml
               betwixt/src/java/org/apache/commons/betwixt
                        ElementDescriptor.java NodeDescriptor.java
               betwixt/src/test/org/apache/commons/betwixt TestAll.java
  Added:       betwixt/src/java/org/apache/commons/betwixt/digester
                        ElementRule.java InfoRule.java
                        XMLBeanInfoDigester.java package.html
               betwixt/src/test/org/apache/commons/betwixt
                        TestXMLBeanInfoDigester.java
  Log:
  Adding early version of the XMLBeanInfo Digester to allow XMLBeanInfo definitions to be
customized via an XML config file. This new Digester is still not working properly, some work
is still required on the ElementDescriptor tree it creates but it is fairly close.
  
  Revision  Changes    Path
  1.10      +16 -2     jakarta-commons-sandbox/betwixt/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/build.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- build.xml	31 Jan 2002 21:24:42 -0000	1.9
  +++ build.xml	7 Feb 2002 19:17:26 -0000	1.10
  @@ -3,7 +3,7 @@
   
   <!--
           "Digester" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.9 2002/01/31 21:24:42 jstrachan Exp $
  +        $Id: build.xml,v 1.10 2002/02/07 19:17:26 jstrachan Exp $
   -->
   
   
  @@ -252,9 +252,23 @@
   
   
      <target name="test.reader" depends="compile.tests" 
  -      description="Runs sample bean reader">
  +      description="Runs test of bean reader">
       <java classname="org.apache.commons.betwixt.TestBeanReader" fork="yes">
         <classpath refid="test.classpath"/>
  +        <!-- this all seems a bit much to get some logging? -->
  +      <sysproperty key="org.apache.commons.logging.log" value="org.apache.commons.logging.SimpleLog"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester"
value="warn"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax"
value="warn"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  +    </java>
  +   </target>
  +
  +   <target name="test.digester" depends="compile.tests" 
  +      description="Runs the test of the XMLBeanInfo digester">
  +    <java classname="org.apache.commons.betwixt.TestXMLBeanInfoDigester" fork="yes">
  +      <classpath refid="test.classpath"/>
  +        <!-- this all seems a bit much to get some logging? -->
         <sysproperty key="org.apache.commons.logging.log" value="org.apache.commons.logging.SimpleLog"/>
         <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
         <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester"
value="warn"/>
  
  
  
  1.8       +20 -5     jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java
  
  Index: ElementDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ElementDescriptor.java	31 Jan 2002 21:24:42 -0000	1.7
  +++ ElementDescriptor.java	7 Feb 2002 19:17:26 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,v
1.7 2002/01/31 21:24:42 jstrachan Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/01/31 21:24:42 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,v
1.8 2002/02/07 19:17:26 jstrachan Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/02/07 19:17:26 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ElementDescriptor.java,v 1.7 2002/01/31 21:24:42 jstrachan Exp $
  + * $Id: ElementDescriptor.java,v 1.8 2002/02/07 19:17:26 jstrachan Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -70,7 +70,7 @@
     * and <code>ElementDescriptor</code>'s for it's child elements.
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.7 $
  +  * @version $Revision: 1.8 $
     */
   public class ElementDescriptor extends NodeDescriptor {
   
  @@ -126,6 +126,21 @@
       /** Set <code>AttributesDescriptors</code> for this element */
       public void setAttributeDescriptors(AttributeDescriptor[] attributeDescriptors) {
           this.attributeDescriptors = attributeDescriptors;
  +    }
  +    
  +    public void addElementDescriptor(ElementDescriptor descriptor) {
  +        // XXX: not a very efficient way of doing it. Maybe keep an internal List implementation
  +        
  +        if ( elementDescriptors == null ) {
  +            elementDescriptors = new ElementDescriptor[] { descriptor };
  +        }
  +        else {
  +            int size = elementDescriptors.length;
  +            ElementDescriptor[] newValue = new ElementDescriptor[ size + 1 ];
  +            System.arraycopy( elementDescriptors, 0, newValue, 0, size );
  +            newValue[size] = descriptor;
  +            elementDescriptors = newValue;
  +        }
       }
       
       /** Returns the child element descriptors for this element */
  
  
  
  1.6       +18 -5     jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java
  
  Index: NodeDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NodeDescriptor.java	31 Jan 2002 19:56:02 -0000	1.5
  +++ NodeDescriptor.java	7 Feb 2002 19:17:26 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v
1.5 2002/01/31 19:56:02 jstrachan Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/01/31 19:56:02 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v
1.6 2002/02/07 19:17:26 jstrachan Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/02/07 19:17:26 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: NodeDescriptor.java,v 1.5 2002/01/31 19:56:02 jstrachan Exp $
  + * $Id: NodeDescriptor.java,v 1.6 2002/02/07 19:17:26 jstrachan Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -70,7 +70,7 @@
     * or they can have a local name, qualified name and a namespace uri.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.5 $
  +  * @version $Revision: 1.6 $
     */
   public class NodeDescriptor {
   
  @@ -83,6 +83,8 @@
       private Expression textExpression;
       /** the updater used to update the current bean from the text value of this node */
       private Updater updater;
  +    /** The property expression to which this node refers to, or null if it is just a constant
*/
  +    private String propertyName;
       /** the property type associated with this node, if any */
       private Class propertyType;
       
  @@ -177,5 +179,16 @@
       /** Sets the property type associated with this node, if any */
       public void setPropertyType(Class propertyType) {
           this.propertyType = propertyType;
  +    }
  +
  +    
  +    /** @return the property expression to which this node refers to, or null if it is
just a constant */
  +    public String getPropertyName() {
  +        return propertyName;
  +    }
  +    
  +    /** Sets the property expression to which this node refers to, or null if it is just
a constant */
  +    public void setPropertyName(String propertyName) {
  +        this.propertyName = propertyName;
       }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java
  
  Index: ElementRule.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v
1.1 2002/02/07 19:17:27 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 19:17:27 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ElementRule.java,v 1.1 2002/02/07 19:17:27 jstrachan Exp $
   */
  package org.apache.commons.betwixt.digester;
  
  import java.beans.BeanInfo;
  import java.beans.Introspector;
  import java.beans.PropertyDescriptor;
  import java.lang.reflect.Method;
  
  import org.apache.commons.betwixt.AttributeDescriptor;
  import org.apache.commons.betwixt.ElementDescriptor;
  import org.apache.commons.betwixt.XMLBeanInfo;
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.expression.Context;
  import org.apache.commons.betwixt.expression.Updater;
  import org.apache.commons.betwixt.expression.MethodExpression;
  import org.apache.commons.betwixt.expression.MethodUpdater;
  
  import org.apache.commons.digester.Rule;
  import org.apache.commons.digester.Digester;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  /** <p><code>ElementRule</code> the digester Rule for parsing the &lt;element&gt;
elements.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ElementRule extends Rule {
  
      /** Logger */
      private static final Log log = LogSource.getInstance( ElementRule.class );
      
      private ClassLoader classLoader;
      
      public ElementRule(Digester digester) {
          super(digester);
          this.classLoader = getClass().getClassLoader();
      }
      
      // Rule interface
      //-------------------------------------------------------------------------    
      
      /**
       * Process the beginning of this element.
       *
       * @param attributes The attribute list of this element
       */
      public void begin(Attributes attributes) throws Exception {
          //log.debug( "Called with descriptor: " + descriptor + " propertyType: " + descriptor.getPropertyType()
);
          
          ElementDescriptor descriptor = new ElementDescriptor();
          
          descriptor.setQualifiedName( attributes.getValue( "name" ) );
          descriptor.setLocalName( attributes.getValue( "name" ) );
          String uri = attributes.getValue( "uri" );
          if ( uri != null ) {
              descriptor.setURI( uri );        
          }
          descriptor.setPropertyName( attributes.getValue( "property" ) );
          descriptor.setPropertyType( loadClass( attributes.getValue( "type" ) ) );
          
          configureDescriptor(descriptor);
          
          Object top = digester.peek();
          if ( top instanceof XMLBeanInfo ) {
              XMLBeanInfo beanInfo = (XMLBeanInfo) top;
              beanInfo.setElementDescriptor( descriptor );
          }
          else if ( top instanceof ElementDescriptor ) {
              ElementDescriptor parent = (ElementDescriptor) top;
              parent.addElementDescriptor( descriptor );
          }
          else {
              throw new SAXException( "Invalid use of <element>. It should be nested
inside <info> or other <element> nodes" );
          }            
          digester.push(descriptor);        
      }
  
  
      /**
       * Process the end of this element.
       */
      public void end() throws Exception {
          Object top = digester.pop();
      }
  
      
      // Implementation methods
      //-------------------------------------------------------------------------    
      protected Class loadClass( String name ) {
          // XXX: should use a ClassLoader to handle complex class loading situations
          if ( name != null ) {
              try {
                  return classLoader.loadClass(name);
              }
              catch (Exception e) {
              }
          }
          return null;            
      }
      
      /** Set the Expression and Updater from a bean property name */
      protected void configureDescriptor(ElementDescriptor elementDescriptor) {
          Class beanClass = elementDescriptor.getPropertyType();
          if ( beanClass != null ) {
              String name = elementDescriptor.getPropertyName();
              if ( name != null ) {
                  try {
                      BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
                      PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
                      if ( descriptors != null ) {
                          for ( int i = 0, size = descriptors.length; i < size; i++ ) {
                              PropertyDescriptor descriptor = descriptors[i];
                              if ( name.equals( descriptor.getName() ) ) {
                                  Method readMethod = descriptor.getReadMethod();
                                  Method writeMethod = descriptor.getWriteMethod();
                                  if ( readMethod != null ) {
                                      elementDescriptor.setTextExpression( new MethodExpression(
readMethod ) );
                                  }
                                  if ( writeMethod != null ) {
                                      elementDescriptor.setTextExpression( new MethodExpression(
writeMethod ) );
                                  }
                                  break;
                              }
                          }
                      }
                  }
                  catch (Exception e) {
                      log.info( "Caught introspection exception", e );
                  }
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java
  
  Index: InfoRule.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java,v
1.1 2002/02/07 19:17:27 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 19:17:27 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: InfoRule.java,v 1.1 2002/02/07 19:17:27 jstrachan Exp $
   */
  package org.apache.commons.betwixt.digester;
  
  import org.apache.commons.betwixt.AttributeDescriptor;
  import org.apache.commons.betwixt.ElementDescriptor;
  import org.apache.commons.betwixt.XMLBeanInfo;
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.expression.Context;
  import org.apache.commons.betwixt.expression.Updater;
  
  import org.apache.commons.digester.Rule;
  import org.apache.commons.digester.Digester;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  import org.xml.sax.Attributes;
  
  /** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class InfoRule extends Rule {
  
      /** Logger */
      private static final Log log = LogSource.getInstance( InfoRule.class );
      
      private XMLBeanInfo xmlBeanInfo;
      
      
      public InfoRule(Digester digester) {
          super(digester);
      }
      
      // Rule interface
      //-------------------------------------------------------------------------    
      
      /**
       * Process the beginning of this element.
       *
       * @param attributes The attribute list of this element
       */
      public void begin(Attributes attributes) throws Exception {
          xmlBeanInfo = new XMLBeanInfo();
          
          getDigester().push(xmlBeanInfo);
          
      }
  
  
      /**
       * Process the end of this element.
       */
      public void end() throws Exception {
          Object top = getDigester().pop();
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------    
      
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java
  
  Index: XMLBeanInfoDigester.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java,v
1.1 2002/02/07 19:17:27 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 19:17:27 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: XMLBeanInfoDigester.java,v 1.1 2002/02/07 19:17:27 jstrachan Exp $
   */
  package org.apache.commons.betwixt.digester;
  
  import javax.xml.parsers.SAXParser;
  
  import org.apache.commons.digester.Rule;
  import org.apache.commons.digester.Digester;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  import org.xml.sax.XMLReader;
  
  /** <p><code>XMLBeanInfoDigester</code> is a digester of XML files
    * containing XMLBeanInfo definitions for a JavaBean.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class XMLBeanInfoDigester extends Digester {
  
      /** Logger */
      private static final Log log = LogSource.getInstance( XMLBeanInfoDigester.class );
      
      /**
       * Construct a new XMLBeanInfoDigester with default properties.
       */
      public XMLBeanInfoDigester() {
      }
  
      /**
       * Construct a new XMLBeanInfoDigester, allowing a SAXParser to be passed in.  This
       * allows XMLBeanInfoDigester to be used in environments which are unfriendly to
       * JAXP1.1 (such as WebLogic 6.0).  Thanks for the request to change go to
       * James House (james@interobjective.com).  This may help in places where
       * you are able to load JAXP 1.1 classes yourself.
       */
      public XMLBeanInfoDigester(SAXParser parser) {
          super(parser);
      }
  
      /**
       * Construct a new XMLBeanInfoDigester, allowing an XMLReader to be passed in.  This
       * allows XMLBeanInfoDigester to be used in environments which are unfriendly to
       * JAXP1.1 (such as WebLogic 6.0).  Note that if you use this option you
       * have to configure namespace and validation support yourself, as these
       * properties only affect the SAXParser and emtpy constructor.
       */
      public XMLBeanInfoDigester(XMLReader reader) {
          super(reader);
      }
      
      // Implementation methods
      //-------------------------------------------------------------------------        
      protected void configure() {
          if (! configured) {
              configured = true;
           
              // add the various rules
              
              addRule( "info", new InfoRule( this ) );
              addRule( "*/element", new ElementRule( this ) );
          }
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p> This package contains the Digester and associated rules and helper classes
  	for parsing the XMLBeanInfo metadata from an XML file format.</p>
  
  </body>
  </html>
  
  
  
  1.5       +6 -5      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestAll.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestAll.java	31 Jan 2002 19:56:03 -0000	1.4
  +++ TestAll.java	7 Feb 2002 19:17:27 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestAll.java,v
1.4 2002/01/31 19:56:03 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/01/31 19:56:03 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestAll.java,v
1.5 2002/02/07 19:17:27 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/07 19:17:27 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TestAll.java,v 1.4 2002/01/31 19:56:03 jstrachan Exp $
  + * $Id: TestAll.java,v 1.5 2002/02/07 19:17:27 jstrachan Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -71,7 +71,7 @@
   /** Entry point for all JUnit tests.
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
    */
   public class TestAll extends TestCase {
       
  @@ -84,6 +84,7 @@
           suite.addTest(TestBeanWriter.suite());
           suite.addTest(TestXMLIntrospector.suite());
           suite.addTest(TestEvaluation.suite());
  +        suite.addTest(TestXMLBeanInfoDigester.suite());
           return suite;
       }
       
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestXMLBeanInfoDigester.java
  
  Index: TestXMLBeanInfoDigester.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestXMLBeanInfoDigester.java,v
1.1 2002/02/07 19:17:27 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 19:17:27 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: TestXMLBeanInfoDigester.java,v 1.1 2002/02/07 19:17:27 jstrachan Exp $
   */
  package org.apache.commons.betwixt;
  
  import java.io.InputStream;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
  import org.apache.commons.digester.rss.Channel;
  
  /** Test harness for the Digester of XMLBeanInfo
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class TestXMLBeanInfoDigester extends AbstractTestCase {
      
      public static void main( String[] args ) {
          TestRunner.run( suite() );
      }
      
      public static Test suite() {
          return new TestSuite(TestXMLBeanInfoDigester.class);
      }
          
      public TestXMLBeanInfoDigester(String testName) {
          super(testName);
      }
      
      public void testDigester() throws Exception {
          XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
  
          InputStream in = Channel.class.getResourceAsStream( "Channel.betwixt.xml" );
          
          XMLBeanInfo info = (XMLBeanInfo) digester.parse( in );
          
          assertTrue( "Found XMLBeanInfo", info != null );
          
          ElementDescriptor descriptor = info.getElementDescriptor();
          
          assertTrue( "Found root element descriptor", descriptor != null );
          assertEquals( "Element name correct", "channel", descriptor.getLocalName() );
          
          ElementDescriptor[] elements = descriptor.getElementDescriptors();
          
          assertTrue( "Found elements", elements != null && elements.length > 0
);
          
          descriptor = elements[0];
          assertEquals( "Element name correct", "title", descriptor.getLocalName() );
          assertEquals( "Element property correct", "title", descriptor.getPropertyName()
);
      }
  }
  
  
  
  

--
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