Package gd.xml.tiny

Examples of gd.xml.tiny.ParsedXML


        entity = new QuadMech();

        // 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 stunnedTurns node?
            else if (childName.equals("mascTurns")) {

                // Get the Mech's stunned turns.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the mascTurns for a QuadMech unit.");
                }

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

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

                // See if the Mech used MASC.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode mascUsed for a QuadMech unit.");
                }
View Full Code Here


        entity = new Infantry();

        // 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 Infantry unit.");
                }
View Full Code Here

        // TODO : perform version checking.

        // Find the terrains node.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            if (child.getName().equals("terrains")) {

                // There should be only one terrains node.
                if (null != retVal) {
                    throw new IllegalStateException(
                            "More than one 'terrains' node in a hex node.");
                }

                // Create an array to hold all the terrains.
                ITerrain[] terrains = new ITerrain[Terrains.SIZE];

                // Walk through the subnodes, parsing out terrain nodes.
                Enumeration<?> subnodes = child.elements();
                while (subnodes.hasMoreElements()) {

                    // Is this a "terrain" node?
                    ParsedXML subnode = (ParsedXML) subnodes.nextElement();
                    if (subnode.getName().equals("terrain")) {

                        // Try to parse the terrain node.
                        try {
                            final int type = Integer.parseInt(subnode
                                    .getAttribute("type"));
                            final boolean exitsSpecified = StringUtil
                                    .parseBoolean(subnode
                                            .getAttribute("exitsSpecified"));
                            final int level = Integer.parseInt(subnode
                                    .getAttribute("level"));
                            final int exits = Integer.parseInt(subnode
                                    .getAttribute("exits"));
                            terrains[type] = f.createTerrain(type, level,
                                    exitsSpecified, exits);
                        } catch (Throwable thrown) {
                            throw new IllegalStateException(
View Full Code Here

        entity = new Protomech();

        // 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 main gun node?
            else if (childName.equals("hasMainGun")) {

                // See if the Proto has a main gun.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode hasMainGun for a Protomech unit.");
                }

                // If the value is "true", the Proto has a main gun.
                if (attrStr.equals("true")) {
                    entity.setHasMainGun(true);
                } else {
                    entity.setHasMainGun(false);
                }
            }

            // Did we find the location-specific pilot damage node?
            else if (childName.equals("pilotDamageTaken")) {

                // Get the damage taken by the pilot in this location.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the damage for a Protomech unit.");
                }

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

                // Get this location.
                attrStr = child.getAttribute("loc");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the location for a Protomech unit.");
                }
View Full Code Here

        // TODO : perform version checking.

        // Walk the packet node's children. Try to find a "packetData" node.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML subNode = (ParsedXML) children.nextElement();
            if (subNode.getName().equals("packetData")) {

                // How many data elements are in the packet data?
                final int count = Integer.parseInt(subNode
                        .getAttribute("count"));
                data = new Object[count];

                // Do we need to unzip the data elements?
                Enumeration<?> dataElements = null;
                if (subNode.getAttribute("isGzipped").equals("true")) {

                    // Try to find the zipped content.
                    String cdata = subNode.getContent();
                    if (null == cdata) {
                        Enumeration<?> cdataEnum = subNode.elements();
                        while (cdataEnum.hasMoreElements() && null == cdata) {
                            final ParsedXML cdataNode = (ParsedXML) cdataEnum
                                    .nextElement();
                            if (cdataNode.getTypeName().equals("text")) {
                                cdata = cdataNode.getContent();
                            } else if (cdataNode.getTypeName().equals("cdata")) {
                                cdata = cdataNode.getContent();
                            }
                        }
                    } // End look-for-cdata-nodes

                    // Did we find the zipped content?
                    if (null == cdata) {
                        throw new IllegalStateException(
                                "Could not find CDATA for packetData.");
                    }

                    // Yup. Unencode the data from Base64.
                    byte[] unBase64 = Base64.decodeToBytes(cdata);
                    InputStream parseStream;
                    try {
                        // Unzip the data.
                        parseStream = new GZIPInputStream(
                                new ByteArrayInputStream(unBase64));
                    } catch (IOException ioErr) {
                        StringBuffer iobuf = new StringBuffer();
                        iobuf.append("Could not unzip data elements: ").append(
                                ioErr.getMessage());
                        throw new IllegalStateException(iobuf.toString());
                    }

                    try {
                        /*******************************************************
                         * BEGIN debug code try { parseStream.mark(64000); int
                         * inChar = 0; while ( -1 != (inChar =
                         * parseStream.read()) ) { System.out.print( (char)
                         * inChar ); } System.out.println( "" );
                         * parseStream.reset(); } catch ( IOException debugErr ) {
                         * debugErr.printStackTrace(); } END debug code *
                         ******************************************************/

                        // Parse the XML.
                        ParsedXML dummyNode = TinyParser.parseXML(parseStream);
                        dataElements = dummyNode.elements();
                    } catch (ParseException parseErr) {
                        StringBuffer parsebuf = new StringBuffer();
                        parsebuf.append("Could not parse data elements: ")
                                .append(parseErr.getMessage());
                        throw new IllegalStateException(parsebuf.toString());
View Full Code Here

        entity = new Tank();

        // 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 stunnedTurns node?
            else if (childName.equals("stunnedTurns")) {

                // Get the Tank's stunned turns.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the stunnedTurns for a Tank unit.");
                }

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

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

                // See if the Tank has a no turret.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode hasNoTurret for a Tank unit.");
                }

                // If the value is "true", the Tank has a no turret.
                if (attrStr.equals("true")) {
                    entity.setHasNoTurret(true);
                } else {
                    entity.setHasNoTurret(false);
                }
            }

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

                // See if the Tank has a move hit.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode moveHit for a Tank unit.");
                }

                // If the value is "true", the Tank move a hit pending.
                if (attrStr.equals("true")) {
                    entity.immobilize();
                    entity.applyDamage();
                }
            }

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

                // See if the Tank has a move hit pending.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode moveHitPending for a Tank unit.");
                }

                // If the value is "true", the Tank move a hit pending.
                if (attrStr.equals("true")) {
                    entity.immobilize();
                }
            }

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

                // Get the Tank's facing.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the facing for a Tank unit.");
                }

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

            // Did we find the turret's secondaryFacing node?
            else if (childName.equals("turretFacing")) {

                // Get the Tank's turret's facing.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the turret's secondaryFacing for a Tank unit.");
                }

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

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

                // See if the Tank move a hit pending.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode turretLocked for a Tank unit.");
                }
View Full Code Here

        Vector<Coords> coordVec = new Vector<Coords>();
        Map<Coords, Boolean> burning = new HashMap<Coords, Boolean>();
        Map<Coords, Integer> curCF = new HashMap<Coords, Integer>();
        Map<Coords, Integer> phaseCF = new HashMap<Coords, Integer>();
        Enumeration<?> subnodes = null;
        ParsedXML subnode = null;
        Coords coords = null;
        int type = -1;
        int id = -1;
        String name = null;

        // Walk the building 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 buildingData node?
            else if (childName.equals("buildingData")) {

                // There should be only one buildingData node.
                if (null != retVal) {
                    throw new IllegalStateException(
                            "More than one 'buildingData' node in a building node.");
                }

                // Read the coords of the building.
                subnodes = child.elements();
                while (subnodes.hasMoreElements()) {
                    subnode = (ParsedXML) subnodes.nextElement();

                    // Have we found the coords subnode?
                    if (subnode.getName().equals("coords")) {
                        coords = CoordsEncoder.decode(subnode, game);
                        if (null != coords) {
                            coordVec.addElement(coords);
                        }
                        // Do we have a 'currentCF' attribute?
                        attrStr = subnode.getAttribute("currentCF");
                        if (null != attrStr) {

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

                            // Do we have a valid value?
                            if (0 > attrVal) {
                                throw new IllegalStateException(
                                        "Illegal value for currentCF: " + attrStr);
                            }
                            curCF.put(coords, attrVal);
                        }

                        // Do we have a 'phaseCF' attribute?
                        attrStr = subnode.getAttribute("phaseCF");
                        if (null != attrStr) {

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

                            // Do we have a valid value?
                            if (0 >= attrVal) {
                                throw new IllegalStateException(
                                        "Illegal value for phaseCF: " + attrStr);
                            }
                            phaseCF.put(coords, attrVal);
                        }
                        // Set the building's 'isBurning' flag.
                        burning.put(coords,StringUtil.parseBoolean(child
                                .getAttribute("isBurning")));
                    }

                } // Check the next subnode

                // We *did* find at least one coords for the building, right?
                if (0 >= coordVec.size()) {
                    throw new IllegalStateException(
                            "Couldn't decode the coords for the building.");
                }

                // Get the building type.
                attrStr = child.getAttribute("type");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }

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

                // Do we have a valid value?
                if (type < 0 || type > Building.WALL) {
                    throw new IllegalStateException("Illegal value for type: "
                            + attrStr);
                }

                // Get the building id.
                attrStr = child.getAttribute("id");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }

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

                // Do we have a valid value?
                if (0 >= id) {
                    throw new IllegalStateException("Illegal value for id: "
                            + attrStr);
                }

                // Get the building name.
                attrStr = child.getAttribute("name");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the buildingData for a building node.");
                }
                name = attrStr;
View Full Code Here

TOP

Related Classes of gd.xml.tiny.ParsedXML

Copyright © 2018 www.massapicom. 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.