Commit b868ff2f authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Fixed default configurator-bug

leading to sub-elements with the same tag being initialized only once
(e.g., multiple topology `<view>` instances within `<topology>` would
only result in *one* topology view being instantiated)
parent 0c80da45
......@@ -58,10 +58,12 @@ import de.tud.kom.p2psim.api.scenario.Composable;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.scenario.Configurator;
import de.tud.kom.p2psim.impl.util.toolkits.Dom4jToolkit;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.Component;
import de.tudarmstadt.maki.simonstrator.api.component.GlobalComponent;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -190,6 +192,10 @@ public class DefaultConfigurator implements Configurator {
@Override
public void register(String name, Component component) {
configurables.put(name, component);
if (component instanceof GlobalComponent) {
// register in the binder
Binder.registerComponent((GlobalComponent) component);
}
}
/**
......@@ -235,9 +241,7 @@ public class DefaultConfigurator implements Configurator {
assert root.getName().equals(Configurator.CONFIGURATION_ROOT_TAG);
configureFirstLevel(root);
componentList = null;
return configurables.values();
return componentList;
} catch (DocumentException e) {
throw new ConfigurationException(
"Failed to load configuration from file " + configFile, e);
......@@ -320,12 +324,17 @@ public class DefaultConfigurator implements Configurator {
Monitor.log(DefaultConfigurator.class, Level.DEBUG,
"Configure component " + name);
/*
* FIXED (BR) - if a component specifies a class-tag, do NOT reuse the
* old component for configuration. Instead, create a new component.
*/
// Constructor Attributes
Object component = configurables.get(name);
// register new component (if not done yet)
Set<String> consAttrs = new HashSet<String>(); // attributes that were
// part of the
// constructor
if (component == null) {
Set<String> consAttrs = new HashSet<String>();
String clazz = getAttributeValue(elem.attribute(CLASS_TAG));
if (clazz != null) {
// Create component
component = createComponent(elem, consAttrs);
}
......@@ -370,8 +379,9 @@ public class DefaultConfigurator implements Configurator {
component = createInstance(className,
getAttributeValue(elem.attribute(STATIC_CREATION_METHOD_TAG)),
consAttrs, elem);
if (component instanceof Component)
if (component instanceof Component) {
register(elem.getName(), (Component) component);
}
// composable can use other components
if (component instanceof Composable) {
Monitor.log(DefaultConfigurator.class, Level.DEBUG,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment