//***************************************************************************** //* * //* "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 shows how you can use the Enterprise JavaBeans (EJB) interface * to run non-interruptible processes. * * Running a microflow, you have to differentiate whether it has a unique * starting service or not. * * If the starting service is unique, you can run the microflow with the call() method * with process template name as parameter. * * If the starting service is not unique, you have to determine a starting service. * The method getStartActivities() lists all starting services from which you can choose one * depending on the portType, namespace and operation. You can run the microflow * with the call() method using service that you chose. */ import com.ibm.bpe.api.*; import commonj.sdo.DataObject; public class RunMicroProcess { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); // retrieve the first 10 process templates of non-interuptable processes // ordered by name String whereClause = "PROCESS_TEMPLATE.EXECUTION_MODE = PROCESS_TEMPLATE.EXECUTION_MODE.EXECUTION_MODE_MICROFLOW"; String orderClause = "PROCESS_TEMPLATE.NAME"; Integer threshold = new Integer(10); ProcessTemplateData[] processTemplates = bfm.queryProcessTemplates(whereClause, orderClause, threshold, null ); if ( processTemplates.length == 0 ) { System.out.println("\n > no templates of micro-processes found.\n" ); System.exit(0); } // For this sample, we assume that there are at least two templates where the first one has // a unique starting service. // Start the first process. // We assume that the starting service is unique. // In this case you can pass the template ID resp. template name as input to the methods // createMessage() and call(). if ( processTemplates.length > 0 ) { ProcessTemplateData template = processTemplates[0]; // create a message for the single starting receive activity ClientObjectWrapper input = bfm.createMessage( template.getID(), template.getInputMessageTypeName()); DataObject inputMessage = null; if (input.getObject() != null && input.getObject() instanceof DataObject) { inputMessage = (DataObject)input.getObject(); /* * fill in the code snippet to set the content of the input message */ } // run the process ClientObjectWrapper output = bfm.call( template.getName(), input ); if (output.getObject() != null && output.getObject() instanceof DataObject) { DataObject outputMessage = (DataObject)output.getObject(); /* * fill in code snippet to analyse the content of output message */ } } // Start the second process found. // We assume that the starting service is not unique. // In this case you have to retrieve the starting activities first // and you can use one of these activities to call the methods // createMessage() and call() if ( processTemplates.length > 1 ) { ProcessTemplateData template = processTemplates[1]; // Determine the starting service to be called. ActivityServiceTemplateData[] startServices = bfm.getStartActivities( template.getID() ); // In general you get the starting activities and based on portTypeName, portTypeNamespace // and operation you choose the the starting activity you want. // Choose for example the first starting service ActivityServiceTemplateData activityService = startServices[0]; // Create a message for the service to be called ClientObjectWrapper input = bfm.createMessage( activityService.getServiceTemplateID(), activityService.getActivityTemplateID(), activityService.getInputMessageTypeName() ); DataObject inputMessage = null; if (input.getObject() != null && input.getObject() instanceof DataObject) { inputMessage = (DataObject)input.getObject(); /* * fill in your code snippet here to set the content of the input message */ } // Run the process ClientObjectWrapper output = bfm.call( activityService.getServiceTemplateID(), activityService.getActivityTemplateID(), input ); if (output.getObject() != null && output.getObject() instanceof DataObject) { DataObject outputMessage = (DataObject)output.getObject(); /* * fill in your code snippet here to analyse the content of the output message */ } } System.out.println(" > successfully processed." ); 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); } } }