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