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

https://github.com/michelpohle/jbpm · Java · 77 lines · 44 code · 13 blank · 20 comment · 2 complexity · 337c71309b47ae0c66b2c54985cd9e4c 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.runtime.process.EventListener;
  18. import org.drools.runtime.process.NodeInstance;
  19. import org.drools.runtime.rule.impl.InternalAgenda;
  20. import org.jbpm.workflow.core.node.RuleSetNode;
  21. /**
  22. * Runtime counterpart of a ruleset node.
  23. *
  24. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  25. */
  26. public class RuleSetNodeInstance extends StateBasedNodeInstance implements EventListener {
  27. private static final long serialVersionUID = 510l;
  28. protected RuleSetNode getRuleSetNode() {
  29. return (RuleSetNode) getNode();
  30. }
  31. public void internalTrigger(final NodeInstance from, String type) {
  32. if ( !org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals( type ) ) {
  33. throw new IllegalArgumentException( "A RuleSetNode only accepts default incoming connections!" );
  34. }
  35. addRuleSetListener();
  36. ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda())
  37. .activateRuleFlowGroup( getRuleSetNode().getRuleFlowGroup(), getProcessInstance().getId(), getUniqueId() );
  38. }
  39. public void addEventListeners() {
  40. super.addEventListeners();
  41. addRuleSetListener();
  42. }
  43. private String getRuleSetEventType() {
  44. return "RuleFlowGroup_" + getRuleSetNode().getRuleFlowGroup();
  45. }
  46. private void addRuleSetListener() {
  47. getProcessInstance().addEventListener(getRuleSetEventType(), this, true);
  48. }
  49. public void removeEventListeners() {
  50. super.removeEventListeners();
  51. getProcessInstance().removeEventListener(getRuleSetEventType(), this, true);
  52. }
  53. public void cancel() {
  54. super.cancel();
  55. ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda())
  56. .deactivateRuleFlowGroup( getRuleSetNode().getRuleFlowGroup() );
  57. }
  58. public void signalEvent(String type, Object event) {
  59. if (getRuleSetEventType().equals(type)) {
  60. removeEventListeners();
  61. triggerCompleted();
  62. }
  63. }
  64. }