ManFileFormat.java [src/config/nodes] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package config.nodes;
import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import static utils.Constants.*;
/**
*
* @author Brad
*/
public class ManFileFormat {
private Map<Identity, ManActionFormat> actionFormats;
private ManActionFormat targetYield;
private Identity cropIdentity;
public ManFileFormat() {
actionFormats = new HashMap<>();
}
public ManActionFormat getManActionFormat(Identity identity) {
return actionFormats.get(identity);
}
public ManActionFormat getYieldFormat() {
return targetYield;
}
public Identity getcropIdentiy() {
return cropIdentity;
}
public void parse(XMLEventReader reader) throws XMLStreamException {
XMLEvent event;
ManActionFormat actionformat = null;
StartElement startElement;
String variable;
while (reader.hasNext()) {
event = reader.nextEvent();
switch (event.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
startElement = event.asStartElement();
if (startElement.getName().getLocalPart().equals(ACTIONFORMAT)) {
actionformat = new ManActionFormat();
variable = actionformat.parse(reader);
actionFormats.put(actionformat.getIdentity(), actionformat);
if (variable.equals("tgtyield"))
targetYield = actionformat;
if (variable.equals("gcropname")) {
cropIdentity = actionformat.getIdentity();
}
}
break;
}
}
}
}