Rules Guide

CHAPTER 5

Condition and Action Wizards

This chapter describes how to use the Condition Wizard and Action Wizard in exteNd Director to create custom conditions and actions. It includes these topics:

For more information    For background information, see Developing Custom Conditions and Actions.

 
Top of page

Using the Condition Wizard and Action Wizard

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

exteNd Director provides a Condition Wizard and an Action Wizard to create a Java source file template.

Procedure To use the Condition Wizard or Action Wizard:

  1. From the exteNd Director 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:

    Option

    What to do

    Class Name

    Enter a name for the class.

    Package

    (Optional) Enter a package name.

    By default, exteNd Director adds 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 using the resource set in Developing exteNd Director Applications.

    Include logging code

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

  5. Click Finish.

    Based on your information, exteNd Director creates a Java template for creating either a custom condition or a custom action.

 
Top of page

Using Java templates to define custom conditions and actions

This section describes the methods defined in the condition and action Java templates.

For more information    For a summary of methods, 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
  {
    // 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 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 Java condition and action 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 Using 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 portlet.

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 portlet can include in its generated content, or you can change the portlet'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 portlet.

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

Using 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

Deploying custom conditions and actions

After you have completed your condition or action source file, you need to compile it. exteNd Director then 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.

 
Top of section

Compiling the condition or action source code

Procedure To compile the condition or action source:

  1. Highlight the file in exteNd Director Source view.

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

    exteNd Director compiles the source. If there are no compile errors, exteNd Director 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.



Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...