Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/com/sun/beans/introspect/ClassInfo.java
41171 views
1
/*
2
* Copyright (c) 2014, 2020, 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 com.sun.beans.introspect;
27
28
import java.lang.reflect.Method;
29
import java.util.List;
30
import java.util.Map;
31
32
import com.sun.beans.util.Cache;
33
34
import static sun.reflect.misc.ReflectUtil.checkPackageAccess;
35
36
public final class ClassInfo {
37
private static final ClassInfo DEFAULT = new ClassInfo(null);
38
private static final Cache<Class<?>,ClassInfo> CACHE
39
= new Cache<Class<?>,ClassInfo>(Cache.Kind.SOFT, Cache.Kind.SOFT) {
40
@Override
41
public ClassInfo create(Class<?> type) {
42
return new ClassInfo(type);
43
}
44
};
45
46
public static ClassInfo get(Class<?> type) {
47
if (type == null) {
48
return DEFAULT;
49
}
50
try {
51
checkPackageAccess(type);
52
return CACHE.get(type);
53
} catch (SecurityException exception) {
54
return DEFAULT;
55
}
56
}
57
58
public static void clear() {
59
CACHE.clear();
60
}
61
62
public static void remove(Class<?> clz) {
63
CACHE.remove(clz);
64
}
65
66
private final Object mutex = new Object();
67
private final Class<?> type;
68
private List<Method> methods;
69
private Map<String,PropertyInfo> properties;
70
private Map<String,EventSetInfo> eventSets;
71
72
private ClassInfo(Class<?> type) {
73
this.type = type;
74
}
75
76
public List<Method> getMethods() {
77
if (this.methods == null) {
78
synchronized (this.mutex) {
79
if (this.methods == null) {
80
this.methods = MethodInfo.get(this.type);
81
}
82
}
83
}
84
return this.methods;
85
}
86
87
public Map<String,PropertyInfo> getProperties() {
88
if (this.properties == null) {
89
synchronized (this.mutex) {
90
if (this.properties == null) {
91
this.properties = PropertyInfo.get(this.type);
92
}
93
}
94
}
95
return this.properties;
96
}
97
98
public Map<String,EventSetInfo> getEventSets() {
99
if (this.eventSets == null) {
100
synchronized (this.mutex) {
101
if (this.eventSets == null) {
102
this.eventSets = EventSetInfo.get(this.type);
103
}
104
}
105
}
106
return this.eventSets;
107
}
108
}
109
110