This topic provides examples of handcrafted 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.
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.
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)
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.
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:
@java("(new Boolean(tools.getRequestor().getTextOrientation() == PRRequestor.ORIENTATION_RIGHT_TO_LEFT)).toString()")
These methods are in the BuildStream class of the PublicAPI.
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
void appendString(java.lang.String aSource)
Use the appendString() Java method to append a string into the output text stream.
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)