/machinelearning/5.0.x/drools-core/src/main/java/org/drools/workflow/core/node/Join.java

https://github.com/etirelli/droolsjbpm-contributed-experiments · Java · 100 lines · 51 code · 15 blank · 34 comment · 4 complexity · abb56186c27af68b5d222f859ca70e98 MD5 · raw file

  1. package org.drools.workflow.core.node;
  2. /*
  3. * Copyright 2005 JBoss Inc
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import java.util.List;
  18. import org.drools.definition.process.Connection;
  19. import org.drools.workflow.core.impl.NodeImpl;
  20. /**
  21. * Default implementation of a join.
  22. *
  23. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  24. */
  25. public class Join extends NodeImpl {
  26. public static final int TYPE_UNDEFINED = 0;
  27. /**
  28. * The outgoing connection of a join of this type is triggered
  29. * when all its incoming connections have been triggered.
  30. */
  31. public static final int TYPE_AND = 1;
  32. /**
  33. * The outgoing connection of a join of this type is triggered
  34. * when one of its incoming connections has been triggered.
  35. */
  36. public static final int TYPE_XOR = 2;
  37. /**
  38. * The outgoing connection of a join of this type is triggered
  39. * when one of its incoming connections has been triggered. It then
  40. * waits until all other incoming connections have been triggered
  41. * before allowing
  42. */
  43. public static final int TYPE_DISCRIMINATOR = 3;
  44. private static final long serialVersionUID = 400L;
  45. private int type;
  46. public Join() {
  47. this.type = TYPE_UNDEFINED;
  48. }
  49. public void setType(final int type) {
  50. this.type = type;
  51. }
  52. public int getType() {
  53. return this.type;
  54. }
  55. public Connection getTo() {
  56. final List<Connection> list =
  57. getOutgoingConnections(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
  58. if (list.size() > 0) {
  59. return (Connection) list.get(0);
  60. }
  61. return null;
  62. }
  63. public List<Connection> getDefaultIncomingConnections() {
  64. return getIncomingConnections(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
  65. }
  66. public void validateAddIncomingConnection(final String type,
  67. final Connection connection) {
  68. super.validateAddIncomingConnection(type, connection);
  69. if (!org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  70. throw new IllegalArgumentException(
  71. "This type of node only accepts default incoming connection type!");
  72. }
  73. }
  74. public void validateAddOutgoingConnection(final String type, final Connection connection) {
  75. super.validateAddOutgoingConnection(type, connection);
  76. if (!org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  77. throw new IllegalArgumentException(
  78. "This type of node only accepts default outgoing connection type!");
  79. }
  80. if (!getOutgoingConnections(org.drools.workflow.core.Node.CONNECTION_DEFAULT_TYPE).isEmpty()) {
  81. throw new IllegalArgumentException(
  82. "This type of node cannot have more than one outgoing connection");
  83. }
  84. }
  85. }