/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/WorkItemNode.java

https://github.com/wintonxu/jbpm · Java · 152 lines · 104 code · 27 blank · 21 comment · 22 complexity · d04d397d85d9db591ecc14074d4ee1fd 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.core.node;
  17. import java.util.Collections;
  18. import java.util.HashMap;
  19. import java.util.Map;
  20. import java.util.LinkedList;
  21. import java.util.List;
  22. import org.drools.definition.process.Connection;
  23. import org.drools.process.core.Work;
  24. import org.jbpm.process.core.context.variable.Mappable;
  25. /**
  26. * Default implementation of a task node.
  27. *
  28. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  29. */
  30. public class WorkItemNode extends StateBasedNode implements Mappable {
  31. private static final long serialVersionUID = 510l;
  32. private Work work;
  33. private List<DataAssociation> inMapping = new LinkedList<DataAssociation>();
  34. private List<DataAssociation> outMapping = new LinkedList<DataAssociation>();
  35. private boolean waitForCompletion = true;
  36. // TODO boolean independent (cancel work item if node gets cancelled?)
  37. public Work getWork() {
  38. return work;
  39. }
  40. public void setWork(Work work) {
  41. this.work = work;
  42. }
  43. public void addInMapping(String parameterName, String variableName) {
  44. inMapping.add(new DataAssociation(variableName, parameterName, null, null));
  45. }
  46. public void setInMappings(Map<String, String> inMapping) {
  47. this.inMapping = new LinkedList<DataAssociation>();
  48. for(Map.Entry<String, String> entry : inMapping.entrySet()) {
  49. addInMapping(entry.getKey(), entry.getValue());
  50. }
  51. }
  52. public String getInMapping(String parameterName) {
  53. return getInMappings().get(parameterName);
  54. }
  55. public Map<String, String> getInMappings() {
  56. Map<String,String> in = new HashMap<String, String>();
  57. for(DataAssociation a : inMapping) {
  58. if(a.getSources().size() ==1 && (a.getAssignments() == null || a.getAssignments().size()==0) && a.getTransformation() == null) {
  59. in.put(a.getTarget(), a.getSources().get(0));
  60. }
  61. }
  62. return in;
  63. }
  64. public void addInAssociation(DataAssociation dataAssociation) {
  65. inMapping.add(dataAssociation);
  66. }
  67. public List<DataAssociation> getInAssociations() {
  68. return Collections.unmodifiableList(inMapping);
  69. }
  70. public void addOutMapping(String parameterName, String variableName) {
  71. outMapping.add(new DataAssociation(parameterName, variableName, null, null));
  72. }
  73. public void setOutMappings(Map<String, String> outMapping) {
  74. this.outMapping = new LinkedList<DataAssociation>();
  75. for(Map.Entry<String, String> entry : outMapping.entrySet()) {
  76. addOutMapping(entry.getKey(), entry.getValue());
  77. }
  78. }
  79. public String getOutMapping(String parameterName) {
  80. return getOutMappings().get(parameterName);
  81. }
  82. public Map<String, String> getOutMappings() {
  83. Map<String,String> out = new HashMap<String, String>();
  84. for(DataAssociation a : outMapping) {
  85. if(a.getSources().size() ==1 && (a.getAssignments() == null || a.getAssignments().size()==0) && a.getTransformation() == null) {
  86. out.put(a.getSources().get(0), a.getTarget());
  87. }
  88. }
  89. return out;
  90. }
  91. public void addOutAssociation(DataAssociation dataAssociation) {
  92. outMapping.add(dataAssociation);
  93. }
  94. public List<DataAssociation> getOutAssociations() {
  95. return Collections.unmodifiableList(outMapping);
  96. }
  97. public boolean isWaitForCompletion() {
  98. return waitForCompletion;
  99. }
  100. public void setWaitForCompletion(boolean waitForCompletion) {
  101. this.waitForCompletion = waitForCompletion;
  102. }
  103. public void validateAddIncomingConnection(final String type, final Connection connection) {
  104. super.validateAddIncomingConnection(type, connection);
  105. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  106. throw new IllegalArgumentException(
  107. "This type of node only accepts default incoming connection type!");
  108. }
  109. if (getFrom() != null) {
  110. throw new IllegalArgumentException(
  111. "This type of node cannot have more than one incoming connection!");
  112. }
  113. }
  114. public void validateAddOutgoingConnection(final String type, final Connection connection) {
  115. super.validateAddOutgoingConnection(type, connection);
  116. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  117. throw new IllegalArgumentException(
  118. "This type of node only accepts default outgoing connection type!");
  119. }
  120. if (getTo() != null) {
  121. throw new IllegalArgumentException(
  122. "This type of node cannot have more than one outgoing connection!");
  123. }
  124. }
  125. }