Coverage Report - org.seasar.teeda.core.scope.impl.ScopeManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ScopeManagerImpl
89%
25/28
50%
3/6
1.833
 
 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.Collections;
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.seasar.teeda.core.scope.Scope;
 23  
 import org.seasar.teeda.core.scope.ScopeAlreadyRegisteredException;
 24  
 import org.seasar.teeda.core.scope.ScopeManager;
 25  
 import org.seasar.teeda.core.scope.ScopeTranslator;
 26  
 
 27  
 /**
 28  
  * @author shot
 29  
  */
 30  
 public class ScopeManagerImpl implements ScopeManager {
 31  
 
 32  
     private ScopeTranslator translator_;
 33  
 
 34  1
     private static final Map SCOPES = new HashMap();
 35  
 
 36  
     private static final Map DEFAULT_SCOPES;
 37  
 
 38  
     static {
 39  1
         SCOPES.put(Scope.APPLICATION.getScopeKey(), Scope.APPLICATION);
 40  1
         SCOPES.put(Scope.SESSION.getScopeKey(), Scope.SESSION);
 41  1
         SCOPES.put(Scope.REQUEST.getScopeKey(), Scope.REQUEST);
 42  1
         SCOPES.put(Scope.NONE.getScopeKey(), Scope.NONE);
 43  1
         Map map = new HashMap();
 44  1
         map.put(Scope.APPLICATION.getScopeKey(), Scope.APPLICATION);
 45  1
         map.put(Scope.SESSION.getScopeKey(), Scope.SESSION);
 46  1
         map.put(Scope.REQUEST.getScopeKey(), Scope.REQUEST);
 47  1
         map.put(Scope.NONE.getScopeKey(), Scope.NONE);
 48  1
         DEFAULT_SCOPES = Collections.unmodifiableMap(map);
 49  1
     }
 50  
 
 51  1342
     public ScopeManagerImpl() {
 52  1342
     }
 53  
 
 54  
     public Scope getScope(String scopeKey) {
 55  7
         if (scopeKey == null) {
 56  0
             throw new IllegalArgumentException();
 57  
         }
 58  7
         return (Scope) SCOPES.get(scopeKey);
 59  
     }
 60  
 
 61  
     public void addScope(Scope scope, Object outerComponentScope)
 62  
             throws ScopeAlreadyRegisteredException {
 63  1
         String scopeKey = scope.getScopeKey();
 64  1
         if (SCOPES.containsKey(scopeKey)) {
 65  0
             throw new ScopeAlreadyRegisteredException(new Object[] { scopeKey });
 66  
         }
 67  1
         SCOPES.put(scopeKey, scope);
 68  1
         if (translator_ != null) {
 69  0
             translator_.addScope(scope, outerComponentScope);
 70  
         }
 71  1
     }
 72  
 
 73  
     public boolean isDefaultScope(Scope scope) {
 74  5
         return DEFAULT_SCOPES.containsValue(scope);
 75  
     }
 76  
 
 77  
     public void setScopeTranslator(ScopeTranslator translator) {
 78  1340
         translator_ = translator;
 79  1340
     }
 80  
 
 81  
     public ScopeTranslator getScopeTranslator() {
 82  16
         return translator_;
 83  
     }
 84  
 
 85  
 }