You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sloan Seaman <sl...@sgi.net> on 2003/06/11 15:57:54 UTC

Digester

I'm having trouble getting the Digester to properly populate some java object and I was wondering if someone could help me out.

It keeps trying to call setConnection() on my JDOPlugIn object when I want it to call setConnection() on my JDOConfig object.

Help?


Here is my XML:
<jdo-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <jdo-providers>
  <jdo id="ANALYSIS" provider="org.xorm.InterfaceManagerFactory" default="true">
   <connection
    driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"
    url="jdbc:microsoft:sqlserver://xx.xx.xx.xx:1433;DatabaseName=OMS;SelectMethod=cursor" 
    username="x"
    password="x"
    minPool="2"
    maxPool="10"
    />
   <providerSpecific>
    <property name="org.xorm.datastore.database" 
     value="/com/symbol/mc/oms/jdo/xorm-db.xml"/>
    <property name="org.xorm.ModelMappingFile"
     value="/com/symbol/mc/oms/jdo/bean.jdo"/>
    <property name="org.xorm.option.ValidateXML"
     value="false"/>
   </providerSpecific>
  </jdo>
 </jdo-providers>
</jdo-config>

And here is my code:
private void process(InputStream _is) 
  throws IllegalAccessException, IOException, SAXException
 {
  Digester digester = new Digester();
  digester.push(this);
  addRuleInstances(digester);
  digester.parse(_is);
 }
 
 private void addRuleInstances(Digester _digester) {
  _digester.addSetProperties(
   "jdo-config/jdo-providers");
  _digester.addSetNext(
   "jdo-config/jdo-providers",
   "addJDOConfig",
   "com.symbol.mc.struts.plugin.jdo.JDOConfig");
  
  _digester.addObjectCreate(
   "jdo-config/jdo-providers/jdo",
   "com.symbol.mc.struts.plugin.jdo.JDOConfig");
  _digester.addSetProperties(
   "jdo-config/jdo-providers/jdo");
  _digester.addSetNext(
   "jdo-config/jdo-providers/jdo/connection",
   "setConnection",
   "com.symbol.mc.struts.plugin.common.ConnectionConfig");
  _digester.addSetNext(
   "jdo-config/jdo-providers/jdo/providerSpecific",
   "setProviderSpecific",
   "com.symbol.mc.struts.plugin.common.ProviderSpecificConfig");
  
  _digester.addObjectCreate(
   "jdo-config/jdo-providers/jdo/connection",
   "com.symbol.mc.struts.plugin.common.ConnectionConfig");
  _digester.addSetProperties(
   "jdo-config/jdo-providers/jdo/connection");

  _digester.addObjectCreate(
   "jdo-config/jdo-providers/jdo/providerSpecific",
   "com.symbol.mc.struts.plugin.common.ProviderSpecificConfig");
  _digester.addCallMethod(
   "jdo-config/jdo-providers/jdo/providerSpecific/property",
   "addProperty", 2);
  _digester.addCallParam(
   "jdo-config/jdo-providers/jdo/providerSpecific/property",
   0,
   "name");
  _digester.addCallParam(
   "jdo-config/jdo-providers/jdo/providerSpecific/property",
   1,
   "value");
 }


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Re: Digester

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Following "http://www.onjava.com/lpt/a/2746" reference:
"Note that it is possible to register several rules for the same pattern.
If this occurs, the rules are executed in the order in which they are 
added to the Digester."

You are entering rules in the wrong order, the line :
  _digester.addSetNext( "jdo-config/jdo-providers/jdo/connection",
                                       "setConnection",
                                       
"com.symbol.mc.struts.plugin.common.ConnectionConfig");
must be the last one for this path.
I think addSetNext must be allways the last one for a given path.
I wold write:
  _digester.addObjectCreate( "jdo-config/jdo-providers/jdo", 
                                              
"com.symbol.mc.struts.plugin.jdo.JDOConfig");
  _digester.addSetProperties( "jdo-config/jdo-providers/jdo");

  _digester.addObjectCreate( "jdo-config/jdo-providers/jdo/connection",  
                                              
"com.symbol.mc.struts.plugin.common.ConnectionConfig");
  _digester.addSetProperties("jdo-config/jdo-providers/jdo/connection");

  _digester.addSetNext( "jdo-config/jdo-providers/jdo/connection",  
                                     "setConnection",  
                                      
"com.symbol.mc.struts.plugin.common.ConnectionConfig");

This will create a JDOConfig on the stack and set its properties, after 
that create a ConnectionConfig on top of the stack and set its properties.
Finally it will call setConnection on the JDOConfig object (stack's top) 
when popping from the ConnectionConfig from the stack.

I hope this could help.

Sloan Seaman wrote:

>I'm having trouble getting the Digester to properly populate some java object and I was wondering if someone could help me out.
>
>It keeps trying to call setConnection() on my JDOPlugIn object when I want it to call setConnection() on my JDOConfig object.
>
>Help?
>
>
>Here is my XML:
><jdo-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <jdo-providers>
>  <jdo id="ANALYSIS" provider="org.xorm.InterfaceManagerFactory" default="true">
>   <connection
>    driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"
>    url="jdbc:microsoft:sqlserver://xx.xx.xx.xx:1433;DatabaseName=OMS;SelectMethod=cursor" 
>    username="x"
>    password="x"
>    minPool="2"
>    maxPool="10"
>    />
>   <providerSpecific>
>    <property name="org.xorm.datastore.database" 
>     value="/com/symbol/mc/oms/jdo/xorm-db.xml"/>
>    <property name="org.xorm.ModelMappingFile"
>     value="/com/symbol/mc/oms/jdo/bean.jdo"/>
>    <property name="org.xorm.option.ValidateXML"
>     value="false"/>
>   </providerSpecific>
>  </jdo>
> </jdo-providers>
></jdo-config>
>
>And here is my code:
>private void process(InputStream _is) 
>  throws IllegalAccessException, IOException, SAXException
> {
>  Digester digester = new Digester();
>  digester.push(this);
>  addRuleInstances(digester);
>  digester.parse(_is);
> }
> 
> private void addRuleInstances(Digester _digester) {
>  _digester.addSetProperties(
>   "jdo-config/jdo-providers");
>  _digester.addSetNext(
>   "jdo-config/jdo-providers",
>   "addJDOConfig",
>   "com.symbol.mc.struts.plugin.jdo.JDOConfig");
>  
>  _digester.addObjectCreate(
>   "jdo-config/jdo-providers/jdo",
>   "com.symbol.mc.struts.plugin.jdo.JDOConfig");
>  _digester.addSetProperties(
>   "jdo-config/jdo-providers/jdo");
>  _digester.addSetNext(
>   "jdo-config/jdo-providers/jdo/connection",
>   "setConnection",
>   "com.symbol.mc.struts.plugin.common.ConnectionConfig");
>  _digester.addSetNext(
>   "jdo-config/jdo-providers/jdo/providerSpecific",
>   "setProviderSpecific",
>   "com.symbol.mc.struts.plugin.common.ProviderSpecificConfig");
>  
>  _digester.addObjectCreate(
>   "jdo-config/jdo-providers/jdo/connection",
>   "com.symbol.mc.struts.plugin.common.ConnectionConfig");
>  _digester.addSetProperties(
>   "jdo-config/jdo-providers/jdo/connection");
>
>  _digester.addObjectCreate(
>   "jdo-config/jdo-providers/jdo/providerSpecific",
>   "com.symbol.mc.struts.plugin.common.ProviderSpecificConfig");
>  _digester.addCallMethod(
>   "jdo-config/jdo-providers/jdo/providerSpecific/property",
>   "addProperty", 2);
>  _digester.addCallParam(
>   "jdo-config/jdo-providers/jdo/providerSpecific/property",
>   0,
>   "name");
>  _digester.addCallParam(
>   "jdo-config/jdo-providers/jdo/providerSpecific/property",
>   1,
>   "value");
> }
>
>
>________________________________________________________________________
>This email has been scanned for all viruses by the MessageLabs Email
>Security System. For more information on a proactive email security
>service working around the clock, around the globe, visit
>http://www.messagelabs.com
>________________________________________________________________________
>  
>