|
Rules Guide |
This chapter describes how to use the Condition Wizard and Action Wizard in Workbench. It includes these topics:
For information about developing custom conditions and actions, see
Developing Custom 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.
To use the Condition Wizard or Action Wizard:
Select the Condition or Action icon:
The appropriate wizard panel displays:
Complete the information in the wizard panel:
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.
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
{
// 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>";
}
}
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.
|
|
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.
|
|
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.
|
|
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:
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 about resource sets, see the chapter on application architecture in the Core Development Guide.
To compile the condition or action source:
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.
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, see the chapter on application architecture in the Core Development Guide.
|
Rules Guide |
Copyright © 2002, SilverStream Software, LLC, a wholly owned subsidiary of Novell, Inc. All rights reserved.