Rules Guide
CHAPTER 5
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 background information, see Developing Custom Conditions and Actions.
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.
To use the Condition Wizard or Action Wizard:
Select the Condition or Action icon:
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. |
Based on your information, exteNd Director creates a Java template for creating either a custom condition or a custom action.
This section describes the methods defined in the condition and action Java templates.
For a summary of methods, see About the template methods.
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>"; } }
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>"; } }
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.
|
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.
|
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.
|
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.
|
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:
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.
To compile the condition or action source:
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.
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 ...