TermWare - JSR94 API
Most simple case of XML representation - just wrap definition in original termware language in XML element as text. So, root element is 'termware-text': all what is inside this element is original TermWare definitions.
DTD fragemnt looks as follow:
<!-- XML DTD -->
<?xml version="1.0" encoding="utf-8"?>
<!-- One root element - TermWare and text inside on -->
<!ELEMENT termware-text (#PCDATA)>
For example, next definition:
system(SemiGroup,default,
ruleset( ($x*$y)*$z -> $x*($y*$z) ),
FirstTop)
);
Will be look in XML syntax as:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE termware-text PUBLIC
"-//GradSoft//DTD TermWare ruleset form 1//EN"
"http://www.gradsoft.ua/dtd/termware-1.dtd">
<termware-text>
<![CDATA[
system(SemiGroup,default,
ruleset( ($x*$y)*$z -> $x*($y*$z) ),
FirstTop)
);
]]>
</termware-text>
Next format, which can be useful - mark out XML elements for domains and systems. (System in Termware is analog of ruleset, with domains we can group systems into hierarchy). Name of system, facts db and strategy are attributes of system term.
DTD fragment looks as follow:
<!-- XML DTD -->
<?xml version="1.0" encoding="utf-8"?>
<! -->
<!ELEMENT termware domain>
<!ELEMENT domain (domain* system-text*) >
<!ATTLIST domain
name CDATA #REQUIRED
id NMTOKEN #IMPLIED
>
<!ELEMENT system-text (#PCDATA) >
<!ATTLIST system-text
name CDATA #REQUIRED,
facts CDATA #REQUIRED,
strategy CDATA #REQUIRED,
id NMTOKEN #IMPLIED
>
Example:
<termware>
<domain name="examples" >
<system-text name="Life" strategy="FirstTop" facts="ua.gradsoft.termwaredemos.life.Life1Facts" >
<![CDATA[
#@description born-of-new-cell
{ l($i,$j) : $T} [ n($i,$j) == 3 ] -> $T [ putCell($i,$j) ],
#@description static-cell
{ l($i,$j) : $T} [ n($i,$j) == 2 ] -> $T [ existsCell($i,$j) ? putCell($i,$j) : removeCell($i,$j) ] ,
#@description die-of-cell
{ l($i,$j) : $T} [ n($i,$j) > 3 || n($i,$j) < 2 ] -> $T [ removeCell($i,$j) ],
#@description empty-set
{ } -> checkEmpty($T) [ showGeneration(), generateNextTestSet($T) ],
#@description check-empty-notnull
checkEmpty({$x:$Y}) -> { $x:$Y },
#@description check-empty-null
checkEmpty({}) -> END
]]>
</system-text>
</domain>
</termware>
In next level of detalization we can mark out XML element for each rule.:
<!-- XML DTD -->
<?xml version="1.0" encoding="utf-8"?>
<! -->
<!ELEMENT termware domain>
<!ELEMENT domain (domain* system*) >
<!ATTLIST domain
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT system (import-ruleset | rule-text)* >
<!ATTLIST system
name CDATA #REQUIRED,
facts CDATA #REQUIRED,
strategy CDATA #REQUIRED,
id ID #IMPLIED
>
<!ELEMENT import-ruleset (#PCDATA) >
<!ATTLIST import-ruleset
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT rule-text (#PCDATA) >
<!ATTLIST rule-text
name CDATA #IMPLIED
description PCDATA #IMPLIED
id ID #IMPLIED
>
Previous example can be rewriten as:
<domain name="examples" >
<system name="Life" strategy="FirstTop" facts="ua.gradsoft.termwaredemos.life.Life1Facts" >
<rule-text description="born-of-new-cell>
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) == 3 ] -> $T [ putCell($i,$j) ]
]]>
</rule-text>
<rule-text description="static cell">
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) == 2 ] -> $T [ existsCell($i,$j) ? putCell($i,$j) : removeCell($i,$j) ]
]]>
<rule-text description="die">
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) > 3 || n($i,$j) < 2 ] -> $T [ removeCell($i,$j) ]
]]>
</rule-text>
<rule-text description="empty set">
<![CDATA[
{ } -> checkEmpty($T) [ showGeneration() , generateNextTestSet($T) ],
]]>
</rule-text>
<rule-text description="check-empty-notempty">
<![CDATA[
checkEmpty({$x:$Y}) -> { $x:$Y },
]]>
</rule-text>
<rule-text description="check-empty-empty">
<![CDATA[
checkEmpty({}) -> END
]]>
</rule-text>
]]>
</system-text>
</domain>
So, complete DTD is:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : termware.dtd
Author : Ruslan Shevchenko
Description:
DTD for XML representation of TermWare systems
PUBLIC ID : -//GradSoft//DTD TermWare ruleset//EN
SYSTEM ID : http://www.gradsoft.ua/termware/termware.dtd
-->
<!ELEMENT termware (domain*) >
<!ELEMENT termware-text (#PCDATA) >
<!ELEMENT domain (domain | system | system-text )* >
<!ATTLIST domain
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT system (import-ruleset | rule-text)* >
<!ATTLIST system
name CDATA #REQUIRED
facts CDATA #REQUIRED
strategy CDATA #REQUIRED
id ID #IMPLIED
debug CDATA #IMPLIED
debug-entity CDATA #IMPLIED
pass-via CDATA #IMPLIED
>
<!ELEMENT import-ruleset (#PCDATA) >
<!ATTLIST import-ruleset
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT rule-text (#PCDATA) >
<!ATTLIST rule-text
name CDATA #IMPLIED
description CDATA #IMPLIED
id ID #IMPLIED
>
As you can see, all is evident. Some peculuarities:
Domain attributes:
name - name of domain. Special name 'root' means root domain.
id - id of XML elements. This iid soes not used inside rule system, but can be usefull during processing of XML files.
Domain chidlren elements:
domain - definition od subdomain.
system - definition of Term System (in JSR-94 terminology - rule execution set).
system-text - definition of term system in plain text.
System attribute:
name - name of system.
facts - name of facts database. (see. Semantics Description).
strategy - name of strategy (see Semantics Description).
id - id of element.
debug - boolean property, which is equivalent to call of setDebugMode with appropriative parameter after system initialization.
debug-entity - string, which define scope of debug output. Usially all or full name of debug class. Used only if 'debug' set to 'true'.
pass-via - If exists, than define name of term, in which object list is wrapped during passing to rule execution set. By default system receive list of object (i. e. term in form [a,b,c,d]. This is often incovenient to use, beccouse generic list is too generic object (sorry for tautology). If parameter of pass-via is set to name X , then during passing to rule execution set list of objects a, b, c, d , system will receive term X([a,b,c,d]).
System child elements:
import-ruleset - import specification for set of rules from other system.
rule-text - text of rule.
'import-ruleset' attributes:
name - name of system, from which we import rules.
id - id of elements.
Child elements are absent.
name - name of rule. optional.
description - description of rule.
id - id of element.
'system-text' attributes are the same, as in 'system' element
RoundingMode - rounding mode for decimal values. Must be integer value, one of constant which is defined in java.math.BigDecimal
DecimalScale - target precision during dividing of big decimal values.
It is necessory to download and unzip JSR-94 Technology Compability Kit from jcp site.
In distributive termware cd to jtests-jsr94. subdir.
Set property tckhome in file run_tck.xml .
Start target run in run_tck.xml with command
System will copy tck to build subdir, owerride files tck.conf , tck_res1.xml , tck_res2.xml by own and start testing process. Of course, it is also possible to do this by hands.
After tests execution, junit reports can be found in subdir build/reports .