Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 International Business Machines Corp.
   * 
   * See the NOTICE file distributed with this work for additional information
   * regarding copyright ownership. Licensed under the Apache License, 
   * Version 2.0 (the "License"); you may not use this file except in compliance
   * with the License. You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 */
 package com.ibm.jbatch.container.jsl.impl;
 
 import java.util.List;
 
 
 
 public class FlowNavigatorImpl implements Navigator<Flow> {
 
     private final static Logger logger = Logger.getLogger(FlowNavigatorImpl.class.getName());
     private Flow flow = null;
 
     public FlowNavigatorImpl(Flow flow) {
         this. = flow;
     }
 
     @Override
     public Transition getNextTransition(ExecutionElement currentElemString currentExitStatus) {
         final String method = "getNextTransition";
         if (.isLoggable(.))
             .fine(method + " ,currentExitStatus=" + currentExitStatus);
 
         String nextAttrId = null;
         ExecutionElement nextExecutionElement = null;
         Transition returnTransition = new TransitionImpl();
 
         if (currentElem instanceof Step) {
             nextAttrId = ((StepcurrentElem).getNextFromAttribute();
             nextExecutionElement = getExecutionElementByID(nextAttrId);
         } else if (currentElem instanceof Split) {
             nextAttrId = ((SplitcurrentElem).getNextFromAttribute();
             nextExecutionElement = getExecutionElementByID(nextAttrId);
         } else if (currentElem instanceof Flow) {
         	nextAttrId = ((FlowcurrentElem).getNextFromAttribute();
         	nextExecutionElement = getExecutionElementByID(nextAttrId);
         } else if (currentElem instanceof Decision) {
             // Nothing special to do in this case.
         }
 
         List<TransitionElementtransitionElements = currentElem.getTransitionElements();
 
         if (nextExecutionElement == null && transitionElements.isEmpty()) {
             if (.isLoggable(.))
                 .fine(method + " return null, there is no next step");
             // Don't set anything special on return transition.
             return returnTransition;
         } else if (nextExecutionElement != null) {
             if (.isLoggable(.))
                 .fine(method + " return execution element:" + nextExecutionElement);
             returnTransition.setNextExecutionElement(nextExecutionElement);
             return returnTransition;
         } else if (transitionElements.size() > 0) {
 
             Iterator<TransitionElementiterator = transitionElements.iterator();
             while (iterator.hasNext()) {
 
                 TransitionElement elem = iterator.next();
 
                 if (.isLoggable(.)) {
                     .fine(method + " Trying to match next control element: " + elem);
                 }
 
                 if (elem instanceof Stop) {
                     String exitStatusToMatch = ((Stopelem).getOn();
                     boolean isMatched = matchSpecifiedExitStatus(currentExitStatusexitStatusToMatch);
                     if (isMatched == true) {
                         if (.isLoggable(.))
                             .fine(method + " , Stop element matches to " + exitStatusToMatch);
 
                        returnTransition.setTransitionElement(elem);
                        return returnTransition;
                    }
                } else if (elem instanceof End) {
                    String exitStatusToMatch = ((Endelem).getOn();
                    boolean isMatched = matchSpecifiedExitStatus(currentExitStatusexitStatusToMatch);
                    if (isMatched == true) {
                        if (.isLoggable(.))
                            .fine(method + " , End element matches to " + exitStatusToMatch);
                        returnTransition.setTransitionElement(elem);
                        return returnTransition;
                    }
                } else if (elem instanceof Fail) {
                    String exitStatusToMatch = ((Failelem).getOn();
                    boolean isMatched = matchSpecifiedExitStatus(currentExitStatusexitStatusToMatch);
                    if (isMatched == true) {
                        if (.isLoggable(.))
                            .fine(method + " , Fail element matches to " + exitStatusToMatch);
                        returnTransition.setTransitionElement(elem);
                        return returnTransition;
                    }
                } else if (elem instanceof Next) {
                    String exitStatusToMatch = ((Nextelem).getOn();
                    boolean isMatched = matchSpecifiedExitStatus(currentExitStatusexitStatusToMatch);
                    if (isMatched == true) {
                        // go to next executionElement
                        nextExecutionElement = getExecutionElementByID(((Nextelem).getTo());
                        if (.isLoggable(.))
                            .fine(method + " , match to " + exitStatusToMatch + ". Continue to step "
                                    + nextExecutionElement.getId());
                        // No point setting the TransitionElement in the transition.
                        returnTransition.setNextExecutionElement(nextExecutionElement);
                        return returnTransition;
                    }
                } else {
                    throw new IllegalStateException("Shouldn't be possible to get here. Unknown control element,  " + elem.toString());
                }
            }
        }
        //TODO - Is this an error case or a valid end/completion case?
        return null;
    }
    @Override
    public Step getFirstExecutionElement(String restartOn) {
        final String method = "getFirstExecutionElement";
        if (.isLoggable(.)) {
            .fine(method + " , restartOn = " + restartOn);
        }
        ExecutionElement startElement = null;
        if (restartOn != null) {
            startElement = getExecutionElementByID(restartOn);
            if (startElement == null) {
                throw new IllegalStateException("Didn't find an execution element maching restart-on designated element: " + restartOn);
            }
        } else {
            if (.getExecutionElements().size() > 0) {     
                startElement = .getExecutionElements().get(0);
            } else {
                if (.isLoggable(.)) {
                    .fine(method + " , Job appears to contain no execution elements.  Returning.");
                }
                return null;
            }
        }
        if (.isLoggable(.)) {
            .fine(method + " , Found start element: " + startElement);
        }                
        if (startElement instanceof Step) {
            return (StepstartElement;
        } else {
            throw new IllegalStateException("Didn't get this far yet implementing.\nOnly support <step> as first execution element.");
        }
    }
    public Flow getJSL() {
        return this.;
    }
        if (id != null) {
        	.finer("attribute value is " + id);
            for (ExecutionElement elem : .getExecutionElements()) {
                if (elem.getId().equals(id)) {
                    return elem;
                }
            }
            .warning("In flow, no local execution element found with id = " + id);
            throw new IllegalStateException("In flow, no local execution element found with id = " + id);
        } else {
        	.finer("attribute value is <null>, so simply exiting...");
        	return null;
        }
    }
    /*
     * 
     */
    private static boolean matchSpecifiedExitStatus(String currentStepExitStatusString exitStatusPattern) {
    	
    	
        if (.isLoggable(.)) {
            .finer("matchSpecifiedExitStatus, matching current exitStatus  " + currentStepExitStatus + 
            		" against pattern: " + exitStatusPattern);
        }
        
        GlobPatternMatcherImpl matcher = new GlobPatternMatcherImpl(); 
        boolean match = matcher.matchWithoutBackslashEscape(currentStepExitStatusexitStatusPattern);
                
        if (match) {
            if (.isLoggable(.)) {
                .finer("matchSpecifiedExitStatus, match=YES");
            }
            return true;
        }
        else {
            if (.isLoggable(.)) {
                .finer("matchSpecifiedExitStatus, match=NO");
            }
            return false;
        }
    }
    
    
    public String getId() {
        return .getId();
    }
New to GrepCode? Check out our FAQ X