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