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    import java.util.ArrayList;
018    import java.util.List;
019    
020    //TODO javadoc
021    public class ForkNodeDef extends NodeDef {
022    
023        public static final String FORK_COUNT_PREFIX = "workflow.fork.";
024    
025        ForkNodeDef() {
026        }
027    
028        public ForkNodeDef(String name, List<String> transitions) {
029            super(name, null, ForkNodeHandler.class, transitions);
030        }
031    
032        public static class ForkNodeHandler extends NodeHandler {
033    
034            public boolean enter(Context context) {
035                return true;
036            }
037    
038            // the return list contains (parentExecutionPath/transition#transition)+
039            public List<String> multiExit(Context context) {
040                List<String> transitions = context.getNodeDef().getTransitions();
041                context.setVar(FORK_COUNT_PREFIX + context.getExecutionPath(), "" + transitions.size());
042    
043                List<String> fullTransitions = new ArrayList<String>(transitions.size());
044    
045                for (String transition : transitions) {
046                    String childExecutionPath = context.createExecutionPath(transition);
047                    String fullTransition = context.createFullTransition(childExecutionPath, transition);
048                    fullTransitions.add(fullTransition);
049                }
050                return fullTransitions;
051            }
052    
053            public String exit(Context context) {
054                throw new UnsupportedOperationException();
055            }
056    
057            public void kill(Context context) {
058            }
059    
060            public void fail(Context context) {
061            }
062    
063        }
064    
065    }