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

View File

@@ -18,6 +18,7 @@ public interface Vendor extends Comparable<Vendor> {
void add(SERVICE_TYPE service);
void remove(SERVICE_TYPE service);
boolean has(SERVICE_TYPE service);
Collection<SERVICE_TYPE> getServices();
void add(Offer offer);
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);
}
@Override
public Collection<SERVICE_TYPE> getServices() {
return vendor.getServices();
}
@Override
protected void addOffer(Offer offer) {
OfferProxy oProxy = ((OfferProxy)offer);

View File

@@ -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<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 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<String,Item> 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) {

View File

@@ -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);
}

View File

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

View File

@@ -6,13 +6,19 @@
<xs:complexType name="marketType">
<xs:sequence>
<xs:element name="items" type="itemsType"/>
<xs:element name="places" type="vendorsType"/>
<xs:element name="places" type="placesType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="vendorsType">
<xs:complexType name="placesType">
<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:complexType>
@@ -44,9 +50,9 @@
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="vendorType" mixed="true">
<xs:complexType name="placeType" mixed="true">
<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:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="x" type="xs:double" use="optional"/>
@@ -54,10 +60,34 @@
<xs:attribute name="z" type="xs:double" use="optional"/>
</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:attribute name="item" type="xs:IDREFS" use="required"/>
<xs:attribute name="type" type="OFFER_TYPE" use="required"/>
<xs:attribute name="price" type="xs:double" use="required"/>
<xs:attribute name="count" type="xs:long" use="required"/>
</xs:complexType>
<xs:simpleType name="OFFER_TYPE">

View File

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

File diff suppressed because one or more lines are too long