Package nexj.core.meta.workflow

Examples of nexj.core.meta.workflow.Step


   public static Step loadTryCatch(Element element, final TryCatch tryCatch,
      final Activity outerActivity, final XMLMetadataHelper helper, final Metadata metadata,
      final ActivityLoader loader)
   {
      final Pair codeHolder = new Pair(null);
      Step outerStep;

      XMLUtil.withFirstChildElement(element, "Finally", false, new ElementHandler()
      {
         public void handleElement(Element finallyElement)
         {
View Full Code Here


         int nCookie = m_helper.pushMarker(MetadataValidationException.TYPE_NAME, sElement);
         m_helper.pushMarker("step", sStepName);

         try
         {
            Step step;

            if (sElement.equals("Action"))
            {
               if (isWorkflowHandler(element))
               {
                  step = new Trigger(sStepName);
                  step.setActivity(activity);
                  loadWorkflowHandler(element, (Handler)step, activity.getFlow());
               }
               else
               {
                  step = new Script(sStepName);
                  step.setActivity(activity);
               }

               String sCleanup = XMLUtil.getStringAttr(element, "cleanup");

               if (sCleanup != null)
               {
                  for (StringTokenizer tokenizer = new StringTokenizer(sCleanup); tokenizer.hasMoreTokens();)
                  {
                     step.addCleanupAssoc(Symbol.define(tokenizer.nextToken()));
                  }
               }

               ((Scripted)step).setBody((Pair)m_helper.parse(m_helper.getElementValue(element),
                  true, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
            }
            else if (sElement.equals("Timeout"))
            {
               Timeout timeout = new Timeout(sStepName);

               timeout.setActivity(activity);
               timeout.setValue(m_helper.parse(XMLUtil.getReqStringAttr(element, "value"),
                  false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               activity.addStep(timeout);
               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()
                  {
                     return "Branch";
                  }

                  public Branch createBranch()
                  {
                     return new Branch();
                  }

                  public void loadActivity(Element element, Activity activity)
                  {
                     XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
                  }
               });

               step = decision;
            }
            else if (sElement.equals("Loop"))
            {
               loadLoop(element, activity, false, m_helper, m_metadata, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
                  }
               });
               step = null;
            }
            else if (sElement.equals("TryCatch"))
            {
               TryCatch tryCatch = new TryCatch(sStepName);

               step = loadTryCatch(element, tryCatch, activity, m_helper, m_metadata, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
                  }
               });
            }
            else if (sElement.equals("Join"))
            {
               final Fork fork = new Fork(sStepName);

               fork.setActivity(activity);

               Join join = new Join(fork);
               String sType = XMLUtil.getStringAttr(element, "type", "all");

               if (sType.equals("all"))
               {
                  join.setAny(false);
               }
               else if (sType.equals("any"))
               {
                  join.setAny(true);
               }
               else
               {
                  throw new MetadataException("err.meta.workflow.joinType",
                     new Object[]{sType, activity.getFlow().getFullName()});
               }

               XMLUtil.forEachChildElement(element, "Activity", new ElementHandler()
               {
                  public void handleElement(Element activityElement)
                  {
                     Concurrent concurrent = new Concurrent();

                     concurrent.setFork(fork);
                     loadActivity(activityElement.getFirstChild(), concurrent);
                     fork.addConcurrent(concurrent);
                  }
               });

               activity.addStep(fork);
               step = join;
            }
            else if (sElement.equals("Assignment"))
            {
               Flow workflow = activity.getFlow();
               Assignment assignment = new Assignment(sStepName);

               assignment.setActivity(activity);
               assignment.setQueue(parseQueueName(XMLUtil.getStringAttr(element, "queue"), activity, m_machine));
               assignment.setPriority(m_helper.parse(XMLUtil.getStringAttr(element, "priority"),
                  false, workflow.getPosMap(), assignment.getPriority(), m_metadata.getGlobalEnvironment()));
               assignment.setAssignee(m_helper.parse(XMLUtil.getStringAttr(element, "assignee"),
                  false, workflow.getPosMap(), assignment.getAssignee(), m_metadata.getGlobalEnvironment()));
               assignment.setOwner(m_helper.parse(XMLUtil.getStringAttr(element, "owner"),
                  false, workflow.getPosMap(), assignment.getOwner(), m_metadata.getGlobalEnvironment()));
               assignment.setCaption(m_helper.parse(XMLUtil.getStringAttr(element, "title"),
                  false, workflow.getPosMap(), XMLUtil.getStringAttr(element, "caption"),
                  m_metadata.getGlobalEnvironment()));
               assignment.setFactory((Pair)m_helper.parse(XMLUtil.getStringAttr(element, "factory"),
                  true, workflow.getPosMap(), assignment.getFactory(),
                  m_metadata.getGlobalEnvironment()));

               boolean bTarget = loadTarget(element, assignment, Boolean.TRUE, null, false);

               activity.addStep(assignment);

               if (isWorkflowHandler(element))
               {
                  AutoCompletion unassignment = new AutoCompletion(assignment);

                  loadWorkflowHandler(element, unassignment, workflow);
                  step = unassignment;
               }
               else
               {
                  step = new ManualCompletion(assignment);
               }

               nextElement = XMLUtil.findFirstElement(element.getNextSibling());

               if (nextElement != null)
               {
                  if (nextElement.getNodeName().equals("UIAction"))
                  {
                     loadTarget(element, assignment, Boolean.TRUE, null, bTarget);
                  }
                  else
                  {
                     nextElement = null;
                  }
               }

               assignment.setNext(step);
            }
            else if (sElement.equals("Semaphore"))
            {
               step = loadSemaphore(element, sStepName, activity, m_machine, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
                  }
               });
            }
            else if (sElement.equals("Goto"))
            {
               step = new Goto();
               step.setActivity(activity);
            }
            else if (sElement.equals("Queue"))
            {
               final Flow workflow = activity.getFlow();
               Assignment assignment = new Assignment(sStepName);

               assignment.setActivity(activity);
               assignment.setQueue(parseQueueName(XMLUtil.getStringAttr(element, "queue"), activity, m_machine));
               assignment.setPriority(m_helper.parse(XMLUtil.getStringAttr(element, "priority"),
                  false, workflow.getPosMap(), assignment.getPriority(), m_metadata.getGlobalEnvironment()));
               assignment.setAssignee(m_helper.parse(XMLUtil.getStringAttr(element, "assignee"),
                  false, workflow.getPosMap(), assignment.getAssignee(), m_metadata.getGlobalEnvironment()));
               assignment.setOwner(m_helper.parse(XMLUtil.getStringAttr(element, "owner"),
                  false, workflow.getPosMap(), assignment.getOwner(), m_metadata.getGlobalEnvironment()));
               assignment.setCaption(m_helper.parse(XMLUtil.getStringAttr(element, "title"),
                  false, workflow.getPosMap(), XMLUtil.getStringAttr(element, "caption"),
                  m_metadata.getGlobalEnvironment()));
               assignment.setFactory((Pair)m_helper.parse(XMLUtil.getStringAttr(element, "factory"),
                  true, workflow.getPosMap(), assignment.getFactory(),
                  m_metadata.getGlobalEnvironment()));

               activity.addStep(assignment);
               step = loadQueue(element, assignment);
            }
            else if (sElement.equals("UIAction"))
            {
               m_helper.restoreMarker(nCookie);
               throw new MetadataException("err.meta.workflow.misplacedElement",
                  new Object[]{sElement, activity.getFlow().getFullName()});
            }
            else
            {
               step = loadFlowMacroScript(element, sStepName, activity);

               if (step == null)
               {
                  m_helper.restoreMarker(nCookie);
                  throw new MetadataException("err.meta.workflow.invalidElement",
                     new Object[]{sElement, activity.getFlow().getFullName()});
               }
            }

            final String sNextStepName = XMLUtil.getStringAttr(element, "next");

            if (sNextStepName != null)
            {
               if (step == null)
               {
                  step = new Goto();
               }

               final Step fstep = step;

               m_flowFixupList.add(new ContextFixup(getHelper())
               {
                  public void fixup()
                  {
                     fstep.setNext(activity.getFlow().getFlowStep(sNextStepName));
                  }
               });
            }

            if (step != null)
View Full Code Here

      XMLUtil.forEachChildElement(sequenceElement, null, m_helper.new ElementHandler("step")
      {
         public void handleElement(Element element, String sStepName)
         {
            String sElement = element.getNodeName();
            Step step;

            if (sElement.equals("Script"))
            {
               Script script = new Script(sStepName);

               script.setActivity(activity);
               script.setBody((Pair)m_helper.parse(m_helper.getElementValue(element),
                  true, activity.getFlow().getPosMap(), Jump.BODY, m_metadata.getGlobalEnvironment()));
               step = script;
            }
            else if (sElement.equals("Transform"))
            {
               Transform transform = new Transform(sStepName);

               transform.setActivity(activity);
               transform.setTransformationExpression(m_helper.parse(XMLUtil.getReqStringAttr(element, "transformation"),
                  false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               transform.setTransformationArguments(m_helper.parse(XMLUtil.getStringAttr(element, "args", null),
                  true, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               step = transform;
            }
            else if (sElement.equals("Dispatch"))
            {
               final Dispatch dispatch = new Dispatch(sStepName);

               dispatch.setActivity(activity);
               loadDecision(element, dispatch, m_helper, m_metadata, new BranchLoader()
               {
                  public String getElementName()
                  {
                     return "Case";
                  }

                  public Branch createBranch()
                  {
                     return new Case();
                  }

                  public void loadActivity(Element element, Activity activity)
                  {
                     String sMessage = XMLUtil.getStringAttr(element, "message");

                     if (sMessage != null)
                     {
                        ((Case)activity).setMessage(m_metadata.getMessage(sMessage));
                     }

                     loadSequence(element, activity);
                  }
               });

               step = dispatch;
            }
            else if (sElement.equals("Loop"))
            {
               loadLoop(element, activity, true, m_helper, m_metadata, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     loadSequence(element, activity);
                  }
               });
               step = null;
            }
            else if (sElement.equals("TryCatch"))
            {
               TryCatch tryCatch = new TryCatch(sStepName);

               step = loadTryCatch(element, tryCatch, activity, m_helper, m_metadata, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     loadSequence(element, activity);
                  }
               });
            }
            else if (sElement.equals("Persist"))
            {
               final Persist persist = new Persist(sStepName);
               persist.setActivity(activity);
               persist.setRespond(XMLUtil.getBooleanAttr(element, "respond", persist.isRespond()));
               persist.setOnError(getOnError(element));
               step = persist;
            }
            else if (sElement.equals("Sync"))
            {
               Sync sync = new Sync(sStepName);
               sync.setSyncLink(m_helper.parse(XMLUtil.getReqStringAttr(element, "link"), false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               sync.setSyncScript((Pair)m_helper.parse(m_helper.getElementValue(element), true, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               sync.setOnError(getOnError(element));
               step = sync;
            }
            else if (sElement.equals("Send"))
            {
               Send send = new Send(sStepName);
               send.setActivity(activity);
               String sOutput = XMLUtil.getStringAttr(element, "output");
               send.setOutputExpression(m_helper.parse(sOutput, false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
               String sInterface = XMLUtil.getStringAttr(element, "interface");

               if (sInterface != null)
               {
                  send.setInterface(m_metadata.defineInterface(sInterface, send));
               }

               step = send;
            }
            else if (sElement.equals("SendReceive"))
            {
               SendReceive send = new SendReceive(sStepName);

               send.setActivity(activity);

               String sOutput = XMLUtil.getStringAttr(element, "output");

               if (sOutput != null)
               {
                  Object outputExpression = m_helper.parse(sOutput, false, activity.getFlow().getPosMap(), Boolean.TRUE, m_metadata.getGlobalEnvironment());
                  send.setOutputExpression(outputExpression);
               }

               String sInterface = XMLUtil.getStringAttr(element, "interface");

               if (sInterface != null)
               {
                  send.setInterface(m_metadata.defineInterface(sInterface, send));
               }

               step = send;
            }
            else if (sElement.equals("Semaphore"))
            {
               step = loadSemaphore(element, sStepName, activity, m_machine, new ActivityLoader()
               {
                  public void loadActivity(Element element, Activity activity)
                  {
                     loadSequence(element, activity);
                  }
               });
            }
            else if (sElement.equals("Goto"))
            {
               step = new Jump();
               step.setActivity(activity);
            }
            else
            {
               step = loadFlowMacroScript(element, sStepName, activity);

               if (step == null)
               {
                  throw new MetadataException("err.meta.service.invalidElement",
                     new Object[]{sElement, activity.getFlow().getFullName()});
               }
            }

            final String sNextStepName = XMLUtil.getStringAttr(element, "next");

            if (sNextStepName != null)
            {
               if (step == null)
               {
                  step = new Jump();
               }

               final Step fstep = step;

               m_flowFixupList.add(new ContextFixup(getHelper())
               {
                  public void fixup()
                  {
                     fstep.setNext(activity.getFlow().getFlowStep(sNextStepName));
                  }
               });
            }

            if (step != null)
View Full Code Here

TOP

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

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.