public XMLMatch(String location, String player)
{
try
{
SAXBuilder builder = new SAXBuilder();
// Stub the entity resolver in order to avoid crashes when the
// xml referenced dtd is not available
builder.setEntityResolver(new EntityResolver()
{
@Override
public InputSource resolveEntity(String arg0, String arg1)
throws SAXException, IOException
{
return new InputSource(new StringReader(""));
}
});
Map<Integer,SerializableAction> actions = new HashMap<Integer,SerializableAction>();
// First get the moves history from the final state file
{
String filename = location + "/finalstate.xml";
File file = new File(filename);
if(!file.exists())
{
throw new FileNotFoundException(filename);
}
Element root = builder.build(file).getRootElement();
int player_id = getPlayerId(root,player);
role = getRole(root,player_id);
for(Element e : root.getChild("history").getChildren("step"))
{
String s = e.getChildren("step-number").get(0).getText();
int stepnum = Integer.parseInt(s);
String action_term = e.getChildren("move").get(player_id).getText();
GroundFact fact = createAction(action_term,role);
actions.put(stepnum, new SerializableAction(fact));
}
}
// Register the state-action couples by browsing the step_x.xml
// files in the right order.
int step = 1;
while(true)
{
String filename = getStateFilename(location,step);
File file = new File(filename);
if(!file.exists())
{
break;
}
Element root = builder.build(file).getRootElement();
List<Element> states = root.getChildren("state");
SerializableState state = getState(states.get(0));
SerializableAction action = actions.get(step);
if(action != null)
{