Sun IDM: XPRESS Language

 

Intro

* A functional language that uses
– syntax based on XML
– prefix notation ( == x 42 vs x == 42 )
* and can
– invoke methods of any Java class
– evaluate JavaScript
* Examples:
– Hello world:

<print><s>Hello World!</s></print>

– Add calculation:

<add> <ref>counter</ref> <i>10</i> </add>

* Used in IDM for:
– Customize UIs
– Defined workflow flow control
– Implement workflow actions

Example Usages

Control Field Visibility

* Hide HomeDirectory if account type is not Solaris:

<Field name='HomeDirectory'>
   <Display class='Text'/>
      <Property name='title' value='HomeDirectory'/>
   </Display>
   <Disable>
      <not>
          <contains>
            <ref>accountInfo.typeNames</ref>
            <s>Solaris</s>
         </contains>
      </not>
   </Disable>
</Field>

Calculating Default Field Values

<Field name='waveset.accountId'>
   <Display class='Text'/>
      <Property name='title' value='AccountID'/>
   </Display>
   <Default>
	   <cond>
		 <and>
		   <notnull><ref>accounts[AD].firstname</ref></notnull>
		   <notnull><ref>accounts[AD].lastname</ref></notnull>
		 </and>
		 <concat>
		   <substr>
				<ref>accounts[AD].firstname</ref>
				<i>0</i>
				<i>1</i>
			</substr>
		   <ref>accounts[AD].lastname</ref>
		 </concat>
	   </cond>
   </Default>
</Field>

Deriving Field Values

* Display location based on location code:

<Field name='location' prompt='Location'>
   <Display class='Text'/>
      <Derivation>
         <switch>
            <ref>accounts[Oracle].locCode</ref>
            <case>
               <s>AUS</s>
               <s>Austin</s>
            </case>
            <case>
               <s>HOU</s>
               <s>Houston</s>
            </case>
            <case>
               <s>DAL</s>
               <s>Dallas</s>
            </case>
            <case default='true'>
               <s>unknown</s>
            </case>
         </switch>
   </Derivation>
</Field>

Generating Field Values

<Field name='accounts[Oracle].locCode'>
   <Expansion>
      <switch>
         <ref>location</ref>
         <case>
            <s>Austin</s>
            <s>AUS</s>
         </case>
         <case>
            <s>Houston</s>
            <s>HOU</s>
         </case>
         <case>
            <s>Dallas</s>
            <s>DAL</s>
         </case>
      </switch>
   </Expansion>
</Field>

Workflow Transition Conditions

<Activity name='Check Results'>
   <Transition to='Log Errors'>
      <gt> <ref>ERROR_COUNT</ref> <i>0</i> </gt>
   </Transition>
   <Transition to='end'/>
</Activity>

Workflow Actions

<Activity name='Increment Counter'>
   <Action>
      <expression>
         <set name='counter'>
            <add> <ref>counter</ref> <i>1</i> </add>
         </set>
      </expression>
   </Action>
   <Transition to='Next'/>
</Activity>

Invoking Java Methods from Workflow Actions

<Activity name='Log Status'>
 
   <Action>
      <expression>
         <invoke name='logStatus'
            class='custom.OracleStatusLog'>
            <ref>accountId</ref>
            <ref>email</ref>
            <ref>status</ref>
         </invoke>
      </expression>
   </Action>
   <Transition to='Next'/>
</Activity>

Test Expressions

* With lh command:

cd %WSHOME%\bin
lh xmlparse xpress_file

Tracing XPRESS Evaluation

* Two tracing levels:
– global
– block level
* Turn on global tracing in Waveset.properties (and don’t forget to reload properties):
xpress.trace=true
* Turn on block level tracing:

<block trace='true'>
   <invoke name='getTime' class='java.util.Date'/>
</block>
<Default>
   <block trace = 'true'>
      <ref>global.accountId</ref>
   </block>
</Default>

– invalid block examples:

<block trace='true'>
   <Field name ='field1'></Field>
</block>
<Field name='Field2'>
   <block trace='true'>
      <Default>
         <ref>global.accounts</ref>
      </Default>
   </block>
</Field>

Functions

Value Constructor Expressions

* array

<array>
   <s>apples</s>
   <s>oranges</s>
   <s>wiper blades</s>
</array>

* i

<i>42</i>
<i>-1234</i>

* list

	<list>
   <s>apples</s>
   <s>oranges</s>
   <s>wiper blades</s>
</list>

* map

<map>
   <!--Key 1-->
   <!--Value 1-->
   <!--Key n-->
   <!--Value n-->
</map>

* null

<null/>
<null></null>

* s

<s>Now is the time</s>

Arithmetic Expressions

* add

<add> <i>40</i> <i>1</i> <s>1</s> </add>

* div

<div> <i>84</i> <i>2</i></div>

* mod

<mod> <i>142</i> <i>100</i> </mod>

* mult

<mult> <i>7</i> <i>3</i> <i>2</i> </mult>

* sub

<sub> <i>50</i> <i>6</i> <i>2</i> </sub>

Logical Expressions

* and

<and> <i>42</i> <s>cat</s> <i>null</i> </and> # return zero
<and> <i>42</i> <s>cat</s> </and> # return cat

* cmp

<cmp>
    <i>20</i>
    <i>100</i>
 </cmp> # returns -1
 
 <cmp>
    <s>bob</s>
    <s>ray</s>
 </cmp> # returns -16 (b is 16 positions behind r)
 <cmp>
    <s>daryl</s>
    <s>daryl</s>
 </cmp> # returns true

* eq
0: false
1: true

<eq> <ref>role</ref> <s>engineering</s> </eq>

* gt

<gt>
    <ref>age</ref>
    <i>42</i>
 </gt>

* gte

<gte>
   <i>10</i>
   <i>5</i>
</gte> # return 1 (true)

* isFalse

0: true
1: false
<isFalse>
   <s>false</s>
</isFalse> # returns 1 (false)

* isnull
0: not null
1: is null

<isnull> <null/> </isnull> # returns 1 (null)
<isnull> <i>0</i> </isnull> # return 0 (not null)

* isTrue
0: the argument is logically false. The following are considered true: the string true, a Boolean true, and a non-zero integer. (Anything else is considered false.)
1: the argument is logically true.

<isTrue>
   <s>false</s>
</isTrue> # returns 0

* lt

<lt>
   <i>10</i>
   <i>5</i>
 </lt>

* lte

<lte>
    <ref>age</ref>
    <i>42</i>
 </lte>

* ncmp (case insensitive comparison)

<ncmp>
   <s>Daryl</s>
   <s>daryl</s>
</ncmp> # returns 0 (equal)

* neq

<neq>
    <ref>role</ref>
    <s>management</s>
 </neq>

* not

 <not> <eq> <i>42</i> <i>24</i> </eq> </not> # returns 1

* or

<or> <i>0</i> <i>0</i> </or> # returns 0, logical false
<or> <i>0</i> <s>cat</s> </or> # returns cat, logical true

* notnull

<notnull>
   <ref>firstname</ref>
</notnull> # returns 1
<notnull><null/></notnull> # returns 0

String Manipulation Expressions

* indexOf

<indexOf>
   <s>abcabc</s>
   <s>abc</s>
   <s>l</s>
</indexOf> # returns 3

* concat

<concat>
   <s>Now </s><s>is </s><s>the </s><s>time</s>
</concat> # returns <s>Now is the time</s>

* downcase

<downcase><s>ABC</s></downcase> # returns <s>abc</s>

* length

<length>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
</length> # returns 2
 
<length>
   <s>Hello world!</s>
</length> # returns 11

* ltrim

<ltrim><s> hello</s></ltrim>

* match: deprecated, use contains instead

 

* message

<message severity-'ok' name='DEFAULT_MESSAGE'>
   <!--message parameter 0-->
   <!--message parameter n-->
</message>

* pad

<pad>
   <s> email</s>
   <i>10</i>
</pad>

* rtrim

 

* split

<split>
   <s>Austin City Limits</s>
   <s> </s>
</split>
# returns:
	<list>
   <s>Austin</s>
   <s>City</s>
   <s>Limits</s>
</list>
 
<split>
   <s>(512)338-1818</s>
   <s>()-</s>
</split>
# returns:
	<list>
   <s>512</s>
   <s>338</s>
   <s>1818</s>
</list>

* substr

<substr>
   <s>Now is the time</s>
   <i>0</i>
   <i>3</i>
</substr> # returns: <s>Now</s>
 
<block>
    <substr l='4'>
        <s>Hello World</s> --> Hello World
    </substr> --> Hell
</block> --> Hell

* trim

<trim><s> hello </s></trim>

* upcase

<upcase><s>abc</s></upcase>

* ztrim

<ztrim>
   <s>00000sample</s>
</ztrim> # returns <s>sample</s>

List Manipulation Expressions

* append

<append>
    <ref>srclist</ref>
    <s>oranges</s>
</append>
 
<set name= 'somelist'>
   <List>
    <s>We</s>
    <s>say</s>
  </List>
</set>
<append name= 'somelist'>
  <s>Hello</s>
  <s>World</s>
</append>
<ref>someList</ref>

* appendAll

<appendAll>
   <ref>srclist</ref>
   	<list>
      <s>apples</s>
      <s>oranges</s>
      <s>peaches</s>
   </list>
</appendAll> # Create a new list by combining srclist and three elements
 
<appendAll name='srclist'>
   	<list>
      <s>apples</s>
      <s>oranges</s>
      <s>peaches</s>
   </list>
</appendAll> # Add three elements to srclist

* contains

<contains>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
   <s>apples</s>
</contains> # returns 1
 
<contains>
   <s>foobar</s>
   <s>foo</s>
</contains> # also returns 1

* containsAll

 

*

 

*

 

* containsAny

 

* filterdup

 

* filternull

 

* expand
– Returns the string value of the subexpression with $() variable references expanded.

<Rule name="testExpand">
	<RuleArgument name="str"/>
	<expand><s>Expanded: $(str)</s></expand>
</Rule>
 
<!-- If input str is 'test' we'll get: -->
<String>Expanded: test</String>

* get: Retrieves the value of the nth element in the list. The list indexes starts count from zero (0). Arguments are a list and an integer.

<get>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
   <i>1</i>
</get> # returns <s>oranges</s>

* indexOf

<indexOf>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
   <s>oranges</s>
</indexOf> # returns 1
 
<indexOf>
   	<list
      <s>apples</s>
      <s>oranges</s>
   </list>
   <s>oranges</s>
<i>2</i>
</indexOf> # returns 3??

* insert

<insert>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
   <i>1</i>
   <s>wiper blades</s>
</insert>
 
This expression returns the following list.
 
	<list>
   <s>apples</s>
   <s>wiper blades</s>
   <s>oranges</s>
</list>

* length

<length>
   	<list>
      <s>apples</s>
      <s>oranges</s>
   </list>
</length> # returns 2

* remove

<remove>
    <ref>srclist</ref>
    <s>oranges</s>
</remove>

* removeAll

 

* retainAll

 

* setlist (and overwrites)

<setlist>
   	<list>
      <s>apples</s>
      <s>oranges</s>
      <s>wiper blades</s>
   </list>
   <i>2</i>
   <s>bassoons</s>
</setlist>
 
This expression results in the following list and returns null.
 
	<list>
   <s>apples</s>
   <s>oranges</s>
   <s>bassoons</s>
</list>

Conditional, Iteration, and Block Expressions

* block

<block>
    <s>Hello there!</s>
    <add> <i>100</i> <i>2</i> </add>
    <i>42</i>
</block> # returns 42

* break

<dolist name='el'>
<ref>list</ref>
   <cond><eq><ref>el</ref><s>000</s></eq>
      <break>
         <ref>el</ref>
      </break>
   </cond>
<null/>
</dolist>

* cond (if/else)

<cond>
     <gt>
      <ref>age</ref>
       <i>40</i>
     </gt>
   <s>old</s>
   <s>young</s>
</cond>

* dolist
The following expression creates a list called subset, which contains the subset of elements in srclist that exceed 10.

<set name='subset'>
    <dolist name='el'>
      <ref>srclist</ref>
      <cond>
        <gt>
          <ref>el</ref>
          <i>10</i>
        </gt>
      </cond>
      <ref>el</ref>
    </dolist>
 </set>

* switch

<switch>
   <s>A</s>
   <case default='true'>
      <s>unknown</s>
   </case>
   <case>
      <s>A</s>
      <s>apples</s>
   </case>
   <case>
      <s>B</s>
      <s>oranges</s>
   </case>
</switch>

* select: Returns the first non-null (and non-zero) value in a list.

<select>
    <ref>:display.session</ref>
    <ref>context</ref>
</select>
 
If you have the following statement:
 
<select>
   <ref>first/ref>
   <ref>second</ref>
   <ref>third</ref.
</select>

* while

<while>
    <gt>
       <ref>counter</ref>
      <i>0</i>
    </gt>
   <set name='counter'>
      <sub> <ref>counter</ref>
         <i>1</i>
       </sub>
   </set>
</while>

Variables and Function Definition Expressions

* ref: References the value of a variable. The variable can either be an external variable supported by the host application or an internal variable defined with defvar.

<ref>waveset.role</ref>
 
<defvar name='milk'><s>milkvalue</s></defvar>
<defvar name='shake'><s>milk</s></defvar>
<ref><ref>shake</ref> # returns <s>milkshake</s>

* defvar

<defvar name='theList'>
  	<list>
     <s>apples</s>
     <s>oranges</s>
  </list>
</defvar>
 
<defvar name='counter'>
   <i>0</i>
</defvar>

* defarg: Defines an argument within a function defined with defun. Arguments are similar to variables, but they must be defined in the order in which arguments are passed to the function.

<defarg name='arg1'/>
<defarg name='arg2'/>

* defun: Defines a new function. The defarg function must be used to declare the arguments to a function. Use the call function to execute the function. Functions are typically defined within forms.

<defun name='add100'>
   <defarg name='input'/>
    <add>
       <ref>input</ref>
       <i>100</i>
    </add>
</defun>

* call

<call name='add100'>
   <i>42</i>
</call>

* rule: Calls a rule

<rule name='getEmployeeId'>
    <argument name='accountId' value='maurelius'/>
</rule>
 
<rule name='getEmployeeId'>
   <argument name='accountId'>
       <ref>username</ref>
   </argument>
</rule>

Object Manipulation Expressions

* get: Retrieves a value from within an object.

<get>
   <!--List, Map, or Object -->
   <!-- String -->
</get>

* putmap

<putmap>
   <ref>userView</ref>
   <s>waveset.role</s>
   <s>engineering</s>
</putmap>

* setlist

<setlist>
   <ref>myList</ref>
   <i>s</i>
   <s>accounts</s>
</setlist>

* setvar

<setvar>
   <ref>var</ref>
   <s>text</s>
</setvar>

* instanceof

<instanceof name='List'>
    <new class='java.util.ArrayList'/>
</instanceof>

Java and JavaScript Expressions

* invoke
– static method

<invoke class='class name' name='method name'>
   <!--method argument 0 -->
   <!--method argument n-->
</invoke>

– instance method

<invoke class='method name'>
   <!--the object to invoke the method on -->
   <!--method argument 0 -->
   <!--method argument n-->
</invoke>

* new: Creates an instance of a Java class.

<new class='classname'/>
<!--constructor argument 0-->
<!--constructor argument n-->
</new>

* script: Encapsulates a fragment of JavaScript.

<script>
   var arg1 = env.get('arg1');
   arg1 + 100;
</script>
 
<script>
   importPackage(Packages.java.util);
   var cal Now = Calendar.getInstance();
   cal Now.getTime()
</script>

Debugging and Testing Expressions

* trace

<trace><i>1</i></trace>
 
<trace><i>0</i></trace>

* print: Prints the value of each subexpression to standard output.

<print>
   <s>Ashley World!</s>
</print>

Data Types

* integer
* list
* null
* object
* string

References

* IDM XPRESS
* Chapter 5 XPRESS Language

This entry was posted in SunIDM and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.