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