KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > core > WebFlowOgnlExpressionParser


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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, new MapAdaptablePropertyAccessor());
40         addPropertyAccessor(MutableAttributeMap.class, new MutableAttributeMapPropertyAccessor());
41     }
42
43     /**
44      * The {@link MapAdaptable} property accessor.
45      *
46      * @author Keith Donald
47      */

48     private static class MapAdaptablePropertyAccessor implements PropertyAccessor {
49         public Object JavaDoc getProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc name) throws OgnlException {
50             return ((MapAdaptable)target).asMap().get(name);
51         }
52
53         public void setProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc name, Object JavaDoc value) throws OgnlException {
54             throw new UnsupportedOperationException JavaDoc(
55                     "Cannot mutate immutable attribute collections; operation disallowed");
56         }
57     }
58
59     /**
60      * The {@link MutableAttributeMap} property accessor.
61      *
62      * @author Keith Donald
63      */

64     private static class MutableAttributeMapPropertyAccessor extends MapAdaptablePropertyAccessor {
65         public void setProperty(Map JavaDoc context, Object JavaDoc target, Object JavaDoc name, Object JavaDoc value) throws OgnlException {
66             ((MutableAttributeMap)target).put((String JavaDoc)name, value);
67         }
68     }
69 }
Popular Tags