KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > beans > SimpleBeanInfo


1 /*
2  * @(#)SimpleBeanInfo.java 1.27 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.beans;
9
10 /**
11  * This is a support class to make it easier for people to provide
12  * BeanInfo classes.
13  * <p>
14  * It defaults to providing "noop" information, and can be selectively
15  * overriden to provide more explicit information on chosen topics.
16  * When the introspector sees the "noop" values, it will apply low
17  * level introspection and design patterns to automatically analyze
18  * the target bean.
19  */

20
21 public class SimpleBeanInfo implements BeanInfo JavaDoc {
22
23     /**
24      * Deny knowledge about the class and customizer of the bean.
25      * You can override this if you wish to provide explicit info.
26      */

27     public BeanDescriptor JavaDoc getBeanDescriptor() {
28     return null;
29     }
30
31     /**
32      * Deny knowledge of properties. You can override this
33      * if you wish to provide explicit property info.
34      */

35     public PropertyDescriptor JavaDoc[] getPropertyDescriptors() {
36     return null;
37     }
38
39     /**
40      * Deny knowledge of a default property. You can override this
41      * if you wish to define a default property for the bean.
42      */

43     public int getDefaultPropertyIndex() {
44     return -1;
45     }
46
47     /**
48      * Deny knowledge of event sets. You can override this
49      * if you wish to provide explicit event set info.
50      */

51     public EventSetDescriptor JavaDoc[] getEventSetDescriptors() {
52     return null;
53     }
54
55     /**
56      * Deny knowledge of a default event. You can override this
57      * if you wish to define a default event for the bean.
58      */

59     public int getDefaultEventIndex() {
60     return -1;
61     }
62
63     /**
64      * Deny knowledge of methods. You can override this
65      * if you wish to provide explicit method info.
66      */

67     public MethodDescriptor JavaDoc[] getMethodDescriptors() {
68     return null;
69     }
70
71     /**
72      * Claim there are no other relevant BeanInfo objects. You
73      * may override this if you want to (for example) return a
74      * BeanInfo for a base class.
75      */

76     public BeanInfo JavaDoc[] getAdditionalBeanInfo() {
77     return null;
78     }
79
80     /**
81      * Claim there are no icons available. You can override
82      * this if you want to provide icons for your bean.
83      */

84     public java.awt.Image JavaDoc getIcon(int iconKind) {
85     return null;
86     }
87
88     /**
89      * This is a utility method to help in loading icon images.
90      * It takes the name of a resource file associated with the
91      * current object's class file and loads an image object
92      * from that file. Typically images will be GIFs.
93      * <p>
94      * @param resourceName A pathname relative to the directory
95      * holding the class file of the current class. For example,
96      * "wombat.gif".
97      * @return an image object. May be null if the load failed.
98      */

99     public java.awt.Image JavaDoc loadImage(final String JavaDoc resourceName) {
100     try {
101         final Class JavaDoc c = getClass();
102         java.awt.image.ImageProducer JavaDoc ip = (java.awt.image.ImageProducer JavaDoc)
103         java.security.AccessController.doPrivileged(
104         new java.security.PrivilegedAction JavaDoc() {
105             public Object JavaDoc run() {
106             java.net.URL JavaDoc url;
107             if ((url = c.getResource(resourceName)) == null) {
108                 return null;
109             } else {
110                 try {
111                 return url.getContent();
112                 } catch (java.io.IOException JavaDoc ioe) {
113                 return null;
114                 }
115             }
116             }
117         });
118
119         if (ip == null)
120         return null;
121         java.awt.Toolkit JavaDoc tk = java.awt.Toolkit.getDefaultToolkit();
122         return tk.createImage(ip);
123     } catch (Exception JavaDoc ex) {
124         return null;
125     }
126     }
127
128 }
129
Popular Tags