Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/java/beans/PropertyEditorManager.java
41152 views
1
/*
2
* Copyright (c) 1996, 2021, 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
* The PropertyEditorManager can be used to locate a property editor for
30
* any given type name. This property editor must support the
31
* java.beans.PropertyEditor interface for editing a given object.
32
* <P>
33
* The PropertyEditorManager uses three techniques for locating an editor
34
* for a given type. First, it provides a registerEditor method to allow
35
* an editor to be specifically registered for a given type. Second it
36
* tries to locate a suitable class by adding "Editor" to the full
37
* qualified classname of the given type (e.g. "foo.bah.FozEditor").
38
* Finally it takes the simple classname (without the package name) adds
39
* "Editor" to it and looks in a search-path of packages for a matching
40
* class.
41
* <P>
42
* So for an input class foo.bah.Fred, the PropertyEditorManager would
43
* first look in its tables to see if an editor had been registered for
44
* foo.bah.Fred and if so use that. Then it will look for a
45
* foo.bah.FredEditor class. Then it will look for (say)
46
* standardEditorsPackage.FredEditor class.
47
* <p>
48
* Default PropertyEditors will be provided for the Java primitive types
49
* "boolean", "byte", "short", "int", "long", "float", and "double"; and
50
* for the classes java.lang.String. java.awt.Color, and java.awt.Font.
51
*
52
* @since 1.1
53
*/
54
55
public class PropertyEditorManager {
56
57
/**
58
* Constructs a {@code PropertyEditorManager}.
59
*/
60
public PropertyEditorManager() {}
61
62
/**
63
* Registers an editor class to edit values of the given target class.
64
* If the editor class is {@code null},
65
* then any existing definition will be removed.
66
* Thus this method can be used to cancel the registration.
67
* The registration is canceled automatically
68
* if either the target or editor class is unloaded.
69
* <p>
70
* If there is a security manager, its {@code checkPropertiesAccess}
71
* method is called. This could result in a {@linkplain SecurityException}.
72
*
73
* @param targetType the class object of the type to be edited
74
* @param editorClass the class object of the editor class
75
* @throws SecurityException if a security manager exists and
76
* its {@code checkPropertiesAccess} method
77
* doesn't allow setting of system properties
78
*
79
* @see SecurityManager#checkPropertiesAccess
80
*/
81
public static void registerEditor(Class<?> targetType, Class<?> editorClass) {
82
@SuppressWarnings("removal")
83
SecurityManager sm = System.getSecurityManager();
84
if (sm != null) {
85
sm.checkPropertiesAccess();
86
}
87
ThreadGroupContext.getContext().getPropertyEditorFinder().register(targetType, editorClass);
88
}
89
90
/**
91
* Locate a value editor for a given target type.
92
*
93
* @param targetType The Class object for the type to be edited
94
* @return An editor object for the given target class.
95
* The result is null if no suitable editor can be found.
96
*/
97
public static PropertyEditor findEditor(Class<?> targetType) {
98
return ThreadGroupContext.getContext().getPropertyEditorFinder().find(targetType);
99
}
100
101
/**
102
* Gets the package names that will be searched for property editors.
103
*
104
* @return The array of package names that will be searched in
105
* order to find property editors.
106
* <p> The default value for this array is implementation-dependent,
107
* e.g. Sun implementation initially sets to {"sun.beans.editors"}.
108
*/
109
public static String[] getEditorSearchPath() {
110
return ThreadGroupContext.getContext().getPropertyEditorFinder().getPackages();
111
}
112
113
/**
114
* Change the list of package names that will be used for
115
* finding property editors.
116
*
117
* <p>First, if there is a security manager, its {@code checkPropertiesAccess}
118
* method is called. This could result in a SecurityException.
119
*
120
* @param path Array of package names.
121
* @exception SecurityException if a security manager exists and its
122
* {@code checkPropertiesAccess} method doesn't allow setting
123
* of system properties.
124
* @see SecurityManager#checkPropertiesAccess
125
*/
126
public static void setEditorSearchPath(String[] path) {
127
@SuppressWarnings("removal")
128
SecurityManager sm = System.getSecurityManager();
129
if (sm != null) {
130
sm.checkPropertiesAccess();
131
}
132
ThreadGroupContext.getContext().getPropertyEditorFinder().setPackages(path);
133
}
134
}
135
136