This project has retired. For details please refer to its
Attic page.
ReadOnlyVariableResolverFactory 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.mvel;
22
23 import java.util.HashMap;
24
25 import org.apache.tiles.context.TilesRequestContextHolder;
26 import org.mvel2.UnresolveablePropertyException;
27 import org.mvel2.integration.VariableResolver;
28 import org.mvel2.integration.impl.BaseVariableResolverFactory;
29
30
31
32
33
34
35 public abstract class ReadOnlyVariableResolverFactory extends
36 BaseVariableResolverFactory {
37
38
39
40
41 protected TilesRequestContextHolder requestHolder;
42
43
44
45
46
47
48
49 public ReadOnlyVariableResolverFactory(TilesRequestContextHolder requestHolder) {
50 this.requestHolder = requestHolder;
51 variableResolvers = new HashMap<String, VariableResolver>();
52 }
53
54
55 public VariableResolver createVariable(String name, Object value) {
56 if (nextFactory != null) {
57 return nextFactory.createVariable(name, value);
58 }
59 throw new UnsupportedOperationException("This variable resolver factory is read only");
60 }
61
62
63 public VariableResolver createVariable(String name, Object value,
64 Class<?> type) {
65 variableResolvers = new HashMap<String, VariableResolver>();
66 if (nextFactory != null) {
67 return nextFactory.createVariable(name, value, type);
68 }
69 throw new UnsupportedOperationException("This variable resolver factory is read only");
70 }
71
72
73 public boolean isResolveable(String name) {
74 return isTarget(name) || isNextResolveable(name);
75 }
76
77
78 @Override
79 public VariableResolver getVariableResolver(String name) {
80 if (isResolveable(name)) {
81 if (variableResolvers != null && variableResolvers.containsKey(name)) {
82 return variableResolvers.get(name);
83 } else if (isTarget(name)) {
84 VariableResolver variableResolver = createVariableResolver(name);
85 variableResolvers.put(name, variableResolver);
86 return variableResolver;
87 } else if (nextFactory != null) {
88 return nextFactory.getVariableResolver(name);
89 }
90 }
91
92 throw new UnresolveablePropertyException("unable to resolve variable '" + name + "'");
93 }
94
95
96
97
98
99
100
101
102 public abstract VariableResolver createVariableResolver(String name);
103
104
105
106
107
108
109
110 public abstract static class ReadOnlyVariableResolver implements VariableResolver {
111
112
113
114
115 protected String name;
116
117
118
119
120
121
122
123 public ReadOnlyVariableResolver(String name) {
124 this.name = name;
125 }
126
127
128 public int getFlags() {
129 return 0;
130 }
131
132
133 public String getName() {
134 return name;
135 }
136
137
138 public void setStaticType(@SuppressWarnings("rawtypes") Class type) {
139
140 }
141
142
143 public void setValue(Object value) {
144 throw new UnsupportedOperationException("This resolver is read-only");
145 }
146 }
147 }