01: /*
02: * Copyright 2005 Joe Walker
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.directwebremoting.impl;
17:
18: import java.lang.reflect.Field;
19: import java.lang.reflect.Method;
20:
21: import org.directwebremoting.extend.MarshallException;
22: import org.directwebremoting.extend.Property;
23:
24: /**
25: * An implementation of {@link Property} that proxies to a {@link Field}
26: * @author Joe Walker [joe at getahead dot ltd dot uk]
27: */
28: public class FieldProperty implements Property {
29: /**
30: * @param field The Field that we are proxying to
31: */
32: public FieldProperty(Field field) {
33: this .field = field;
34: }
35:
36: /* (non-Javadoc)
37: * @see org.directwebremoting.extend.Property#getName()
38: */
39: public String getName() {
40: return field.getName();
41: }
42:
43: /* (non-Javadoc)
44: * @see org.directwebremoting.extend.Property#getPropertyType()
45: */
46: public Class<?> getPropertyType() {
47: return field.getType();
48: }
49:
50: /* (non-Javadoc)
51: * @see org.directwebremoting.extend.Property#getValue(java.lang.Object)
52: */
53: public Object getValue(Object bean) throws MarshallException {
54: try {
55: return field.get(bean);
56: } catch (Exception ex) {
57: throw new MarshallException(bean.getClass(), ex);
58: }
59: }
60:
61: /* (non-Javadoc)
62: * @see org.directwebremoting.extend.Property#setValue(java.lang.Object, java.lang.Object)
63: */
64: public void setValue(Object bean, Object value)
65: throws MarshallException {
66: try {
67: field.set(bean, value);
68: } catch (Exception ex) {
69: throw new MarshallException(bean.getClass(), ex);
70: }
71: }
72:
73: /* (non-Javadoc)
74: * @see org.directwebremoting.extend.Property#getSetter()
75: */
76: public Method getSetter() {
77: return null;
78: }
79:
80: /**
81: * The Field that we are proxying to
82: */
83: private Field field;
84: }
|