//***************************************************************************** //* * //* "This sample program is provided AS IS and may be used, executed, copied * //* and modified without royalty payment by customer * //* (a) for its own instruction and study, * //* (b) in order to develop applications designed to run with an * //* IBM WebSphere product, either for customer's own internal use or for * //* redistribution by customer, as part of such an application, in * //* customer's own products." * //* * //* Product 5655-FLW, * //* (C) COPYRIGHT International Business Machines Corp., 2006 * //* All Rights Reserved * Licensed Materials - Property of IBM * //* * //***************************************************************************** //* * //* DISCLAIMER * //* * //* This material contains programming source code for your consideration. * //* These examples have not been thoroughly tested under all conditions. * //* IBM, therefore, cannot guarantee or imply reliability, serviceability, * //* or function of these programs. * //* ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY * //* WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT * //* NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * //* FOR A PARTICULAR PURPOSE. * //* * //***************************************************************************** /* * This sample initiates the 'OrderApprovalProcess'. * * */ import com.ibm.websphere.bo.BOFactory; import commonj.sdo.DataObject; import commonj.sdo.Property; import com.ibm.websphere.sca.ServiceManager; import com.ibm.bpe.api.*; public class StartOrderApprovalProcess { public static void main(String[] args) { try { BusinessFlowManager bfm = ApiHelper.initializeBFM(); // To initiate a process you first must get the process template. // You can call the method getProcessTemplate() with process template name as input // or you can call queryProcessTemplates() with an appropriate where clause. // This sample uses queryProcessTemplates() to get process template of the // 'OrderApprovalProcess'. String whereClause = "PROCESS_TEMPLATE.NAME = 'OrderApprovalProcess'"; ProcessTemplateData[] processTemplates = bfm.queryProcessTemplates(whereClause, null, null, null); ProcessTemplateData processTemplate = null; if (processTemplates.length == 1) { processTemplate = processTemplates[0]; } // Get the startActivity // In general you get the starting activities and based on portTypeName, portTypeNamespace // and operation you chose the starting activity you want. // The sample 'OrderApprovalProcess' has only one starting activity. ActivityServiceTemplateData startActivity = null; if (processTemplate != null) { ActivityServiceTemplateData[] startActivities = bfm.getStartActivities(processTemplate.getID()); startActivity = startActivities[0]; } // get the input message ClientObjectWrapper input = null; if ( startActivity != null) { input = bfm.createMessage( startActivity.getServiceTemplateID(), startActivity.getActivityTemplateID(), startActivity.getInputMessageTypeName() ); // set the initial values in the input message if (input.getObject()!= null && input.getObject() instanceof DataObject ) { DataObject inputMessage = (DataObject)input.getObject(); MyTrace.trace(inputMessage); // set the initial values in the input message String request = "approvalRequest"; Property property = (Property)inputMessage.getType().getProperty(request); BOFactory boFactory = (BOFactory) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory"); DataObject dataObject = boFactory.create( property.getType().getURI(), property.getType().getName()); MyTrace.trace(dataObject); // set the initial values in the input message // For instance: The requestor is "Smith" , item is "item_3737", number is 100, // the price is 1000 and reason is "new equipment". dataObject.setString("requester", "Smith"); dataObject.setString("item", "item_3737"); dataObject.setInt("number", 1); dataObject.setDouble("price", 1000); dataObject.setString("reason", "new equipment"); MyTrace.trace(dataObject); inputMessage.setDataObject(request, dataObject); } else { System.out.println(" input.getObject() == null"); System.out.println(" processing not successful."); System.exit(0); } // create a process instance PIID piid = bfm.sendMessage( startActivity.getServiceTemplateID(), startActivity.getActivityTemplateID(), input ); MyTrace.trace( piid, "process instance created" ,bfm ); } System.out.println("\n successfully processed \n"); System.exit(0); } catch ( com.ibm.bpe.api.ProcessException xcpt) { System.out.println( xcpt ); } catch (java.lang.Exception xcpt ) { System.out.println( xcpt ); } catch (Throwable xcpt ) { System.out.println( xcpt ); } finally { System.exit(0); } } }