1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.core.session.IoSession;
28
29
30
31
32
33
34 public class IoSessionPropertyAccessor extends AbstractPropertyAccessor {
35
36 @Override
37 protected Object getProperty0(OgnlContext context, Object target,
38 String name) throws OgnlException {
39 if (target instanceof IoSession && "attributes".equals(name)) {
40 Map<String, Object> attributes = new TreeMap<String, Object>();
41 IoSession s = (IoSession) target;
42 for (Object key: s.getAttributeKeys()) {
43 Object value = s.getAttribute(key);
44 if (value == null) {
45 continue;
46 }
47 attributes.put(String.valueOf(key), value);
48 }
49 return attributes;
50 }
51
52 return OgnlRuntime.NotFound;
53 }
54
55 @Override
56 protected boolean hasGetProperty0(OgnlContext context, Object target,
57 String name) throws OgnlException {
58 return target instanceof IoSession && "attributes".equals(name);
59 }
60
61 @Override
62 protected boolean hasSetProperty0(OgnlContext context, Object target,
63 String name) throws OgnlException {
64 return false;
65 }
66
67 @Override
68 protected Object setProperty0(OgnlContext context, Object target,
69 String name, Object value) throws OgnlException {
70 return OgnlRuntime.NotFound;
71 }
72 }