ApplicationContext registers context-specific ClassArrayEditor for its bean ClassLoader (SPR-1461)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3682 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
508217e113
commit
db51f1666e
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,6 +19,7 @@ package org.springframework.beans.propertyeditors;
|
|||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -30,6 +31,7 @@ import org.springframework.util.StringUtils;
|
|||
* to the standard {@link Class#forName(String)} method.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ClassArrayEditor extends PropertyEditorSupport {
|
||||
|
|
@ -52,8 +54,7 @@ public class ClassArrayEditor extends PropertyEditorSupport {
|
|||
* (or pass <code>null</code> for the thread context <code>ClassLoader</code>)
|
||||
*/
|
||||
public ClassArrayEditor(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader != null
|
||||
? classLoader : ClassUtils.getDefaultClassLoader();
|
||||
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,14 +77,9 @@ public class ClassArrayEditor extends PropertyEditorSupport {
|
|||
@Override
|
||||
public String getAsText() {
|
||||
Class[] classes = (Class[]) getValue();
|
||||
if (classes == null || classes.length == 0) {
|
||||
if (ObjectUtils.isEmpty(classes)) {
|
||||
return "";
|
||||
}
|
||||
return toCommaDelimitedString(classes);
|
||||
}
|
||||
|
||||
|
||||
private static String toCommaDelimitedString(Class[] classes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < classes.length; ++i) {
|
||||
if (i > 0) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -53,8 +53,7 @@ public class ClassEditor extends PropertyEditorSupport {
|
|||
* (or <code>null</code> for the thread context ClassLoader)
|
||||
*/
|
||||
public ClassEditor(ClassLoader classLoader) {
|
||||
this.classLoader =
|
||||
(classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
|
||||
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.xml.sax.InputSource;
|
|||
import org.springframework.beans.PropertyEditorRegistrar;
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.PropertyEditorRegistrySupport;
|
||||
import org.springframework.beans.propertyeditors.ClassArrayEditor;
|
||||
import org.springframework.beans.propertyeditors.ClassEditor;
|
||||
import org.springframework.beans.propertyeditors.FileEditor;
|
||||
import org.springframework.beans.propertyeditors.InputSourceEditor;
|
||||
|
|
@ -89,8 +90,9 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
|
|||
doRegisterEditor(registry, URL.class, new URLEditor(baseEditor));
|
||||
|
||||
ClassLoader classLoader = this.resourceLoader.getClassLoader();
|
||||
doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
|
||||
doRegisterEditor(registry, URI.class, new URIEditor(classLoader));
|
||||
doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
|
||||
doRegisterEditor(registry, Class[].class, new ClassArrayEditor(classLoader));
|
||||
|
||||
if (this.resourceLoader instanceof ResourcePatternResolver) {
|
||||
doRegisterEditor(registry, Resource[].class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue