/** * Writes a request to AugmentPTA into an XML node and returns the constructed node. * * @param data what to write * @return constructed XML node. */ protected Element writeAugmentPTA(AugmentPTAData data) { Element result = doc.createElement(StatechumXML.ELEM_AUGMENTPTA.name()); result.setAttribute(StatechumXML.ATTR_KIND.name(), data.kind.name()); if (data.colour != null) result.setAttribute(StatechumXML.ATTR_COLOUR.name(), data.colour.name()); result.setAttribute(StatechumXML.ATTR_ACCEPT.name(), Boolean.toString(data.accept)); StringBuffer writer = new StringBuffer(); labelio.writeInputSequence(writer, data.sequence); result.setTextContent(writer.toString()); return result; }
/** * Reads the arguments to AugmentPTA from XML element. * * <p>At the moment, storage of instances of leaf nodes in trees is not implemented (and leaf * nodes are used in filtering), hence I have to rely on storage of the whole set of sequences. * * @param element data to load from * @return constructed arguments. */ protected AugmentPTAData readAugmentPTA(Element element) { if (!element.getNodeName().equals(StatechumXML.ELEM_AUGMENTPTA.name())) throw new IllegalArgumentException( "cannot load augmentPTA data from " + element.getNodeName()); AugmentPTAData result = new AugmentPTAData(); if (!element.hasAttribute(StatechumXML.ATTR_ACCEPT.name())) throw new IllegalArgumentException("missing accept"); if (!element.hasAttribute(StatechumXML.ATTR_KIND.name())) throw new IllegalArgumentException("missing kind"); String accept = element.getAttribute(StatechumXML.ATTR_ACCEPT.name()), colour = element.getAttribute(StatechumXML.ATTR_COLOUR.name()), kind = element.getAttribute(StatechumXML.ATTR_KIND.name()), sequence = element.getTextContent(); if (sequence.length() == 0) throw new IllegalArgumentException("missing sequence"); result.sequence = labelio.readInputSequence(sequence); result.accept = Boolean.valueOf(accept); if (colour.length() > 0) result.colour = Enum.valueOf(JUConstants.class, colour); result.kind = Enum.valueOf(RestartLearningEnum.class, kind); return result; }