Path: blob/master/src/java.desktop/share/classes/com/sun/beans/introspect/ClassInfo.java
41171 views
/*1* Copyright (c) 2014, 2020, 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 com.sun.beans.introspect;2627import java.lang.reflect.Method;28import java.util.List;29import java.util.Map;3031import com.sun.beans.util.Cache;3233import static sun.reflect.misc.ReflectUtil.checkPackageAccess;3435public final class ClassInfo {36private static final ClassInfo DEFAULT = new ClassInfo(null);37private static final Cache<Class<?>,ClassInfo> CACHE38= new Cache<Class<?>,ClassInfo>(Cache.Kind.SOFT, Cache.Kind.SOFT) {39@Override40public ClassInfo create(Class<?> type) {41return new ClassInfo(type);42}43};4445public static ClassInfo get(Class<?> type) {46if (type == null) {47return DEFAULT;48}49try {50checkPackageAccess(type);51return CACHE.get(type);52} catch (SecurityException exception) {53return DEFAULT;54}55}5657public static void clear() {58CACHE.clear();59}6061public static void remove(Class<?> clz) {62CACHE.remove(clz);63}6465private final Object mutex = new Object();66private final Class<?> type;67private List<Method> methods;68private Map<String,PropertyInfo> properties;69private Map<String,EventSetInfo> eventSets;7071private ClassInfo(Class<?> type) {72this.type = type;73}7475public List<Method> getMethods() {76if (this.methods == null) {77synchronized (this.mutex) {78if (this.methods == null) {79this.methods = MethodInfo.get(this.type);80}81}82}83return this.methods;84}8586public Map<String,PropertyInfo> getProperties() {87if (this.properties == null) {88synchronized (this.mutex) {89if (this.properties == null) {90this.properties = PropertyInfo.get(this.type);91}92}93}94return this.properties;95}9697public Map<String,EventSetInfo> getEventSets() {98if (this.eventSets == null) {99synchronized (this.mutex) {100if (this.eventSets == null) {101this.eventSets = EventSetInfo.get(this.type);102}103}104}105return this.eventSets;106}107}108109110