Coverage Report - net.admin4j.util.notify.NotifierUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
NotifierUtils
52%
12/23
33%
4/12
3
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.util.notify;
 15  
 
 16  
 import java.util.Properties;
 17  
 
 18  
 import javax.servlet.FilterConfig;
 19  
 import javax.servlet.ServletConfig;
 20  
 import javax.servlet.ServletException;
 21  
 
 22  
 import net.admin4j.config.Admin4JConfiguration;
 23  
 import net.admin4j.deps.commons.lang3.StringUtils;
 24  
 
 25  
 /**
 26  
  * Generic utilities for Notifier setup.
 27  
  * @author D. Ashmore
 28  
  *
 29  
  */
 30  0
 public class NotifierUtils {
 31  
 
 32  
     /**
 33  
      * Standard configuration for Servlet Filters.
 34  
      * @param config
 35  
      * @param notifierClassName
 36  
      * @return
 37  
      * @throws InstantiationException
 38  
      * @throws IllegalAccessException
 39  
      * @throws ClassNotFoundException
 40  
      * @throws ServletException
 41  
      */
 42  
     public static Notifier configure(FilterConfig config, String notifierClassName)
 43  
             throws InstantiationException, IllegalAccessException,
 44  
             ClassNotFoundException, ServletException {
 45  24
         Notifier notifier = null;
 46  0
         if ( !StringUtils.isEmpty(notifierClassName) ) {
 47  24
             notifier = (Notifier)Class.forName(notifierClassName).newInstance();
 48  24
             notifier.configure(config);
 49  
         }
 50  0
         else if (Admin4JConfiguration.getDefaultNotifier() != null) {
 51  0
             notifier = Admin4JConfiguration.getDefaultNotifier();
 52  
         }
 53  24
         return notifier;
 54  
     }
 55  
     
 56  
     /**
 57  
      * Standard Notifier configuration for Servlets
 58  
      * @param config
 59  
      * @param notifierClassName
 60  
      * @return
 61  
      * @throws InstantiationException
 62  
      * @throws IllegalAccessException
 63  
      * @throws ClassNotFoundException
 64  
      * @throws ServletException
 65  
      */
 66  
     public static Notifier configure(ServletConfig config, String notifierClassName)
 67  
     throws InstantiationException, IllegalAccessException,
 68  
     ClassNotFoundException, ServletException {
 69  9
         Notifier notifier = null;
 70  0
         if ( !StringUtils.isEmpty(notifierClassName) ) {
 71  9
             notifier = (Notifier)Class.forName(notifierClassName).newInstance();
 72  9
             notifier.configure(config);
 73  
         }
 74  0
         else if (Admin4JConfiguration.getDefaultNotifier() != null) {
 75  0
             notifier = Admin4JConfiguration.getDefaultNotifier();
 76  
         }
 77  9
         return notifier;
 78  
     }
 79  
     
 80  
     /**
 81  
      * Standard Notifier configuration based on properties input.
 82  
      * @param namePrefix
 83  
      * @param config
 84  
      * @return
 85  
      * @throws InstantiationException
 86  
      * @throws IllegalAccessException
 87  
      * @throws ClassNotFoundException
 88  
      * @throws ServletException
 89  
      */
 90  
     public static Notifier configure(String namePrefix, Properties config)
 91  
     throws InstantiationException, IllegalAccessException,
 92  
     ClassNotFoundException, ServletException {
 93  3
         String notifierClassName = config.getProperty(namePrefix + ".class");
 94  3
         Notifier notifier = null;
 95  0
         if ( !StringUtils.isEmpty(notifierClassName) ) {
 96  0
             notifier = (Notifier)Class.forName(notifierClassName).newInstance();
 97  0
             notifier.configure(namePrefix, config);
 98  
         }
 99  3
         else if (Admin4JConfiguration.getDefaultNotifier() != null) {
 100  0
             notifier = Admin4JConfiguration.getDefaultNotifier();
 101  
         }
 102  3
         return notifier;
 103  
     }
 104  
 
 105  
 }