Coverage Report - org.seasar.teeda.core.util.CancelUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
CancelUtil
88%
21/24
88%
14/16
6.5
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.util;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 
 21  
 import org.seasar.framework.log.Logger;
 22  
 
 23  
 /**
 24  
  * @author shot
 25  
  */
 26  0
 public class CancelUtil {
 27  
 
 28  3
     private static final Logger logger = Logger.getLogger(CancelUtil.class);
 29  
 
 30  1
     private static CancelHandler handler = null;
 31  
 
 32  
     public static boolean isCancelled(Throwable t) {
 33  6
         if (t == null) {
 34  0
             return false;
 35  
         }
 36  6
         if (handler == null) {
 37  2
             handler = (CancelHandler) DIContainerUtil
 38  
                     .getComponentNoException(CancelHandler.class);
 39  2
             if (handler == null) {
 40  0
                 return false;
 41  
             }
 42  
         }
 43  6
         final List candidates = handler.getCancellableExceptions();
 44  6
         for (Iterator itr = candidates.iterator(); itr.hasNext();) {
 45  5
             Class tc = (Class) itr.next();
 46  5
             if (t.getClass() == tc) {
 47  1
                 logger.log("WTDA0206", new Object[] { t });
 48  1
                 return true;
 49  
             }
 50  
         }
 51  5
         final List nameCandidates = handler.getCancellableExceptionNames();
 52  5
         for (Iterator itr = nameCandidates.iterator(); itr.hasNext();) {
 53  2
             final String name = (String) itr.next();
 54  2
             if (t.getClass().getName().endsWith(name)) {
 55  1
                 logger.log("WTDA0206", new Object[] { t });
 56  1
                 return true;
 57  
             }
 58  
         }
 59  4
         return false;
 60  
     }
 61  
 
 62  
     public static void clear() {
 63  2
         handler = null;
 64  2
     }
 65  
 }