commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tslus...@InPhact.com
Subject RE: Digester: Cannot get <call-param-rule> to parse?
Date Mon, 24 Mar 2003 15:45:21 GMT
I think you are wanting something like this...

xml to parse:

<?xml version="1.0"?>
<Context>
  <ResourceParams name="jdbc/db2" value="foo">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
  </ResourceParams>
</Context>

rules file:

<?xml version="1.0"?>
<digester-rules>
  <pattern value="Context/ResourceParams">
    <object-create-rule
      classname="com.merck.common.rcpool.deploy.ResourceParams"/>
    <set-properties-rule>
      <alias attr-name="name" prop-name="name"/>
    </set-properties-rule>
    <pattern value="parameter">
      <call-method-rule methodname="addParameter" paramcount="2"/>
      <call-param-rule pattern="name" paramnumber="0" />
      <call-param-rule pattern="value" paramnumber="1" />
    </pattern>
  </pattern>
</digester-rules>

ResourceParams.java:
...
public void setName(String name)
{
  this.name = name;	// this will hold the jdbc/db2 value
}

public void addParameter(String name, String value)
{
  setValue(name + "=" + value);  // this will hold the factory=...
}
...

Hope this helps!

Ted-

-----Original Message-----
From: Lafredo, Stephen [mailto:stephen_lafredo@merck.com]
Sent: Monday, March 24, 2003 8:53 AM
To: 'Jakarta Commons Users List'
Subject: RE: Digester: Cannot get <call-param-rule> to parse?


Hi,

I have the following configured w/in my rules file...

...
  <pattern value="Context/ResourceParams">

    <object-create-rule
classname="com.merck.common.rcpool.deploy.ResourceParams"
                         attrname="resourcesParameters"/>

    <!-- map the element's XML attributes to the bean properties -->
    <set-properties-rule>
      <alias attr-name="name" prop-name="name" />
    </set-properties-rule>

    <call-method-rule methodname="addParameter" paramcount="2" />
    <call-param-rule paramnumber="0" attrname="name" />
    <call-param-rule paramnumber="1" attrname="value"  />

  </pattern>
...

This is the portion of the xml file I am parsing...

  <ResourceParams name="jdbc/db2" value="foo">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
  </ResourceParams>

When the rules file is configured as described above the "ResourceParams"
ATTRIBUTES and not the contained "parameter" ELEMENTS are being parsed!

This is the sample output...

ResourceParams[name=jdbc/db2, parameters={jdbc/db2=foo}]

What I am expecting is...

ResourceParams[name=jdbc/db2,
parameters={factory=org.apache.commons.dbcp.BasicDataSourceFactory}]

Am I misunderstanding the functionality of call-method-rule?

Thank you.

Stephen Lafredo


-----Original Message-----

Hi,

I have corrected the rules file as described below but I am still getting an
error when I try to specify a method w/parameters?

Mar 24, 2003 9:03:29 AM org.apache.commons.digester.Digester peekParams
WARNING: Empty stack (returning null) 
Mar 24, 2003 9:03:29 AM org.apache.commons.digester.Digester startElement
SEVERE: Begin event threw exception java.lang.NullPointerException
 	at
org.apache.commons.digester.CallParamRule.begin(CallParamRule.java:232)
 	at org.apache.commons.digester.Rule.begin(Rule.java:200) 

...

java.lang.NullPointerException
 	at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2383)
at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2409)
at org.apache.commons.digester.Digester.startElement(Digester.java:1271) 

The release notes suggests that this functionality has been implemented but
is it?

Any suggestions?

Thank you.

Stephen Lafredo


----------------------------------------------------------------------------
--
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named in this
message.  If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.

============================================================================
==


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

Mime
View raw message