KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > impl > PropertyDescriptorProperty


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.lang.reflect.InvocationTargetException JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
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     /**
32      * @param descriptor The PropertyDescriptor that we are proxying to
33      */

34     public PropertyDescriptorProperty(PropertyDescriptor JavaDoc descriptor)
35     {
36         this.descriptor = descriptor;
37     }
38
39     /* (non-Javadoc)
40      * @see org.directwebremoting.extend.Property#getName()
41      */

42     public String JavaDoc getName()
43     {
44         return descriptor.getName();
45     }
46
47     /* (non-Javadoc)
48      * @see org.directwebremoting.extend.Property#getPropertyType()
49      */

50     public Class JavaDoc getPropertyType()
51     {
52         return descriptor.getPropertyType();
53     }
54
55     /* (non-Javadoc)
56      * @see org.directwebremoting.extend.Property#getValue(java.lang.Object)
57      */

58     public Object JavaDoc getValue(Object JavaDoc bean) throws MarshallException
59     {
60         try
61         {
62             return descriptor.getReadMethod().invoke(bean, new Object JavaDoc[0]);
63         }
64         catch (InvocationTargetException JavaDoc ex)
65         {
66             throw new MarshallException(bean.getClass(), ex.getTargetException());
67         }
68         catch (Exception JavaDoc ex)
69         {
70             throw new MarshallException(bean.getClass(), ex);
71         }
72     }
73
74     /* (non-Javadoc)
75      * @see org.directwebremoting.extend.Property#setValue(java.lang.Object, java.lang.Object)
76      */

77     public void setValue(Object JavaDoc bean, Object JavaDoc value) throws MarshallException
78     {
79         try
80         {
81             descriptor.getWriteMethod().invoke(bean, new Object JavaDoc[] { value });
82         }
83         catch (InvocationTargetException JavaDoc ex)
84         {
85             throw new MarshallException(bean.getClass(), ex.getTargetException());
86         }
87         catch (Exception JavaDoc ex)
88         {
89             throw new MarshallException(bean.getClass(), ex);
90         }
91     }
92
93     /* (non-Javadoc)
94      * @see org.directwebremoting.extend.Property#getSetter()
95      */

96     public Method JavaDoc getSetter()
97     {
98         return descriptor.getWriteMethod();
99     }
100
101     /**
102      * The PropertyDescriptor that we are proxying to
103      */

104     protected PropertyDescriptor JavaDoc descriptor;
105 }
106
Popular Tags