You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2003/05/26 19:02:13 UTC

DO NOT REPLY [Bug 20249] New: - When using digester rules xml file, digester connot assign date, int or foalt setter fields type to a bean.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20249>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20249

When using digester rules xml file, digester connot assign date, int or foalt setter fields type to a bean. 

           Summary: When using digester rules xml file, digester connot
                    assign date, int or foalt setter fields type to a bean.
           Product: Commons
           Version: 1.5 Final
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Digester
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: pierre.lessard@promutuel.ca


When using digester rules xml file, digester connot assign date, int or foalt 
setter fields type to a bean. Look at the sample code attached below. 
Meanwhile, when defining rules programmatically, it works, see Digester Driver.

The setters which are not working are setId(long), setDate(java.sql.Date) and 
setPrice(float) on the Magazine class.

For more info, please email-me.

Pete



Xml Driver:
===========

package pro.prepreuve.digester;

import org.apache.commons.digester.*;
import org.apache.commons.digester.xmlrules.*;

import java.io.*;
import java.util.*;

public class XmlRulesDigesterDriver {
   public static void main( String[] args ) {
      try {

         File rules = new File
( "C:/ClearCaseProjects/D00PLE_pete/prepreuve/digester-rules.xml");
         File input = new File( "C:/ClearCaseProjects/D00PLE_pete/prepreuve/in-
digester.xml" );

         Digester digester = DigesterLoader.createDigester(rules.toURL
());         
         
         Object o =  digester.parse( input );
         System.out.println( o.toString() );
  
      } catch( Exception exc ) {
         exc.printStackTrace();
      }
   }
}


xml input file
==============

<?xml version="1.0"?>

<catalog library="somewhere">

   <book>
      <author>Author 1</author>
      <title>Title 1</title>
   </book>

   <book>
      <author>Author 2</author>
      <title>His One Book tertert</title>
   </book>

   <magazine>
      <name>Mag Title 1</name>

      <article page="5">
         <headline>Some Headline erterter</headline>
      </article>

      <article page="9">
         <headline>Another Headline ertertertert</headline>
      </article>
   </magazine>

   <book>
      <author>Author 2</author>
      <title>His Other Book</title>
   </book>

   <magazine>
      <name>Mag Title 2</name>

      <article page="17">
         <headline>Second Headline</headline>
      </article>
   </magazine>


<magazine>
      <name>Mag Title 3</name>

      <article page="17">
         <headline>Second Headline</headline>
      </article>
   </magazine>
   
   
   <magazine>
   	 
         <name>Mag Title 4</name>
         <id>3434343432</id>
         <price>345.34</price>
         <date>2002-01-01</date>
         <author>John GG</author>
         
   
         <article page="17">
            <headline>Second Headline</headline>
         </article>
         
          <article page="17">
	             <headline>Second Headline</headline>
         </article>
         
          <article page="17">
	             <headline>Second Headline</headline>
         </article>
   </magazine>
   
   
   <toto>
    <tata>ttt</tata>
   </toto>

</catalog>


rules.xml
==========


<?xml version="1.0"?>

<digester-rules>

   <object-create-rule pattern="catalog" 
classname="pro.prepreuve.digester.Catalog" />

   <set-properties-rule pattern="catalog" >
      <alias attr-name="library" prop-name="library" />
   </set-properties-rule>

   <pattern value="catalog/book">
      <object-create-rule classname="pro.prepreuve.digester.Book" />
      <call-method-rule pattern="author" methodname="setAuthor"
	                paramcount="0" />
      <call-method-rule pattern="title" methodname="setTitle" 
	                paramcount="0" />
      <set-next-rule methodname="addBook" />
   </pattern>

   <pattern value="catalog/magazine">
   
   	<object-create-rule classname="pro.prepreuve.digester.Magazine" />
   	
   	<call-method-rule pattern="name" methodname="setName" 
paramcount="0" />   
   	<call-method-rule pattern="author" methodname="setAuthor" 
paramcount="0" />  
   	
   	<call-method-rule pattern="id" methodname="setId" paramcount="0" />  
   	<call-method-rule pattern="price" methodname="setPrice" 
paramcount="0" />  
   	<call-method-rule pattern="date" methodname="setDate" 
paramcount="0" />  
   	

      
   	
   	<pattern value="article">
        	<object-create-rule 
classname="pro.prepreuve.digester.Article" />
         		
         		<set-properties-rule>
            			<alias attr-name="page" prop-name="page" />
            
         		</set-properties-rule>    
         
         	<call-method-rule pattern="headline" methodname="setHeadline" 
paramcount="0" />
         
         	<set-next-rule methodname="addArticle" />
      	</pattern>

      	<set-next-rule methodname="addMagazine" /> 
      	
   </pattern>   
   
</digester-rules>

StackTrace Error:
=================

[ERROR] Digester - -End event threw exception <java.lang.NoSuchMethodException: 
No such accessible method: setId() on object: 
pro.prepreuve.digester.Magazine>java.lang.NoSuchMethodException: No such 
accessible method: setId() on object: pro.prepreuve.digester.Magazine
	at org.apache.commons.beanutils.MethodUtils.invokeMethod
(MethodUtils.java:250)
	at org.apache.commons.digester.CallMethodRule.end
(CallMethodRule.java:505)
	at org.apache.commons.digester.Rule.end(Rule.java:276)
	at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
	at org.apache.xerces.parsers.AbstractSAXParser.endElement
(AbstractSAXParser.java:569)
	at org.apache.xerces.impl.XMLNamespaceBinder.endElement
(XMLNamespaceBinder.java:646)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement
(XMLDTDValidator.java:3003)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement
(XMLDTDValidator.java:931)
	at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElement
(XMLDocumentFragmentScannerImpl.java:1147)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement
(XMLDocumentFragmentScannerImpl.java:988)
	at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.
dispatch(XMLDocumentFragmentScannerImpl.java:1448)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:333)
	at org.apache.xerces.parsers.StandardParserConfiguration.parse
(StandardParserConfiguration.java:525)
	at org.apache.xerces.parsers.StandardParserConfiguration.parse
(StandardParserConfiguration.java:581)
	at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
	at org.apache.xerces.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1158)
	at org.apache.commons.digester.Digester.parse(Digester.java:1532)
	at pro.prepreuve.digester.XmlRulesDigesterDriver.main
(XmlRulesDigesterDriver.java:20)

java.lang.NoSuchMethodException: No such accessible method: setId() on object: 
pro.prepreuve.digester.Magazine
	at org.apache.commons.digester.Digester.createSAXException
(Digester.java:2540)
	at org.apache.commons.digester.Digester.createSAXException
(Digester.java:2566)
	at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
	at org.apache.xerces.parsers.AbstractSAXParser.endElement
(AbstractSAXParser.java:569)
	at org.apache.xerces.impl.XMLNamespaceBinder.endElement
(XMLNamespaceBinder.java:646)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement
(XMLDTDValidator.java:3003)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement
(XMLDTDValidator.java:931)
	at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElement
(XMLDocumentFragmentScannerImpl.java:1147)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement
(XMLDocumentFragmentScannerImpl.java:988)
	at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.
dispatch(XMLDocumentFragmentScannerImpl.java:1448)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:333)
	at org.apache.xerces.parsers.StandardParserConfiguration.parse
(StandardParserConfiguration.java:525)
	at org.apache.xerces.parsers.StandardParserConfiguration.parse
(StandardParserConfiguration.java:581)
	at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
	at org.apache.xerces.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1158)
	at org.apache.commons.digester.Digester.parse(Digester.java:1532)
	at pro.prepreuve.digester.XmlRulesDigesterDriver.main
(XmlRulesDigesterDriver.java:20)


Magzine modified class:
========================

package pro.prepreuve.digester;

import java.util.Vector;

public class Magazine {
   private String name;
   private String author;
   private long id;
   private float price;
   private java.sql.Date date;
   private Vector articles;

   public Magazine() {
      articles = new Vector();
      date = new java.sql.Date(System.currentTimeMillis());
   }

   public void setName( String rhs ) { name = rhs; }

   public void addArticle( Article a ) {
      articles.addElement( a );
   }

   public String toString() {
      StringBuffer buf = new StringBuffer( "Magazine: Name='" + name + "', id " 
+ id + ", Date: " + date + ", price: " + price + ", Author:  " + author + " ");
      for( int i=0; i<articles.size(); i++ ){
         buf.append( articles.elementAt(i).toString() );
      }
      return buf.toString();
   }
/**
 * Returns the id.
 * @return long
 */
public long getId() {
	return id;
}

/**
 * Sets the id.
 * @param id The id to set
 */
public void setId(long id) {
	this.id = id;
}

/**
 * Returns the date.
 * @return java.sql.Date
 */
public java.sql.Date getDate() {
	return date;
}

/**
 * Sets the date.
 * @param date The date to set
 */
public void setDate(java.sql.Date date) {
	this.date = date;
}

/**
 * Returns the price.
 * @return float
 */
public float getPrice() {
	return price;
}

/**
 * Sets the price.
 * @param price The price to set
 */
public void setPrice(float price) {
	this.price = price;
}

/**
 * Returns the author.
 * @return String
 */
public String getAuthor() {
	return author;
}

/**
 * Sets the author.
 * @param author The author to set
 */
public void setAuthor(String author) {
	this.author = author;
}

}

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