Coverage Report - net.admin4j.ui.servlets.Admin4JServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
Admin4JServlet
95%
21/22
50%
2/4
1.5
 
 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.ui.servlets;
 15  
 
 16  
 import java.util.HashMap;
 17  
 import java.util.HashSet;
 18  
 import java.util.Map;
 19  
 import java.util.Set;
 20  
 
 21  
 import javax.servlet.ServletConfig;
 22  
 import javax.servlet.ServletException;
 23  
 import javax.servlet.http.HttpServlet;
 24  
 
 25  
 import org.slf4j.Logger;
 26  
 import org.slf4j.LoggerFactory;
 27  
 
 28  
 import net.admin4j.config.Admin4JConfiguration;
 29  
 
 30  
 /**
 31  
  * Base servlet for all Admin4J Servlets.  
 32  
  * @author D. Ashmore
 33  
  *
 34  
  */
 35  57
 abstract class Admin4JServlet extends HttpServlet {
 36  
 
 37  
     private static final long serialVersionUID = -1960693935838064409L;
 38  
     
 39  
     @SuppressWarnings("rawtypes")
 40  27
     private static Map<Class, Set<HttpServlet>> registryMap = new HashMap<Class, Set<HttpServlet>>();
 41  
 
 42  57
     protected Logger logger = LoggerFactory.getLogger(this.getClass());
 43  
     
 44  
     /* (non-Javadoc)
 45  
      * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
 46  
      */
 47  
     @Override
 48  
     public void init() throws ServletException {
 49  51
         super.init();
 50  51
         logger.debug("Initializing Servlet {}", this.getClass().getName());
 51  51
         new Admin4JConfiguration();
 52  
         
 53  51
         synchronized(registryMap) {
 54  51
             Set<HttpServlet> registrySet = registryMap.get(this.getClass());
 55  51
             if (registrySet == null) {
 56  51
                 registrySet = new HashSet<HttpServlet>();
 57  51
                 registryMap.put(this.getClass(), registrySet);
 58  
             }
 59  51
             registrySet.add(this);
 60  51
         }
 61  51
     }
 62  
     
 63  
     /* (non-Javadoc)
 64  
      * @see javax.servlet.GenericServlet#init()
 65  
      */
 66  
     @Override
 67  
     public void init(ServletConfig config) throws ServletException {
 68  51
         this.init();
 69  51
     }
 70  
     
 71  
     public static Set<HttpServlet> getRegisteredServletSet(@SuppressWarnings("rawtypes") Class klass) {
 72  6
         Set<HttpServlet> registrySet = new HashSet<HttpServlet>();
 73  6
         synchronized(registryMap) {
 74  6
             if (registryMap.containsKey(klass)) {
 75  0
                 registrySet.addAll(registryMap.get(klass));
 76  
             }
 77  6
         }
 78  
         
 79  6
         return registrySet;
 80  
     }
 81  
     
 82  
     public abstract boolean hasDisplay();
 83  
 
 84  
 
 85  
 
 86  
 }