01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.base.access;
17:
18: import javax.servlet.http.HttpServletRequest;
19:
20: import de.odysseus.calyxo.base.util.MapFacade;
21:
22: /**
23: * Base class for accessors, that produce a lookup map.
24: *
25: * @author Christoph Beck
26: */
27: public abstract class DynamicMapAccessor implements Accessor {
28:
29: /**
30: * Produce a lookup map which delegates calls to
31: * <code>get(Object)</code> to outer class method
32: * <code>get(HttpServletRequest, Object)</code> and calls
33: * to <code>toString()</code> to outer class method
34: * <code>@link #toString(HttpServletRequest)</code>
35: */
36: public final Object get(final HttpServletRequest request) {
37: return new MapFacade() {
38: public Object get(Object key) {
39: return DynamicMapAccessor.this .get(request, key);
40: }
41:
42: public String toString() {
43: return DynamicMapAccessor.this .toString(request);
44: }
45: };
46: }
47:
48: /**
49: * Lookup method.
50: * To be implemented by subclasses.
51: */
52: protected abstract Object get(HttpServletRequest request, Object key);
53:
54: /**
55: * This implementation simply delegates to <code>toString()</code>
56: * May be overwritten by subclasses.
57: */
58: protected String toString(HttpServletRequest request) {
59: return toString();
60: }
61:
62: /**
63: * @return <code>true</code>
64: */
65: public boolean isCacheable() {
66: return true;
67: }
68: }
|