/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/RuleConstraintEvaluator.java

https://github.com/mariofusco/jbpm · Java · 119 lines · 74 code · 24 blank · 21 comment · 0 complexity · 8bd9e1c43ddc870dcfa4fe180b5435f7 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.process.instance.impl;
  17. import java.io.Serializable;
  18. import org.drools.core.common.InternalAgenda;
  19. import org.jbpm.process.instance.ProcessInstance;
  20. import org.jbpm.workflow.core.Constraint;
  21. import org.jbpm.workflow.core.Node;
  22. import org.jbpm.workflow.instance.NodeInstance;
  23. import org.kie.api.definition.process.Connection;
  24. import org.kie.api.runtime.process.WorkflowProcessInstance;
  25. /**
  26. * Default implementation of a constraint.
  27. *
  28. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  29. */
  30. public class RuleConstraintEvaluator implements Constraint,
  31. ConstraintEvaluator, Serializable {
  32. private static final long serialVersionUID = 510l;
  33. private String name;
  34. private String constraint;
  35. private int priority;
  36. private String dialect;
  37. private String type;
  38. private boolean isDefault;
  39. public String getConstraint() {
  40. return this.constraint;
  41. }
  42. public void setConstraint(final String constraint) {
  43. this.constraint = constraint;
  44. }
  45. public String getName() {
  46. return this.name;
  47. }
  48. public void setName(final String name) {
  49. this.name = name;
  50. }
  51. public String toString() {
  52. return this.name;
  53. }
  54. public int getPriority() {
  55. return this.priority;
  56. }
  57. public void setPriority(final int priority) {
  58. this.priority = priority;
  59. }
  60. public String getDialect() {
  61. return dialect;
  62. }
  63. public void setDialect(String dialect) {
  64. this.dialect = dialect;
  65. }
  66. public String getType() {
  67. return type;
  68. }
  69. public void setType(String type) {
  70. this.type = type;
  71. }
  72. public boolean isDefault() {
  73. return isDefault;
  74. }
  75. public void setDefault(boolean isDefault) {
  76. this.isDefault = isDefault;
  77. }
  78. public boolean evaluate(NodeInstance instance,
  79. Connection connection,
  80. Constraint constraint) {
  81. WorkflowProcessInstance processInstance = instance.getProcessInstance();
  82. InternalAgenda agenda = (InternalAgenda) ((ProcessInstance) processInstance).getKnowledgeRuntime().getAgenda();
  83. String rule = "RuleFlow-Split-" + processInstance.getProcessId() + "-" +
  84. ((Node) instance.getNode()).getUniqueId() + "-" +
  85. ((Node) connection.getTo()).getUniqueId() + "-" + connection.getToType();
  86. boolean isActive = agenda.isRuleActiveInRuleFlowGroup( "DROOLS_SYSTEM", rule, processInstance.getId() );
  87. return isActive;
  88. }
  89. public Object getMetaData(String name) {
  90. return null;
  91. }
  92. public void setMetaData(String name, Object value) {
  93. // Do nothing
  94. }
  95. }