0N/A/*
2535N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.beans;
0N/A
0N/A/**
0N/A * The PropertyEditorManager can be used to locate a property editor for
0N/A * any given type name. This property editor must support the
0N/A * java.beans.PropertyEditor interface for editing a given object.
0N/A * <P>
0N/A * The PropertyEditorManager uses three techniques for locating an editor
0N/A * for a given type. First, it provides a registerEditor method to allow
0N/A * an editor to be specifically registered for a given type. Second it
0N/A * tries to locate a suitable class by adding "Editor" to the full
0N/A * qualified classname of the given type (e.g. "foo.bah.FozEditor").
0N/A * Finally it takes the simple classname (without the package name) adds
0N/A * "Editor" to it and looks in a search-path of packages for a matching
0N/A * class.
0N/A * <P>
0N/A * So for an input class foo.bah.Fred, the PropertyEditorManager would
0N/A * first look in its tables to see if an editor had been registered for
0N/A * foo.bah.Fred and if so use that. Then it will look for a
0N/A * foo.bah.FredEditor class. Then it will look for (say)
0N/A * standardEditorsPackage.FredEditor class.
0N/A * <p>
0N/A * Default PropertyEditors will be provided for the Java primitive types
0N/A * "boolean", "byte", "short", "int", "long", "float", and "double"; and
0N/A * for the classes java.lang.String. java.awt.Color, and java.awt.Font.
0N/A */
0N/A
0N/Apublic class PropertyEditorManager {
0N/A
0N/A /**
632N/A * Registers an editor class to edit values of the given target class.
632N/A * If the editor class is {@code null},
632N/A * then any existing definition will be removed.
632N/A * Thus this method can be used to cancel the registration.
632N/A * The registration is canceled automatically
632N/A * if either the target or editor class is unloaded.
632N/A * <p>
632N/A * If there is a security manager, its {@code checkPropertiesAccess}
632N/A * method is called. This could result in a {@linkplain SecurityException}.
0N/A *
632N/A * @param targetType the class object of the type to be edited
632N/A * @param editorClass the class object of the editor class
632N/A * @throws SecurityException if a security manager exists and
632N/A * its {@code checkPropertiesAccess} method
632N/A * doesn't allow setting of system properties
632N/A *
0N/A * @see SecurityManager#checkPropertiesAccess
0N/A */
1405N/A public static void registerEditor(Class<?> targetType, Class<?> editorClass) {
0N/A SecurityManager sm = System.getSecurityManager();
0N/A if (sm != null) {
0N/A sm.checkPropertiesAccess();
0N/A }
4373N/A ThreadGroupContext.getContext().getPropertyEditorFinder().register(targetType, editorClass);
0N/A }
0N/A
0N/A /**
0N/A * Locate a value editor for a given target type.
0N/A *
0N/A * @param targetType The Class object for the type to be edited
0N/A * @return An editor object for the given target class.
0N/A * The result is null if no suitable editor can be found.
0N/A */
1405N/A public static PropertyEditor findEditor(Class<?> targetType) {
4373N/A return ThreadGroupContext.getContext().getPropertyEditorFinder().find(targetType);
0N/A }
0N/A
0N/A /**
0N/A * Gets the package names that will be searched for property editors.
0N/A *
0N/A * @return The array of package names that will be searched in
0N/A * order to find property editors.
0N/A * <p> The default value for this array is implementation-dependent,
0N/A * e.g. Sun implementation initially sets to {"sun.beans.editors"}.
0N/A */
1405N/A public static String[] getEditorSearchPath() {
4373N/A return ThreadGroupContext.getContext().getPropertyEditorFinder().getPackages();
0N/A }
0N/A
0N/A /**
0N/A * Change the list of package names that will be used for
0N/A * finding property editors.
0N/A *
0N/A * <p>First, if there is a security manager, its <code>checkPropertiesAccess</code>
0N/A * method is called. This could result in a SecurityException.
0N/A *
0N/A * @param path Array of package names.
0N/A * @exception SecurityException if a security manager exists and its
0N/A * <code>checkPropertiesAccess</code> method doesn't allow setting
0N/A * of system properties.
0N/A * @see SecurityManager#checkPropertiesAccess
0N/A */
1405N/A public static void setEditorSearchPath(String[] path) {
0N/A SecurityManager sm = System.getSecurityManager();
0N/A if (sm != null) {
0N/A sm.checkPropertiesAccess();
0N/A }
4373N/A ThreadGroupContext.getContext().getPropertyEditorFinder().setPackages(path);
0N/A }
0N/A}