Search in sources :

Example 1 with PropertyEditorRegistrySupport

use of org.springframework.beans.PropertyEditorRegistrySupport in project grails-core by grails.

the class GrailsWebRequest method getPropertyEditorRegistry.

/**
     * Obtains the PropertyEditorRegistry instance.
     * @return The PropertyEditorRegistry
     */
public PropertyEditorRegistry getPropertyEditorRegistry() {
    final HttpServletRequest servletRequest = getCurrentRequest();
    PropertyEditorRegistry registry = (PropertyEditorRegistry) servletRequest.getAttribute(GrailsApplicationAttributes.PROPERTY_REGISTRY);
    if (registry == null) {
        registry = new PropertyEditorRegistrySupport();
        PropertyEditorRegistryUtils.registerCustomEditors(this, registry, RequestContextUtils.getLocale(servletRequest));
        servletRequest.setAttribute(GrailsApplicationAttributes.PROPERTY_REGISTRY, registry);
    }
    return registry;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PropertyEditorRegistrySupport(org.springframework.beans.PropertyEditorRegistrySupport) PropertyEditorRegistry(org.springframework.beans.PropertyEditorRegistry)

Example 2 with PropertyEditorRegistrySupport

use of org.springframework.beans.PropertyEditorRegistrySupport in project spring-framework by spring-projects.

the class AbstractBeanFactory method registerCustomEditors.

/**
	 * Initialize the given PropertyEditorRegistry with the custom editors
	 * that have been registered with this BeanFactory.
	 * <p>To be called for BeanWrappers that will create and populate bean
	 * instances, and for SimpleTypeConverter used for constructor argument
	 * and factory method type conversion.
	 * @param registry the PropertyEditorRegistry to initialize
	 */
protected void registerCustomEditors(PropertyEditorRegistry registry) {
    PropertyEditorRegistrySupport registrySupport = (registry instanceof PropertyEditorRegistrySupport ? (PropertyEditorRegistrySupport) registry : null);
    if (registrySupport != null) {
        registrySupport.useConfigValueEditors();
    }
    if (!this.propertyEditorRegistrars.isEmpty()) {
        for (PropertyEditorRegistrar registrar : this.propertyEditorRegistrars) {
            try {
                registrar.registerCustomEditors(registry);
            } catch (BeanCreationException ex) {
                Throwable rootCause = ex.getMostSpecificCause();
                if (rootCause instanceof BeanCurrentlyInCreationException) {
                    BeanCreationException bce = (BeanCreationException) rootCause;
                    if (isCurrentlyInCreation(bce.getBeanName())) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("PropertyEditorRegistrar [" + registrar.getClass().getName() + "] failed because it tried to obtain currently created bean '" + ex.getBeanName() + "': " + ex.getMessage());
                        }
                        onSuppressedException(ex);
                        continue;
                    }
                }
                throw ex;
            }
        }
    }
    if (!this.customEditors.isEmpty()) {
        for (Map.Entry<Class<?>, Class<? extends PropertyEditor>> entry : this.customEditors.entrySet()) {
            Class<?> requiredType = entry.getKey();
            Class<? extends PropertyEditor> editorClass = entry.getValue();
            registry.registerCustomEditor(requiredType, BeanUtils.instantiateClass(editorClass));
        }
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) PropertyEditorRegistrySupport(org.springframework.beans.PropertyEditorRegistrySupport) PropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar) PropertyEditor(java.beans.PropertyEditor) BeanCurrentlyInCreationException(org.springframework.beans.factory.BeanCurrentlyInCreationException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PropertyEditorRegistrySupport (org.springframework.beans.PropertyEditorRegistrySupport)2 PropertyEditor (java.beans.PropertyEditor)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PropertyEditorRegistrar (org.springframework.beans.PropertyEditorRegistrar)1 PropertyEditorRegistry (org.springframework.beans.PropertyEditorRegistry)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)1