01: /*
02: * Copyright 2004-2007 the original author or authors.
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 org.springframework.webflow.core;
17:
18: import java.util.Map;
19:
20: import ognl.OgnlException;
21: import ognl.PropertyAccessor;
22:
23: import org.springframework.binding.collection.MapAdaptable;
24: import org.springframework.binding.expression.support.OgnlExpressionParser;
25: import org.springframework.webflow.core.collection.MutableAttributeMap;
26:
27: /**
28: * An extension of {@link OgnlExpressionParser} that registers web flow specific
29: * property accessors.
30: *
31: * @author Keith Donald
32: */
33: class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
34:
35: /**
36: * Creates a webflow-specific ognl expression parser.
37: */
38: public WebFlowOgnlExpressionParser() {
39: addPropertyAccessor(MapAdaptable.class,
40: new MapAdaptablePropertyAccessor());
41: addPropertyAccessor(MutableAttributeMap.class,
42: new MutableAttributeMapPropertyAccessor());
43: }
44:
45: /**
46: * The {@link MapAdaptable} property accessor.
47: *
48: * @author Keith Donald
49: */
50: private static class MapAdaptablePropertyAccessor implements
51: PropertyAccessor {
52: public Object getProperty(Map context, Object target,
53: Object name) throws OgnlException {
54: return ((MapAdaptable) target).asMap().get(name);
55: }
56:
57: public void setProperty(Map context, Object target,
58: Object name, Object value) throws OgnlException {
59: throw new UnsupportedOperationException(
60: "Cannot mutate immutable attribute collections; operation disallowed");
61: }
62: }
63:
64: /**
65: * The {@link MutableAttributeMap} property accessor.
66: *
67: * @author Keith Donald
68: */
69: private static class MutableAttributeMapPropertyAccessor extends
70: MapAdaptablePropertyAccessor {
71: public void setProperty(Map context, Object target,
72: Object name, Object value) throws OgnlException {
73: ((MutableAttributeMap) target).put((String) name, value);
74: }
75: }
76: }
|