001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans; 018 019import java.beans.PropertyEditor; 020 021/** 022 * Encapsulates methods for registering JavaBeans {@link PropertyEditor PropertyEditors}. 023 * This is the central interface that a {@link PropertyEditorRegistrar} operates on. 024 * 025 * <p>Extended by {@link BeanWrapper}; implemented by {@link BeanWrapperImpl} 026 * and {@link org.springframework.validation.DataBinder}. 027 * 028 * @author Juergen Hoeller 029 * @since 1.2.6 030 * @see java.beans.PropertyEditor 031 * @see PropertyEditorRegistrar 032 * @see BeanWrapper 033 * @see org.springframework.validation.DataBinder 034 */ 035public interface PropertyEditorRegistry { 036 037 /** 038 * Register the given custom property editor for all properties of the given type. 039 * @param requiredType the type of the property 040 * @param propertyEditor the editor to register 041 */ 042 void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor); 043 044 /** 045 * Register the given custom property editor for the given type and 046 * property, or for all properties of the given type. 047 * <p>If the property path denotes an array or Collection property, 048 * the editor will get applied either to the array/Collection itself 049 * (the {@link PropertyEditor} has to create an array or Collection value) or 050 * to each element (the {@code PropertyEditor} has to create the element type), 051 * depending on the specified required type. 052 * <p>Note: Only one single registered custom editor per property path 053 * is supported. In the case of a Collection/array, do not register an editor 054 * for both the Collection/array and each element on the same property. 055 * <p>For example, if you wanted to register an editor for "items[n].quantity" 056 * (for all values n), you would use "items.quantity" as the value of the 057 * 'propertyPath' argument to this method. 058 * @param requiredType the type of the property. This may be {@code null} 059 * if a property is given but should be specified in any case, in particular in 060 * case of a Collection - making clear whether the editor is supposed to apply 061 * to the entire Collection itself or to each of its entries. So as a general rule: 062 * <b>Do not specify {@code null} here in case of a Collection/array!</b> 063 * @param propertyPath the path of the property (name or nested path), or 064 * {@code null} if registering an editor for all properties of the given type 065 * @param propertyEditor editor to register 066 */ 067 void registerCustomEditor(Class<?> requiredType, String propertyPath, PropertyEditor propertyEditor); 068 069 /** 070 * Find a custom property editor for the given type and property. 071 * @param requiredType the type of the property (can be {@code null} if a property 072 * is given but should be specified in any case for consistency checking) 073 * @param propertyPath the path of the property (name or nested path), or 074 * {@code null} if looking for an editor for all properties of the given type 075 * @return the registered editor, or {@code null} if none 076 */ 077 PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath); 078 079}