From db51f1666ee0a1977f56163eb00d0414f4de26fd Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 14 Sep 2010 05:09:08 +0000 Subject: [PATCH] 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 --- .../beans/propertyeditors/ClassArrayEditor.java | 14 +++++--------- .../beans/propertyeditors/ClassEditor.java | 5 ++--- .../beans/support/ResourceEditorRegistrar.java | 4 +++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java index ab8e93b48db..4db48197f8e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java @@ -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 null for the thread context ClassLoader) */ 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) { diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java index afdc6ec69c5..4f5fffce466 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java @@ -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 null for the thread context ClassLoader) */ public ClassEditor(ClassLoader classLoader) { - this.classLoader = - (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); + this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); } diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java b/org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java index 6dee35cb291..3c61d853506 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java @@ -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,