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

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