Coverage Report - org.seasar.teeda.core.scope.impl.DispatchScopeFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DispatchScopeFactory
26%
6/23
25%
2/8
2.4
 
 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.scope.impl;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import javax.faces.context.ExternalContext;
 21  
 import javax.faces.context.FacesContext;
 22  
 
 23  
 /**
 24  
  * @author shot
 25  
  * @author yone
 26  
  */
 27  0
 public class DispatchScopeFactory {
 28  
 
 29  2
     public static final String DISPATCH_SCOPE_KEY = DispatchScopeFactory.class
 30  
             .getName()
 31  
             + ".DISPATCH_SCOPE_KEY";
 32  
 
 33  
     public static void create() {
 34  0
         Map requestMap = getRequestMap();
 35  0
         requestMap.put(DISPATCH_SCOPE_KEY, new DispatchScope());
 36  0
     }
 37  
 
 38  
     public static DispatchScope getDispatchScope() {
 39  0
         if (!initialized()) {
 40  0
             create();
 41  
         }
 42  0
         return (DispatchScope) getRequestMap().get(DISPATCH_SCOPE_KEY);
 43  
     }
 44  
 
 45  
     private static boolean initialized() {
 46  0
         Map requestMap = getRequestMap();
 47  0
         if (requestMap == null) {
 48  0
             return false;
 49  
         }
 50  0
         return requestMap.containsKey(DISPATCH_SCOPE_KEY);
 51  
     }
 52  
 
 53  
     public static void destroy() {
 54  0
         Map requestMap = getRequestMap();
 55  0
         if (requestMap == null) {
 56  0
             return;
 57  
         }
 58  0
         getRequestMap().remove(DISPATCH_SCOPE_KEY);
 59  0
         create();
 60  0
     }
 61  
 
 62  
     protected static Map getRequestMap() {
 63  2
         FacesContext context = FacesContext.getCurrentInstance();
 64  2
         if (context == null) {
 65  1
             return null;
 66  
         }
 67  1
         ExternalContext externalContext = context.getExternalContext();
 68  1
         return externalContext.getRequestMap();
 69  
     }
 70  
 
 71  
 }