| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 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 | |
} |