Ejemplo n.º 1
0
  /*
   * Start-->EndmailSendService-->End
   *
   * @see org.fireflow.FireWorkflowJunitEnviroment#createWorkflowProcess()
   */
  @Override
  public WorkflowProcess createWorkflowProcess() {
    WorkflowProcessImpl process = new WorkflowProcessImpl(processName, processDisplayName);
    process.setDescription(description);

    SubProcess mainflow = process.getMainSubProcess();

    PropertyImpl property = new PropertyImpl(mainflow, "mailToList"); // 流程变量x
    property.setDataType(new QName(NameSpaces.JAVA.getUri(), "java.lang.String"));
    property.setInitialValueAsString("[email protected];[email protected]");
    mainflow.getProperties().add(property);

    property = new PropertyImpl(mainflow, "ccToList"); // 流程变量x
    property.setDataType(new QName(NameSpaces.JAVA.getUri(), "java.lang.String"));
    property.setInitialValueAsString("*****@*****.**");
    mainflow.getProperties().add(property);

    mainflow.setDuration(new Duration(5, Duration.MINUTE));

    StartNodeImpl startNode = new StartNodeImpl(process.getMainSubProcess(), "Start");

    ActivityImpl activity = new ActivityImpl(process.getMainSubProcess(), "Activity1");
    activity.setDuration(new Duration(6, Duration.DAY));

    EndNodeImpl endNode = new EndNodeImpl(process.getMainSubProcess(), "End");

    mainflow.setEntry(startNode);
    mainflow.getStartNodes().add(startNode);
    mainflow.getActivities().add(activity);
    mainflow.getEndNodes().add(endNode);

    TransitionImpl transition1 = new TransitionImpl(process.getMainSubProcess(), "start2activity");
    transition1.setFromNode(startNode);
    transition1.setToNode(activity);
    startNode.getLeavingTransitions().add(transition1);
    activity.getEnteringTransitions().add(transition1);

    TransitionImpl transition2 = new TransitionImpl(process.getMainSubProcess(), "activity2end");
    transition2.setFromNode(activity);
    transition2.setToNode(endNode);
    activity.getLeavingTransitions().add(transition2);
    endNode.getEnteringTransitions().add(transition2);

    mainflow.getTransitions().add(transition1);
    mainflow.getTransitions().add(transition2);

    // 创建EmailSendService 并绑定到activity1
    MailSendServiceDef emailSendService = this.buildService1();

    ServiceBinding svcBinding = this.buildServiceBinding(emailSendService);

    // 设置到activity和workflowprocess
    process.addService(emailSendService);
    activity.setServiceBinding(svcBinding);

    return process;
  }
  /**
   * Start-->Activity1(with catch compenstion)-->Activity2(with catch compensation)-->Activity3(with
   * catch compensation)-->End(throw compensation) |-->HandleCompensation1_1
   * |-->HandlerCompensation2_1 |-->HandlerCompensation3_1-->HandlerCompensation3_2
   */
  public WorkflowProcess createWorkflowProcess() {
    WorkflowProcessImpl process = new WorkflowProcessImpl(processName, processDisplayName);

    SubProcess subflow = process.getMainSubProcess();

    // *****************************************/
    // *************** 开始节点          *************/
    // ****************************************/
    StartNodeImpl startNode = new StartNodeImpl(subflow, "Start");

    // *****************************************/
    // *********** Activity1及其异常分支 ********/
    // ****************************************/
    ActivityImpl activity1 = new ActivityImpl(subflow, "Activity1");

    // 异常捕获节点1
    StartNodeImpl catchCompensationNode1 = new StartNodeImpl(subflow, "CatchCompensation1");
    CatchCompensationFeatureImpl catchCompensationDecorator = new CatchCompensationFeatureImpl();
    catchCompensationDecorator.setAttachedToActivity(activity1);
    catchCompensationDecorator.setCompensationCode("ForActivity1");
    catchCompensationNode1.setFeature(catchCompensationDecorator);
    activity1.getAttachedStartNodes().add(catchCompensationNode1);

    ActivityImpl handleCompensationNode1_1 = new ActivityImpl(subflow, "HandleCompensation1_1");

    TransitionImpl transition1_1 =
        new TransitionImpl(subflow, "catchCompensation1_HandleCompensation1_1");
    transition1_1.setFromNode(catchCompensationNode1);
    transition1_1.setToNode(handleCompensationNode1_1);
    catchCompensationNode1.getLeavingTransitions().add(transition1_1);
    handleCompensationNode1_1.getEnteringTransitions().add(transition1_1);

    // *****************************************/
    // *********** Activity2及其异常分支 ********/
    // ****************************************/
    ActivityImpl activity2 = new ActivityImpl(subflow, "Activity2");

    // 异常捕获节点1
    StartNodeImpl catchCompensationNode2 = new StartNodeImpl(subflow, "CatchCompensation2");
    catchCompensationDecorator = new CatchCompensationFeatureImpl();
    catchCompensationDecorator.setAttachedToActivity(activity2);
    catchCompensationDecorator.setCompensationCode("ForActivity2AndActivity3");
    catchCompensationNode2.setFeature(catchCompensationDecorator);
    activity2.getAttachedStartNodes().add(catchCompensationNode2);

    ActivityImpl handleCompensationNode2_1 = new ActivityImpl(subflow, "HandleCompensation2_1");

    TransitionImpl transition2_1 =
        new TransitionImpl(subflow, "catchCompensation2_HandleCompensation2_1");
    transition2_1.setFromNode(catchCompensationNode2);
    transition2_1.setToNode(handleCompensationNode2_1);
    catchCompensationNode2.getLeavingTransitions().add(transition2_1);
    handleCompensationNode2_1.getEnteringTransitions().add(transition2_1);

    // *****************************************/
    // *********** Activity3及其异常分支 ********/
    // ****************************************/
    ActivityImpl activity3 = new ActivityImpl(subflow, "Activity3");

    // 异常捕获节点1
    StartNodeImpl catchCompensationNode3 = new StartNodeImpl(subflow, "CatchCompensation3");
    catchCompensationDecorator = new CatchCompensationFeatureImpl();
    catchCompensationDecorator.setAttachedToActivity(activity3);
    catchCompensationDecorator.setCompensationCode("ForActivity2AndActivity3");
    catchCompensationNode3.setFeature(catchCompensationDecorator);
    activity3.getAttachedStartNodes().add(catchCompensationNode3);

    ActivityImpl handleCompensationNode3_1 = new ActivityImpl(subflow, "HandleCompensation3_1");

    TransitionImpl transition3_1 =
        new TransitionImpl(subflow, "catchCompensation3_HandleCompensation3_1");
    transition3_1.setFromNode(catchCompensationNode3);
    transition3_1.setToNode(handleCompensationNode3_1);
    catchCompensationNode3.getLeavingTransitions().add(transition3_1);
    handleCompensationNode3_1.getEnteringTransitions().add(transition3_1);

    ActivityImpl handleCompensationNode3_2 = new ActivityImpl(subflow, "HandleCompensation3_2");

    TransitionImpl transition3_2 =
        new TransitionImpl(subflow, "catchCompensation3_1_HandleCompensation3_2");
    transition3_2.setFromNode(handleCompensationNode3_1);
    transition3_2.setToNode(handleCompensationNode3_2);
    handleCompensationNode3_1.getLeavingTransitions().add(transition3_2);
    handleCompensationNode3_2.getEnteringTransitions().add(transition3_2);

    // *******************************************/
    // *********** 带有异常装饰器的结束节点 ********/
    // *******************************************/
    EndNodeImpl endNode = new EndNodeImpl(subflow, "End");
    ThrowCompensationFeatureImpl compensationDecorator = new ThrowCompensationFeatureImpl();
    compensationDecorator.addCompensationCode(
        "ForActivity2AndActivity3"); // 只有CompensationCode=‘TheCompensationActivity’的catch
                                     // compensation decorator才会被激发。
    endNode.setFeature(compensationDecorator);

    // ****************************************************/
    // ****链接 activity1,activity2,activity3 **************/
    // ****************************************************/
    TransitionImpl transition_start_activity1 = new TransitionImpl(subflow, "start_activity1");
    transition_start_activity1.setFromNode(startNode);
    transition_start_activity1.setToNode(activity1);
    startNode.getLeavingTransitions().add(transition_start_activity1);
    activity1.getEnteringTransitions().add(transition_start_activity1);

    TransitionImpl transition_activity1_activity2 =
        new TransitionImpl(subflow, "activity1_activity2");
    transition_activity1_activity2.setFromNode(activity1);
    transition_activity1_activity2.setToNode(activity2);
    activity1.getLeavingTransitions().add(transition_activity1_activity2);
    activity2.getEnteringTransitions().add(transition_activity1_activity2);

    TransitionImpl transition_activity2_activity3 =
        new TransitionImpl(subflow, "activity2_activity3");
    transition_activity2_activity3.setFromNode(activity2);
    transition_activity2_activity3.setToNode(activity3);
    activity2.getLeavingTransitions().add(transition_activity2_activity3);
    activity3.getEnteringTransitions().add(transition_activity2_activity3);

    TransitionImpl transition_activiyt3_end = new TransitionImpl(subflow, "activity3_end");
    transition_activiyt3_end.setFromNode(activity3);
    transition_activiyt3_end.setToNode(endNode);
    activity3.getLeavingTransitions().add(transition_activiyt3_end);
    endNode.getEnteringTransitions().add(transition_activiyt3_end);

    // 组装到process中
    subflow.setEntry(startNode);
    subflow.getStartNodes().add(startNode);
    subflow.getStartNodes().add(catchCompensationNode1);
    subflow.getStartNodes().add(catchCompensationNode2);
    subflow.getStartNodes().add(catchCompensationNode3);

    subflow.getActivities().add(activity1);
    subflow.getActivities().add(activity2);
    subflow.getActivities().add(activity3);
    subflow.getActivities().add(handleCompensationNode1_1);
    subflow.getActivities().add(handleCompensationNode2_1);
    subflow.getActivities().add(handleCompensationNode3_1);
    subflow.getActivities().add(handleCompensationNode3_2);
    subflow.getEndNodes().add(endNode);

    subflow.getTransitions().add(transition1_1);
    subflow.getTransitions().add(transition2_1);
    subflow.getTransitions().add(transition3_1);
    subflow.getTransitions().add(transition3_2);

    subflow.getTransitions().add(transition_start_activity1);
    subflow.getTransitions().add(transition_activity1_activity2);
    subflow.getTransitions().add(transition_activity2_activity3);
    subflow.getTransitions().add(transition_activiyt3_end);

    return process;
  }