public void registerCustomEditors(PropertyEditorRegistry registry) { registry.registerCustomEditor(InetSocketAddress.class, this); }
@Override @Nullable public PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath) { return getPropertyEditorRegistry().findCustomEditor(requiredType, propertyPath); }
/** * Override default editor, if possible (since that's what we really mean to do here); * otherwise register as a custom editor. */ private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) { if (registry instanceof PropertyEditorRegistrySupport) { ((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor); } else { registry.registerCustomEditor(requiredType, editor); } }
@Override @Nullable public PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath) { return getPropertyEditorRegistry().findCustomEditor(requiredType, propertyPath); }
@Override public void registerCustomEditor(@Nullable Class<?> requiredType, @Nullable String field, PropertyEditor propertyEditor) { getPropertyEditorRegistry().registerCustomEditor(requiredType, field, propertyEditor); }
/** * This implementation delegates to the * {@link #getPropertyEditorRegistry() PropertyEditorRegistry}'s * editor lookup facility, if available. */ @Override @Nullable public PropertyEditor findEditor(@Nullable String field, @Nullable Class<?> valueType) { PropertyEditorRegistry editorRegistry = getPropertyEditorRegistry(); if (editorRegistry != null) { Class<?> valueTypeToUse = valueType; if (valueTypeToUse == null) { valueTypeToUse = getFieldType(field); } return editorRegistry.findCustomEditor(valueTypeToUse, fixedField(field)); } else { return null; } }
@Override public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) { getPropertyEditorRegistry().registerCustomEditor(requiredType, propertyEditor); }
/** * This implementation delegates to the * {@link #getPropertyEditorRegistry() PropertyEditorRegistry}'s * editor lookup facility, if available. */ @Override @Nullable public PropertyEditor findEditor(@Nullable String field, @Nullable Class<?> valueType) { PropertyEditorRegistry editorRegistry = getPropertyEditorRegistry(); if (editorRegistry != null) { Class<?> valueTypeToUse = valueType; if (valueTypeToUse == null) { valueTypeToUse = getFieldType(field); } return editorRegistry.findCustomEditor(valueTypeToUse, fixedField(field)); } else { return null; } }
/** * Register the given custom property editor for all properties of the given type. * <p>Typically used in conjunction with the default * {@link org.springframework.beans.SimpleTypeConverter}; will work with any * TypeConverter that implements the PropertyEditorRegistry interface as well. * @param requiredType type of the property * @param propertyEditor editor to register * @see #setTypeConverter * @see org.springframework.beans.PropertyEditorRegistry#registerCustomEditor */ public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) { TypeConverter converter = getTypeConverter(); if (!(converter instanceof PropertyEditorRegistry)) { throw new IllegalStateException( "TypeConverter does not implement PropertyEditorRegistry interface: " + converter); } ((PropertyEditorRegistry) converter).registerCustomEditor(requiredType, propertyEditor); }
protected final String convertToString(Class<?> type, Object value, TypeConverter converter) { if (value instanceof String) { return (String) value; } else { if (converter instanceof PropertyEditorRegistry && type != null && type.isInstance(value)) { PropertyEditor editor = ((PropertyEditorRegistry) converter).findCustomEditor(type, null); if (editor != null) { editor.setValue(value); return editor.getAsText(); } } return (String) getTypeConverter().convertIfNecessary(value, String.class); } }
@Override public void registerCustomEditor(@Nullable Class<?> requiredType, @Nullable String field, PropertyEditor propertyEditor) { getPropertyEditorRegistry().registerCustomEditor(requiredType, field, propertyEditor); }
protected final String convertToString(Class<?> type, Object value, TypeConverter converter) { if (value instanceof String) { return (String) value; } else { if (converter instanceof PropertyEditorRegistry && type != null && type.isInstance(value)) { PropertyEditor editor = ((PropertyEditorRegistry) converter).findCustomEditor(type, null); if (editor != null) { editor.setValue(value); return editor.getAsText(); } } return (String) getTypeConverter().convertIfNecessary(value, String.class); } }
@Override public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) { getPropertyEditorRegistry().registerCustomEditor(requiredType, propertyEditor); }
public String convert(MultipartFile source) { PropertyEditor editor = accessor.findCustomEditor(MultipartFile.class, null); if (editor == null) { throw new IllegalStateException("Cannot convert source of type " + source.getClass() + " to type: String"); } editor.setValue(source); return editor.getAsText(); }
String editorNestedPath = editorPath.substring(pos + 1); if (editorNestedProperty.equals(nestedProperty) || editorNestedProperty.equals(actualPropertyName)) { target.registerCustomEditor( editorHolder.getRegisteredType(), editorNestedPath, editorHolder.getPropertyEditor()); target.registerCustomEditor( editorHolder.getRegisteredType(), editorPath, editorHolder.getPropertyEditor());
/** * Register the custom editors with the given registry. * * @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry) */ @Override public void registerCustomEditors(PropertyEditorRegistry registry) { if (this.customEditors != null) { for (Entry<Class<?>, PropertyEditor> entry : customEditors.entrySet()) { registry.registerCustomEditor(entry.getKey(), entry.getValue()); } } }
/** * Override default editor, if possible (since that's what we really mean to do here); * otherwise register as a custom editor. */ private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) { if (registry instanceof PropertyEditorRegistrySupport) { ((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor); } else { registry.registerCustomEditor(requiredType, editor); } }
/** * Add a custom formatter for the field type specified in {@link Formatter} class, * applying it to the specified fields only, if any, or otherwise to all fields. * <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers. * @param formatter the formatter to add, generically declared for a specific type * @param fields the fields to apply the formatter to, or none if to be applied to all * @since 4.2 * @see #registerCustomEditor(Class, String, PropertyEditor) */ public void addCustomFormatter(Formatter<?> formatter, String... fields) { FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter); Class<?> fieldType = adapter.getFieldType(); if (ObjectUtils.isEmpty(fields)) { getPropertyEditorRegistry().registerCustomEditor(fieldType, adapter); } else { for (String field : fields) { getPropertyEditorRegistry().registerCustomEditor(fieldType, field, adapter); } } }
/** * Register the given custom property editor for all properties of the given type. * <p>Typically used in conjunction with the default * {@link org.springframework.beans.SimpleTypeConverter}; will work with any * TypeConverter that implements the PropertyEditorRegistry interface as well. * @param requiredType type of the property * @param propertyEditor editor to register * @see #setTypeConverter * @see org.springframework.beans.PropertyEditorRegistry#registerCustomEditor */ public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) { TypeConverter converter = getTypeConverter(); if (!(converter instanceof PropertyEditorRegistry)) { throw new IllegalStateException( "TypeConverter does not implement PropertyEditorRegistry interface: " + converter); } ((PropertyEditorRegistry) converter).registerCustomEditor(requiredType, propertyEditor); }
/** * Add a custom formatter, applying it to the specified field types only, if any, * or otherwise to all fields matching the {@link Formatter}-declared type. * <p>Registers a corresponding {@link PropertyEditor} adapter underneath the covers. * @param formatter the formatter to add (does not need to generically declare a * field type if field types are explicitly specified as parameters) * @param fieldTypes the field types to apply the formatter to, or none if to be * derived from the given {@link Formatter} implementation class * @since 4.2 * @see #registerCustomEditor(Class, PropertyEditor) */ public void addCustomFormatter(Formatter<?> formatter, Class<?>... fieldTypes) { FormatterPropertyEditorAdapter adapter = new FormatterPropertyEditorAdapter(formatter); if (ObjectUtils.isEmpty(fieldTypes)) { getPropertyEditorRegistry().registerCustomEditor(adapter.getFieldType(), adapter); } else { for (Class<?> fieldType : fieldTypes) { getPropertyEditorRegistry().registerCustomEditor(fieldType, adapter); } } }