This appendix contains the following code examples that show how to use custom data fields and custom activities for Process Manager applications.
Code Example A-2    EmployeeTrainingPerformer.java
/* EmployeeTrainingPerformer.java
|
* Authors: Jocelyn Becker and Sagar
|
* Last modified Sep 5 2000
|
*/
|
|
/* This custom activity schedules a new employee orientation training.
|
* Employees in different departments attend trainings on different days.
|
*
|
* An xml file specifies which departments attend training
|
* on which day, for example:
|
*
|
* <DEPT>Engineering</DEPT>
|
* <DAY>monday</DAY>
|
* <DEPT>Marketing</DEPT>
|
* <DAY>tuesday</DAY>
|
* <DEPT>Human Resource</DEPT>
|
* <DAY>wednesday</DAY>
|
* <DEPT>Sales</DEPT>
|
* <DAY>thursday</DAY>
|
*
|
* The custom activity writes an HTML file that welcomes
|
* the new employee and tells them which day to attend training.
|
* Trainings are held at 2 o'clock in the afternoon.
|
*
|
* The employee will attend training on the first
|
* appropriate day after they start work.
|
* For example, if their training day is tuesday
|
* and they start work on monday, they will be scheduled
|
* for training the following day on tuesday
|
* but if they start on thursday, they will be scheduled
|
* for training on tuesday the following week.
|
*
|
* The custom activity gets
|
* the employee's name from the Emp_name input parameter
|
* the start date from the Start_Date input paramater
|
* and the department name from the Dept input parameter
|
*
|
* These input parameters are mapped to actual data field names
|
* in the TrainingPerformer.xml file:
|
*
|
* <INPUT>
|
* <PARAMETER NAME="Emp_Name" DESCRIPTION="Employee Name">
|
* getData("dfEmpName") </PARAMETER>
|
* <PARAMETER NAME="Dept" DESCRIPTION="Dept. Name">
|
* getData("dfDeptName") </PARAMETER>
|
* <PARAMETER NAME="Start_Date" DESCRIPTION="Employee's Joining Date">
|
* getData("dfStartDate")</PARAMETER>
|
* ... </INPUT>
|
*
|
* Additonal input parameters include the path to the applications directory
|
* and the process instance id:
|
* <PARAMETER NAME="path" DESCRIPTION="Applications path">
|
* getApplicationPath()</PARAMETER>
|
* <PARAMETER NAME="id" DESCRIPTION="Process Instance ID">
|
* getProcessInstance().getInstanceId()</PARAMETER>
|
*
|
*/
|
|
package customer.activities;
|
|
import java.util.*;
|
import java.io.*;
|
import java.net.*;
|
|
//import java.sql.*;
|
|
// This class schedules the training day for a new employee
|
// based on which department the employee is in.
|
public class EmployeeTrainingPerformer implements
|
com.netscape.pm.model.ISimpleWorkPerformer {
|
public final int SUN = 0;
|
public final int MON = 1;
|
public final int TUE = 2;
|
public final int WED = 3;
|
public final int THU = 4;
|
public final int FRI = 5;
|
public final int SAT = 6;
|
|
|
|
public EmployeeTrainingPerformer (){
|
}
|
|
// The init() method does initialization stuff when the application starts.
|
// It is not called for each new process instance.
|
|
public void init(Hashtable env){
|
// nothing to initialize here
|
}
|
|
// The perform() method defines what the custom activity does.
|
// In this case, it reads the TrainingDays.xml file
|
// to populate the trainingDays hash table
|
// then it schedules the training.
|
|
public void perform(Hashtable input, Hashtable output){
|
System.out.println("Entering perform");
|
|
// Get the employee's start date from the input hashtable
|
Date startDate = (Date)input.get("Start_Date");
|
//String startDate = sqlDate.toString();
|
// startDate = startDate.replace('-', '/');
|
|
// Get the new employee's name and their department
|
// from the input hashtable.
|
String dept = (String) input.get( "Dept" );
|
String empName = (String) input.get( "Emp_Name" );
|
|
// Get the application path from the input hashtable
|
String appPath = (String)input.get("path");
|
|
// Get the process instance id from the input hashtable
|
int thisID = ((Double)input.get("id")).intValue();
|
|
// Read the schedule from the TrainingDays.xml file
|
Hashtable trainingDays = readSchedule(appPath);
|
|
// Figure out what day of the week the employee will go to training
|
Date trainingDate = scheduleTraining(startDate, dept, trainingDays);
|
|
// Write a welcome page containing the training info
|
String filename = writeWelcomePage(empName, thisID, appPath,
trainingDate);
|
|
// Put the file name for the HTML page in the output hashtable
|
output.put("welcomePage", filename);
|
System.out.println("Exiting perform");
|
}
|
|
// The readSchedule function reads and parses the TrainingDays.xml file
|
// to find out which departments go to training on which days.
|
// The results are stored in the trainingDays hashtable, keyed by dept.
|
// This happens in perform, not init, so that any changes to the
|
// schedule are reflected in the next process instance that is created.
|
private Hashtable readSchedule(String appPath){
|
System.out.println("Entering readSchedule");
|
Hashtable trainingDays = new Hashtable();
|
//reading from file..
|
try{
|
int Pfound = 0;
|
int MAX_LENGTH = 500;
|
char xml[] = new char[MAX_LENGTH];
|
String Path = appPath + "\\" + "TrainingDays.xml";
|
|
java.io.File f = new java.io.File(Path);
|
|
FileReader fr = new FileReader(f);
|
|
BufferedReader in = new BufferedReader(fr);
|
|
int count = 0;
|
count = in.read(xml, count, MAX_LENGTH);
|
String charSet = new String(xml);
|
|
int charSetLength = charSet.length();
|
String temp = new String();
|
String dept = new String();
|
String day = new String();
|
count = 0;
|
// parse the file. Look for <DEPT> or <DAY>
|
for(; count < charSetLength; count++)
|
{
|
if(charSet.charAt(count) == '<' )
|
{
|
System.out.println("at <");
|
temp = "";
|
for(; charSet.charAt(count) != '>'; count++)
|
{
|
temp = temp + charSet.charAt(count);
|
|
}
|
temp = temp + charSet.charAt(count);
|
|
count++;
|
if(temp.equalsIgnoreCase("<DEPT>"))
|
{
|
for(dept = ""; charSet.charAt(count) != '<' ; dept =
|
dept + charSet.charAt(count++));
|
trainingDays.put(dept, " ");
|
}
|
|
if(temp.equalsIgnoreCase("<DAY>"))
|
{
|
for(day = ""; charSet.charAt(count) != '<' ; day =
|
day + charSet.charAt(count++));
|
trainingDays.put(dept, day);
|
}
|
}
|
}
|
}
|
catch(Exception ignore)
|
{
|
System.out.println("MY EXCEPTION IS: " + ignore.toString());
|
}
|
System.out.println("Exiting readSchedule");
|
return trainingDays;
|
}
|
|
|
// Schedule the training
|
public Date scheduleTraining (Date startDate, String dept, Hashtable
trainingDays)
|
{
|
System.out.println("Entering schedule training");
|
// Get info about the start date
|
|
int thisDay = startDate.getDay();
|
int dayOfMonth = startDate.getDate();
|
int month = startDate.getMonth();
|
int year = startDate.getYear();
|
|
System.out.println("The day is " + (String)trainingDays.get(dept));
|
// Using the dept as the key, get the value of the
|
// training day from the the trainingDays hashtable
|
if(((String)trainingDays.get(dept)).equals("monday") ){
|
dayOfMonth=IncrementForMonday(thisDay, dayOfMonth);
|
}
|
else if(((String)trainingDays.get(dept)).equals("tuesday") ){
|
dayOfMonth=IncrementForTuesday(thisDay, dayOfMonth);
|
}
|
else if(((String)trainingDays.get(dept)).equals("wednesday") ){
|
dayOfMonth=IncrementForWednesday(thisDay, dayOfMonth);
|
}
|
else if(((String)trainingDays.get(dept)).equals("thursday") ){
|
dayOfMonth=IncrementForThursday(thisDay, dayOfMonth);
|
}
|
else if(((String)trainingDays.get(dept)).equals("friday") ){
|
dayOfMonth=IncrementForFriday(thisDay, dayOfMonth);
|
}
|
if(((String)trainingDays.get(dept)).equals("saturday") ){
|
dayOfMonth=IncrementForSaturday(thisDay, dayOfMonth);
|
}
|
else if(((String)trainingDays.get(dept)).equals("sunday") ){
|
dayOfMonth=IncrementForSunday(thisDay, dayOfMonth);
|
}
|
Date trainingDate = new Date(year,month,dayOfMonth);
|
System.out.println("Exiting schedule training");
|
return trainingDate;
|
}
|
|
// Create an HTML page that welcomes the
|
// new employee and tells them when to attend training.
|
// Trainings are held at 2 pm in the afternoon, so that
|
// if the employee needs to go to training on their start date
|
// they have time to find where to go and how to get there.
|
|
public String writeWelcomePage(String employeeName, int thisID, String
appPath, Date trainingDate) {
|
// Format the date string
|
System.out.println("Entering writeWelcomePage");
|
String finalDate = formatDateString(trainingDate);
|
|
// File name is Employee name + ProcessInstance
|
String fileName = employeeName+thisID+".html";
|
|
// Remove all white spaces from the filename
|
fileName = fileName.replace(' ', '_');
|
|
// Path for this Application's folder
|
String thisPath = appPath +fileName;
|
|
|
// Make a file in this Application's folder
|
try
|
{
|
RandomAccessFile HTMLfile = new RandomAccessFile(thisPath, "rw");
|
|
HTMLfile.writeUTF("<HTML>");
|
HTMLfile.writeUTF("<HEAD>");
|
HTMLfile.writeUTF("<TITLE>New Employee Training</TITLE>");
|
HTMLfile.writeUTF("</HEAD>");
|
HTMLfile.writeUTF("<BODY>");
|
HTMLfile.writeUTF("<CENTER><H1><FONT COLOR=MAGENTA>Hello <I>" +
|
employeeName + "</I></FONT></H1></CENTER>");
|
HTMLfile.writeUTF("<H3>Welcome to our company. </H3>");
|
HTMLfile.writeUTF(
|
"<P> Please attend new employee orientation training on ");
|
HTMLfile.writeUTF("<I>" + finalDate +
|
" at 2 pm.</I> in Room B3, which is above the cafeteria.</P>");
|
HTMLfile.writeUTF(
|
"<P>We'll have a tee-shirt, cap and other goodies for you at training!</P>");
|
HTMLfile.writeUTF("</BODY>");
|
HTMLfile.writeUTF("</HTML>");
|
HTMLfile.close();
|
}
|
catch (Exception e)
|
{
|
System.out.println ("Trouble with writing welcome page: " + e);
|
}
|
System.out.println("Exiting writeWelcomePage");
|
return fileName;
|
|
}
|
|
|
private String formatDateString (Date trainingDate){
|
System.out.println("Entering formatDateString");
|
String finalDay ="?";
|
try{
|
// Logic to rearrange date String
|
// eg Mon Oct 16 2000
|
String dateStr = trainingDate.toString();
|
int strIndx = dateStr.indexOf("00:00");
|
|
String tmpDay1 = dateStr.substring(0, strIndx);
|
|
int endIndx = dateStr.indexOf("2000");
|
String tmpDay2 = dateStr.substring(endIndx);
|
finalDay = tmpDay1+ " " + tmpDay2;
|
|
// 09:00:00 PDT/PST Remove PDT/PST
|
String time = dateStr.substring(strIndx, endIndx);
|
|
int i = time.indexOf("P");
|
time = time.substring(0, i);
|
// end of string rearrangement logic
|
}
|
|
catch(Exception e){
|
System.out.println("Error : "+e);
|
}
|
System.out.println("Exiting formatDateString");
|
return finalDay;
|
}
|
|
|
public void destroy(){
|
}
|
// helper functions to find training date
|
private int IncrementForMonday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
// for Monday just Increment Once from Sunday
|
dayOfMonth = dayOfMonth+1;
|
if(thisDay == TUE)
|
// for Monday just Increment 6 from Tue
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == WED)
|
// for Monday just Increment 5 from Wed
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == THU)
|
// for Monday just Increment 4 from Thursday
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == FRI)
|
// for Monday just Increment 3 from Friday
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == SAT)
|
// for Monday just Increment 2 from Saturday
|
dayOfMonth = dayOfMonth+2;
|
|
return dayOfMonth;
|
}
|
|
private int IncrementForTuesday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+1;
|
if(thisDay == WED)
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == THU)
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == FRI)
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == SAT)
|
dayOfMonth = dayOfMonth+3;
|
return dayOfMonth;
|
}
|
|
private int IncrementForWednesday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == TUE)
|
dayOfMonth = dayOfMonth+1;
|
if(thisDay == THU)
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == FRI)
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == SAT)
|
dayOfMonth = dayOfMonth+4;
|
return dayOfMonth;
|
}
|
|
private int IncrementForThursday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == TUE)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == WED)
|
dayOfMonth = dayOfMonth+1;
|
if(thisDay == FRI)
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == SAT)
|
dayOfMonth = dayOfMonth+5;
|
return dayOfMonth;
|
}
|
|
private int IncrementForFriday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == TUE)
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == WED)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == THU)
|
dayOfMonth = dayOfMonth+1;
|
if(thisDay == SAT)
|
dayOfMonth = dayOfMonth+6;
|
return dayOfMonth;
|
}
|
|
private int IncrementForSaturday(int thisDay, int dayOfMonth ){
|
if(thisDay == SUN)
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == TUE)
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == WED)
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == THU)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == FRI)
|
dayOfMonth = dayOfMonth+1;
|
return dayOfMonth;
|
}
|
|
private int IncrementForSunday(int thisDay, int dayOfMonth ){
|
if(thisDay == MON)
|
dayOfMonth = dayOfMonth+6;
|
if(thisDay == TUE)
|
dayOfMonth = dayOfMonth+5;
|
if(thisDay == WED)
|
dayOfMonth = dayOfMonth+4;
|
if(thisDay == THU)
|
dayOfMonth = dayOfMonth+3;
|
if(thisDay == FRI)
|
dayOfMonth = dayOfMonth+2;
|
if(thisDay == SAT)
|
dayOfMonth = dayOfMonth+1;
|
return dayOfMonth;
|
}
|
|
// end of class
|
}
|
Code Example A-3    UpdatableList.java
/* UpdatableList.java
|
*
|
* This data field displays itself as a SELECT list.
|
* It reads the menu options from an XML file.
|
* The data field creates a new instance of myObject to hold
|
* the selected value. Then it saves the object to a file
|
* in the application directory.
|
* The selected option is read back from the object
|
* when the data field is displayed again.
|
*/
|
|
/* The class definition of myObject is:
|
import java.io.*;
|
|
public class myObject implements Serializable {
|
String value;
|
//String var2;
|
//String var3;
|
|
|
public myObject () {
|
}
|
|
}
|
*/
|
|
package customer.fields;
|
|
import com.netscape.pm.model.*;
|
import com.netscape.pm.fields.*;
|
import com.netscape.pm.htmlFE.*;
|
|
import java.io.*;
|
import java.util.*;
|
|
|
public class UpdatableList extends BasicCustomField implements
IPresentationElement ,IDataElement{
|
|
// The name of the file that stores the menu options
|
// This is global across all process instances
|
public String myFileName;
|
|
|
public UpdatableList(){
|
super();
|
}
|
|
// Method from BasicCustomeField that loads
|
// properties that were set in the Builder
|
protected void loadDataElementProperties(Hashtable entry )
|
throws Exception {
|
|
// Get the XML File name from the Builder properties
|
myFileName = (String)entry.get("xmlfile");
|
}
|
|
/* The display() method for a work item
|
* displays the data field in a form in the
|
* work item as a SELECT menu whose name is the same as the datafield name.
|
* If there is no initial selection, the default selection is "Choose now"
|
* If a value has previously been selected, this value
|
* is retrieved by calling getData() which in turn invokes load()
|
* to load the value from the external store.
|
*/
|
|
public void display(IProcessInstance pi, IHTMLPage html, int displayMode,
String displayFormat ) throws Exception {
|
System.out.println("Entering display in work item");
|
|
StringBuffer buffer = new StringBuffer();
|
String selectedOption = null;
|
// Get the value of the data field
|
// If the value is not loaded, getData invokes load()
|
myObject myobj = (myObject) pi.getData(getName());
|
|
// If an object is found, set the selected option
|
// to the value of the object's myvalue variable.
|
if (myobj != null) {
|
selectedOption = myobj.myvalue;
|
}
|
switch(displayMode){
|
// In edit mode, display the data field as a SELECT menu
|
// The menu options are stored in an xml file
|
case MODE_EDIT:
|
// Get the option names from the xml file and store
|
// them in the vector optionNames.
|
Vector optionNames =
fetchDataFromXML();
|
|
buffer.append("<select size=\"1\" name=\"" +
|
getName() + "\" >");
|
|
// If the option was not selected previously show
|
// the default choice
|
String optName = "";
|
if(selectedOption==null){
|
buffer.append("<option selected>Choose now</option>");
|
// For each option in the vector optionNames
|
// write <OPTION> value="optionName"</OPTION>
|
|
for(int i=0; i<optionNames.size(); i++){
|
optName = (String)optionNames.elementAt(i);
|
buffer.append("<option value=\""+ optName + "\">");
|
buffer.append(optName);
|
buffer.append("</option>");
|
System.out.println("display(): Newest option: " +
|
(String)optionNames.elementAt(i));
|
}
|
System.out.println("In display method, the buffer string is "
|
+ buffer);
|
|
}
|
|
// Else write <OPTION SELECTED> value=selectedOption</OPTION>
|
// and the rest of the options below that
|
else
{
|
buffer.append("<option selected>" + selectedOption +
|
"</option>");
|
for(int i=0; i<optionNames.size(); i++){
|
|
// For each option in the vector optionNames
|
// check if this option is the selected one
|
// If it is, ignore it since we already wrote the HTML
|
// code for the selected option.
|
// If it is not the selected one,
|
// write <OPTION> value="optionName"</OPTION>
|
optName = (String)optionNames.elementAt(i);
|
if(!optName.equals(selectedOption)){
|
buffer.append("<option value=\""+ optName + "\">");
|
buffer.append(optName);
|
buffer.append("</option>");
|
}
|
}
|
}
|
// End the Select list
|
buffer.append("</select>");
|
break;
|
|
case MODE_VIEW:
|
// In View mode, display the selected option as a string
|
// The user cannot change the value in View mode
|
buffer.append(" "+ selectedOption);
|
break;
|
}
|
// Write the contents to the HTML page
|
html.write(buffer.toString());
|
}
|
|
|
/* The display method for an entry point
|
* displays the data field in an entrypoint form
|
* as a SELECT menu whose name is the same as the data field name.
|
* In this case, there will be no previously selected value in edit mode.
|
* The data field should not be displayed in view mode.
|
*/
|
|
public void display(IHTMLPage html, int displayMode,
|
String displayFormat ) throws Exception {
|
|
StringBuffer buffer = new StringBuffer();
|
switch(displayMode){
|
case MODE_EDIT:
|
|
// Get the option names from the xml file and store
|
// them in the vector optionNames.
|
Vector optionNames = fetchDataFromXML();
|
|
//The selected option is "Choose now"
|
buffer.append("<select size=1 name=" + getName() + " >");
|
buffer.append("<option selected>Choose now</option>");
|
|
// Get the option names from the xml file
|
// and store them in the vector optionNames.
|
// For each option, write <option> value=optionName</option>
|
|
for(int i=0; i<optionNames.size(); i++){
|
|
buffer.append("<option value=\"" +
|
(String)optionNames.elementAt(i)+"\">");
|
buffer.append((String)optionNames.elementAt(i));
|
buffer.append("</option>");
|
}
|
|
// Close the select tag
|
buffer.append("</select>");
|
break;
|
|
// Display a warning in view mode.
|
// We hope that the developer will see this during testing.
|
|
case MODE_VIEW:
|
buffer.append("<B>Incorrect use of this datafield,");
|
buffer.append(
|
" <BLINK>it must be in EDIT Mode </BLINK>in an Entry Point!!!</B>");
|
break;
|
}
|
// Write the contents to the HTML page
|
html.write(buffer.toString());
|
|
}
|
|
// The update() method parses the form parameters when
|
// the HTML form is submitted.
|
// In this case, it creates a new instance of myObject
|
// whose "myvalue" variable is set to the value of the form element
|
// that has the same name as this data field.
|
// The new object is put into the process instance
|
public void update(IProcessInstance pi, IPMRequest rq ) throws Exception {
|
|
// Create a new myObject to hold the results
|
myObject obj1 = new myObject();
|
try {
|
obj1.myvalue = (String) rq.getParameter(getName());
|
// put the object into the pi
|
pi.setData(getName(), obj1);
|
}
|
catch (Exception e) {
|
System.out.println("Problem translating the form values: " + e);
|
}
|
}
|
|
|
// The load() method generates and sets the value of the data field.
|
// This method is called if getData() is invoked when the
|
// data field value is not already loaded.
|
// In this case, read the object from the file
|
// and get its "myvalue" variable
|
public void load(IProcessInstance pi) throws Exception
|
{
|
// Get the name of the file. It is stored as the entity key.
|
// An example is thisfield123.txt
|
String thisFileName = (String)
pi.getEntityKey(getName());
|
if (thisFileName != null)
|
{
|
try {
|
// Get a handle to the file at the location
|
// in the application directory
|
// eg rootdir/Applications/myApplication/thisfield123.html
|
String myPath = getMyApplicationsPath();
|
thisFileName = myPath + "\\" + thisFileName;
|
|
// Get a file reader and read in the object
|
FileInputStream fis = new FileInputStream(thisFileName);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
myObject newobj = (myObject) ois.readObject();
|
|
// Put the object in the data field in the process instance
|
pi.setData(getName(), newobj);
|
}
|
catch (Exception e)
|
{
|
System.out.println("Error while reading value from file: " + e);
|
}
|
}
|
else {
|
pi.setData(getName(), null);
|
}
|
}
|
|
// The store method stores the value of the data field in
|
// external storage to make it persistent.
|
// In this case, we store the value as an object in a file whose
|
// name is dataFieldNamePID.html, for example thisDataField123.txt
|
public void store(IProcessInstance pi) throws Exception{
|
|
// Get the data field name
|
String thisID = getName();
|
// Get the process instance ID
|
long procID = pi.getInstanceId();
|
|
// Concatenate the data field name with the PID
|
// to keep the name unique across all process instances
|
thisID = thisID + procID;
|
String thisFileName = thisID + ".txt";
|
|
// Store the file name as the entity key
|
pi.setEntityKey(getName(), thisFileName);
|
|
// Get the application directory
|
String appdir = getMyApplicationsPath();
|
// Generate the file name where the value will be stored
|
thisFileName = appdir + "\\" + thisFileName;
|
|
// Get the value of the data field from the pi,
|
// which should be an instance of myObject
|
myObject myobj = (myObject) pi.getData(getName());
|
|
// Write the object to a file
|
try {
|
FileOutputStream fos = new FileOutputStream(thisFileName);
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
oos.writeObject(myobj);
|
}
|
catch (Exception e)
|
{System.out.println("Error while storing data field value to file:"
|
+ e);
|
}
|
|
// end store method
|
}
|
|
public void create(IProcessInstance pi) throws Exception {
|
// no default value
|
System.out.println("entering create method but doing nothing here");
|
}
|
|
// Fetch the set of menu options from the XML file
|
public Vector fetchDataFromXML(){
|
Vector optionNames = new Vector();
|
|
try
|
{
|
int MAX_LENGTH = 2000;
|
char xml[] = new char[MAX_LENGTH];
|
|
// Get the path for the xml file
|
// myFileName is a global variable --
|
// it is the same for all process instances
|
String Path = getMyApplicationsPath();
|
Path = Path + "\\" + myFileName;
|
|
// Get a file reader
|
java.io.File f = new java.io.File(Path);
|
FileReader fr = new FileReader(f);
|
BufferedReader in = new BufferedReader(fr);
|
|
|
int count =0;
|
// Read the entire xml file into the array xml
|
count = in.read(xml, count, MAX_LENGTH);
|
|
String charSet = new String(xml);
|
int charSetLength = charSet.length();
|
|
count = 0;
|
for(; count < charSetLength; count++)
|
{
|
parseForItemTag(count, charSetLength, charSet, optionNames);
|
}
|
}
|
catch(Exception e)
|
{
|
System.out.println("Error while fetching data from xml file : "
|
+ e);
|
}
|
|
// return the vector of option names
|
return optionNames;
|
}
|
|
|
// This method parses an array of characters
|
// to extract the items embedded ini <ITEM>...</ITEM> tags
|
public void parseForItemTag (int count, int charSetLength,
|
String charSet, Vector optionNames)
|
{
|
String temp;
|
Object tempobj;
|
if(charSet.charAt(count) == '<' )
|
{
|
temp = "";
|
for(; charSet.charAt(count) != '>'; count++)
|
{
|
temp = temp + charSet.charAt(count);
|
}
|
temp = temp + charSet.charAt(count);
|
count++;
|
if(temp.equalsIgnoreCase("<ITEM>"))
|
{
|
for(temp = ""; charSet.charAt(count) != '<' ;
|
temp = temp + charSet.charAt(count++))
|
|
temp = temp;
|
// Convert the string to an object and
|
// add the object to the vector of options
|
tempobj = (Object) temp;
|
optionNames.addElement(tempobj);
|
}
|
}
|
}
|
|
|
// Returns the path to the folder where the application is saved
|
String getMyApplicationsPath ()
|
{
|
String path = "";
|
try {
|
path = getPMApplication().getHomePath();
|
}
|
catch (Exception e) {
|
System.out.println("Exception while getting application path" + e);
|
}
|
return path;
|
}
|
|
|
// Use this function for debugging if necessary
|
// to read the object from the file after storing it.
|
public void readMyObject (String filename) {
|
System.out.println("Entering readMyObject");
|
// read the object from the file
|
try {
|
FileInputStream fis = new FileInputStream(filename);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
myObject mo = (myObject) ois.readObject();
|
|
System.out.println ("value: " + (String) mo.myvalue);
|
}
|
catch (Exception e)
|
{System.out.println(e);
|
}
|
System.out.println("Exiting readMyObject");
|
}
|
|
// end of class
|
}
|
|
Code Example A-4    UpdatableList.jsb
/**
|
* CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
* NETSCAPE COMMUNICATIONS CORPORATION
|
* Copyright (c) 1997, 1998 Netscape Communications Corporation.
|
* All Rights Reserved.
|
*
|
* Use of this Source Code is subject to the terms of the applicable license
|
* agreement from Netscape Communications Corporation.
|
*
|
* The copyright notice(s) in this Source Code does not indicate actual or
|
* intended publication of this Source Code.
|
*
|
*/
|
|
|
<JSB>
|
<JSB_DESCRIPTOR NAME="customer.fields.UpdatableList"
|
DISPLAYNAME="Updatable Options List"
|
SHORTDESCRIPTION="Enhanced HTML Select" >
|
|
/***
|
* Properties of the Core WFObject
|
**/
|
<JSB_PROPERTY NAME="cn"
|
DISPLAYNAME="Name of this field"
|
SHORTDESCRIPTION="Unique identifier of this field"
|
ISDESIGNTIMEREADONLY>
|
|
<JSB_PROPERTY NAME="description"
|
DISPLAYNAME="Short Description"
|
SHORTDESCRIPTION="Short Description of this field">
|
|
<JSB_PROPERTY NAME="prettyname" TYPE="string"
|
DISPLAYNAME="Display Name"
|
SHORTDESCRIPTION="Display Name of this field">
|
|
<JSB_PROPERTY NAME="help" TYPE="string"
|
DISPLAYNAME="Help Message"
|
SHORTDESCRIPTION="Help message associated with this
field">
|
|
/***
|
* Properties of the Field Object
|
**/
|
<JSB_PROPERTY NAME="fieldclassid"
|
DISPLAYNAME="Field Class ID"
|
SHORTDESCRIPTION="Defines how the field is displayed to
the user"
|
DEFAULTVALUE="customer.fields.UpdatableList"
|
ISDESIGNTIMEREADONLY>
|
|
<JSB_PROPERTY NAME="fieldtype"
|
DISPLAYNAME="Data Type"
|
SHORTDESCRIPTION="Defines how the field is stored by the
application"
|
DEFAULTVALUE="TEXT"
|
VALUESET="TEXT,LONGTEXT,INT,FLOAT,DATE,DATETIME"
|
ISEXPERT>
|
|
<JSB_PROPERTY NAME="allow_search"
|
TYPE="boolean"
|
DISPLAYNAME="Allow Search"
|
DEFAULTVALUE="false"
|
VALUESET="true,false"
|
SHORTDESCRIPTION="Can participants use this field to
search for instances?">
|
|
|
/***
|
* Properties related to this specific format of field
|
**/
|
<JSB_PROPERTY NAME="length"
|
TYPE="int"
|
DISPLAYNAME="Length"
|
DEFAULTVALUE=20
|
SHORTDESCRIPTION="Length of the Select"
|
ISEXPERT>
|
<JSB_PROPERTY NAME="xmlfile"
|
TYPE="string"
|
DISPLAYNAME="XML file name"
|
DEFAULTVALUE="MenuOptions.xml"
|
SHORTDESCRIPTION="XML file for populating the options for
Select">
|
<JSB_PROPERTY NAME="default_value"
|
TYPE="string"
|
DISPLAYNAME="Default Value"
|
SHORTDESCRIPTION="Default Value of this field">
|
<JSB_PROPERTY NAME="on_focus"
|
TYPE="JS Expression"
|
DISPLAYNAME="on Focus"
|
SHORTDESCRIPTION="Focus Handler">
|
<JSB_PROPERTY NAME="on_change"
|
TYPE="JS Expression"
|
DISPLAYNAME="on Value Change"
|
SHORTDESCRIPTION="Value Change Event Handler">
|
<JSB_PROPERTY NAME="on_blur"
|
TYPE="JS Expression"
|
DISPLAYNAME="on Blur"
|
SHORTDESCRIPTION="Blur Handler">
|
|
|
</JSB>
|
|
/*** Template Property Squeleton: Cut, paste and fill it up.
|
<JSB_PROPERTY NAME="[[]]"
|
TYPE="[[]]"
|
DISPLAYNAME="[[]]"
|
SHORTDESCRIPTION="[[]]"
|
DEFAULTVALUE="[[]]"
|
VALUESET="[[]]"
|
?ISDESIGNTIMEREADONLY?>
|
***/
|