Issue #3743 - Using Location based XmlConfiguration where possible
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
6686083462
commit
a72a6ab875
|
@ -68,6 +68,45 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
|||
private DefaultListableBeanFactory _beanFactory;
|
||||
private String _main;
|
||||
|
||||
@Override
|
||||
public void init(org.eclipse.jetty.util.resource.Resource jettyResource, XmlParser.Node config, XmlConfiguration configuration)
|
||||
{
|
||||
try
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
Resource springResource;
|
||||
|
||||
if (jettyResource != null)
|
||||
{
|
||||
springResource = new UrlResource(jettyResource.getURI());
|
||||
}
|
||||
else
|
||||
{
|
||||
springResource = new ByteArrayResource(("" +
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
|
||||
config).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
_beanFactory = new DefaultListableBeanFactory()
|
||||
{
|
||||
@Override
|
||||
protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs)
|
||||
{
|
||||
_configuration.initializeDefaults(bw.getWrappedInstance());
|
||||
super.applyPropertyValues(beanName, mbd, bw, pvs);
|
||||
}
|
||||
};
|
||||
|
||||
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration)
|
||||
{
|
||||
|
|
|
@ -38,8 +38,9 @@ public interface ConfigurationProcessor
|
|||
*/
|
||||
@Deprecated
|
||||
void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
|
||||
|
||||
void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration);
|
||||
|
||||
|
||||
Object configure( Object obj) throws Exception;
|
||||
Object configure() throws Exception;
|
||||
}
|
||||
|
|
|
@ -268,6 +268,15 @@ public class XmlConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
private String getLocation()
|
||||
{
|
||||
if (_location == null)
|
||||
{
|
||||
return "UNKNOWN-LOCATION";
|
||||
}
|
||||
return _location.toString();
|
||||
}
|
||||
|
||||
private void setConfig(XmlParser.Node config)
|
||||
{
|
||||
if ("Configure".equals(config.getTag()))
|
||||
|
@ -283,7 +292,7 @@ public class XmlConfiguration
|
|||
break;
|
||||
}
|
||||
if (_processor == null)
|
||||
throw new IllegalStateException("Unknown configuration type: " + config.getTag() + " in " + this);
|
||||
throw new IllegalStateException("Unknown configuration type: " + config.getTag() + " in " + getLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -371,7 +380,7 @@ public class XmlConfiguration
|
|||
@Override
|
||||
public void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
|
||||
{
|
||||
_location = resource == null ? null : resource.toString();
|
||||
_location = resource == null ? "UNKNOWN_RESOURCE" : resource.toString();
|
||||
_root = root;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
@ -379,7 +388,7 @@ public class XmlConfiguration
|
|||
@Override
|
||||
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
|
||||
{
|
||||
_location = url == null ? null : url.toString();
|
||||
_location = url == null ? "UNKNOWN_URL" : url.toString();
|
||||
_root = root;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
|
|
@ -666,7 +666,6 @@ public class XmlConfigurationTest
|
|||
" </New>" +
|
||||
" </Set>" +
|
||||
"</Configure>");
|
||||
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
|
||||
|
||||
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
|
||||
|
||||
|
|
Loading…
Reference in New Issue