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

https://github.com/mariofusco/jbpm · Java · 78 lines · 47 code · 11 blank · 20 comment · 10 complexity · 8bd12cfdd51ddcc05bd0cfaec25c7046 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 org.kie.api.definition.process.Connection;
  18. import org.jbpm.workflow.core.Constraint;
  19. import org.jbpm.workflow.core.impl.ConnectionRef;
  20. /**
  21. * Default implementation of a milestone node.
  22. *
  23. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  24. */
  25. public class MilestoneNode extends StateBasedNode implements Constrainable {
  26. private static final long serialVersionUID = 510l;
  27. private String constraint;
  28. public void addConstraint(ConnectionRef connection, Constraint constraint) {
  29. if (connection != null) {
  30. throw new IllegalArgumentException(
  31. "A Milestone node only accepts one simple constraint");
  32. }
  33. this.constraint = constraint.getConstraint();
  34. }
  35. public void setConstraint(String constraint){
  36. this.constraint = constraint;
  37. }
  38. public String getConstraint(){
  39. return this.constraint;
  40. }
  41. public void validateAddIncomingConnection(final String type, final Connection connection) {
  42. super.validateAddIncomingConnection(type, connection);
  43. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  44. throw new IllegalArgumentException(
  45. "This type of node [" + connection.getTo().getMetaData().get("UniqueId") + ", " + connection.getTo().getName()
  46. + "] only accepts default incoming connection type!");
  47. }
  48. if (getFrom() != null && !"true".equals(System.getProperty("jbpm.enable.multi.con"))) {
  49. throw new IllegalArgumentException(
  50. "This type of node [" + connection.getTo().getMetaData().get("UniqueId") + ", " + connection.getTo().getName()
  51. + "] cannot have more than one incoming connection!");
  52. }
  53. }
  54. public void validateAddOutgoingConnection(final String type, final Connection connection) {
  55. super.validateAddOutgoingConnection(type, connection);
  56. if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
  57. throw new IllegalArgumentException(
  58. "This type of node [" + connection.getFrom().getMetaData().get("UniqueId") + ", " + connection.getFrom().getName()
  59. + "] only accepts default outgoing connection type!");
  60. }
  61. if (getTo() != null && !"true".equals(System.getProperty("jbpm.enable.multi.con"))) {
  62. throw new IllegalArgumentException(
  63. "This type of node [" + connection.getFrom().getMetaData().get("UniqueId") + ", " + connection.getFrom().getName()
  64. + "] cannot have more than one outgoing connection!");
  65. }
  66. }
  67. }