Back Forward Examples — Using inline Java and PublicAPI facilities

Advanced featureThis topic provides examples of handcrafted Java.

Rules assembly and generated Java

At the time of first use, Process Commander rules are translated into server Java code and compiled. A second user who later executes the same rule (in the same RuleSet context) accesses the compiled CLASS file for it, bypassing the translation and compilation steps. The second use typically retrieves the code from an in-memory rules assembly cache linked to the loaded CLASS file, bypassing the server file system.

As a benefit of this approach, experienced Java developers can incorporate Java operations and expressions directly in activities and stream rules (HTML rules, XML Stream rules, correspondence, and other rule types derived from the Rule-Stream class).

Generated Java classes extend the com.pegarules.generated class.

The system stores generated Java files in subdirectories named PRGenClasses and PRGenJava. These directories are subdirectories of a temporary directory specified in a prconfig.xml file setting; this directory name is visible on the process page as pxProcess.pxTempPath. Both the .java files and the .CLASS files are viewed as temporary because they can be regenerated if needed.

Environment

Within generated Java, several member variables are available. The tools object provides access to the entire PublicAPI, and is available within most rule types.

Within an activity, the variable myStepPage refers to the current step page, and this refers to the current activity.

Get a string value from a clipboard value

F-124 Use getString() to access a Single Value or scalar property:

string updateoperator = tools.findPage("pyWorkPage").getString(pxUpdateOpName)

For properties on an embedded page, use the fully qualified name of the page:

string updateoperator =
tools.findPage("pyWorkPage.pyWorkParty(Originator")).getString(pxPartyRole)

Set a clipboard value from a Java string

Use putString() to set the value of a Single Value or scalar property:

tools.findPage("pyWorkPage").putString(".Color", "red")

where Color is a Single Value property. Clipboard pages are strongly typed, and the class of the page pyWorkPage must permit a property named ".Color" (as defined in the data dictionary by a Rule-Obj-Property rule) at the time of this assignment. CLINB 3/13/06

Include Java in an expression

An expression can employ the built-in function @java() to incorporate Java code, including PublicAPI calls. For example, a when condition rule can evaluate this Boolean test: OSMAE 10/15/05

@java("(new Boolean(tools.getRequestor().getTextOrientation() == PRRequestor.ORIENTATION_RIGHT_TO_LEFT)).toString()")

StreamBuilderToolkit Class

These methods are in the BuildStream class of the PublicAPI.

Append a formatted string

void appendFormatted(java.lang.String aSource, byte aFormat)

Use the appendFormatted() PublicAPI method to instruct the system to insert HTML characters into the output of stream processing after formatting. For the second (format) parameter, enter one of these keywords. See Reference directive for details on these formats.

FMT_BLOCK
FMT_HTML
FMT_LITERAL
FMT_NORMAL
FMT_STREAM
FMT_TEXT

Append a string

void appendString(java.lang.String aSource)

Use the appendString() Java method to append a string into the output text stream.

Append a property value

Use this Java method to append a Single Value property value into the output text stream.

void appendProperty(ClipboardProperty aProperty, java.lang.String aStreamSpec, boolean aWantInput) REMOVED DEPRECATED Property thisRef() per CLINB 3/13/06

Definitions Pega log, PublicAPI, temporary files
Related topics Activity rules — Reserved names for parameters and local variables
Using Java in activity steps
How to set up a Java development environment
Process Commander for Java developers — Concepts and terms

UpTechnical category