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
21 import ognl.ObjectPropertyAccessor;
22 import ognl.OgnlContext;
23 import ognl.OgnlException;
24 import ognl.OgnlRuntime;
25 import ognl.PropertyAccessor;
26
27
28
29
30
31
32
33 @SuppressWarnings("unchecked")
34 public abstract class AbstractPropertyAccessor extends ObjectPropertyAccessor {
35
36 static final Object READ_ONLY_MODE = new Object();
37 static final Object QUERY = new Object();
38
39 @Override
40 public final boolean hasGetProperty(OgnlContext context, Object target,
41 Object oname) throws OgnlException {
42 if (oname == null) {
43 return false;
44 }
45
46 if (hasGetProperty0(context, target, oname.toString())) {
47 return true;
48 } else {
49 return super.hasGetProperty(context, target, oname);
50 }
51 }
52
53 @Override
54 public final boolean hasSetProperty(OgnlContext context, Object target,
55 Object oname) throws OgnlException {
56 if (context.containsKey(READ_ONLY_MODE)) {
57
58 return true;
59 }
60
61 if (oname == null) {
62 return false;
63 }
64
65 if (hasSetProperty0(context, target, oname.toString())) {
66 return true;
67 } else {
68 return super.hasSetProperty(context, target, oname);
69 }
70 }
71
72 @Override
73 public final Object getPossibleProperty(Map context, Object target, String name)
74 throws OgnlException {
75 Object answer = getProperty0((OgnlContext) context, target, name);
76 if (answer == OgnlRuntime.NotFound) {
77 answer = super.getPossibleProperty(context, target, name);
78 }
79 return answer;
80 }
81
82 @Override
83 public final Object setPossibleProperty(Map context, Object target, String name,
84 Object value) throws OgnlException {
85 if (context.containsKey(READ_ONLY_MODE)) {
86 throw new OgnlException("Expression must be read-only: " + context.get(QUERY));
87 }
88
89 Object answer = setProperty0((OgnlContext) context, target, name, value);
90 if (answer == OgnlRuntime.NotFound) {
91 answer = super.setPossibleProperty(context, target, name, value);
92 }
93 return answer;
94 }
95
96 protected abstract boolean hasGetProperty0(
97 OgnlContext context, Object target, String name) throws OgnlException;
98
99 protected abstract boolean hasSetProperty0(
100 OgnlContext context, Object target, String name) throws OgnlException;
101
102 protected abstract Object getProperty0(
103 OgnlContext context, Object target, String name) throws OgnlException;
104
105 protected abstract Object setProperty0(
106 OgnlContext context, Object target, String name, Object value) throws OgnlException;
107
108
109
110
111
112 @Override
113 public final Object getProperty(Map context, Object target, Object oname)
114 throws OgnlException {
115 return super.getProperty(context, target, oname);
116 }
117
118 @Override
119 public final boolean hasGetProperty(Map context, Object target, Object oname)
120 throws OgnlException {
121 return super.hasGetProperty(context, target, oname);
122 }
123
124 @Override
125 public final boolean hasSetProperty(Map context, Object target, Object oname)
126 throws OgnlException {
127 return super.hasSetProperty(context, target, oname);
128 }
129
130 @Override
131 public final void setProperty(Map context, Object target, Object oname,
132 Object value) throws OgnlException {
133 super.setProperty(context, target, oname, value);
134 }
135 }