This project has retired. For details please refer to its
Attic page.
AnyScopePropertyAccessor xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.ognl;
22
23 import java.util.Map;
24
25 import ognl.OgnlContext;
26 import ognl.PropertyAccessor;
27
28 import org.apache.tiles.request.Request;
29
30
31
32
33
34
35 public class AnyScopePropertyAccessor implements PropertyAccessor {
36
37 @Override
38 public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) {
39 Request request = (Request) target;
40 String attributeName = (String) name;
41 for (String scopeName : request.getAvailableScopes()) {
42 Map<String, Object> scope = request.getContext(scopeName);
43 if (scope.containsKey(attributeName)) {
44 return scope.get(attributeName);
45 }
46 }
47 return null;
48 }
49
50 @Override
51 public String getSourceAccessor(OgnlContext context, Object target,
52 Object index) {
53 Request request = (Request) target;
54 String attributeName = (String) index;
55 for (String scopeName : request.getAvailableScopes()) {
56 Map<String, Object> scope = request.getContext(scopeName);
57 if (scope.containsKey(attributeName)) {
58 return ".getContext(\"" + scopeName + "\").get(index)";
59 }
60 }
61 return null;
62 }
63
64 @Override
65 public String getSourceSetter(OgnlContext context, Object target,
66 Object index) {
67 Request request = (Request) target;
68 String attributeName = (String) index;
69 String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
70 for (String scopeName : availableScopes) {
71 Map<String, Object> scope = request.getContext(scopeName);
72 if (scope.containsKey(attributeName)) {
73 return ".getContext(\"" + scopeName + "\").put(index, target)";
74 }
75 }
76 return ".getContext(\"" + availableScopes[0] + "\").put(index, target)";
77 }
78
79 @Override
80 public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
81 Object value) {
82 Request request = (Request) target;
83 String attributeName = (String) name;
84 String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
85 for (String scopeName : availableScopes) {
86 Map<String, Object> scope = request.getContext(scopeName);
87 if (scope.containsKey(attributeName)) {
88 scope.put(attributeName, value);
89 return;
90 }
91 }
92 if (availableScopes.length > 0) {
93 request.getContext(availableScopes[0]).put(attributeName, value);
94 }
95 }
96
97 }