Beispiel #1
0
  /**
   * Adds a new <code>Element</code> to the data element.
   *
   * @param element the new element to add to the result, cannot be <code>null</code>.
   * @throws IllegalArgumentException if <code>element == null</code>.
   * @since XINS 1.1.0
   */
  protected void add(Element element) throws IllegalArgumentException {

    // Check preconditions
    MandatoryArgumentChecker.check("element", element);

    // Lazily initialize _dataElement
    if (_dataElement == null) {
      _dataElement = new Element("data");
    }
    _dataElement.addChild(element);
  }
Beispiel #2
0
  public String toString() {
    String asString = (_code != null) ? "Error code: " + _code + "; " : "Successful result; ";

    // Add all parameters
    asString += PropertyReaderUtils.toString(_parameters, "no parameters") + "; ";

    // Data section
    if (_dataElement == null) {
      asString += "no data section";
    } else {
      asString += _dataElement.toString();
    }

    return asString;
  }
Beispiel #3
0
  /** Tests the <code>ElementBuilder</code> class. */
  public void testElementBuilder() throws Exception {

    // Parse an XML string with namespaces
    String s = "<ns:a xmlns:ns=\"b\" c='2'><ns:e><g xmlns='f'/><h></h></ns:e></ns:a>";
    ElementBuilder builder = new ElementBuilder("html");
    assertNotNull(builder);
    builder.addXMLChild(s);
    Element root = builder.createElement();
    assertEquals("Incorrect root element.", "html", root.getLocalName());
    Element element = root.getUniqueChildElement("a");

    // Parse root 'a' element
    assertEquals("a", element.getLocalName());
    assertEquals("b", element.getNamespaceURI());
    assertEquals(1, element.getAttributeMap().size());
    assertEquals("2", element.getAttribute("c"));
    assertEquals(0, element.getChildElements("d").size());
    assertEquals(0, element.getChildElements("d:e").size());
    assertEquals(null, element.getText());

    // Parse contained 'e' element
    List aChildren = element.getChildElements();
    assertEquals(1, aChildren.size());
    Element eChild = (Element) aChildren.get(0);
    assertEquals("e", eChild.getLocalName());
    assertEquals("b", eChild.getNamespaceURI());
    assertEquals(2, eChild.getChildElements().size());
    assertEquals(0, eChild.getChildElements("d:g").size());
    assertEquals(1, eChild.getChildElements("h").size());
    assertEquals(null, eChild.getText());

    // Parse contained 'g' element
    List eChildren = eChild.getChildElements();
    assertEquals(2, eChildren.size());
    Element gChild = (Element) eChildren.get(0);
    Element hChild = (Element) eChildren.get(1);
    assertEquals("g", gChild.getLocalName());
    assertEquals("f", gChild.getNamespaceURI());
    assertEquals(0, gChild.getChildElements().size());
    assertEquals(null, gChild.getText());
    assertEquals("h", hChild.getLocalName());
    assertEquals(null, hChild.getNamespaceURI());
    assertEquals(0, hChild.getChildElements().size());
    assertEquals(null, hChild.getText());
  }