KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > schema2beans > DDBeanInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.schema2beans;
21
22 import java.beans.*;
23 import java.util.*;
24 import java.lang.reflect.*;
25
26 public class DDBeanInfo extends SimpleBeanInfo {
27
28     private static final String JavaDoc BEANINFO = "BeanInfo"; // NOI18N
29

30     private PropertyDescriptor[] properties = null;
31
32     private boolean propertiesInited = false;
33     
34     private void initProperties() {
35     ArrayList al = new ArrayList();
36     String JavaDoc classname = null;
37     BeanInfo bi;
38
39     try {
40         classname = this.getClass().getName();
41         if (!classname.endsWith(BEANINFO)) {
42         return;
43         }
44         classname = classname.substring(0,(classname.length() -
45                            BEANINFO.length()));
46         bi = Introspector.getBeanInfo(Class.forName(classname));
47     } catch (ClassNotFoundException JavaDoc e) {
48         System.err.println("Class name = " + classname); // NOI18N
49
return;
50     } catch (IntrospectionException e) {
51         Thread.dumpStack();
52         return;
53     }
54
55     PropertyDescriptor[] pd = bi.getPropertyDescriptors();
56     Method m = null;
57     for (int i=0;i<pd.length; i++) {
58         Class JavaDoc c = null;
59         if (pd[i] instanceof IndexedPropertyDescriptor) {
60         IndexedPropertyDescriptor ipd =
61             (IndexedPropertyDescriptor)pd[i];
62         c = ipd.getIndexedPropertyType();
63         } else {
64         c = pd[i].getPropertyType();
65         }
66         // Check for the following:
67
// 1: Does the metohd have a return type that implements
68
// the DDNode interface?
69
// 2: Is it a class in java.lang? but not getClass
70
// which is inherited from Object
71
// 3: Is it a primitive java type? This would have no "."
72
// chars in it.
73
if (c != null) {
74         if (BaseBean.class.isAssignableFrom(c) ||
75             (c.getName().startsWith("java.lang.")
76              && !c.getName().equals("java.lang.Class")) // NOI18N
77
|| (c.getName().indexOf(".") < 0)) { // NOI18N
78

79             al.add(pd[i]);
80         }
81         }
82     }
83     properties = (PropertyDescriptor[])al.toArray(new PropertyDescriptor[al.size()]);
84     
85     }
86     
87     
88     /**
89      * Gets the beans <code>PropertyDescriptor</code>s.
90      *
91      * @return An array of PropertyDescriptors describing the editable
92      * properties supported by this bean. May return null if the
93      * information should be obtained by automatic analysis.
94      * <p>
95      * If a property is indexed, then its entry in the result array will
96      * belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor.
97      * A client of getPropertyDescriptors can use "instanceof" to check
98      * if a given PropertyDescriptor is an IndexedPropertyDescriptor.
99      */

100     public PropertyDescriptor[] getPropertyDescriptors() {
101     if (!propertiesInited) {
102         // Avoid recursion here
103
propertiesInited = true;
104         initProperties();
105     }
106     return properties;
107     }
108     
109 }
110
Popular Tags