Coverage Report - org.seasar.teeda.core.scope.impl.S2ScopeTranslator
 
Classes in this File Line Coverage Branch Coverage Complexity
S2ScopeTranslator
65%
15/23
12%
1/8
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.scope.impl;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.seasar.framework.container.InstanceDef;
 22  
 import org.seasar.framework.container.deployer.InstanceDefFactory;
 23  
 import org.seasar.teeda.core.scope.Scope;
 24  
 import org.seasar.teeda.core.scope.ScopeAlreadyRegisteredException;
 25  
 import org.seasar.teeda.core.scope.ScopeTranslator;
 26  
 
 27  
 /**
 28  
  * @author shot
 29  
  * 
 30  
  * Scope translation between Teeda and S2.
 31  
  */
 32  1342
 public class S2ScopeTranslator implements ScopeTranslator {
 33  
 
 34  1
     private static final Map SCOPE_TO_INSTANCEDEF_MAP = new HashMap();
 35  
 
 36  1
     private static final Map INSTANCEDEF_TO_SCOPE_MAP = new HashMap();
 37  
     static {
 38  1
         SCOPE_TO_INSTANCEDEF_MAP.put(Scope.NONE, InstanceDefFactory.OUTER);
 39  1
         SCOPE_TO_INSTANCEDEF_MAP.put(Scope.REQUEST, InstanceDefFactory.REQUEST);
 40  1
         SCOPE_TO_INSTANCEDEF_MAP.put(Scope.SESSION, InstanceDefFactory.SESSION);
 41  1
         SCOPE_TO_INSTANCEDEF_MAP.put(Scope.APPLICATION,
 42  
                 InstanceDefFactory.APPLICATION);
 43  
 
 44  1
         INSTANCEDEF_TO_SCOPE_MAP.put(InstanceDefFactory.OUTER, Scope.NONE);
 45  1
         INSTANCEDEF_TO_SCOPE_MAP.put(InstanceDefFactory.REQUEST, Scope.REQUEST);
 46  1
         INSTANCEDEF_TO_SCOPE_MAP.put(InstanceDefFactory.SESSION, Scope.SESSION);
 47  1
         INSTANCEDEF_TO_SCOPE_MAP.put(InstanceDefFactory.APPLICATION,
 48  
                 Scope.APPLICATION);
 49  
 
 50  1
     }
 51  
 
 52  
     public Scope toScope(Object obj) {
 53  6
         if (!(obj instanceof InstanceDef)) {
 54  0
             throw new IllegalArgumentException();
 55  
         }
 56  6
         return (Scope) INSTANCEDEF_TO_SCOPE_MAP.get(obj);
 57  
     }
 58  
 
 59  
     public Object toExternalComponentScope(Scope scope) {
 60  18
         return SCOPE_TO_INSTANCEDEF_MAP.get(scope);
 61  
     }
 62  
 
 63  
     public void addScope(Scope scope, Object externalComponentScope)
 64  
             throws ScopeAlreadyRegisteredException {
 65  0
         if (scope == null || externalComponentScope == null) {
 66  0
             throw new IllegalArgumentException();
 67  
         }
 68  0
         if (SCOPE_TO_INSTANCEDEF_MAP.containsKey(scope)) {
 69  0
             throw new ScopeAlreadyRegisteredException(new Object[] { scope
 70  
                     .getScopeKey() });
 71  
         }
 72  0
         SCOPE_TO_INSTANCEDEF_MAP.put(scope, externalComponentScope);
 73  0
         INSTANCEDEF_TO_SCOPE_MAP.put(externalComponentScope, scope);
 74  0
     }
 75  
 
 76  
 }