Archived
0

change xml store format

This commit is contained in:
iMoHax
2014-11-18 13:16:35 +03:00
parent cf34c7cfb0
commit 5ffe7c4b3a
10 changed files with 2663 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@@ -18,6 +18,7 @@ public interface Vendor extends Comparable<Vendor> {
void add(SERVICE_TYPE service); void add(SERVICE_TYPE service);
void remove(SERVICE_TYPE service); void remove(SERVICE_TYPE service);
boolean has(SERVICE_TYPE service); boolean has(SERVICE_TYPE service);
Collection<SERVICE_TYPE> getServices();
void add(Offer offer); void add(Offer offer);
Offer addOffer(OFFER_TYPE type, Item item, double price, long count); Offer addOffer(OFFER_TYPE type, Item item, double price, long count);

View File

@@ -59,6 +59,11 @@ public class VendorProxy extends AbstractVendor {
store.getVendorAccessor().update(vendor); store.getVendorAccessor().update(vendor);
} }
@Override
public Collection<SERVICE_TYPE> getServices() {
return vendor.getServices();
}
@Override @Override
protected void addOffer(Offer offer) { protected void addOffer(Offer offer) {
OfferProxy oProxy = ((OfferProxy)offer); OfferProxy oProxy = ((OfferProxy)offer);

View File

@@ -3,6 +3,7 @@ package ru.trader.store.berkeley.entities;
import com.sleepycat.persist.model.*; import com.sleepycat.persist.model.*;
import ru.trader.core.SERVICE_TYPE; import ru.trader.core.SERVICE_TYPE;
import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
@Entity(version = 1) @Entity(version = 1)
@@ -69,4 +70,7 @@ public class BDBVendor {
return services.contains(service); return services.contains(service);
} }
public Collection<SERVICE_TYPE> getServices() {
return services;
}
} }

View File

@@ -16,8 +16,11 @@ public class MarketDocHandler extends DefaultHandler {
protected final static String MARKET = "market"; protected final static String MARKET = "market";
protected final static String ITEM_LIST = "items"; protected final static String ITEM_LIST = "items";
protected final static String ITEM = "item"; 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 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 OFFER = "offer";
protected final static String GROUP = "group"; 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 NAME_ATTR = "name";
protected final static String TYPE_ATTR = "type"; protected final static String TYPE_ATTR = "type";
protected final static String PRICE_ATTR = "price"; 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 ITEM_ATTR = "item";
protected final static String X_ATTR = "x"; protected final static String X_ATTR = "x";
protected final static String Y_ATTR = "y"; protected final static String Y_ATTR = "y";
@@ -32,7 +36,7 @@ public class MarketDocHandler extends DefaultHandler {
protected SimpleMarket world; protected SimpleMarket world;
protected Vendor curVendor; protected Vendor curVendor;
protected Place curSystem; protected Place curPlace;
protected Group curGroup; protected Group curGroup;
protected final HashMap<String,Item> items = new HashMap<>(); protected final HashMap<String,Item> items = new HashMap<>();
@@ -46,8 +50,12 @@ public class MarketDocHandler extends DefaultHandler {
switch (qName){ switch (qName){
case ITEM: parseItem(attributes); case ITEM: parseItem(attributes);
break; break;
case PLACE: parsePlace(attributes);
break;
case VENDOR: parseVendor(attributes); case VENDOR: parseVendor(attributes);
break; break;
case SERVICE: parseService(attributes);
break;
case OFFER: parseOffer(attributes); case OFFER: parseOffer(attributes);
break; break;
case GROUP: parseGroup(attributes); case GROUP: parseGroup(attributes);
@@ -58,7 +66,9 @@ public class MarketDocHandler extends DefaultHandler {
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
switch (qName){ switch (qName){
case VENDOR: curVendor = null; curSystem = null; case PLACE: curPlace = null;
break;
case VENDOR: curVendor = null;
break; break;
case GROUP: curGroup = null; case GROUP: curGroup = null;
break; break;
@@ -70,15 +80,28 @@ public class MarketDocHandler extends DefaultHandler {
world.commit(); world.commit();
} }
protected void parseVendor(Attributes attributes) throws SAXException { protected void parsePlace(Attributes attributes) throws SAXException {
String name = attributes.getValue(NAME_ATTR); String name = attributes.getValue(NAME_ATTR);
String x = attributes.getValue(X_ATTR); String x = attributes.getValue(X_ATTR);
String y = attributes.getValue(Y_ATTR); String y = attributes.getValue(Y_ATTR);
String z = attributes.getValue(Z_ATTR); String z = attributes.getValue(Z_ATTR);
LOG.debug("parse vendor {} position ({};{};{})", name, x, y, z); LOG.debug("parse place {} 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); 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 { protected void parseItem(Attributes attributes) throws SAXException {
String name = attributes.getValue(NAME_ATTR); String name = attributes.getValue(NAME_ATTR);
String id = attributes.getValue(ID_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)); throw new SAXException(String.format("Item (id = %s) not found", refid));
OFFER_TYPE offerType = OFFER_TYPE.valueOf(attributes.getValue(TYPE_ATTR)); OFFER_TYPE offerType = OFFER_TYPE.valueOf(attributes.getValue(TYPE_ATTR));
double price = Double.valueOf(attributes.getValue(PRICE_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 { protected void parseGroup(Attributes attributes) throws SAXException {
@@ -103,16 +127,20 @@ public class MarketDocHandler extends DefaultHandler {
onGroup(name, type); onGroup(name, type);
} }
protected void onOffer(OFFER_TYPE offerType, Item item, double price){ protected void onOffer(OFFER_TYPE offerType, Item item, double price, long count){
if (curVendor == null){ curVendor.addOffer(offerType, item, price, count);
curVendor = curSystem.addVendor("STATION OF "+curSystem.getName());
curVendor.add(SERVICE_TYPE.MARKET);
}
curVendor.addOffer(offerType, item, price, 1000);
} }
protected void onVendor(String name, double x, double y, double z){ protected void onPlace(String name, double x, double y, double z){
curSystem = world.addPlace(name, x, y, 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) { protected void onItem(String name, String id) {

View File

@@ -69,7 +69,7 @@ public class MarketStreamWriter {
} }
protected void writeVendors() throws XMLStreamException { protected void writeVendors() throws XMLStreamException {
out.writeStartElement(MarketDocHandler.VENDOR_LIST); out.writeStartElement(MarketDocHandler.PLACES_LIST);
for (Place place : market.get()) { for (Place place : market.get()) {
for (Vendor vendor : place.get()) { for (Vendor vendor : place.get()) {
writeVendor(vendor); writeVendor(vendor);
@@ -85,6 +85,12 @@ public class MarketStreamWriter {
out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(place.getX())); out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(place.getX()));
out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(place.getY())); out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(place.getY()));
out.writeAttribute(MarketDocHandler.Z_ATTR, String.valueOf(place.getZ())); 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()) { for (Offer offer : vendor.getAllSellOffers()) {
writeOffer(offer); writeOffer(offer);
} }

View File

@@ -83,6 +83,11 @@ public class SimpleVendor extends AbstractVendor {
return services.contains(service); return services.contains(service);
} }
@Override
public Collection<SERVICE_TYPE> getServices() {
return services;
}
@Override @Override
public Collection<Offer> get(OFFER_TYPE offerType) { public Collection<Offer> get(OFFER_TYPE offerType) {
switch (offerType) { switch (offerType) {

View File

@@ -6,13 +6,19 @@
<xs:complexType name="marketType"> <xs:complexType name="marketType">
<xs:sequence> <xs:sequence>
<xs:element name="items" type="itemsType"/> <xs:element name="items" type="itemsType"/>
<xs:element name="places" type="vendorsType"/> <xs:element name="places" type="placesType"/>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
<xs:complexType name="vendorsType"> <xs:complexType name="placesType">
<xs:sequence> <xs:sequence>
<xs:element name="vendor" type="vendorType" maxOccurs="unbounded"/> <xs:element name="place" type="placeType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="servicesType">
<xs:sequence>
<xs:element name="service" type="serviceType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
@@ -44,9 +50,9 @@
<xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType> </xs:complexType>
<xs:complexType name="vendorType" mixed="true"> <xs:complexType name="placeType" mixed="true">
<xs:sequence> <xs:sequence>
<xs:element name="offer" type="offerType" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="vendor" type="vendorType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence> </xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="x" type="xs:double" use="optional"/> <xs:attribute name="x" type="xs:double" use="optional"/>
@@ -54,10 +60,34 @@
<xs:attribute name="z" type="xs:double" use="optional"/> <xs:attribute name="z" type="xs:double" use="optional"/>
</xs:complexType> </xs:complexType>
<xs:complexType name="vendorType" mixed="true">
<xs:sequence>
<xs:element name="services" type="servicesType"/>
<xs:element name="offer" type="offerType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="serviceType">
<xs:attribute name="type" type="SERVICE_TYPE" use="required"/>
</xs:complexType>
<xs:simpleType name="SERVICE_TYPE">
<xs:restriction base="xs:string">
<xs:enumeration value="MARKET"/>
<xs:enumeration value="BLACK_MARKET"/>
<xs:enumeration value="REPAIR"/>
<xs:enumeration value="MUNITION"/>
<xs:enumeration value="OUTFIT"/>
<xs:enumeration value="SHIPYARD"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="offerType"> <xs:complexType name="offerType">
<xs:attribute name="item" type="xs:IDREFS" use="required"/> <xs:attribute name="item" type="xs:IDREFS" use="required"/>
<xs:attribute name="type" type="OFFER_TYPE" use="required"/> <xs:attribute name="type" type="OFFER_TYPE" use="required"/>
<xs:attribute name="price" type="xs:double" use="required"/> <xs:attribute name="price" type="xs:double" use="required"/>
<xs:attribute name="count" type="xs:long" use="required"/>
</xs:complexType> </xs:complexType>
<xs:simpleType name="OFFER_TYPE"> <xs:simpleType name="OFFER_TYPE">

View File

@@ -9,11 +9,12 @@
<item name="Item 6" id="i6"/> <item name="Item 6" id="i6"/>
</items> </items>
<places> <places>
<vendor name="Vendor 1"> <place name="Place 1">
<offer item="i1" type="SELL" price="140"/> <vendor name="Vendor 1">
</vendor> <services><service type="MARKET"/></services>
<offer item="i1" type="SELL" price="140" count="10"/>
<vendor name="Empty system" x="1" y="2" z="3"/> </vendor>
</place>
<place name="Empty system" x="1" y="2" z="3"/>
</places> </places>
</market> </market>

File diff suppressed because one or more lines are too long