Examples of ParsedXML


Examples of gd.xml.tiny.ParsedXML

        entity = new BattleArmor();

        // Walk the board node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the shootingStrength node?
            else if (childName.equals("shootingStrength")) {

                // Get the number of men shooting.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the shootingStrength for an BattleArmor unit.");
                }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        }

        // Try to find the inferno detail nodes.
        Enumeration<?> details = node.elements();
        while (details.hasMoreElements()) {
            ParsedXML detail = (ParsedXML) details.nextElement();

            // Have we found the Arrow IV inferno detail?
            if (detail.getName().equals("arrowiv")) {

                // Get the burn turns attribute.
                attrStr = detail.getAttribute("turns");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the burn turns for an Arrow IV inferno round.");
                }

                // Try to pull the value from the string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }

                // Add the number of Arrow IV burn turns.
                entity.infernos.add(InfernoTracker.INFERNO_IV_TURN, attrVal);

            } // End found-arrowiv-detail

            // Have we found the standard inferno entry?
            else if (detail.getName().equals("standard")) {

                // Get the burn turns attribute.
                attrStr = detail.getAttribute("turns");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the burn turns for a standard inferno round.");
                }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        String attrStr = null;
        int attrVal = 0;
        boolean attrTrue = false;
        Entity entity = null;
        Coords coords = null;
        ParsedXML actionNode = null;
        ParsedXML narcNode = null;
        ParsedXML infernoNode = null;
        ParsedXML loadedUnitsNode = null;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The entityData is null.");
        }

        // Make sure that the node is for a EntityData object.
        if (!node.getName().equals("entityData")) {
            throw new IllegalStateException("Not passed a entityData node.");
        }

        // TODO : perform version checking.

        // Walk the entityData node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the coords node?
            else if (childName.equals("coords")) {

                // We can decode the coords immediately.
                coords = CoordsEncoder.decode(child, game);

            } // End found-"coords"-child

            // Did we find the action node?
            // TODO : rename me
            else if (childName.equals("action")) {

                // Save the action node for later decoding.
                actionNode = child;

            } // End found-"action"-child

            // Did we find the narcs node?
            else if (childName.equals("narcs")) {

                // Save the narc node for later decoding.
                narcNode = child;

            } // End found-"narc"-child

            // Did we find the inferno node?
            else if (childName.equals("inferno")) {

                // Save the inferno node for later decoding.
                infernoNode = child;

            } // End found-"inferno"-child

            // Did we find the loadedUnits node?
            else if (childName.equals("loadedUnits")) {

                // Save the loadedUnits node for later decoding.
                loadedUnitsNode = child;

            } // End found-"loadedUnits"-child

            // Did we find the class node?
            else if (childName.equals("class")) {

                // Create the appropriate sub-class of Entity.
                attrStr = child.getAttribute("name");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the name of a class node.");
                } else if (attrStr.equals("BipedMech")) {
                    entity = BipedMechEncoder.decode(child, game);
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

    public static Entity decode(ParsedXML node, IGame game) {
        String attrStr = null;
        int attrVal = 0;
        Entity entity = null;
        Vector<ParsedXML> locations = new Vector<ParsedXML>();
        ParsedXML pilotNode = null;
        ParsedXML equipNode = null;
        Enumeration<?> children = null;
        ParsedXML child = null;
        String childName;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The entity is null.");
        }

        // Make sure that the node is for a Entity object.
        if (!node.getName().equals("entity")) {
            throw new IllegalStateException("Not passed a entity node.");
        }

        // TODO : perform version checking.

        // Walk the entity node's children, finding bits for later parsing..
        children = node.elements();
        while (children.hasMoreElements()) {
            child = (ParsedXML) children.nextElement();
            childName = child.getName();

            // Handle null child childNames.
            if (null == childName) {

                // No-op.
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

    private static MechSummaryCache mechSummaryCache = null;
    public TestXMLOption mechOption = new TestXMLOption();
    public TestXMLOption tankOption = new TestXMLOption();

    public EntityVerifier(File config) {
        ParsedXML root = null;
        try {
            root = TinyParser.parseXML(new FileInputStream(config));
            for (Enumeration<?> e = root.elements(); e.hasMoreElements();) {
                ParsedXML child = (ParsedXML) e.nextElement();
                if (child.getTypeName().equals("tag")
                        && child.getName().equals(BASE_NODE)) {
                    readOptions(child);
                }
            }
            // System.out.println("Using config file: " + config.getPath());
        } catch (ParseException e) {
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        System.out.println("Total Failures: " + failures);
    }

    private void readOptions(ParsedXML node) {
        for (Enumeration<?> e = node.elements(); e.hasMoreElements();) {
            ParsedXML child = (ParsedXML) e.nextElement();
            if (child.getName().equals(BASE_TANK_NODE))
                tankOption.readXMLOptions(child);
            else if (child.getName().equals(BASE_MECH_NODE))
                mechOption.readXMLOptions(child);
        }
    }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

     * (non-Javadoc)
     *
     * @see megamek.common.net.marshall.PacketMarshaller#unmarshall(java.io.InputStream)
     */
    public Packet unmarshall(InputStream stream) throws Exception {
        ParsedXML root = TinyParser.parseXML(stream);
        Enumeration<?> rootChildren = root.elements();
        if (!rootChildren.hasMoreElements()) {
            throw new ParseException("No children of the root.");
        }
        ParsedXML rootNode = (ParsedXML) rootChildren.nextElement();
        Packet packet = PacketEncoder.decode(rootNode, null);
        return packet;
    }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        load(cfgName);
        clientPreferences = new ClientPreferences(clientPreferenceStore);
    }

    protected void load(String fileName) {
        ParsedXML root = null;
        InputStream is = null;

        try {
            is = new FileInputStream(new File(fileName));
        } catch (FileNotFoundException e) {
            return;
        }

        try {
            root = TinyParser.parseXML(is);
        } catch (ParseException e) {
            System.out
                    .println("Error parsing settings file'" + fileName + ",.");
            e.printStackTrace(System.out);
            return;
        }

        Enumeration<?> rootChildren = root.elements();
        ParsedXML optionsNode = (ParsedXML) rootChildren.nextElement();

        if (optionsNode.getName().equals(ROOT_NODE_NAME)) {
            Enumeration<?> children = optionsNode.elements();
            while (children.hasMoreElements()) {
                ParsedXML child = (ParsedXML) children.nextElement();
                if (child != null && child.getName().equals(STORE_NODE_NAME)) {
                    String name = child.getAttribute(NAME_ATTRIBUTE);
                    if (name.equals(CLIENT_SETTINGS_STORE_NAME)) {
                        loadGroup(child, clientPreferenceStore);
                    } else {
                        loadGroup(child, getPreferenceStore(name));
                    }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

    }

    protected void loadGroup(ParsedXML node, IPreferenceStore cp) {
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            if (child != null && child.getName().equals(PREFERENCE_NODE_NAME)) {
                String name = child.getAttribute(NAME_ATTRIBUTE);
                String value = child.getAttribute(VALUE_ATTRIBUTE);
                if (name != null && value != null) {
                    cp.putValue(name, value);
                }
            }
        }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

    public Vector<IOption> loadOptions() {
        return loadOptions(new File(GAME_OPTIONS_FILE_NAME));
    }

    public Vector<IOption> loadOptions(File file) {
        ParsedXML root = null;
        InputStream is = null;
        Vector<IOption> changedOptions = new Vector<IOption>(1, 1);

        try {
            is = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            return changedOptions;
        }

        try {
            root = TinyParser.parseXML(is);
        } catch (ParseException e) {
            System.out.println("Error parsing game options xml file."); //$NON-NLS-1$
            e.printStackTrace(System.out);
            return changedOptions;
        }

        Enumeration<?> rootChildren = root.elements();
        ParsedXML optionsNode = (ParsedXML) rootChildren.nextElement();

        if (optionsNode.getName().equals("options")) { //$NON-NLS-1$
            Enumeration<?> children = optionsNode.elements();

            while (children.hasMoreElements()) {
                IOption option = parseOptionNode((ParsedXML) children
                        .nextElement());

                if (null != option) {
                    changedOptions.addElement(option);
                }
            }

            return changedOptions;
        }
        System.out
                .println("Root node of game options file is incorrectly named. Name should be 'options' but name is '" + optionsNode.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
        return changedOptions;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.