Coverage Report - org.kuali.rice.kew.engine.node.service.impl.BranchServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BranchServiceImpl
0%
0/36
0%
0/10
2
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.engine.node.service.impl;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.log4j.Logger;
 22  
 import org.kuali.rice.kew.engine.node.Branch;
 23  
 import org.kuali.rice.kew.engine.node.BranchState;
 24  
 import org.kuali.rice.kew.engine.node.dao.BranchDAO;
 25  
 import org.kuali.rice.kew.engine.node.service.BranchService;
 26  
 
 27  
 
 28  
 
 29  0
 public class BranchServiceImpl implements BranchService {
 30  0
     private static final Logger LOG = Logger.getLogger(BranchServiceImpl.class);
 31  
 
 32  
     private BranchDAO branchDAO;
 33  
     
 34  
     public void save(Branch branch){
 35  0
         getBranchDAO().save(branch);
 36  0
     }
 37  
     
 38  
      public BranchDAO getBranchDAO() {
 39  0
         return branchDAO;
 40  
     }
 41  
     public void setBranchDAO(BranchDAO branchDAO) {
 42  0
         this.branchDAO = branchDAO;
 43  0
     }
 44  
     
 45  
     public void deleteBranchStates(List statesToBeDeleted){
 46  0
         getBranchDAO().deleteBranchStates(statesToBeDeleted);
 47  0
     }
 48  
 
 49  
     /**
 50  
      * Walks up the Branch/scope hierarchy trying to find a variable with the specified name
 51  
      * @param branch the lowermost branch at which to start the search
 52  
      * @param name name of the variable to search for
 53  
      * @return a BranchState object in the first Branch/scope in which the variable was found
 54  
      */
 55  
     private BranchState resolveScopedVariable(Branch branch, String name) {
 56  0
         Branch b = branch;
 57  0
         while (b != null) {
 58  0
             for (BranchState bs: b.getBranchState()) {
 59  0
                 LOG.debug(bs);
 60  
             }
 61  0
             LOG.debug("Resolving variable: '" + name + "' in scope (branch): '" + branch.getName() + "' (" + branch.getBranchId() + ")");
 62  0
             BranchState bs = b.getBranchState(name);
 63  0
             if (bs != null) {
 64  0
                 return bs;    
 65  
             }
 66  0
             b = b.getParentBranch();
 67  0
         }
 68  0
         return null;
 69  
     }
 70  
 
 71  
     public String getScopedVariableValue(Branch branch, String name) {
 72  0
         BranchState bs = resolveScopedVariable(branch, name);
 73  0
         if (bs != null) return bs.getValue();
 74  0
         return null;
 75  
     }
 76  
 
 77  
     public String setScopedVariableValue(Branch branch, String name, String value) {
 78  0
         LOG.debug("Setting scoped variable value: " + name + " " + value);
 79  0
         BranchState bs = resolveScopedVariable(branch, name);
 80  0
         String oldValue = null;
 81  0
         if (bs == null) {
 82  0
             LOG.debug("Defining new variable named '" + name + "' at scope '" + branch + "'");
 83  
             // create new variable at initial search scope
 84  0
             bs = new BranchState(name, value);
 85  0
             bs.setBranch(branch);
 86  0
             branch.addBranchState(bs);
 87  
         } else {
 88  0
             oldValue = bs.getValue();
 89  0
             LOG.debug("Replacing old value of variable '" + name + "' (" + oldValue + ") at scope '" + branch + "' with new value: " + value);
 90  0
             bs.setValue(value);
 91  
         }
 92  
         // now save the Branch whose state we just modified
 93  0
         save(bs.getBranch());
 94  0
         return oldValue;
 95  
     }
 96  
     
 97  
 }