Coverage Report - org.jtheque.core.spring.factory.ActivableManagerHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivableManagerHandler
0 %
0/7
0 %
0/2
2
 
 1  
 package org.jtheque.core.spring.factory;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.ActivableManager;
 20  
 import org.jtheque.core.managers.Managers;
 21  
 import org.jtheque.core.managers.log.ILoggingManager;
 22  
 
 23  
 import java.lang.reflect.InvocationHandler;
 24  
 import java.lang.reflect.InvocationTargetException;
 25  
 import java.lang.reflect.Method;
 26  
 
 27  
 /**
 28  
  * An invocation handler to disable the manager.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  
 final class ActivableManagerHandler implements InvocationHandler {
 33  
     private final ActivableManager manager;
 34  
 
 35  
     /**
 36  
      * Construct a new ActivableManagerHandler.
 37  
      *
 38  
      * @param manager The manager to handle.
 39  
      */
 40  
     ActivableManagerHandler(ActivableManager manager) {
 41  0
         super();
 42  
 
 43  0
         this.manager = manager;
 44  0
     }
 45  
 
 46  
     @Override
 47  
     public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
 48  0
         if (manager.isEnabled()) {
 49  0
             return method.invoke(manager, args);
 50  
         } else {
 51  0
             Managers.getManager(ILoggingManager.class).getLogger(manager.getClass()).warn("The manager is disabled. ");
 52  
 
 53  0
             return null;
 54  
         }
 55  
     }
 56  
 }