commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mykel Alvis <mykel.al...@gmail.com>
Subject Digester wildcard question
Date Tue, 21 Jun 2005 15:18:16 GMT
I have a slightly different need than Frank, but I'm posting with the
same subject line. :)

I'm using XML digester rules to parse configurations.  I have a series
of tags that I think should be matched as wildcards but don't seem to
be.

The code to parse my rules is as follows:

		URL u = this.getClass().getResource("/jave-ruleset-digester.xml");
		Digester digester = DigesterLoader.createDigester(u);
		List l = new ArrayList();
		digester.push(l);
		try {
			digester.parse(file);
		} catch (IOException e) {
			log.error(e);
			throw new RulesParseException(e);
		} catch (SAXException e) {
			log.error(e);
			throw new RulesParseException(e);
		}


The rules defs:
------------------------------
<digester-rules>
    <pattern value="javerules/rulesets/ruleset">
        <object-create-rule
classname="com.sungard.omnirules.implementation.jave.rules.RuleList"
/>
        <set-next-rule methodname="add" paramtype="java.lang.Object"/>
        <set-properties-rule/>
        <pattern value="rule">
            <object-create-rule classname="RelationalOperatorRule" />
            <set-next-rule methodname="add" paramtype="Rule" />
            <set-properties-rule/>
            <pattern value="condition">    
                <pattern value="leftoperand">
                    <object-create-rule classname="Variable" />
                    <set-next-rule methodname="setLhs"
paramtype="Variable" />
                    <set-properties-rule/>
                </pattern>            
                <pattern value="operator">
                    <object-create-rule classname="RelationalOperator"
/>
                    <set-next-rule methodname="setOperator"
paramtype="RelationalOperator" />
                    <set-properties-rule/>
                </pattern>            
                <pattern value="rightoperand">
                    <object-create-rule classname="Variable" />
                    <set-next-rule methodname="setRhs"
paramtype="Variable" />
                    <set-properties-rule/>
                </pattern>        
            </pattern>
            <pattern value = "true">
                <object-create-rule classname="ConsequenceList" />
                <set-next-rule methodname="setTrueConsequence"
paramtype="Consequence" />
                <set-properties-rule/>
            </pattern>
            <pattern value = "false">
                <object-create-rule classname="ConsequenceList" />
                <set-next-rule methodname="setFalseConsequence"
paramtype="Consequence" />
                <set-properties-rule/>
            </pattern>
            <pattern value="*/message">
                <object-create-rule classname="Message" />
                <set-next-rule methodname="add" paramtype="Consequence" />
                <set-properties-rule/>
            </pattern>

         </pattern>
    </pattern>
</digester-rules>
----------------------

Parsing the following file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<javerules>
    <rulesets>
        <ruleset name="/WYZX">
            <class>RulesImpl</class>
            <rule name="someotherrulename">
                <condition>
                    <!-- ALWAYS TRUE sort of condition -->
                    <leftoperand key="current.someproperty"
description="descofcurrent.someprop" />
                    <operator operator="=" />
                    <rightoperand key="current.someproperty"
description="descofcurrent.someprop" />
                </condition>
                <true>
                    <message message="Always true is true"/>
                    <message message="Always true is STILL true" />
                </true>
                <false>
                    <message message="Always true is false" />
                    <message message="Always true is also false" />
                    <message message="Always true is STILL false" />
                </false>
            </rule>
            <rule name="WEQE">
                <condition>
                    <leftoperand key="current.someproperty"
description="descofcurrent.someprop" />
                    <operator operator="=" />
                    <rightoperand key="previous.someproperty"
description="descofprevious.someprop" />
                </condition>
                <true>
                    <message name="truemessage" message="True fired!"
terminationPoint="true" />
                </true>
                <false>
                        <message name="somemessage" description="desc"
mesage="False fired!" />
                </false>
            </rule>
        </ruleset>
    </rulesets>
</javerules>

-----

Class definitions as follows:

public class ConsequenceList extends BaseConsequence implements
Consequence, Serializable {
...
    public void add(Consequence consequence)
	{
		list.add(consequence);
	}

}
public class Message extends BaseConsequence implements Consequence,
Serializable {
...blah
}


What I'm trying to do is have a single rule for adding Consquence
instances to either the true or false ConsequenceList, depending on if
they're contained inside a <true> tag or a <false> tag
Noting that */message as a pattern should invoke the rule to create a
Message and it's set-next should invoke an add on the next-to-the-top
of the stack, and being that that item is a ConsequnceList which has
an add element to it, I thought this would work.  However, per the
log:
-------------------------
DEBUG (SetPropertiesRule.java:243)
[SetPropertiesRule]{javerules/rulesets/ruleset/rule/true} Set
ConsequenceList properties
DEBUG (BeanUtilsBean.java:795) BeanUtils.populate(ConsequenceList@93df2c[
  ConsequenceList@93df2c[
  list=[]
  parameters=<null>
]
  List=[]
  Termination Point=false
], {})
DEBUG (Digester.java:1002) characters(
					)
DEBUG (Digester.java:1318) startElement(,,message)
DEBUG (Digester.java:1325)   Pushing body text '
					'
DEBUG (Digester.java:1344)   New
match='javerules/rulesets/ruleset/rule/true/message'
DEBUG (Digester.java:1372)   No rules found matching
'javerules/rulesets/ruleset/rule/true/message'.
DEBUG (Digester.java:1072) endElement(,,message)
DEBUG (Digester.java:1075)  
match='javerules/rulesets/ruleset/rule/true/message'
DEBUG (Digester.java:1076)   bodyText=''
DEBUG (Digester.java:1111)   No rules found matching
'javerules/rulesets/ruleset/rule/true/message'.
DEBUG (Digester.java:1118)   Popping body text '
					'
DEBUG (Digester.java:1002) characters(
				)
DEBUG (Digester.java:1072) endElement(,,true)
--------


No rules found matching 'javerules/rulesets/ruleset/rule/true/message'
is definitely not what I expected to see.
Am I creating my rulesets wrong?  I extended DigesterLoader and set an
ExtendedBaseRules implementation as the rules base in my "create a
digester" code but to no avail.

I would appreciate advice on what I'm doing wrong.

Mykel

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