Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/beans/PropertyEditorManager.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;2627/**28* The PropertyEditorManager can be used to locate a property editor for29* any given type name. This property editor must support the30* java.beans.PropertyEditor interface for editing a given object.31* <P>32* The PropertyEditorManager uses three techniques for locating an editor33* for a given type. First, it provides a registerEditor method to allow34* an editor to be specifically registered for a given type. Second it35* tries to locate a suitable class by adding "Editor" to the full36* qualified classname of the given type (e.g. "foo.bah.FozEditor").37* Finally it takes the simple classname (without the package name) adds38* "Editor" to it and looks in a search-path of packages for a matching39* class.40* <P>41* So for an input class foo.bah.Fred, the PropertyEditorManager would42* first look in its tables to see if an editor had been registered for43* foo.bah.Fred and if so use that. Then it will look for a44* foo.bah.FredEditor class. Then it will look for (say)45* standardEditorsPackage.FredEditor class.46* <p>47* Default PropertyEditors will be provided for the Java primitive types48* "boolean", "byte", "short", "int", "long", "float", and "double"; and49* for the classes java.lang.String. java.awt.Color, and java.awt.Font.50*/5152public class PropertyEditorManager {5354/**55* Registers an editor class to edit values of the given target class.56* If the editor class is {@code null},57* then any existing definition will be removed.58* Thus this method can be used to cancel the registration.59* The registration is canceled automatically60* if either the target or editor class is unloaded.61* <p>62* If there is a security manager, its {@code checkPropertiesAccess}63* method is called. This could result in a {@linkplain SecurityException}.64*65* @param targetType the class object of the type to be edited66* @param editorClass the class object of the editor class67* @throws SecurityException if a security manager exists and68* its {@code checkPropertiesAccess} method69* doesn't allow setting of system properties70*71* @see SecurityManager#checkPropertiesAccess72*/73public static void registerEditor(Class<?> targetType, Class<?> editorClass) {74SecurityManager sm = System.getSecurityManager();75if (sm != null) {76sm.checkPropertiesAccess();77}78ThreadGroupContext.getContext().getPropertyEditorFinder().register(targetType, editorClass);79}8081/**82* Locate a value editor for a given target type.83*84* @param targetType The Class object for the type to be edited85* @return An editor object for the given target class.86* The result is null if no suitable editor can be found.87*/88public static PropertyEditor findEditor(Class<?> targetType) {89return ThreadGroupContext.getContext().getPropertyEditorFinder().find(targetType);90}9192/**93* Gets the package names that will be searched for property editors.94*95* @return The array of package names that will be searched in96* order to find property editors.97* <p> The default value for this array is implementation-dependent,98* e.g. Sun implementation initially sets to {"sun.beans.editors"}.99*/100public static String[] getEditorSearchPath() {101return ThreadGroupContext.getContext().getPropertyEditorFinder().getPackages();102}103104/**105* Change the list of package names that will be used for106* finding property editors.107*108* <p>First, if there is a security manager, its <code>checkPropertiesAccess</code>109* method is called. This could result in a SecurityException.110*111* @param path Array of package names.112* @exception SecurityException if a security manager exists and its113* <code>checkPropertiesAccess</code> method doesn't allow setting114* of system properties.115* @see SecurityManager#checkPropertiesAccess116*/117public static void setEditorSearchPath(String[] path) {118SecurityManager sm = System.getSecurityManager();119if (sm != null) {120sm.checkPropertiesAccess();121}122ThreadGroupContext.getContext().getPropertyEditorFinder().setPackages(path);123}124}125126127