01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.mina.integration.ognl;
18:
19: import java.util.Map;
20: import java.util.TreeMap;
21:
22: import ognl.OgnlContext;
23: import ognl.OgnlException;
24: import ognl.OgnlRuntime;
25: import ognl.PropertyAccessor;
26:
27: import org.apache.mina.common.IoSession;
28:
29: /**
30: * An OGNL {@link PropertyAccessor} for {@link IoSession}.
31: *
32: * @author The Apache MINA Project (dev@mina.apache.org)
33: * @version $Rev: 598118 $, $Date: 2007-11-25 21:14:29 -0700 (Sun, 25 Nov 2007) $
34: */
35: @SuppressWarnings("unchecked")
36: public class IoSessionPropertyAccessor extends AbstractPropertyAccessor {
37:
38: @Override
39: protected Object getProperty0(OgnlContext context, Object target,
40: String name) throws OgnlException {
41: if (target instanceof IoSession && "attributes".equals(name)) {
42: Map<String, Object> attributes = new TreeMap<String, Object>();
43: IoSession s = (IoSession) target;
44: for (Object key : s.getAttributeKeys()) {
45: Object value = s.getAttribute(key);
46: if (value == null) {
47: continue;
48: }
49: attributes.put(String.valueOf(key), value);
50: }
51: return attributes;
52: }
53:
54: return OgnlRuntime.NotFound;
55: }
56:
57: @Override
58: protected boolean hasGetProperty0(OgnlContext context,
59: Object target, String name) throws OgnlException {
60: return target instanceof IoSession && "attributes".equals(name);
61: }
62:
63: @Override
64: protected boolean hasSetProperty0(OgnlContext context,
65: Object target, String name) throws OgnlException {
66: return false;
67: }
68:
69: @Override
70: protected Object setProperty0(OgnlContext context, Object target,
71: String name, Object value) throws OgnlException {
72: return OgnlRuntime.NotFound;
73: }
74: }
|