Improved object generation
This commit is contained in:
parent
01e43e20a7
commit
0ba95a1728
@ -1,5 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE channels [
|
||||
<!ELEMENT channels (channel)*>
|
||||
<!ELEMENT channel (#PCDATA)>
|
||||
<!ATTLIST channel
|
||||
type CDATA #REQUIRED>
|
||||
]>
|
||||
<channels>
|
||||
<channel type="MEET"></channel>
|
||||
<channel type="MEAT"></channel>
|
||||
<channel type="VEGETABLE"></channel>
|
||||
<channel type="FRUIT"></channel>
|
||||
</channels>
|
||||
@ -1,18 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE nodes [
|
||||
<!ELEMENT nodes (node)*>
|
||||
<!ELEMENT node (money|channels)*>
|
||||
<!ATTLIST node
|
||||
type CDATA #REQUIRED>
|
||||
<!ELEMENT money (#PCDATA)>
|
||||
<!ELEMENT channels (#PCDATA)>
|
||||
]>
|
||||
<nodes>
|
||||
<node type = "Farmer">
|
||||
<money>100</money>
|
||||
<channels>MEET PURCHASE;VEGETABLE PURCHASE;FRUIT PURCHASE</channels>
|
||||
<channels>MEAT PURCHASE;VEGETABLE PURCHASE;FRUIT PURCHASE</channels>
|
||||
</node>
|
||||
<node type = "Processor">
|
||||
<money>0</money>
|
||||
<channels>MEET SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||
<channels>MEAT SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||
</node>
|
||||
<node type = "Distributor">
|
||||
<money>1500</money>
|
||||
<channels>MEET SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||
<channels>MEAT SALE_AND_PURCHASE;VEGETABLE SALE_AND_PURCHASE;FRUIT SALE_AND_PURCHASE</channels>
|
||||
</node>
|
||||
<node type = "Customer">
|
||||
<money>250</money>
|
||||
<channels>MEET SALE;VEGETABLE SALE;FRUIT SALE</channels>
|
||||
<channels>MEAT SALE;VEGETABLE SALE;FRUIT SALE</channels>
|
||||
</node>
|
||||
</nodes>
|
||||
@ -1,3 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE products [
|
||||
<!ELEMENT products (product)*>
|
||||
<!ELEMENT product (name|type|price)*>
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
<!ELEMENT type (#PCDATA)>
|
||||
<!ELEMENT price (#PCDATA)>
|
||||
]>
|
||||
<products>
|
||||
<product>
|
||||
<name>jablko</name>
|
||||
@ -31,17 +39,17 @@
|
||||
</product>
|
||||
<product>
|
||||
<name>vepřové</name>
|
||||
<type>MEET</type>
|
||||
<type>MEAT</type>
|
||||
<price>20</price>
|
||||
</product>
|
||||
<product>
|
||||
<name>hovězí</name>
|
||||
<type>MEET</type>
|
||||
<type>MEAT</type>
|
||||
<price>50</price>
|
||||
</product>
|
||||
<product>
|
||||
<name>kuřecí</name>
|
||||
<type>MEET</type>
|
||||
<type>MEAT</type>
|
||||
<price>30</price>
|
||||
</product>
|
||||
</products>
|
||||
@ -1,3 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE scenarios [
|
||||
<!ELEMENT scenarios (scenario)*>
|
||||
<!ELEMENT scenario (steps)*>
|
||||
<!ATTLIST scenario
|
||||
type CDATA #REQUIRED>
|
||||
<!ELEMENT steps (#PCDATA)>
|
||||
]>
|
||||
<scenarios>
|
||||
<scenario type="Farmer">
|
||||
<steps>
|
||||
|
||||
7
pom.xml
7
pom.xml
@ -9,9 +9,10 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.money</groupId>
|
||||
<artifactId>money-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<groupId>org.javamoney</groupId>
|
||||
<artifactId>moneta</artifactId>
|
||||
<version>1.4.2</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -6,7 +6,8 @@ import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ConfigurationParser;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResult;
|
||||
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||
import cz.cvut.fel.sit.omo.foodchain.pool.ChannelPool;
|
||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@ -22,6 +23,11 @@ public class FoodChain
|
||||
{
|
||||
parseChannels();
|
||||
parseNodes();
|
||||
parseProducts();
|
||||
parseScenarios();
|
||||
|
||||
getFactoryManager().getPoolDatabaseInstance().getChannelPoolInstance().findAll().stream().forEach(ch -> System.out.println(ch.getProductType()));
|
||||
getFactoryManager().getPoolDatabaseInstance().getNodePoolInstance().findAll().stream().forEach(ch -> System.out.println(ch));
|
||||
}
|
||||
|
||||
public static FactoryManager getFactoryManager()
|
||||
@ -29,7 +35,6 @@ public class FoodChain
|
||||
return factoryManager;
|
||||
}
|
||||
|
||||
|
||||
// todo maybe some refactoring needed?
|
||||
// add other entities
|
||||
public static void parseChannels()
|
||||
@ -37,7 +42,7 @@ public class FoodChain
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("../conf/channels.xml");
|
||||
ConfigurationParser.parseDocument("conf/channels.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("channel");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
@ -51,17 +56,14 @@ public class FoodChain
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseNodes()
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("../conf/nodes.xml");
|
||||
ConfigurationParser.parseDocument("conf/nodes.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("node");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
for (ParserResultElement el : elements)
|
||||
@ -75,7 +77,45 @@ public class FoodChain
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
catch (Exception e)
|
||||
}
|
||||
|
||||
public static void parseProducts()
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/products.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("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()
|
||||
{
|
||||
try
|
||||
{
|
||||
// parse channel configuration
|
||||
ConfigurationParser.parseDocument("conf/scenarios.xml");
|
||||
ParserResult parserResult = ConfigurationParser.getElements("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());
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class NodeFactory
|
||||
{
|
||||
nodeType = NodeType.valueOf(input.getAttribute("type"));
|
||||
|
||||
subsChannels = input.getChild("subscribed_channels");
|
||||
subsChannels = input.getChild("channels");
|
||||
startMoney = Double.parseDouble(input.getChild("money"));
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
|
||||
@ -21,7 +21,6 @@ public class ScenarioFactory
|
||||
{
|
||||
Scenario s = null;
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,10 +31,19 @@ public class ConfigurationParser {
|
||||
Node tmpNode = elements.item(i);
|
||||
ParserResultElement element = new ParserResultElement();
|
||||
for (int j = 0; j < tmpNode.getAttributes().getLength(); j++) {
|
||||
element.addAttribute(tmpNode.getAttributes().item(i).getNodeName(), tmpNode.getAttributes().item(i).getTextContent());
|
||||
element
|
||||
.addAttribute(
|
||||
tmpNode
|
||||
.getAttributes()
|
||||
.item(j)
|
||||
.getNodeName(),
|
||||
tmpNode
|
||||
.getAttributes()
|
||||
.item(j)
|
||||
.getTextContent());
|
||||
}
|
||||
for (int j = 0; j < tmpNode.getChildNodes().getLength(); j++) {
|
||||
element.addChild(tmpNode.getChildNodes().item(i).getNodeName(), tmpNode.getChildNodes().item(i).getTextContent());
|
||||
element.addChild(tmpNode.getChildNodes().item(j).getNodeName(), tmpNode.getChildNodes().item(j).getTextContent());
|
||||
}
|
||||
resultList.addElement(element);
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ public class ParserResultElement {
|
||||
private Map<String, String> children;
|
||||
|
||||
public ParserResultElement() {
|
||||
children = new HashMap<>();
|
||||
attributes = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@ -3,5 +3,4 @@ package cz.cvut.fel.sit.omo.foodchain.pool;
|
||||
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||
|
||||
public class NodePool extends PoolListBase<NodeBase> {
|
||||
//TODO Tomas Angelo
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ public class Ticker {
|
||||
public static void start() {
|
||||
timer = new Timer(500, actionEvent -> {
|
||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||
db.getChannelPoolInstance().findAll().forEach(ch -> ch.tick()); // change TTL of requirements
|
||||
db.getNodePoolInstance().findAll().forEach(ch -> ch.tick()); // do next step in scenario
|
||||
db.getProductPoolInstance().findAll().forEach(ch -> ch.tick()); // change duration of action
|
||||
db.getScenarioPoolInstance().findAll().forEach(ch -> ch.tick()); // maybe unnecessary
|
||||
// db.getChannelPoolInstance().findAll().forEach(ch -> ch.tick()); // change TTL of requirements
|
||||
// db.getNodePoolInstance().findAll().forEach(ch -> ch.tick()); // do next step in scenario
|
||||
// db.getProductPoolInstance().findAll().forEach(ch -> ch.tick()); // change duration of action
|
||||
// db.getScenarioPoolInstance().findAll().forEach(ch -> ch.tick()); // maybe unnecessary
|
||||
});
|
||||
timer.start();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user