KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > MetadataTargetImpl


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.tag;
16
17 import java.beans.BeanInfo JavaDoc;
18 import java.beans.IntrospectionException JavaDoc;
19 import java.beans.Introspector JavaDoc;
20 import java.beans.PropertyDescriptor JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  *
27  * @author Jacob Hookom
28  * @version $Id: MetadataTargetImpl.java,v 1.2 2005/08/24 04:38:47 jhook Exp $
29  */

30 final class MetadataTargetImpl extends MetadataTarget {
31
32     private final Map JavaDoc pd;
33     private final Class JavaDoc type;
34     
35     
36     public MetadataTargetImpl(Class JavaDoc type) throws IntrospectionException JavaDoc {
37         this.type = type;
38         this.pd = new HashMap JavaDoc();
39         BeanInfo JavaDoc info = Introspector.getBeanInfo(type);
40         PropertyDescriptor JavaDoc[] pda = info.getPropertyDescriptors();
41         for (int i = 0; i < pda.length; i++) {
42             this.pd.put(pda[i].getName(), pda[i]);
43         }
44     }
45
46     public PropertyDescriptor JavaDoc getProperty(String JavaDoc name) {
47         return (PropertyDescriptor JavaDoc) this.pd.get(name);
48     }
49
50     public boolean isTargetInstanceOf(Class JavaDoc type) {
51         return type.isAssignableFrom(this.type);
52     }
53
54     public Class JavaDoc getTargetClass() {
55         return this.type;
56     }
57
58     public Class JavaDoc getPropertyType(String JavaDoc name) {
59         PropertyDescriptor JavaDoc pd = this.getProperty(name);
60         if (pd != null) {
61             return pd.getPropertyType();
62         }
63         return null;
64     }
65
66     public Method JavaDoc getWriteMethod(String JavaDoc name) {
67         PropertyDescriptor JavaDoc pd = this.getProperty(name);
68         if (pd != null) {
69             return pd.getWriteMethod();
70         }
71         return null;
72     }
73
74     public Method JavaDoc getReadMethod(String JavaDoc name) {
75         PropertyDescriptor JavaDoc pd = this.getProperty(name);
76         if (pd != null) {
77             return pd.getReadMethod();
78         }
79         return null;
80     }
81
82 }
83
Popular Tags