Workflow Guide

CHAPTER 6

Java Activity Wizard

This chapter describes how to create a Java activity to use in a workflow process. It has these sections:

 
Top of page

About Java activities

A Java activity is a Java class that executes within the context of an exteNd Director workflow application. A Java activity allows you to write custom business logic that executes automatically without user intervention.

You can create the Java activity using the Java Activity Wizard, code the resulting Java class template, and add the activity in the Workflow Modeler. The workflow engine automatically forwards work after the Java activity is processed.

 
Top of page

Using the Java Activity Wizard

Procedure To generate the Java activity code template:

  1. With your project open in exteNd Director, select File>New>File.

  2. From the New File dialog, select the Workflow tab and click Java Activity:

    JActivityWizMenu

  3. Click OK to start the wizard. This panels displays:

    JActivityWizMenu2

  4. Complete the wizard panel:

    Option

    What to do

    Class name

    Specify a class name for the Java activity

    Package

    (Optional) Specify a package hierarchy (with levels separated by periods) to place the Java activity in a subdirectory of the base directory.

    This affects only the directory where the Java activity is saved. For example, if the base directory is ProjectDir/src and you specify com.myco as the package, the Java activity will be created in ProjectDir/src/com/myco.

    Resource Set

    Select the Resource Set in which to store your application data.

  5. Click Finish. The wizard generates the Java source template.

  6. Click OK on the popup to access the template.

 
Top of page

Coding the Java activity

The generated class implements the EbiJavaActivity interface and generates a method stub for the invoke() method. This method supplies the workflow context, and is called when work is forwarded to the Java activity in the workflow process.

 
Top of section

Accessing a scoped path

The following example shows how to access a scoped path in the Java activity at runtime. This example uses the Session scope. Typically workitems in a workflow are stored in the Flow scope.

  import com.sssw.wf.api.*;
   
    public void invoke(EbiContext context) {
  
          try {
              // how to get a value from a scopedPath. ( assuming a request var of fname )
              com.sssw.fw.api.EbiScopedPath fname =
                com.sssw.fw.factory.EboScopedPathFactory.createScopedPath(
                   "/Request/param/fname");
              String theFirstName = (String)fname.getValue( context );
   
              // how to set a value on a scopedPath.
              com.sssw.fw.api.EbiScopedPath sessionDoc =
                com.sssw.fw.factory.EboScopedPathFactory.createScopedPath(
                  "/Session/DOC");
              sessionDoc.setValue( context, "mySessionDocValue" );
   
              // how to copy the request Referer into a session variable
              com.sssw.fw.api.EbiScopedPath from =
                com.sssw.fw.factory.EboScopedPathFactory.createScopedPath(
                  "/Request/prop/Referer");
              com.sssw.fw.api.EbiScopedPath to =
                com.sssw.fw.factory.EboScopedPathFactory.createScopedPath(
                  "/Session/Referer");
              com.sssw.fw.core.EboScopedPathUtil.copy( context, from, to );
          }
          catch (Exception e) {
              System.out.println(e);
          }
  
      }

 
Top of section

Performing a JNDI lookup

In the code for a Java activity, you cannot use the InitialContext object to perform a JNDI lookup. Instead, you need to use EbiServiceLocator interface.

For example, suppose you have an environment entry in the web.xml descriptor for a exteNd Director WAR file:

  <env-entry>
  <env-entry-name>mydata</env-entry-name>
  <env-entry-value>myvalue</env-entry-value>
  <env-entry-type>java.lang.String</env-entry-type>
  </env-entry>

If you use the following code to try to retrieve the environment entry, you will not be able to access the environment entry:

  Context ic = new InitialContext();
  Context env = (Context) ic.lookup("java:comp/env");
  String value = (String) env.lookup("mydata");

However, the following code will work:

  com.sssw.fw.api.EbiServiceLocator locator =   com.sssw.fw.factory.EboFactory.getServiceLocator();
  String value = (String) locator.getEnvEntry("mydata");




Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...