Search in sources :

Example 1 with MessageHandlerChainSetParser

use of org.apollo.game.io.MessageHandlerChainSetParser 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();
    }
}
Also used : XmlParser(org.apollo.util.xml.XmlParser) XmlNode(org.apollo.util.xml.XmlNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MessageHandlerChainSetParser(org.apollo.game.io.MessageHandlerChainSetParser)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessageHandlerChainSetParser (org.apollo.game.io.MessageHandlerChainSetParser)1 XmlNode (org.apollo.util.xml.XmlNode)1 XmlParser (org.apollo.util.xml.XmlParser)1