Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/beans/BeanDescriptor.java
38829 views
/*1* Copyright (c) 1996, 2011, 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*/2425package java.beans;2627import java.lang.ref.Reference;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*/3637public class BeanDescriptor extends FeatureDescriptor {3839private Reference<? extends Class<?>> beanClassRef;40private Reference<? extends Class<?>> customizerClassRef;4142/**43* Create a BeanDescriptor for a bean that doesn't have a customizer.44*45* @param beanClass The Class object of the Java class that implements46* the bean. For example sun.beans.OurButton.class.47*/48public BeanDescriptor(Class<?> beanClass) {49this(beanClass, null);50}5152/**53* Create a BeanDescriptor for a bean that has a customizer.54*55* @param beanClass The Class object of the Java class that implements56* the bean. For example sun.beans.OurButton.class.57* @param customizerClass The Class object of the Java class that implements58* the bean's Customizer. For example sun.beans.OurButtonCustomizer.class.59*/60public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {61this.beanClassRef = getWeakReference(beanClass);62this.customizerClassRef = getWeakReference(customizerClass);6364String name = beanClass.getName();65while (name.indexOf('.') >= 0) {66name = name.substring(name.indexOf('.')+1);67}68setName(name);69}7071/**72* Gets the bean's Class object.73*74* @return The Class object for the bean.75*/76public Class<?> getBeanClass() {77return (this.beanClassRef != null)78? this.beanClassRef.get()79: null;80}8182/**83* Gets the Class object for the bean's customizer.84*85* @return The Class object for the bean's customizer. This may86* be null if the bean doesn't have a customizer.87*/88public Class<?> getCustomizerClass() {89return (this.customizerClassRef != null)90? this.customizerClassRef.get()91: null;92}9394/*95* Package-private dup constructor96* This must isolate the new object from any changes to the old object.97*/98BeanDescriptor(BeanDescriptor old) {99super(old);100beanClassRef = old.beanClassRef;101customizerClassRef = old.customizerClassRef;102}103104void appendTo(StringBuilder sb) {105appendTo(sb, "beanClass", this.beanClassRef);106appendTo(sb, "customizerClass", this.customizerClassRef);107}108}109110111