1 /* 2 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.beans; 27 28 /** 29 * This is a support class to make it easier for people to provide 30 * BeanInfo classes. 31 * <p> 32 * It defaults to providing "noop" information, and can be selectively 33 * overriden to provide more explicit information on chosen topics. 34 * When the introspector sees the "noop" values, it will apply low 35 * level introspection and design patterns to automatically analyze 36 * the target bean. 37 * 38 * @since 1.1 39 */ 40 41 public class SimpleBeanInfo implements BeanInfo { 42 43 /** 44 * Deny knowledge about the class and customizer of the bean. 45 * You can override this if you wish to provide explicit info. 46 */ 47 public BeanDescriptor getBeanDescriptor() { 48 return null; 49 } 50 51 /** 52 * Deny knowledge of properties. You can override this 53 * if you wish to provide explicit property info. 54 */ 55 public PropertyDescriptor[] getPropertyDescriptors() { 56 return null; 57 } 58 59 /** 60 * Deny knowledge of a default property. You can override this 61 * if you wish to define a default property for the bean. 62 */ 63 public int getDefaultPropertyIndex() { 64 return -1; 65 } 66 67 /** 68 * Deny knowledge of event sets. You can override this 69 * if you wish to provide explicit event set info. 70 */ 71 public EventSetDescriptor[] getEventSetDescriptors() { 72 return null; 73 } 74 75 /** 76 * Deny knowledge of a default event. You can override this 77 * if you wish to define a default event for the bean. 78 */ 79 public int getDefaultEventIndex() { 80 return -1; 81 } 82 83 /** 84 * Deny knowledge of methods. You can override this 85 * if you wish to provide explicit method info. 86 */ 87 public MethodDescriptor[] getMethodDescriptors() { 88 return null; 89 } 90 91 /** 92 * Claim there are no other relevant BeanInfo objects. You 93 * may override this if you want to (for example) return a 94 * BeanInfo for a base class. 95 */ 96 public BeanInfo[] getAdditionalBeanInfo() { 97 return null; 98 } 99 100 /** 101 * Claim there are no icons available. You can override 102 * this if you want to provide icons for your bean. 103 */ 104 public java.awt.Image getIcon(int iconKind) { 105 return null; 106 } 107 108 /** 109 * This is a utility method to help in loading icon images. 110 * It takes the name of a resource file associated with the 111 * current object's class file and loads an image object 112 * from that file. Typically images will be GIFs. 113 * 114 * @param resourceName A pathname relative to the directory 115 * holding the class file of the current class. For example, 116 * "wombat.gif". 117 * @return an image object. May be null if the load failed. 118 */ 119 public java.awt.Image loadImage(final String resourceName) { 120 try { 121 final Class<?> c = getClass(); 122 java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer) 123 java.security.AccessController.doPrivileged( 124 new java.security.PrivilegedAction<Object>() { 125 public Object run() { 126 java.net.URL url; 127 if ((url = c.getResource(resourceName)) == null) { 128 return null; 129 } else { 130 try { 131 return url.getContent(); 132 } catch (java.io.IOException ioe) { 133 return null; 134 } 135 } 136 } 137 }); 138 139 if (ip == null) 140 return null; 141 java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit(); 142 return tk.createImage(ip); 143 } catch (Exception ex) { 144 return null; 145 } 146 } 147 148 }