KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Field JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
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     /**
31      * @param field The Field that we are proxying to
32      */

33     public FieldProperty(Field JavaDoc field)
34     {
35         this.field = field;
36     }
37
38     /* (non-Javadoc)
39      * @see org.directwebremoting.extend.Property#getName()
40      */

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

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

57     public Object JavaDoc getValue(Object JavaDoc bean) throws MarshallException
58     {
59         try
60         {
61             return field.get(bean);
62         }
63         catch (Exception JavaDoc ex)
64         {
65             throw new MarshallException(bean.getClass(), ex);
66         }
67     }
68
69     /* (non-Javadoc)
70      * @see org.directwebremoting.extend.Property#setValue(java.lang.Object, java.lang.Object)
71      */

72     public void setValue(Object JavaDoc bean, Object JavaDoc value) throws MarshallException
73     {
74         try
75         {
76             field.set(bean, value);
77         }
78         catch (Exception JavaDoc ex)
79         {
80             throw new MarshallException(bean.getClass(), ex);
81         }
82     }
83
84     /* (non-Javadoc)
85      * @see org.directwebremoting.extend.Property#getSetter()
86      */

87     public Method JavaDoc getSetter()
88     {
89         return null;
90     }
91
92     /**
93      * The Field that we are proxying to
94      */

95     private Field JavaDoc field;
96 }
97
Popular Tags