/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/StartNodeInstance.java

https://github.com/mariofusco/jbpm · Java · 75 lines · 45 code · 10 blank · 20 comment · 10 complexity · 49860c1261b69535010b51e1f389fd53 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.instance.node;
  17. import org.jbpm.process.core.context.variable.VariableScope;
  18. import org.jbpm.process.core.event.EventTransformer;
  19. import org.jbpm.process.instance.context.variable.VariableScopeInstance;
  20. import org.jbpm.workflow.core.node.StartNode;
  21. import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
  22. import org.kie.api.runtime.process.NodeInstance;
  23. /**
  24. * Runtime counterpart of a start node.
  25. *
  26. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  27. */
  28. public class StartNodeInstance extends NodeInstanceImpl {
  29. private static final long serialVersionUID = 510l;
  30. public void internalTrigger(final NodeInstance from, String type) {
  31. if (type != null) {
  32. throw new IllegalArgumentException(
  33. "A StartNode does not accept incoming connections!");
  34. }
  35. if (from != null) {
  36. throw new IllegalArgumentException(
  37. "A StartNode can only be triggered by the process itself!");
  38. }
  39. triggerCompleted();
  40. }
  41. public void signalEvent(String type, Object event) {
  42. String variableName = (String) getStartNode().getMetaData("TriggerMapping");
  43. if (variableName != null) {
  44. VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
  45. resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
  46. if (variableScopeInstance == null) {
  47. throw new IllegalArgumentException(
  48. "Could not find variable for start node: " + variableName);
  49. }
  50. EventTransformer transformer = getStartNode().getEventTransformer();
  51. if (transformer != null) {
  52. event = transformer.transformEvent(event);
  53. }
  54. variableScopeInstance.setVariable(variableName, event);
  55. }
  56. triggerCompleted();
  57. }
  58. public StartNode getStartNode() {
  59. return (StartNode) getNode();
  60. }
  61. public void triggerCompleted() {
  62. ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(getLevel());
  63. triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, true);
  64. }
  65. }