Package nexj.core.meta.workflow

Examples of nexj.core.meta.workflow.Decision


    */
   protected Step loadQueue(Element queueElement, final Assignment assignment)
   {
      final Lookup eventMap = new HashTab();
      final Fork fork = new Fork();
      final Decision decision = new Decision();

      fork.setActivity(assignment.getActivity());
      decision.setActivity(assignment.getActivity());

      XMLUtil.forEachChildElement(queueElement, null,
         m_helper.new ElementHandler("queueEvent")
      {
         private boolean m_bTimer;

         protected String getName(Element eventElement)
         {
            return XMLUtil.getStringAttr(eventElement, "name");
         }

         public void handleElement(Element eventElement, String sEventName)
         {
            Node child = eventElement.getFirstChild();
            String sElement = eventElement.getNodeName();
            Concurrent activity = new Concurrent();
            Branch branch = null;

            activity.setFork(fork);

            if (sElement.equals("TimerEvent"))
            {
               if (m_bTimer)
               {
                  throw new MetadataException("err.meta.workflow.multipleQueueTimers",
                     new Object[]{assignment.getName()});
               }

               Timeout timeout = new Timeout();

               timeout.setActivity(activity);
               timeout.setValue(m_helper.parse(XMLUtil.getReqStringAttr(eventElement, "value"),
                  false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               activity.addStep(timeout);

               Wait wait = new Wait(timeout);

               timeout.setNext(wait);
               activity.addStep(wait);

               m_bTimer = true;
            }
            else if (sElement.equals("ClassEvent"))
            {
               AutoCompletion completion = new AutoCompletion(assignment);

               loadWorkflowHandler(eventElement, completion, activity.getFlow());
               activity.addStep(completion);
            }
            else if (sElement.equals("ManualEvent"))
            {
               Object condition = m_helper.parse(XMLUtil.getStringAttr(eventElement, "condition"),
                  false, assignment.getActivity().getFlow().getPosMap(),
                  Boolean.TRUE, m_metadata.getGlobalEnvironment());
               boolean bTarget = loadTarget(eventElement, assignment, condition, sEventName, false);
               Element first = XMLUtil.findFirstElement(child);

               if (first != null && first.getNodeName().equals("UIAction"))
               {
                  loadTarget(first, assignment, condition, sEventName, bTarget);
                  child = first.getNextSibling();
               }

               if (assignment.getManualCompletion() == null)
               {
                  ManualCompletion completion = new ManualCompletion(assignment);

                  activity.addStep(completion);
               }
               else
               {
                  activity = null;
               }
            }
            else if (sElement.equals("ProcessEvent"))
            {
               branch = new Branch();
               decision.addBranch(branch);

               assignment.setSemaphore(true);

               Semaphore semaphore = new Semaphore(assignment.getName() + ":Semaphore", assignment);

               semaphore.setActivity(activity);
               activity.addStep(semaphore);

               Block block = new Block();

               block.setActivity(branch);
               branch.addStep(block);
               loadActivity(child, block.getContainedActivity());
               block.setCleanupCode(semaphore.getExitCode());
            }
            else
            {
               throw new MetadataException("err.meta.workflow.invalidQueueElement",
                  new Object[]{sElement, assignment.getName()});
            }

            if (eventMap.put(sEventName, Boolean.TRUE) != null)
            {
               throw new MetadataException("err.meta.workflow.queueEventDup",
                  new Object[]{sEventName, assignment.getName()});
            }

            Variable var = assignment.getActivity().getFlow().findVariable(assignment.getName());

            if (var == null)
            {
               var = new Variable(assignment.getName());
               assignment.getActivity().getFlow().addVariable(var);
            }

            if (activity != null)
            {
               Object code;

               if (activity.getStep(0) instanceof ManualCompletion)
               {
                  // ((:state'bind ('<assignment>'targetFunction)) '() (:flow'getToken <step>))
                  code =
                     Pair.list(
                        Pair.list(Symbol._STATE, Pair.quote(Symbol.BIND),
                           Pair.list(Pair.quote(assignment), Pair.quote(Symbol.TARGETFUNCTION))),
                        null,
                        Pair.list(Symbol._FLOW, Pair.quote(Symbol.GETTOKEN), Pair.quote(activity.getStep(0))));
               }
               else
               {
                  code = sEventName;
               }

               Script script = new Script();

               script.setBody(Pair.list(Pair.list(Symbol.SET, var.getSymbol(), code)));
               activity.addStep(script);
               fork.addConcurrent(activity);
            }

            if (branch == null)
            {
               branch = new Branch();
               decision.addBranch(branch);
               loadActivity(child, branch);
            }

            branch.setCondition(Pair.list(Symbol.EQUAL_P, var.getSymbol(), sEventName));
         }
      });

      if (fork.getConcurrentCount() == 0)
      {
         throw new MetadataException("err.meta.workflow.eventlessQueue",
            new Object[]{assignment.getName()});
      }

      if (fork.getConcurrentCount() == 1)
      {
         Activity activity = fork.getConcurrent(0);

         if (activity.getStep(0) instanceof Timeout)
         {
            activity.addStep(new Completion(assignment));
         }

         if (decision.getBranchCount() > 1)
         {
            for (int i = 0; i != activity.getStepCount(); ++i)
            {
               assignment.getActivity().addStep(activity.getStep(i));
            }

            return decision;
         }

         if (decision.getBranch(0).getStepCount() != 0)
         {
            for (int i = 0; i != activity.getStepCount(); ++i)
            {
               assignment.getActivity().addStep(activity.getStep(i));
            }

            activity = decision.getBranch(0);

            for (int i = 0; i != activity.getStepCount() - 1; ++i)
            {
               assignment.getActivity().addStep(activity.getStep(i));
            }
View Full Code Here


               step = new Wait(timeout);
               timeout.setNext(step);
            }
            else if (sElement.equals("Decision"))
            {
               final Decision decision = new Decision(sStepName);

               decision.setActivity(activity);
               decision.setManual(XMLUtil.getBooleanAttr(element, "manual", false));

               loadDecision(element, decision, m_helper, m_metadata, new BranchLoader()
               {
                  public String getElementName()
                  {
View Full Code Here

      }

      activity.addStep(initializer);

      // Loop test step
      Decision decision = new Decision(sLoopName + ":branch");
      Branch loopBody = new Branch();

      decision.setActivity(activity);
      loopBody.setDecision(decision);
      loopBody.setCondition(Pair.list(Symbol.COND,
         Pair.list(Pair.list(Symbol.PAIR_P, collectionSym),
            Pair.list(Symbol.NOT, Pair.list(Symbol.NULL_P, indexSym))),
         Pair.list(Pair.list(Symbol.VECTOR_P, collectionSym),
            Pair.list(Symbol.LT, indexSym, Pair.list(Symbol.VECTOR_LENGTH, collectionSym))),
         Pair.list(Symbol.ELSE,
            Pair.list(collectionSym, Pair.quote(XMLMetadataLoader.HAS_NEXT)))
      ));

      // Get current item and advance to next step
      Script getItem = new Script(sLoopName + ":next");

      getItem.setActivity(loopBody);
      getItem.setBody(new Pair(
         Pair.list(Symbol.COND,
            Pair.list(Pair.list(Symbol.PAIR_P, collectionSym),
               Pair.list(Symbol.SET, itemSym, Pair.list(Symbol.CAR, indexSym)),
               Pair.list(Symbol.SET, indexSym, Pair.list(Symbol.CDR, indexSym))
            ),
            Pair.list(Pair.list(Symbol.VECTOR_P, collectionSym),
               Pair.list(Symbol.SET, itemSym, Pair.list(collectionSym, indexSym)),
               Pair.list(Symbol.SET, indexSym, Pair.list(Symbol.PLUS, indexSym, Primitive.ONE_INTEGER))
            ),
            Pair.list(Symbol.ELSE,
               Pair.list(Symbol.SET, itemSym, Pair.list(collectionSym, Pair.quote(XMLMetadataLoader.NEXT)))
            )
         ),
         activity.getFlow().getDefaultReturnCode()
      ));
      loopBody.addStep(getItem);

      // Load loop body
      loader.loadActivity(element, loopBody);

      loopBody.getStep(loopBody.getStepCount() - 1).setNext(decision);
      decision.addBranch(loopBody);

      // Branch to follow when done
      Branch doneBranch = new Branch();

      doneBranch.setDecision(decision);
      doneBranch.setCondition(Boolean.TRUE);
      decision.addBranch(doneBranch);

      // Finish the loop expansion
      activity.addStep(decision);
   }
View Full Code Here

TOP

Related Classes of nexj.core.meta.workflow.Decision

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.