Coverage Report - org.seasar.teeda.core.managedbean.impl.ManagedBeanScopeSaverImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ManagedBeanScopeSaverImpl
89%
17/19
67%
4/6
3
 
 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.managedbean.impl;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.faces.context.FacesContext;
 22  
 
 23  
 import org.seasar.teeda.core.managedbean.IllegalManagedBeanScopeException;
 24  
 import org.seasar.teeda.core.managedbean.ManagedBeanScopeSaver;
 25  
 import org.seasar.teeda.core.scope.Scope;
 26  
 import org.seasar.teeda.core.scope.ScopeAlreadyRegisteredException;
 27  
 import org.seasar.teeda.core.scope.ScopeSaver;
 28  
 import org.seasar.teeda.core.scope.impl.ApplicationScopeSaver;
 29  
 import org.seasar.teeda.core.scope.impl.NoneScopeSaver;
 30  
 import org.seasar.teeda.core.scope.impl.RequestScopeSaver;
 31  
 import org.seasar.teeda.core.scope.impl.SessionScopeSaver;
 32  
 
 33  
 /**
 34  
  * @author shot
 35  
  */
 36  
 public class ManagedBeanScopeSaverImpl implements ManagedBeanScopeSaver {
 37  
 
 38  1
     private static Map scopeSavers_ = new HashMap();
 39  
 
 40  
     static {
 41  1
         scopeSavers_.put(Scope.APPLICATION, new ApplicationScopeSaver());
 42  1
         scopeSavers_.put(Scope.REQUEST, new RequestScopeSaver());
 43  1
         scopeSavers_.put(Scope.SESSION, new SessionScopeSaver());
 44  1
         scopeSavers_.put(Scope.NONE, new NoneScopeSaver());
 45  1
     }
 46  
 
 47  1343
     public ManagedBeanScopeSaverImpl() {
 48  1343
     }
 49  
 
 50  
     public void saveToScope(FacesContext context, Scope scope, String key,
 51  
             Object value) {
 52  7
         if (scope == null) {
 53  0
             throw new IllegalArgumentException();
 54  
         }
 55  7
         ScopeSaver saver = (ScopeSaver) scopeSavers_.get(scope);
 56  7
         if (saver != null) {
 57  6
             saver.saveToScope(context, key, value);
 58  
         } else {
 59  1
             throw new IllegalManagedBeanScopeException(key, value);
 60  
         }
 61  6
     }
 62  
 
 63  
     public void addScope(Scope scope, ScopeSaver saver)
 64  
             throws ScopeAlreadyRegisteredException {
 65  1
         if (scopeSavers_.containsKey(scope)) {
 66  0
             throw new ScopeAlreadyRegisteredException(new Object[] { scope
 67  
                     .getScopeKey() });
 68  
         }
 69  1
         scopeSavers_.put(scope, saver);
 70  1
     }
 71  
 
 72  
 }