Пример #1
0
 public static String stepLiteralName(NamedElement s) {
   String result = "";
   if (s instanceof Vertex) {
     result = EmfStateMachineUtil.getStatePath((Vertex) s);
   } else if (s instanceof ActivityNode) {
     result = EmfActivityUtil.getNodePath((ActivityNode) s);
   }
   return JavaNameGenerator.toJavaName(result.replace("::", "_").toUpperCase());
 }
 private OJBlock checkWeight(OJOperation operationContext, OJBlock block, ActivityNode node) {
   StringBuilder sb = new StringBuilder();
   // Check if all weights have been satisfied
   // NB!! the weight logic only makes sense on AcceptEventActions. This is the only place where
   // outputpin value count equates to
   // weight. Everywhere else it is impossible to determine weight. In other places it could also
   // lead to stuck contractedProcesses
   // TODO implement validation
   for (ActivityEdge edge : EmfActivityUtil.getDefaultOutgoing(node)) {
     if (edge.getSource() instanceof OutputPin) {
       PropertyMap map = ojUtil.buildStructuralFeatureMap((OutputPin) edge.getSource());
       if (edge.getWeight() != null) {
         if (map.isCollection()) {
           Classifier integerType = getLibrary().getIntegerType();
           if (edge.getWeight() != null) {}
           String weight =
               valueSpecificationUtil.expressValue(
                   operationContext,
                   edge.getWeight(),
                   EmfActivityUtil.getContainingActivity(edge.getSource()),
                   integerType);
           if (sb.length() > 0) {
             sb.append(" && ");
           }
           sb.append(map.getter() + "().size()>=" + weight);
         } else {
           // would not make sense - ignore
         }
       }
     }
   }
   if (sb.length() > 0) {
     OJIfStatement ifStatement = new OJIfStatement();
     block.addToStatements(ifStatement);
     ifStatement.setCondition(sb.toString());
     block = ifStatement.getThenPart();
   }
   return block;
 }
 private Collection<ElementsWaitingForEvent> getEventActions(Activity activity) {
   Map<Element, ElementsWaitingForEvent> results = new HashMap<Element, ElementsWaitingForEvent>();
   for (ActivityNode node : EmfActivityUtil.getActivityNodesRecursively(activity)) {
     if (node instanceof AcceptEventAction && !(node instanceof AcceptCallAction)) {
       AcceptEventAction action = (AcceptEventAction) node;
       for (Trigger trigger : action.getTriggers()) {
         if (trigger.getEvent() != null) {
           ElementsWaitingForEvent eventActions = results.get(trigger.getEvent());
           if (eventActions == null) {
             eventActions = new ElementsWaitingForEvent(trigger.getEvent());
             results.put(trigger.getEvent(), eventActions);
           }
           eventActions.addWaitingNode(action);
         }
       }
     }
   }
   return results.values();
 }
 @Override
 protected void implementEventConsumer(
     Behavior behavior, OJAnnotatedClass ojBehavior, ElementsWaitingForEvent eventActions) {
   OJAnnotatedOperation eventConsumer =
       super.createEventConsumerSignature(behavior, ojBehavior, eventActions.getEvent());
   OJForStatement forEachToken =
       new OJForStatement("token", ActivityProcessImplementor.ACTIVITY_TOKEN, "getTokens()");
   eventConsumer.getBody().addToStatements(forEachToken);
   for (NamedElement waitingNode : eventActions.getWaitingNodes()) {
     AcceptEventAction action = (AcceptEventAction) waitingNode;
     OJPathName waitingClass = ojUtil.classifierPathname(action);
     ojBehavior.addToImports(waitingClass);
     if (EmfActivityUtil.getAllEffectiveIncoming(action).isEmpty()) {
       // TODO check if the activityNodeContainer of this action is active and create a new token
     } else {
       String condition =
           "result==false && token.isActive() && token.getCurrentExecutionElement() instanceof "
               + waitingClass.getName();
       OJIfStatement ifMatchFound = new OJIfStatement(condition);
       forEachToken.getBody().addToStatements(ifMatchFound);
       OJAnnotatedField stateActivation = new OJAnnotatedField("state", waitingClass);
       stateActivation.setInitExp(
           "(" + waitingClass.getName() + ")token.getCurrentExecutionElement()");
       ifMatchFound.getThenPart().addToLocals(stateActivation);
       for (ActivityEdge transition : action.getOutgoings()) {
         OJPathName tpn = ojUtil.classifierPathname(transition);
         OJIfStatement ifAccept =
             new OJIfStatement(
                 "result==false &&  get"
                     + tpn.getLast()
                     + "()."
                     + OperationAnnotator.delegateParameters(eventConsumer));
         ifMatchFound.getThenPart().addToStatements(ifAccept);
         ifAccept.getThenPart().addToStatements("result=true");
         ifAccept.getThenPart().addToStatements("break");
         break;
       }
     }
   }
 }
 @VisitBefore(matchSubclasses = true)
 public void visitActivity(Activity activity) {
   if (EmfBehaviorUtil.isProcess(activity)) {
     OJAnnotatedClass activityClass = findJavaClass(activity);
     super.implementEventConsumption(activityClass, activity, getEventActions(activity));
     for (ActivityNode n : EmfActivityUtil.getActivityNodesRecursively(activity)) {
       if (n instanceof AcceptCallAction) {
         AcceptCallAction acc = (AcceptCallAction) n;
         Operation no = EmfActionUtil.getOperation(acc);
         OperationMap map = ojUtil.buildOperationMap(no);
         OJAnnotatedOperation oper =
             operationAnnotator.findOrCreateOperation(activity, activityClass, map, true);
         OJBlock mainBlock = oper.getBody();
         if (EmfBehaviorUtil.hasExecutionInstance(no)) {
           PropertyMap actionMap = ojUtil.buildStructuralFeatureMap(acc);
           final String EXECUTE_STATEMENT = "executeStatement";
           oper.getBody()
               .removeFromStatements(oper.getBody().findStatementRecursive(EXECUTE_STATEMENT));
           mainBlock.addToStatements(actionMap.setter() + "(result)");
         } else {
           for (OutputPin pin : acc.getResults()) {
             PropertyMap pinMap = ojUtil.buildStructuralFeatureMap(pin);
             PropertyMap parameterMap =
                 ojUtil.buildStructuralFeatureMap(EmfActionUtil.getLinkedTypedElement(pin));
             mainBlock.addToStatements(pinMap.setter() + "(" + parameterMap.fieldname() + ")");
           }
         }
         if (!EmfBehaviorUtil.hasExecutionInstance(no)) {
           for (InputPin pin : EmfActionUtil.getReplyAction(acc).getReplyValues()) {
             if (((Parameter) EmfActionUtil.getLinkedTypedElement(pin)).getDirection()
                 == ParameterDirectionKind.RETURN_LITERAL) {
               Jbpm5ObjectNodeExpressor expressor = new Jbpm5ObjectNodeExpressor(ojUtil);
               mainBlock.addToStatements(
                   "result=" + expressor.expressInputPinOrOutParamOrExpansionNode(mainBlock, pin));
             }
           }
         }
         if (!activity.conformsTo((Classifier) no.getOwner())
             && activity.getContext() != null
             && activity.getContext().conformsTo((Classifier) no.getOwner())) {
           // TODO find the right activity and delegate to it
         }
       } else if (EmfActionUtil.isEmbeddedTask(n)) {
         Action t = (Action) n;
         String stereotypeName =
             n instanceof OpaqueAction
                 ? StereotypeNames.EMBEDDED_SINGLE_SCREEN_TASK
                 : StereotypeNames.EMBEDDED_SCREEN_FLOW_TASK;
         for (TimeEvent d :
             getLibrary().getResponsibilityDefinition(t, stereotypeName).getDeadlines()) {
           OJPathName date = ojUtil.classifierPathname(getLibrary().getDateType());
           OJPathName task = ojUtil.classifierPathname(t);
           String consumerName = eventUtil.getEventConsumerName(d);
           OJOperation findOperation =
               activityClass.findOperation(consumerName, Arrays.asList(date, task));
           if (findOperation == null) {
             findOperation = new OJAnnotatedOperation(consumerName, new OJPathName("boolean"));
             activityClass.addToOperations(findOperation);
             findOperation.addParam("date", date);
             findOperation.addParam("task", task);
             findOperation.getBody().addToStatements("return false");
           }
         }
       }
     }
   }
 }