use of org.apollo.util.xml.XmlParser in project apollo by apollo-rsps.
the class GameService method init.
/**
* Initializes the game service.
*
* @throws IOException If there is an error accessing the file.
* @throws SAXException If there is an error parsing the file.
* @throws ReflectiveOperationException If a MessageHandler could not be created.
*/
private void init() throws IOException, SAXException, ReflectiveOperationException {
try (InputStream input = new FileInputStream("data/messages.xml")) {
MessageHandlerChainSetParser chainSetParser = new MessageHandlerChainSetParser(input);
handlers = chainSetParser.parse(world);
}
try (InputStream input = new FileInputStream("data/synchronizer.xml")) {
XmlParser parser = new XmlParser();
XmlNode root = parser.parse(input);
if (!root.getName().equals("synchronizer")) {
throw new IOException("Invalid root node name.");
}
XmlNode active = root.getChild("active");
if (active == null || !active.hasValue()) {
throw new IOException("No active node/value.");
}
Class<?> clazz = Class.forName(active.getValue());
synchronizer = (ClientSynchronizer) clazz.newInstance();
}
}
use of org.apollo.util.xml.XmlParser in project apollo by apollo-rsps.
the class LoginService method init.
/**
* Initialises the login service.
*
* @throws SAXException If there is an error parsing the XML file.
* @throws IOException If there is an error accessing the file.
* @throws ReflectiveOperationException If the {@link PlayerSerializer} implementation could not be created.
*/
private void init() throws SAXException, IOException, ReflectiveOperationException {
XmlParser parser = new XmlParser();
XmlNode rootNode;
try (InputStream is = new FileInputStream("data/login.xml")) {
rootNode = parser.parse(is);
}
if (!rootNode.getName().equals("login")) {
throw new IOException("Unexpected root node name, expected 'login'.");
}
XmlNode serializer = rootNode.getChild("serializer");
if (serializer == null || !serializer.hasValue()) {
throw new IOException("No serializer child node or value.");
}
Class<?> clazz = Class.forName(serializer.getValue());
this.serializer = (PlayerSerializer) clazz.getConstructor(World.class).newInstance(world);
}
Aggregations