/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/ActionNodeInstance.java

https://github.com/mariofusco/jbpm · Java · 65 lines · 33 code · 9 blank · 23 comment · 1 complexity · 61e1c7a2d67622c57d23a04c295c22bf MD5 · raw file

  1. /**
  2. * Copyright 2005 JBoss Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jbpm.workflow.instance.node;
  17. import org.drools.core.spi.ProcessContext;
  18. import org.jbpm.process.instance.impl.Action;
  19. import org.jbpm.workflow.core.node.ActionNode;
  20. import org.jbpm.workflow.instance.WorkflowRuntimeException;
  21. import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
  22. import org.kie.api.runtime.process.NodeInstance;
  23. /**
  24. * Runtime counterpart of an action node.
  25. *
  26. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  27. */
  28. public class ActionNodeInstance extends NodeInstanceImpl {
  29. private static final long serialVersionUID = 510l;
  30. protected ActionNode getActionNode() {
  31. return (ActionNode) getNode();
  32. }
  33. public void internalTrigger(final NodeInstance from, String type) {
  34. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  35. throw new IllegalArgumentException(
  36. "An ActionNode only accepts default incoming connections!");
  37. }
  38. Action action = (Action) getActionNode().getAction().getMetaData("Action");
  39. try {
  40. ProcessContext context = new ProcessContext(getProcessInstance().getKnowledgeRuntime());
  41. context.setNodeInstance(this);
  42. executeAction(action);
  43. } catch( WorkflowRuntimeException wre) {
  44. throw wre;
  45. } catch (Exception e) {
  46. // for the case that one of the following throws an exception
  47. // - the ProcessContext() constructor
  48. // - or context.setNodeInstance(this)
  49. throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
  50. }
  51. triggerCompleted();
  52. }
  53. public void triggerCompleted() {
  54. triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, true);
  55. }
  56. }