diff --git a/client/ext-resources/all/world.xml b/client/ext-resources/all/world.xml index e1373e3..8ce9d7f 100644 --- a/client/ext-resources/all/world.xml +++ b/client/ext-resources/all/world.xml @@ -1 +1,175 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/java/ru/trader/core/Vendor.java b/core/src/main/java/ru/trader/core/Vendor.java index 97c4099..74b8644 100644 --- a/core/src/main/java/ru/trader/core/Vendor.java +++ b/core/src/main/java/ru/trader/core/Vendor.java @@ -18,6 +18,7 @@ public interface Vendor extends Comparable { void add(SERVICE_TYPE service); void remove(SERVICE_TYPE service); boolean has(SERVICE_TYPE service); + Collection getServices(); void add(Offer offer); Offer addOffer(OFFER_TYPE type, Item item, double price, long count); diff --git a/core/src/main/java/ru/trader/store/berkeley/VendorProxy.java b/core/src/main/java/ru/trader/store/berkeley/VendorProxy.java index d438d0c..7df7c9d 100644 --- a/core/src/main/java/ru/trader/store/berkeley/VendorProxy.java +++ b/core/src/main/java/ru/trader/store/berkeley/VendorProxy.java @@ -59,6 +59,11 @@ public class VendorProxy extends AbstractVendor { store.getVendorAccessor().update(vendor); } + @Override + public Collection getServices() { + return vendor.getServices(); + } + @Override protected void addOffer(Offer offer) { OfferProxy oProxy = ((OfferProxy)offer); diff --git a/core/src/main/java/ru/trader/store/berkeley/entities/BDBVendor.java b/core/src/main/java/ru/trader/store/berkeley/entities/BDBVendor.java index 05ad67f..689bd3d 100644 --- a/core/src/main/java/ru/trader/store/berkeley/entities/BDBVendor.java +++ b/core/src/main/java/ru/trader/store/berkeley/entities/BDBVendor.java @@ -3,6 +3,7 @@ package ru.trader.store.berkeley.entities; import com.sleepycat.persist.model.*; import ru.trader.core.SERVICE_TYPE; +import java.util.Collection; import java.util.EnumSet; @Entity(version = 1) @@ -69,4 +70,7 @@ public class BDBVendor { return services.contains(service); } + public Collection getServices() { + return services; + } } diff --git a/core/src/main/java/ru/trader/store/simple/MarketDocHandler.java b/core/src/main/java/ru/trader/store/simple/MarketDocHandler.java index 4474d9e..301ae27 100644 --- a/core/src/main/java/ru/trader/store/simple/MarketDocHandler.java +++ b/core/src/main/java/ru/trader/store/simple/MarketDocHandler.java @@ -16,8 +16,11 @@ public class MarketDocHandler extends DefaultHandler { protected final static String MARKET = "market"; protected final static String ITEM_LIST = "items"; protected final static String ITEM = "item"; - protected final static String VENDOR_LIST = "places"; + protected final static String PLACES_LIST = "places"; + protected final static String PLACE = "place"; protected final static String VENDOR = "vendor"; + protected final static String SERVICES_LIST = "services"; + protected final static String SERVICE = "service"; protected final static String OFFER = "offer"; protected final static String GROUP = "group"; @@ -25,6 +28,7 @@ public class MarketDocHandler extends DefaultHandler { protected final static String NAME_ATTR = "name"; protected final static String TYPE_ATTR = "type"; protected final static String PRICE_ATTR = "price"; + protected final static String COUNT_ATTR = "count"; protected final static String ITEM_ATTR = "item"; protected final static String X_ATTR = "x"; protected final static String Y_ATTR = "y"; @@ -32,7 +36,7 @@ public class MarketDocHandler extends DefaultHandler { protected SimpleMarket world; protected Vendor curVendor; - protected Place curSystem; + protected Place curPlace; protected Group curGroup; protected final HashMap items = new HashMap<>(); @@ -46,8 +50,12 @@ public class MarketDocHandler extends DefaultHandler { switch (qName){ case ITEM: parseItem(attributes); break; + case PLACE: parsePlace(attributes); + break; case VENDOR: parseVendor(attributes); break; + case SERVICE: parseService(attributes); + break; case OFFER: parseOffer(attributes); break; case GROUP: parseGroup(attributes); @@ -58,7 +66,9 @@ public class MarketDocHandler extends DefaultHandler { @Override public void endElement(String uri, String localName, String qName) throws SAXException { switch (qName){ - case VENDOR: curVendor = null; curSystem = null; + case PLACE: curPlace = null; + break; + case VENDOR: curVendor = null; break; case GROUP: curGroup = null; break; @@ -70,15 +80,28 @@ public class MarketDocHandler extends DefaultHandler { world.commit(); } - protected void parseVendor(Attributes attributes) throws SAXException { + protected void parsePlace(Attributes attributes) throws SAXException { String name = attributes.getValue(NAME_ATTR); String x = attributes.getValue(X_ATTR); String y = attributes.getValue(Y_ATTR); String z = attributes.getValue(Z_ATTR); - LOG.debug("parse vendor {} position ({};{};{})", name, x, y, z); - onVendor(name, x != null ? Double.valueOf(x) : 0, y != null ? Double.valueOf(y) : 0, z != null ? Double.valueOf(z) : 0); + LOG.debug("parse place {} position ({};{};{})", name, x, y, z); + onPlace(name, x != null ? Double.valueOf(x) : 0, y != null ? Double.valueOf(y) : 0, z != null ? Double.valueOf(z) : 0); } + protected void parseVendor(Attributes attributes) throws SAXException { + String name = attributes.getValue(NAME_ATTR); + LOG.debug("parse vendor {} position ({};{};{})", name); + onVendor(name); + } + + protected void parseService(Attributes attributes) throws SAXException { + SERVICE_TYPE type = SERVICE_TYPE.valueOf(attributes.getValue(TYPE_ATTR)); + LOG.debug("add service {}", type); + onService(type); + } + + protected void parseItem(Attributes attributes) throws SAXException { String name = attributes.getValue(NAME_ATTR); String id = attributes.getValue(ID_ATTR); @@ -93,7 +116,8 @@ public class MarketDocHandler extends DefaultHandler { throw new SAXException(String.format("Item (id = %s) not found", refid)); OFFER_TYPE offerType = OFFER_TYPE.valueOf(attributes.getValue(TYPE_ATTR)); double price = Double.valueOf(attributes.getValue(PRICE_ATTR)); - onOffer(offerType, item, price); + long count = Long.valueOf(attributes.getValue(COUNT_ATTR)); + onOffer(offerType, item, price, count); } protected void parseGroup(Attributes attributes) throws SAXException { @@ -103,16 +127,20 @@ public class MarketDocHandler extends DefaultHandler { onGroup(name, type); } - protected void onOffer(OFFER_TYPE offerType, Item item, double price){ - if (curVendor == null){ - curVendor = curSystem.addVendor("STATION OF "+curSystem.getName()); - curVendor.add(SERVICE_TYPE.MARKET); - } - curVendor.addOffer(offerType, item, price, 1000); + protected void onOffer(OFFER_TYPE offerType, Item item, double price, long count){ + curVendor.addOffer(offerType, item, price, count); } - protected void onVendor(String name, double x, double y, double z){ - curSystem = world.addPlace(name, x, y, z); + protected void onPlace(String name, double x, double y, double z){ + curPlace = world.addPlace(name, x, y, z); + } + + protected void onVendor(String name){ + curVendor = curPlace.addVendor(name); + } + + protected void onService(SERVICE_TYPE type){ + curVendor.add(type); } protected void onItem(String name, String id) { diff --git a/core/src/main/java/ru/trader/store/simple/MarketStreamWriter.java b/core/src/main/java/ru/trader/store/simple/MarketStreamWriter.java index 0fd15c2..bf0009a 100644 --- a/core/src/main/java/ru/trader/store/simple/MarketStreamWriter.java +++ b/core/src/main/java/ru/trader/store/simple/MarketStreamWriter.java @@ -69,7 +69,7 @@ public class MarketStreamWriter { } protected void writeVendors() throws XMLStreamException { - out.writeStartElement(MarketDocHandler.VENDOR_LIST); + out.writeStartElement(MarketDocHandler.PLACES_LIST); for (Place place : market.get()) { for (Vendor vendor : place.get()) { writeVendor(vendor); @@ -85,6 +85,12 @@ public class MarketStreamWriter { out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(place.getX())); out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(place.getY())); out.writeAttribute(MarketDocHandler.Z_ATTR, String.valueOf(place.getZ())); + out.writeStartElement(MarketDocHandler.SERVICES_LIST); + for (SERVICE_TYPE service_type : vendor.getServices()) { + out.writeEmptyElement(MarketDocHandler.SERVICE); + out.writeAttribute(MarketDocHandler.TYPE_ATTR, service_type.toString()); + } + out.writeEndElement(); for (Offer offer : vendor.getAllSellOffers()) { writeOffer(offer); } diff --git a/core/src/main/java/ru/trader/store/simple/SimpleVendor.java b/core/src/main/java/ru/trader/store/simple/SimpleVendor.java index fc9b453..7cc74e0 100644 --- a/core/src/main/java/ru/trader/store/simple/SimpleVendor.java +++ b/core/src/main/java/ru/trader/store/simple/SimpleVendor.java @@ -83,6 +83,11 @@ public class SimpleVendor extends AbstractVendor { return services.contains(service); } + @Override + public Collection getServices() { + return services; + } + @Override public Collection get(OFFER_TYPE offerType) { switch (offerType) { diff --git a/core/src/main/resources/store/trader.xsd b/core/src/main/resources/store/trader.xsd index 6fe76e6..2c5afc9 100644 --- a/core/src/main/resources/store/trader.xsd +++ b/core/src/main/resources/store/trader.xsd @@ -6,13 +6,19 @@ - + - + - + + + + + + + @@ -44,9 +50,9 @@ - + - + @@ -54,10 +60,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/test/resources/test.xml b/core/src/test/resources/test.xml index 34bc240..a6db7ad 100644 --- a/core/src/test/resources/test.xml +++ b/core/src/test/resources/test.xml @@ -9,11 +9,12 @@ - - - - - - + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/world.xml b/core/src/test/resources/world.xml index 0698c23..cc75e9b 100644 --- a/core/src/test/resources/world.xml +++ b/core/src/test/resources/world.xml @@ -1 +1,2381 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file