Path: blob/master/src/java.desktop/share/classes/java/beans/BeanDescriptor.java
41152 views
/*1* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package java.beans;2526import java.lang.ref.Reference;27import javax.swing.SwingContainer;2829/**30* A BeanDescriptor provides global information about a "bean",31* including its Java class, its displayName, etc.32* <p>33* This is one of the kinds of descriptor returned by a BeanInfo object,34* which also returns descriptors for properties, method, and events.35*36* @since 1.137*/3839public class BeanDescriptor extends FeatureDescriptor {4041private Reference<? extends Class<?>> beanClassRef;42private Reference<? extends Class<?>> customizerClassRef;4344/**45* Create a BeanDescriptor for a bean that doesn't have a customizer.46*47* @param beanClass The Class object of the Java class that implements48* the bean. For example sun.beans.OurButton.class.49*/50public BeanDescriptor(Class<?> beanClass) {51this(beanClass, null);52}5354/**55* Create a BeanDescriptor for a bean that has a customizer.56*57* @param beanClass The Class object of the Java class that implements58* the bean. For example sun.beans.OurButton.class.59* @param customizerClass The Class object of the Java class that implements60* the bean's Customizer. For example sun.beans.OurButtonCustomizer.class.61*/62public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {63this.beanClassRef = getWeakReference(beanClass);64this.customizerClassRef = getWeakReference(customizerClass);6566String name = beanClass.getName();67while (name.indexOf('.') >= 0) {68name = name.substring(name.indexOf('.')+1);69}70setName(name);7172JavaBean annotation = beanClass.getAnnotation(JavaBean.class);73if (annotation != null) {74setPreferred(true);75String description = annotation.description();76if (!description.isEmpty()) {77setShortDescription(description);78}79}80SwingContainer container = beanClass.getAnnotation(SwingContainer.class);81if (container != null) {82setValue("isContainer", container.value());83setValue("containerDelegate", container.delegate());84}85}8687/**88* Gets the bean's Class object.89*90* @return The Class object for the bean.91*/92public Class<?> getBeanClass() {93return (this.beanClassRef != null)94? this.beanClassRef.get()95: null;96}9798/**99* Gets the Class object for the bean's customizer.100*101* @return The Class object for the bean's customizer. This may102* be null if the bean doesn't have a customizer.103*/104public Class<?> getCustomizerClass() {105return (this.customizerClassRef != null)106? this.customizerClassRef.get()107: null;108}109110/*111* Package-private dup constructor112* This must isolate the new object from any changes to the old object.113*/114BeanDescriptor(BeanDescriptor old) {115super(old);116beanClassRef = old.beanClassRef;117customizerClassRef = old.customizerClassRef;118}119120void appendTo(StringBuilder sb) {121appendTo(sb, "beanClass", this.beanClassRef);122appendTo(sb, "customizerClass", this.customizerClassRef);123}124}125126127