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

https://github.com/mariofusco/jbpm · Java · 80 lines · 52 code · 8 blank · 20 comment · 13 complexity · 8427d492d737ff019a9e6850e8e8255e 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.common.InternalKnowledgeRuntime;
  18. import org.jbpm.process.instance.InternalProcessRuntime;
  19. import org.jbpm.process.instance.ProcessInstance;
  20. import org.jbpm.workflow.core.node.EndNode;
  21. import org.jbpm.workflow.instance.NodeInstanceContainer;
  22. import org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl;
  23. import org.kie.api.runtime.process.NodeInstance;
  24. /**
  25. * Runtime counterpart of an end node.
  26. *
  27. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  28. */
  29. public class EndNodeInstance extends ExtendedNodeInstanceImpl {
  30. private static final long serialVersionUID = 510l;
  31. public EndNode getEndNode() {
  32. return (EndNode) getNode();
  33. }
  34. public void internalTrigger(final NodeInstance from, String type) {
  35. super.internalTrigger(from, type);
  36. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  37. throw new IllegalArgumentException(
  38. "An EndNode only accepts default incoming connections!");
  39. }
  40. boolean hidden = false;
  41. if (getNode().getMetaData().get("hidden") != null) {
  42. hidden = true;
  43. }
  44. InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
  45. if (!hidden) {
  46. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  47. .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
  48. }
  49. ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
  50. if (getEndNode().isTerminate()) {
  51. if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
  52. if (getEndNode().getScope() == EndNode.PROCESS_SCOPE) {
  53. getProcessInstance().setState( ProcessInstance.STATE_COMPLETED );
  54. } else {
  55. while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
  56. ((org.jbpm.workflow.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
  57. }
  58. ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
  59. }
  60. } else {
  61. ((NodeInstanceContainer) getNodeInstanceContainer()).setState( ProcessInstance.STATE_COMPLETED );
  62. }
  63. } else {
  64. ((NodeInstanceContainer) getNodeInstanceContainer())
  65. .nodeInstanceCompleted(this, null);
  66. }
  67. if (!hidden) {
  68. ((InternalProcessRuntime) kruntime.getProcessRuntime())
  69. .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
  70. }
  71. }
  72. }