Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 96904 invoked from network); 1 Mar 2006 23:51:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Mar 2006 23:51:06 -0000 Received: (qmail 36701 invoked by uid 500); 1 Mar 2006 23:51:49 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 36619 invoked by uid 500); 1 Mar 2006 23:51:49 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 36608 invoked by uid 500); 1 Mar 2006 23:51:49 -0000 Received: (qmail 36605 invoked by uid 99); 1 Mar 2006 23:51:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2006 15:51:49 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 01 Mar 2006 15:51:48 -0800 Received: (qmail 96790 invoked by uid 65534); 1 Mar 2006 23:50:41 -0000 Message-ID: <20060301235041.96789.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r382201 - in /jakarta/commons/sandbox/scxml/trunk/xdocs: guide.xml guide/custom-actions.xml navigation.xml Date: Wed, 01 Mar 2006 23:50:40 -0000 To: commons-cvs@jakarta.apache.org From: rahul@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rahul Date: Wed Mar 1 15:50:38 2006 New Revision: 382201 URL: http://svn.apache.org/viewcvs?rev=382201&view=rev Log: Add guide to custom actions with Commons SCXML. Added: jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml (with props) Modified: jakarta/commons/sandbox/scxml/trunk/xdocs/guide.xml jakarta/commons/sandbox/scxml/trunk/xdocs/navigation.xml Modified: jakarta/commons/sandbox/scxml/trunk/xdocs/guide.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/xdocs/guide.xml?rev=382201&r1=382200&r2=382201&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/xdocs/guide.xml (original) +++ jakarta/commons/sandbox/scxml/trunk/xdocs/guide.xml Wed Mar 1 15:50:38 2006 @@ -66,7 +66,7 @@

Contains notes about Commons SCXML APIs for extending or altering document semantics.

    -
  • Custom actions - Adding +
  • Custom actions - Adding custom actions to the Commons SCXML object model.
Added: jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml?rev=382201&view=auto ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml (added) +++ jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml Wed Mar 1 15:50:38 2006 @@ -0,0 +1,185 @@ + + + + + + + Using custom actions with Commons SCXML + Commons Documentation Team + + + + +
+ +

Actions are SCXML elements that "do" something. Actions can be + used where "executable content" is permissible, for example, + within <onentry>, <onexit> and <transition> + elements.

+ +

The SCXML specification + (currently a Working Draft) defines a set of "standard actions". + These include <var>, <assign>, <log>, <send>, + <cancel>, <if>, <elseif> and <else>.

+ +

The specification also allows implementations to define "custom actions" + in addition to the standard actions. What such actions "do" is + upto the author of these actions, and these are therefore + called "custom" since they are tied to a specific implementation + of the SCXML specification.

+ +
+ +
+ +

Commons SCXML makes authoring custom actions fairly straightforward.

+ + + +

A custom action in the Commons SCXML implementation has access to: +

    +
  • The current + Context + (and hence, the values of variables in the current Context). +
  • +
  • Any other Context within the document, provided the id of the + parent <state> is known. +
  • +
  • The expression + Evaluator + for this document, and hence the ability to evaluate a given + expression against the current or a identifiable Context. +
  • +
  • The list of other actions in this + Executable + .
  • +
  • The "root" Context, to examine any variable values in the + "document environment".
  • +
  • The + EventDispatcher, + to send or cancel events.
  • +
  • The + ErrorReporter, + to report any errors (that the ErrorReporter knows how to handle).
  • +
  • The histories, for any identifiable <history>.
  • +
  • The + NotificationRegistry, + to obtain the list of listeners attached to identifiable + "observers".
  • +
  • The engine log, to log any information it needs to.
  • +
+

+ +
+ +
+ +
+ +

Lets walk through the development of a simple, custom "hello world" + action.

+ + + +

We need a <hello> action in our (fictitious) namespace + "http://my.custom-actions.domain/CUSTOM". The action "tag" will + have one attribute "name". The action simply logs a hello to the + value of the name attribute when it executes.

+ +
+ + + +

A custom action must extend the Commons SCXML + Action + abstract base class.

+ +

Here is the Java source for our custom + Hello + action. The execute() method contains the logging statement.

+ +
+ + + +

With the custom action implemented, obtain a configured digester which + has the "default" ruleset required for reading (parsing) SCXML + documents, and then register the custom action like so:

+ +
+      // (1) Get Digester with "default" rules for parsing SCXML documents
+      Digester digester = SCXMLDigester.newInstance(null, null);
+
+      // (2) Register the "custom" action(s)
+      SCXMLDigester.addCustomAction(digester,
+          "http://my.custom-actions.domain/CUSTOM", "hello", Hello.class);
+    
+ +

This static addCustomAction() method can only be used if the custom + rule has no body content (child "tags") or if the custom action + implements the + ExternalContent + interface, in which any body content gets read into a list + of DOM nodes. For any other requirements, the digester rules + can be added by directly using the + digester API + .

+ +
+ + + +

This involves parsing the document and making the resulting + SCXML object executor-ready (which allows us to detect any + "model inconsistencies" before feeding it to the + execution engine. That amounts to:

+ +
+      // (3) Parse the SCXML document containing the custom action(s)
+      SCXML scxml = null;
+      try {
+          scxml = (SCXML) digester.parse(<String>);
+          //String method as an example
+      } catch (Exception e) {
+          // bad document, take necessary action
+      }
+      // (4) Wire up the object model for the SCXMLExecutor
+      SCXMLDigester.updateSCXML(scxml);
+    
+ +

Without custom actions, the utility methods of the + SCXMLDigester + should be used. That section is + here.

+ +
+ + + + +

Having obtained the SCXML object beyond step (4) above, + proceed as usual, see the section on the + Commons SCXML engine + for details.

+ +
+ +
+ + + +
Propchange: jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/scxml/trunk/xdocs/guide/custom-actions.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: jakarta/commons/sandbox/scxml/trunk/xdocs/navigation.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/xdocs/navigation.xml?rev=382201&r1=382200&r2=382201&view=diff ============================================================================== --- jakarta/commons/sandbox/scxml/trunk/xdocs/navigation.xml (original) +++ jakarta/commons/sandbox/scxml/trunk/xdocs/navigation.xml Wed Mar 1 15:50:38 2006 @@ -42,8 +42,8 @@ - + --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org