Search in sources :

Example 1 with XmlParser

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();
    }
}
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)

Example 2 with XmlParser

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);
}
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) World(org.apollo.game.model.World) FileInputStream(java.io.FileInputStream)

Aggregations

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