Refactored document parsing in main().
Added configuration file paths from args.
This commit is contained in:
parent
bfde92e92c
commit
f5c2ad80a7
@ -22,10 +22,20 @@ public class FoodChain
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
parseChannels();
|
||||
parseNodes();
|
||||
parseProducts();
|
||||
parseScenarios();
|
||||
if(args.length < 4)
|
||||
{
|
||||
parseChannels("conf/channels.xml");
|
||||
parseNodes("conf/nodes.xml");
|
||||
parseProducts("conf/products.xml");
|
||||
parseScenarios("conf/scenarios.xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
parseChannels(args[1]);
|
||||
parseNodes(args[2]);
|
||||
parseProducts(args[3]);
|
||||
parseScenarios(args[4]);
|
||||
}
|
||||
|
||||
// getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().findAll().stream().forEach(ch -> System.out.println(ch.getProductType()));
|
||||
// getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().findAll().stream().forEach(ch -> System.out.println(ch));
|
||||
@ -33,7 +43,10 @@ public class FoodChain
|
||||
// getFactoryManager().getPoolDatabaseInstance().getScenarioPoolInstance().findAll().stream().forEach(ch -> ch.getSteps().stream().forEach(s -> System.out.println(s)));
|
||||
|
||||
Ticker.start();
|
||||
while (Ticker.getTimer().isRunning());
|
||||
while (Ticker.getTimer().isRunning())
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static FactoryManager getFactoryManager()
|
||||
@ -41,89 +54,61 @@ public class FoodChain
|
||||
return factoryManager;
|
||||
}
|
||||
|
||||
// todo maybe some refactoring needed?
|
||||
// add other entities
|
||||
public static void parseChannels()
|
||||
public static ParserResult parseDocument(String path, String rootElementTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/channels.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("channel");
|
||||
ConfigurationParser.parseDocument(path);
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException | IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
return ConfigurationParser.getElements(rootElementTag);
|
||||
}
|
||||
|
||||
public static void parseChannels(String path)
|
||||
{
|
||||
ParserResult parserResult = parseDocument(path, "channel");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
{
|
||||
ChannelBase res = getFactoryManager().getChannelFactoryInstance().makeChannel(el);
|
||||
getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().add(res);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException | IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseNodes()
|
||||
public static void parseNodes(String path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/nodes.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("node");
|
||||
ParserResult parserResult = parseDocument(path, "node");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
{
|
||||
NodeBase res = getFactoryManager().getNodeFactoryInstance().makeNode(el);
|
||||
getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().add(res);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException | IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseProducts()
|
||||
public static void parseProducts(String path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/products.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("product");
|
||||
ParserResult parserResult = parseDocument(path, "product");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
{
|
||||
Product res = getFactoryManager().getProductFactoryInstance().makeProduct(el);
|
||||
getFactoryManager().getPoolDatabaseInstance().getProductPoolInstance().add(res);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException | IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseScenarios()
|
||||
public static void parseScenarios(String path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/scenarios.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("scenario");
|
||||
ParserResult parserResult = parseDocument(path, "scenario");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
{
|
||||
Scenario res = getFactoryManager().getScenarioFactoryInstance().makeScenario(el);
|
||||
getFactoryManager().getPoolDatabaseInstance().getScenarioPoolInstance().add(res);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException | IOException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user