Browse Source

restored support for String-to-ContextResource conversion (SPR-8383)

3.0.x
Juergen Hoeller 15 years ago
parent
commit
fece2c1125
  1. 3
      org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
  2. 4
      org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java
  3. 21
      org.springframework.context/src/test/java/org/springframework/beans/ResourceTestBean.java
  4. 3
      org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resourceImport.xml

3
org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

@ -223,7 +223,8 @@ class TypeConverterDelegate {
} }
if (editor != null) { if (editor != null) {
msg.append(": PropertyEditor [").append(editor.getClass().getName()).append( msg.append(": PropertyEditor [").append(editor.getClass().getName()).append(
"] returned inappropriate value"); "] returned inappropriate value of type [").append(
ClassUtils.getDescriptiveType(convertedValue)).append("]");
throw new IllegalArgumentException(msg.toString()); throw new IllegalArgumentException(msg.toString());
} }
else { else {

4
org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import org.springframework.beans.propertyeditors.InputSourceEditor;
import org.springframework.beans.propertyeditors.InputStreamEditor; import org.springframework.beans.propertyeditors.InputStreamEditor;
import org.springframework.beans.propertyeditors.URIEditor; import org.springframework.beans.propertyeditors.URIEditor;
import org.springframework.beans.propertyeditors.URLEditor; import org.springframework.beans.propertyeditors.URLEditor;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
@ -84,6 +85,7 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) { public void registerCustomEditors(PropertyEditorRegistry registry) {
ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader); ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader);
doRegisterEditor(registry, Resource.class, baseEditor); doRegisterEditor(registry, Resource.class, baseEditor);
doRegisterEditor(registry, ContextResource.class, baseEditor);
doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor)); doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor));
doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor)); doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor));
doRegisterEditor(registry, File.class, new FileEditor(baseEditor)); doRegisterEditor(registry, File.class, new FileEditor(baseEditor));

21
org.springframework.context/src/test/java/org/springframework/beans/ResourceTestBean.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.beans;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map; import java.util.Map;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
@ -29,6 +30,8 @@ public class ResourceTestBean {
private Resource resource; private Resource resource;
private ContextResource contextResource;
private InputStream inputStream; private InputStream inputStream;
private Resource[] resourceArray; private Resource[] resourceArray;
@ -47,22 +50,30 @@ public class ResourceTestBean {
} }
public Resource getResource() {
return resource;
}
public void setResource(Resource resource) { public void setResource(Resource resource) {
this.resource = resource; this.resource = resource;
} }
public void setInputStream(InputStream inputStream) { public ContextResource getContextResource() {
this.inputStream = inputStream; return contextResource;
} }
public Resource getResource() { public void setContextResource(ContextResource contextResource) {
return resource; this.contextResource = contextResource;
} }
public InputStream getInputStream() { public InputStream getInputStream() {
return inputStream; return inputStream;
} }
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public Resource[] getResourceArray() { public Resource[] getResourceArray() {
return resourceArray; return resourceArray;
} }

3
org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resourceImport.xml

@ -7,6 +7,9 @@
<property name="resource"> <property name="resource">
<value>test.properties</value> <value>test.properties</value>
</property> </property>
<property name="contextResource">
<value>testBeans.properties</value>
</property>
<property name="inputStream"> <property name="inputStream">
<value>classpath:org/springframework/beans/factory/xml/test.properties</value> <value>classpath:org/springframework/beans/factory/xml/test.properties</value>
</property> </property>

Loading…
Cancel
Save