You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Soaring Eagle <co...@gmail.com> on 2005/04/14 16:19:59 UTC

[Digester] [repost] Using digester to select events (tags) based on parent events (tags)

Hello,

I am using Digester to create a rules engine for an application. This
rules engine should be capable of determining what should be done for
certain financial securities based on their type and the
business event that has occured. Such rules are maintained in XML. How
do I apply digester rules based on nested criteria in this case?

For example, in the XML below, I would like to instantiate the class
com.services.EmailAction only if the type of security is "MEGA" and
the action is "Publish". How do i do that?

This is how I am achieving the desired effect right now:
I am extending the Rule abstract class and in the begin event for
Security and Event tags, I check for required conditions. If
conditions match, I add a boolean true object on a named object stack
(named as "SecurityEventMatch"). I have another Rule object that looks
for the body of a "ClassName" tag and then instantiates the class in
the ClassName tag only of all objects on the SecurityEventMatch stack
are true. In this process, I remove all objects from the
SecurityEventMatch stack.

The above approach works fine, but is highly dependent on the xml
contents (i.e. this is not generic), is dependent on the names I use
in code.

I am thinking that this may be a usual problem for many developers and
am hoping to find a design pattern that will help here.

<Services>
       <Security type="DUSARM">
               <Event type="Preview">
                       <Action>
                               <ClassName>
                                       com.services.EmailAction
                               </ClassName>
                               <ClassName>
                                       com.services.EmailAction
                               </ClassName>
                       </Action>
               </Event>
       </Security>
       <Security type="MEGA">
               <Event type="Preview">
                       <Action>
                               <ClassName>
                                       com.services.EmailAction
                               </ClassName>
                               <ClassName>
                                       com.services.EmailAction
                               </ClassName>
                       </Action>
               </Event>
       </Security>
</Services>


--
Thanks in advance!
Eagle

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


Re: [Digester] Using digester to select events (tags) based on parent events (tags)

Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2005-04-19 at 11:32 -0400, Soaring Eagle wrote:
> Hello,
> 
> I am using Digester to create a rules engine for an application. This
> rules engine should be capable of determining what should be done for
> certain financial securities based on their type and the
> business event that has occured. Such rules are maintained in XML. How
> do I apply digester rules based on nested criteria in this case?
> 
> For example, in the XML below, I would like to instantiate the class
> com.services.EmailAction only if the type of security is "MEGA" and
> the action is "Publish". How do i do that?

What do you want to do if this criteria is not matched?

> 
> This is how I am achieving the desired effect right now:
> I am extending the Rule abstract class and in the begin event for
> Security and Event tags, I check for required conditions. If
> conditions match, I add a boolean true object on a named object stack
> (named as "SecurityEventMatch"). I have another Rule object that looks
> for the body of a "ClassName" tag and then instantiates the class in
> the ClassName tag only of all objects on the SecurityEventMatch stack
> are true. In this process, I remove all objects from the
> SecurityEventMatch stack.
> 
> The above approach works fine, but is highly dependent on the xml
> contents (i.e. this is not generic), is dependent on the names I use
> in code.
> 
> I am thinking that this may be a usual problem for many developers and
> am hoping to find a design pattern that will help here.

> 
> <Services>
>       <Security type="DUSARM">
>               <Event type="Preview">
>                       <Action>
>                               <ClassName>
>                                       com.services.EmailAction
>                               </ClassName>
>                               <ClassName>
>                                       com.services.EmailAction
>                               </ClassName>
>                       </Action>
>               </Event>
>       </Security>
>       <Security type="MEGA">
>               <Event type="Preview">
>                       <Action>
>                               <ClassName>
>                                       com.services.EmailAction
>                               </ClassName>
>                               <ClassName>
>                                       com.services.EmailAction
>                               </ClassName>
>                       </Action>
>               </Event>
>       </Security>
> </Services>


Ideally, patterns associated with a rule would be able to express
conditions, eg

/Services/Security[@type='MEGA']/Event[@type='Publish']/Action/ClassName

However no-one has implemented such a thing, and it would be
non-trivial. I am hoping to implement this, or something similar in
Digester 2.x, but that's not likely to be released any time soon. 

If you wish to contribute an implementation of Rules which supports such
conditional matching, I would be very happy to see it included in
Digester (or Digester2).

There is an entry in Bugzilla proposing "filters" that can be associated
with rules. You may wish to consider whether that would solve your
problems. If it does, I recommend creating your own private
implementation of this., If you find that it solves the problem well,
and you are willing to contribute the code back to Digester then we
would be interested in reviewing the code at that time.
See http://issues.apache.org/bugzilla/show_bug.cgi?id=31329

In the meantime, the solution you describe is a reasonable one. So (I
think) is the one I described in a reply to your previous posting of
this issue.

Regards, 

Simon


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


[Digester] Using digester to select events (tags) based on parent events (tags)

Posted by Soaring Eagle <co...@gmail.com>.
Hello,

I am using Digester to create a rules engine for an application. This
rules engine should be capable of determining what should be done for
certain financial securities based on their type and the
business event that has occured. Such rules are maintained in XML. How
do I apply digester rules based on nested criteria in this case?

For example, in the XML below, I would like to instantiate the class
com.services.EmailAction only if the type of security is "MEGA" and
the action is "Publish". How do i do that?

This is how I am achieving the desired effect right now:
I am extending the Rule abstract class and in the begin event for
Security and Event tags, I check for required conditions. If
conditions match, I add a boolean true object on a named object stack
(named as "SecurityEventMatch"). I have another Rule object that looks
for the body of a "ClassName" tag and then instantiates the class in
the ClassName tag only of all objects on the SecurityEventMatch stack
are true. In this process, I remove all objects from the
SecurityEventMatch stack.

The above approach works fine, but is highly dependent on the xml
contents (i.e. this is not generic), is dependent on the names I use
in code.

I am thinking that this may be a usual problem for many developers and
am hoping to find a design pattern that will help here.

<Services>
      <Security type="DUSARM">
              <Event type="Preview">
                      <Action>
                              <ClassName>
                                      com.services.EmailAction
                              </ClassName>
                              <ClassName>
                                      com.services.EmailAction
                              </ClassName>
                      </Action>
              </Event>
      </Security>
      <Security type="MEGA">
              <Event type="Preview">
                      <Action>
                              <ClassName>
                                      com.services.EmailAction
                              </ClassName>
                              <ClassName>
                                      com.services.EmailAction
                              </ClassName>
                      </Action>
              </Event>
      </Security>
</Services>

--
Thanks in advance!
Eagle

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