change xml store format
This commit is contained in:
@@ -30,6 +30,7 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
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 DISTANCE_ATTR = "distance";
|
||||
protected final static String X_ATTR = "x";
|
||||
protected final static String Y_ATTR = "y";
|
||||
protected final static String Z_ATTR = "z";
|
||||
@@ -91,8 +92,9 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
|
||||
protected void parseVendor(Attributes attributes) throws SAXException {
|
||||
String name = attributes.getValue(NAME_ATTR);
|
||||
LOG.debug("parse vendor {} position ({};{};{})", name);
|
||||
onVendor(name);
|
||||
String distance = attributes.getValue(DISTANCE_ATTR);
|
||||
LOG.debug("parse vendor {}, distance {}", name, distance);
|
||||
onVendor(name, distance != null ? Double.valueOf(distance) : 0);
|
||||
}
|
||||
|
||||
protected void parseService(Attributes attributes) throws SAXException {
|
||||
@@ -135,8 +137,9 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
curPlace = world.addPlace(name, x, y, z);
|
||||
}
|
||||
|
||||
protected void onVendor(String name){
|
||||
protected void onVendor(String name, double distance){
|
||||
curVendor = curPlace.addVendor(name);
|
||||
curVendor.setDistance(distance);
|
||||
}
|
||||
|
||||
protected void onService(SERVICE_TYPE type){
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MarketStreamWriter {
|
||||
protected void writeMarket() throws XMLStreamException {
|
||||
out.writeStartElement(MarketDocHandler.MARKET);
|
||||
writeItems();
|
||||
writeVendors();
|
||||
writePlaces();
|
||||
out.writeEndElement();
|
||||
}
|
||||
|
||||
@@ -68,12 +68,22 @@ public class MarketStreamWriter {
|
||||
out.writeAttribute(MarketDocHandler.ID_ATTR, id);
|
||||
}
|
||||
|
||||
protected void writeVendors() throws XMLStreamException {
|
||||
protected void writePlaces() throws XMLStreamException {
|
||||
out.writeStartElement(MarketDocHandler.PLACES_LIST);
|
||||
for (Place place : market.get()) {
|
||||
for (Vendor vendor : place.get()) {
|
||||
writeVendor(vendor);
|
||||
}
|
||||
writePlace(place);
|
||||
}
|
||||
out.writeEndElement();
|
||||
}
|
||||
|
||||
protected void writePlace(Place place) throws XMLStreamException {
|
||||
out.writeStartElement(MarketDocHandler.PLACE);
|
||||
out.writeAttribute(MarketDocHandler.NAME_ATTR, place.getName());
|
||||
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()));
|
||||
for (Vendor vendor : place.get()) {
|
||||
writeVendor(vendor);
|
||||
}
|
||||
out.writeEndElement();
|
||||
}
|
||||
@@ -81,10 +91,7 @@ public class MarketStreamWriter {
|
||||
protected void writeVendor(Vendor vendor) throws XMLStreamException {
|
||||
out.writeStartElement(MarketDocHandler.VENDOR);
|
||||
out.writeAttribute(MarketDocHandler.NAME_ATTR, vendor.getName());
|
||||
Place place = vendor.getPlace();
|
||||
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.writeAttribute(MarketDocHandler.DISTANCE_ATTR, String.valueOf(vendor.getDistance()));
|
||||
out.writeStartElement(MarketDocHandler.SERVICES_LIST);
|
||||
for (SERVICE_TYPE service_type : vendor.getServices()) {
|
||||
out.writeEmptyElement(MarketDocHandler.SERVICE);
|
||||
@@ -105,6 +112,7 @@ public class MarketStreamWriter {
|
||||
out.writeAttribute(MarketDocHandler.TYPE_ATTR, offer.getType().toString());
|
||||
out.writeAttribute(MarketDocHandler.ITEM_ATTR, items.get(offer.getItem()));
|
||||
out.writeAttribute(MarketDocHandler.PRICE_ATTR, String.valueOf(offer.getPrice()));
|
||||
out.writeAttribute(MarketDocHandler.COUNT_ATTR, String.valueOf(offer.getCount()));
|
||||
}
|
||||
|
||||
protected void writeGroup(Group group) throws XMLStreamException {
|
||||
|
||||
Reference in New Issue
Block a user