You may solve both "issue" by extending Spring. All you need to do is create a new FactoryBean as follows:
Code:
pakage org.adam.factory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.binding.support.Assert;
import org.springframework.core.io.Resource;
/**
* @author <a href="mailto:irbouh@gmail.com">Omar Irbouh</a>
* @since 2005.10.27
*/
public class ResourceFactoryBean implements FactoryBean, InitializingBean {
private String content = null;
private Resource location = null;
public Object getObject() throws Exception {
return content;
}
public Class getObjectType() {
return content.getClass();
}
public boolean isSingleton() {
return true;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(location);
//you may provide a better method for reading the inputStream
byte[] buffer = new byte[location.getInputStream().available()];
if (location.getInputStream().read(buffer) > 0) {
content = new String(buffer);
}
}
public Resource getLocation() {
return location;
}
public void setLocation(Resource location) {
this.location = location;
}
}
This FactoryBean can be used as follows:
Code:
<bean class=...>
<property name="xml">
<bean class="org.adam.factory.ResourceFactoryBean">
<property name="location" value="classpath:myfile.xml"/>
</bean>
</property>
</bean>
Hope this helps.