First Previous Next Last

Rules Guide  

Chapter 5   Condition and Action Wizards

This chapter describes how to use the Condition Wizard and Action Wizard in Workbench. It includes these topics:

For more information    For information about developing custom conditions and actions, see Developing Custom Conditions and Actions.

 
Top of page

Creating conditions and actions

The eXtend Director installation includes a set of conditions and actions that are accessible from the Rule Editor in Workbench. You can also use Workbench to create your own conditions and actions and access them in the same way.

Workbench provides a Condition Wizard and an Action Wizard to create a Java source file template. Both wizards ask for the same type of information before generating the template.

Procedure To use the Condition Wizard or Action Wizard:

  1. From the Workbench main menu, select File>New.

  2. In the New File dialog, select the Rules Engine tab.

  3. Select the Condition or Action icon:

    wbREcaWizard1

    The appropriate wizard panel displays:

    wbREcaWizard2

  4. Complete the information in the wizard panel:

    Wizard option

    What to do

    Class Name

    Enter a name for the class.

    Package

    (Optional) Enter a package name.

    By default, Workbench will add the class to your project source layout in the Resource Set/resource.spf/src directory. If you specify a package, it will be appended to /src.

    Resource Set

    Enter the resource set to use for this condition or action.

    The resource set determines the source and archive locations for the elements in your project. For more information, see the chapter on system architecture in the Core Development Guide.

    Include logging code

    Check if you want the code template to include logging code for error tracing and debugging messages.

  5. Click Finish.

 
Top of page

Using the code templates

When you finish the Condition Wizard or the Action Wizard, Workbench creates a Java code template.

This section describes the methods defined in the condition and action templates. For a summary, see About the template methods.

 
Top of section

Condition template

The defining method for a condition is EbiCondition.doCondition(), where you place the logic for the condition.

Here is the template generated for a condition named myCondition in package myconditions.

  package myconditions;
  
  /**
      myCondition
  */
  public class myCondition implements com.sssw.re.api.EbiCondition
  {
   // an Instance of a log for error/trace reporting
    private com.sssw.fw.api.EbiLog log =
    com.sssw.fw.log.EboLogFactory.getLog( com.sssw.fw.log.EboLogFactory.RE );
      /**
       *  return a component (JPanel) that represents the editor of the
           condition,
       *  OR return null if you would like an editor generated automatically.
       */
     public java.awt.Component getParameterPanel () {
          return null;
      }
  
     public boolean doCondition( com.sssw.re.api.EbiContext context ) throws
        com.sssw.re.exception.EboConditionException {
          // only log items if the log level indicates we should
          if ( log.isTrace() ) {
              log.trace( "myCondition in doCondition method" );
          }
          // place your condition code here...
          return false;
      }
  
      public String toString() {
          return "<i>myCondition</i>";
      }
  }

 
Top of section

Action template

The defining method for an action is EbiAction.doAction(), where you place the logic for the action.

Here is the template generated for a condition named myAction in package myactions.

  package myactions;
  
  /**
      myAction
  */
  public class myAction implements com.sssw.re.api.EbiAction
  {
    // anInstance of a log for error/trace reporting
    private com.sssw.fw.api.EbiLog log =
   com.sssw.fw.log.EboLogFactory.getLog( com.sssw.fw.log.EboLogFactory.RE );
   /**
    *  return a component (JPanel) that represents the editor of the action,
    *  OR return null if you would like an editor generated automatically.
    */
    public java.awt.Component getParameterPanel () {
       return null;
      }
  
    public void doAction( com.sssw.re.api.EbiContext context ) throws
      com.sssw.re.exception.EboActionException {
        // only log items if the log level indicates we should
        if ( log.isTrace() ) {
           log.trace( "myAction in doAction method" );
          }
          // place your action code here...
          context.setResponsePhrase( "myAction" );
      }
  
      public String toString() {
          return "<i>myAction</i>";
      }
  }

 
Top of section

About the template methods

A condition requires implementing the doCondition() method, and an action requires implementing the doAction() method. The other methods are the same for both templates:

Template method

Usage

What it does

getLog()

Optional

Lets you generate trace and error messages for debugging. This method appears if you checked Include logging code in the wizard.

getParameterPanel()

Optional

Lets you create a custom property panel for the condition or action. The Rule subsystem will provide default controls for some data types.

For more information    For more information, see About condition and action properties.

doCondition()

Condition Wizard only

Required

Fulfills the requirements of the EbiCondition interface. In this method, you write code that makes comparisons or evaluates property values and returns a Boolean value.

The EbiContext object is passed to doCondition() so you can access the current session, user, and component.

For more information    For more information, see Defining logic for a condition.

doAction()

Action Wizard only

Required

Fulfills the requirements of the interface. In this method, you write code that performs actions based on whether the associated condition evaluates to true or false. This method typically returns the result of a business rule.

The result returned might be a simple Boolean value or information accessed from a database. You can design rules that return formatted content that the component can include in its generated content, or you can change the component's processing based on the rule's action value.

The EbiContext object is passed to doAction() so that you can access the current session, user, and component.

For more information    For more information, see Defining logic for an action.

toString() method

Required

Returns a String that describes the condition and its current settings as a phrase. Typically, the phrase calls the properties' get methods to include property values. The Rule Editor displays this phrase in the rule definition.

For more information    For more information, see Defining a condition or action rule descriptor.

 
Top of page

About condition and action properties

Typically, conditions and actions are implemented as JavaBeans that include properties you can set in the Rule Editor. Here are the code elements you can use for rendering properties:

Property element type

Usage

For information see

JavaBeans

By defining properties, you allow conditions and actions to be customized in the Rule Editor for use in a variety of rules.

Defining JavaBeans

Generic properties

The Rule subsystem provides default controls for most data types that you can use in your JavaBean implementation.

Using generic property panels

Custom property panel

If you prefer to create your own property panel rather than use generic properties, you can implement the getParameterPanel() method.

Creating a custom property panel

Runtime properties

The Rule subsystem provides string template data types that allow properties in conditions and actions to be set dynamically from runtime whiteboard values.

Defining runtime properties

BeanInfo class

You can include a BeanInfo class to provide formatted property descriptions and to implement Java Resource Bundles for localization.

Writing a BeanInfo class

Resource bundles

Java Resource bundles provide localized descriptions for property panels.

Using resource bundles

 
Top of page

Using custom conditions and actions

When you compile your condition or action source file, Workbench places the result in your resource set. This allows the Rule Editor to find and display the runtime version when you select it from the condition or action dropdown menu.

For more information    For more information about resource sets, see the chapter on application architecture in the Core Development Guide.

Procedure To compile the condition or action source:

  1. Highlight the file in Workbench Source view.

  2. Right-click and choose Compile from the popup menu.

    Workbench compiles the source. If there are no compile errors, Workbench stores the result in the resource set in your project archive.

    Now you can select the condition or action in the Rule Editor.

 
Top of section

Deploying support files

If you have any supporting files such as a BeanInfo class, they must be archived in an appropriate location before you can access the condition or action in the Rule Editor. The location must be specified in the libPath of your ResourceSet.war project web.xml file.

For more information    For more information, see the chapter on application architecture in the Core Development Guide.

    First Previous Next Last

Rules Guide  

Copyright © 2002, SilverStream Software, LLC, a wholly owned subsidiary of Novell, Inc. All rights reserved.