Pageflow and Form Guide
CHAPTER 10
This chapter describes how to create a Java activity to use in a pageflow process. It has these sections:
A Java activity is a system activity that executes a Java class within the context of a pageflow. 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 Pageflow Modeler. The pageflow engine automatically forwards work after the Java Activity is processed.
For information about using the activity within your pageflow, see Java activity.
To generate the Java Activity code template:
With your project open in exteNd Director, select File>New>File.
From the New File dialog select the Portlet tab and click Java Activity for Pageflow:
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. |
ResourceSet |
Select the Resource Set in which to store your application data.
|
Click Finish. The wizard generates the Java source template. Click OK on the popup to access the template.
The generated class implements the EbiJavaActivity interface and generates a method stub for the invoke() method. This method supplies the context, and is called when work is forwarded to the Java activity in the pageflow process.
The following example shows how to code the invoke() method to access a scoped path that is defined in the pageflow in which the Java activity is running:
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); } */ }
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");
One reason you might want to execute a Java class within the context of a pageflow is to start a workflow process.
The following example shows how this is done:
// in the Java activity's invoke method public void invoke(com.sssw.wf.api.EbiContext context) { com.sssw.wf.api.EbiContext newWFContext = com.sssw.wf.client.EboFactory.createEbiContext(); EbiWorkflowEngineDelegate engineDelegate = com.sssw.wf.client.EboFactory.getWorkflowEngineDelegate(); engineDelegate.startProcessByName("someProcess", newWFContext); }
Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved. more ...