Commit 5dfa0449 authored by DominikE's avatar DominikE

Make implementation property optional

parent 9b13ca7c
......@@ -124,13 +124,21 @@ public class Moduli
// --- load modules into modulesList ---
for (int i = 0; i <= config.getMaxIndex("module"); i++)
{
Class<? extends AModule> id = (Class<? extends AModule>) Class
.forName(implsPath + config.getString(moduleMessage(i, "[@id]")));
// --- create implementation- and properties-class ---
Class<? extends AModule> clazz = (Class<? extends AModule>) Class
.forName(implsPath + config.getString(moduleMessage(i, "implementation")));
Class<? extends AModule> clazz;
final String implementationKey = moduleMessage(i, ".implementation");
if (config.containsKey(implementationKey))
{
clazz = (Class<? extends AModule>) Class.forName(implsPath + config.getString(implementationKey));
} else
{
clazz = id;
}
// --- get properties from configuration and put it into a object[] ---
SubnodeConfiguration moduleConfig = config.configurationAt(moduleMessage(i, "properties"));
SubnodeConfiguration moduleConfig = config.configurationAt(moduleMessage(i, ".properties"));
Constructor<?> clazzConstructor = clazz.getConstructor();
......@@ -141,7 +149,7 @@ public class Moduli
module.setSubnodeConfiguration(moduleConfig);
// --- set id ---
module.setId(clazz);
module.setId(id);
// --- check if module is unique ---
if (modules.containsKey(module.getId()))
......@@ -150,7 +158,7 @@ public class Moduli
}
// --- set dependency-list ---
List<String> rawDependencyList = Arrays.asList(config.getStringArray(moduleMessage(i, "dependency")));
List<String> rawDependencyList = Arrays.asList(config.getStringArray(moduleMessage(i, ".dependency")));
List<Class<? extends AModule>> dependencyList = new ArrayList<>();
for (String dependency : rawDependencyList)
{
......@@ -159,7 +167,7 @@ public class Moduli
module.setDependencies(dependencyList);
modules.put(clazz, module);
modules.put(id, module);
log.trace("Module created: " + module);
}
......@@ -395,6 +403,6 @@ public class Moduli
private String moduleMessage(int moduleNumber, String property)
{
return "module(" + moduleNumber + ")." + property;
return "module(" + moduleNumber + ")" + property;
}
}
/*
* Copyright (c) 2009 - 2017, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.moduli.modules;
import edu.tigers.moduli.exceptions.InitModuleException;
import edu.tigers.moduli.exceptions.StartModuleException;
public class ConcreteTestModule extends TestModule
{
private boolean isConstructed = false;
private boolean isInitialized = false;
private boolean isStarted = false;
private boolean isStopped = false;
private boolean isDeinitialized = false;
public ConcreteTestModule()
{
this.isConstructed = true;
}
@Override
public void initModule() throws InitModuleException
{
isInitialized = true;
}
@Override
public void startModule() throws StartModuleException
{
isStarted = true;
}
@Override
public void stopModule()
{
isStopped = true;
}
@Override
public void deinitModule()
{
isDeinitialized = true;
}
@Override
public boolean isConstructed()
{
return isConstructed;
}
@Override
public boolean isInitialized()
{
return isInitialized;
}
@Override
public boolean isStarted()
{
return isStarted;
}
@Override
public boolean isStopped()
{
return isStopped;
}
@Override
public boolean isDeinitialized()
{
return isDeinitialized;
}
}
......@@ -5,79 +5,21 @@
package edu.tigers.moduli.modules;
import edu.tigers.moduli.AModule;
import edu.tigers.moduli.exceptions.InitModuleException;
import edu.tigers.moduli.exceptions.StartModuleException;
public class TestModule extends AModule
public abstract class TestModule extends AModule
{
private boolean isConstructed = false;
private boolean isInitialized = false;
private boolean isStarted = false;
private boolean isStopped = false;
private boolean isDeinitialized = false;
public abstract boolean isConstructed();
public TestModule()
{
this.isConstructed = true;
}
public abstract boolean isInitialized();
@Override
public void initModule() throws InitModuleException
{
isInitialized = true;
}
public abstract boolean isStarted();
@Override
public void startModule() throws StartModuleException
{
isStarted = true;
}
public abstract boolean isStopped();
@Override
public void stopModule()
{
isStopped = true;
}
@Override
public void deinitModule()
{
isDeinitialized = true;
}
public boolean isConstructed()
{
return isConstructed;
}
public boolean isInitialized()
{
return isInitialized;
}
public boolean isStarted()
{
return isStarted;
}
public boolean isStopped()
{
return isStopped;
}
public boolean isDeinitialized()
{
return isDeinitialized;
}
public abstract boolean isDeinitialized();
}
......@@ -7,14 +7,13 @@
<environment>MODULI</environment>
</globalConfiguration>
<module id="testModule">
<implementation>edu.tigers.moduli.modules.TestModule</implementation>
<module id="edu.tigers.moduli.modules.TestModule">
<implementation>edu.tigers.moduli.modules.ConcreteTestModule</implementation>
<properties></properties>
</module>
<module id="configuredModule">
<implementation>edu.tigers.moduli.modules.ConfiguredTestModule</implementation>
<module id="edu.tigers.moduli.modules.ConfiguredTestModule">
<properties>
<testProperty>exists</testProperty>
......
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