[Bugfix] fixed not setting new Impl for component, when overridden

- Now when you set a new Impl for a component, then the dependencies are
also replaced
This commit is contained in:
Robert von Burg 2015-01-09 01:05:48 +01:00
parent 4c631ad07f
commit ee741b5e18
3 changed files with 41 additions and 0 deletions

View File

@ -452,6 +452,10 @@ public class ConfigurationSaxParser extends DefaultHandler {
if (thisComponentBuilder == null) {
this.componentBuilders.add(otherComponentBuilder);
} else {
if (StringHelper.isNotEmpty(otherComponentBuilder.getImpl())) {
thisComponentBuilder.setImpl(otherComponentBuilder.getImpl());
thisComponentBuilder.setDependencies(otherComponentBuilder.getDependencies());
}
thisComponentBuilder.getProperties().putAll(otherComponentBuilder.getProperties());
}
}
@ -552,6 +556,10 @@ public class ConfigurationSaxParser extends DefaultHandler {
return this.dependencies;
}
public void setDependencies(Set<String> dependencies) {
this.dependencies = dependencies;
}
public void addDependency(String dependency) {
this.dependencies.add(dependency);
}

View File

@ -78,6 +78,7 @@ public class ConfigurationParserTest {
assertEquals("li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler",
privilegeHandlerConfiguration.getImpl());
assertEquals(1, privilegeHandlerConfiguration.getPropertyKeys().size());
assertEquals(1, privilegeHandlerConfiguration.getDependencies().size());
assertTrue(privilegeHandlerConfiguration.getDependencies().contains("PersistenceHandler"));
assertEquals("PrivilegeConfig.xml", privilegeHandlerConfiguration.getString("privilegeConfigFile", null));
@ -178,5 +179,26 @@ public class ConfigurationParserTest {
assertEquals(2, realmHandlerConfiguration.getPropertyKeys().size());
assertEquals("EMPTY", realmHandlerConfiguration.getString("dataStoreMode", null));
assertEquals("noob", realmHandlerConfiguration.getString("foo", null));
// <Component>
// <name>ServiceHandler</name>
// <api>li.strolch.service.api.ServiceHandler</api>
// <impl>li.strolch.service.YetAnotherServiceHandler</impl>
// <depends>RealmHandler</depends>
// <Properties>
// <bar>foo</bar>
// </Properties>
// </Component>
ComponentConfiguration serviceHandlerConfiguration = strolchConfiguration
.getComponentConfiguration("ServiceHandler");
assertNotNull("Should have created a ServiceHandler Configuration", serviceHandlerConfiguration);
assertEquals("ServiceHandler", serviceHandlerConfiguration.getName());
assertEquals("li.strolch.service.api.ServiceHandler", serviceHandlerConfiguration.getApi());
assertEquals("li.strolch.service.YetAnotherServiceHandler", serviceHandlerConfiguration.getImpl());
assertEquals(2, serviceHandlerConfiguration.getDependencies().size());
assertTrue(serviceHandlerConfiguration.getDependencies().contains("RealmHandler"));
assertTrue(serviceHandlerConfiguration.getDependencies().contains("PrivilegeHandler"));
assertEquals(1, serviceHandlerConfiguration.getPropertyKeys().size());
assertEquals("foo", serviceHandlerConfiguration.getString("bar", null));
}
}

View File

@ -68,6 +68,17 @@
<foo>noob</foo>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.service.api.ServiceHandler</api>
<impl>li.strolch.service.YetAnotherServiceHandler</impl>
<depends>RealmHandler</depends>
<depends>PrivilegeHandler</depends>
<Properties>
<bar>foo</bar>
</Properties>
</Component>
</env>
</StrolchConfiguration>