You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Simone Tripodi (JIRA)" <ji...@apache.org> on 2011/06/23 20:49:47 UTC

[jira] [Resolved] (DIGESTER-142) Apache digester addSetProperty method is unclear and probably wrong.

     [ https://issues.apache.org/jira/browse/DIGESTER-142?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simone Tripodi resolved DIGESTER-142.
-------------------------------------

       Resolution: Not A Problem
    Fix Version/s: 3.0
         Assignee: Simone Tripodi

I think it is just a misunderstanding; from [Digester#addSetProperty|http://commons.apache.org/digester/commons-digester-2.1/docs/api/org/apache/commons/digester/Digester.html#addSetProperty(java.lang.String, java.lang.String, java.lang.String)] javadoc:


 * pattern - Element matching pattern
 * name - Attribute name containing the property name to be set
 * value - Attribute name containing the property value to set

The {{name}} referred is a POJO property name, where {{value}} is the attribute name where extracting the POJO property value; have a look at the [SetPropertyRuleTestCase|https://svn.apache.org/repos/asf/commons/proper/digester/branches/DIGESTER_2_X/src/test/java/org/apache/commons/digester/SetPropertyRuleTestCase.java] how {{addSetProperty}} works.

Looks like you just tried to use a Digester rule that doesn't fit with your needs

> Apache digester addSetProperty method is unclear and probably wrong.
> --------------------------------------------------------------------
>
>                 Key: DIGESTER-142
>                 URL: https://issues.apache.org/jira/browse/DIGESTER-142
>             Project: Commons Digester
>          Issue Type: Bug
>    Affects Versions: 2.1
>         Environment: linux, 64 bits
>            Reporter: i30817
>            Assignee: Simone Tripodi
>            Priority: Minor
>             Fix For: 3.0
>
>
> The addSetProperty method call:
>             Digester d = new Digester();
>             d.push(this);
>             d.addObjectCreate("rdf:RDF/pgterms:etext", Book.class);
>             d.addSetProperty("rdf:RDF/pgterms:etext", "rdf:ID", "setId");
>  OR
>             d.addSetProperty("rdf:RDF/pgterms:etext", "rdf:ID", "id");
> on a class Book with the method public void setId(String)
> running on this xml (simplified and not tested the simplification):
> <rdf:RDF>
> <pgterms:etext rdf:ID="etext10452">
>   <dc:publisher>&pg;</dc:publisher>
>   <dc:title rdf:parseType="Literal">Peter's Mother</dc:title>
>   <dc:creator rdf:parseType="Literal">De La Pasture, Henry, Mrs., 1866-1945</dc:creator>
>   <pgterms:friendlytitle rdf:parseType="Literal">Peter's Mother by Mrs. Henry De La Pasture</pgterms:friendlytitle>
>   <dc:language><dcterms:ISO639-2><rdf:value>en</rdf:value></dcterms:ISO639-2></dc:language>
>   <dc:created><dcterms:W3CDTF><rdf:value>2003-12-01</rdf:value></dcterms:W3CDTF></dc:created>
>   <dc:rights rdf:resource="&lic;" />
> </pgterms:etext>
> </rdf:RDF>
> gives this exception:
> Nov 8, 2010 2:42:12 PM org.apache.commons.digester.Digester startElement
> SEVERE: Begin event threw exception
> java.lang.NoSuchMethodException: Bean has no property named etext10452
>         at org.apache.commons.digester.SetPropertyRule.begin(SetPropertyRule.java:154)
>         at org.apache.commons.digester.Rule.begin(Rule.java:177)
>         at org.apache.commons.digester.Digester.startElement(Digester.java:1583)
>         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
>         at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:770)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1340)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
>         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
>         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
>         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
>         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
>         at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
>         at org.apache.commons.digester.Digester.parse(Digester.java:1916)
> ...(my code the rest).
> To work around it use instead:
> d.addSetProperties("rdf:RDF/pgterms:etext", "rdf:ID", "id");
> Doesn't make much sense to me. Also the confusion between a javadoc bean property and a xml one is very, very misleading on the javadoc.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira