001 /**
002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software
010 * distributed under the License is distributed on an "AS IS" BASIS,
011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 * See the License for the specific language governing permissions and
013 * limitations under the License. See accompanying LICENSE file.
014 */
015 package org.apache.oozie.workflow.lite;
016
017
018 import org.apache.oozie.workflow.WorkflowException;
019 import org.apache.oozie.util.ParamChecker;
020 import org.apache.oozie.ErrorCode;
021
022 import java.util.ArrayList;
023 import java.util.List;
024
025 /**
026 * Workflow lite start node definition.
027 */
028 public class StartNodeDef extends NodeDef {
029
030 /**
031 * Reserved name fo the start node. <p/> It is an invalid token, it will never match an application node name.
032 */
033 public static final String START = "::start::";
034
035 /**
036 * Default constructor.
037 */
038 public StartNodeDef() {
039 }
040
041 /**
042 * Create a start node definition.
043 *
044 * @param transitionTo transition on workflow start.
045 */
046 public StartNodeDef(String transitionTo) {
047 super(START, null, StartNodeHandler.class, createList(ParamChecker.notEmpty(transitionTo, "transitionTo")));
048 }
049
050 private static List<String> createList(String transition) {
051 List<String> list = new ArrayList<String>();
052 list.add(transition);
053 return list;
054 }
055
056 /**
057 * Start node handler. <p/> It does an immediate transition to the transitionTo node.
058 */
059 public static class StartNodeHandler extends NodeHandler {
060
061 public boolean enter(Context context) throws WorkflowException {
062 if (!context.getSignalValue().equals(StartNodeDef.START)) {
063 throw new WorkflowException(ErrorCode.E0715, context.getSignalValue());
064 }
065 return true;
066 }
067
068 public String exit(Context context) {
069 return context.getNodeDef().getTransitions().get(0);
070 }
071
072 public void kill(Context context) {
073 }
074
075 public void fail(Context context) {
076 }
077 }
078
079 }