📄 startprocess.java
字号:
/** * */package pagecode.article;import javax.faces.component.html.HtmlOutputText;import javax.faces.context.FacesContext;import pagecode.PageCodeBase;import com.ibm.bpe.api.ActivityServiceTemplateData;import com.ibm.bpe.api.BusinessFlowManager;import com.ibm.bpe.api.ClientObjectWrapper;import com.ibm.bpe.api.PIID;import com.ibm.bpe.api.ProcessException;import com.ibm.bpe.api.ProcessTemplateData;import com.ibm.faces.component.html.HtmlScriptCollector;import com.ibm.gbsc.cte.sample.ApiHelper;import com.ibm.gbsc.cte.sample.MyTrace;import commonj.sdo.DataObject;/** * @author Kyle * */public class StartProcess extends PageCodeBase { protected HtmlScriptCollector scriptCollector1; protected HtmlOutputText text1; protected HtmlScriptCollector getScriptCollector1() { if (scriptCollector1 == null) { scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1"); } return scriptCollector1; } protected HtmlOutputText getText1() { if (text1 == null) { text1 = (HtmlOutputText) findComponentInRoot("text1"); } return text1; } /* * (non-Javadoc) * * @see pagecode.PageCodeBase#onPageLoad(javax.faces.context.FacesContext) */ public void onPageLoad(FacesContext context) { try { // get the reference of business flow manager BusinessFlowManager bfm = ApiHelper.initializeBFM(); // create where clause String whereClause = "PROCESS_TEMPLATE.NAME = 'ApprovalProcess'"; // query using template 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 'ArticleProcess' 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 = "uniqueId"; // 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); inputMessage.setString(request, "1"); } else { System.out.println(" input.getObject() == null"); System.out.println(" processing not successful."); throw new Exception("can't get start activity!"); } // create a process instance PIID piid = bfm.sendMessage(startActivity .getServiceTemplateID(), startActivity .getActivityTemplateID(), input); MyTrace.trace(piid, "process instance created", bfm); } } catch (ProcessException e) { e.printStackTrace(); } catch (java.lang.Exception xcpt) { xcpt.printStackTrace(); } catch (Throwable xcpt) { xcpt.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -