use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.
the class TestDetach method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMContainer root;
if (document) {
root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--a--><b/><!--c-->")).getDocument();
} else {
root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><!--a--><b/><!--c--></root>")).getDocumentElement();
}
if (build) {
root.build();
} else {
assertFalse(root.isComplete());
}
OMComment a = (OMComment) root.getFirstOMChild();
assertEquals("a", a.getValue());
OMElement b = (OMElement) a.getNextOMSibling();
assertEquals("b", b.getLocalName());
OMNode returnValue = b.detach();
// Detach is expected to do a "return this"
assertSame(b, returnValue);
assertNull(b.getParent());
assertNull(b.getPreviousOMSibling());
assertNull(b.getNextOMSibling());
OMComment c = (OMComment) a.getNextOMSibling();
assertEquals("c", c.getValue());
assertSame(c, a.getNextOMSibling());
assertSame(a, c.getPreviousOMSibling());
root.close(false);
}
use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.
the class TestGetDescendants method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMContainer root = containerFactory.create(factory);
OMElement child1 = factory.createOMElement("child", null, root);
OMProcessingInstruction child2 = factory.createOMProcessingInstruction(root, "test", "data");
OMText grandchild1 = factory.createOMText(child1, "text");
OMComment grandchild2 = factory.createOMComment(child1, "text");
Iterator<? extends OMSerializable> it = root.getDescendants(includeSelf);
if (includeSelf) {
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(root);
}
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(child1);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(grandchild1);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(grandchild2);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(child2);
assertThat(it.hasNext()).isFalse();
}
use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.
the class TestGetBuilderNull method runTest.
@Override
protected void runTest() throws Throwable {
OMContainer container = containerFactory.create(metaFactory.getOMFactory());
assertThat(container.getBuilder()).isNull();
}
use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = file.getAdapter(XMLSampleAdapter.class).getBuilder(metaFactory);
try {
OMContainer container = containerExtractor.getContainer(builder);
// We need to clone the InputSource objects so that we can dump their contents
// if the test fails
InputSource[] control = duplicateInputSource(containerExtractor.getControl(file.getInputStream()));
XML actual = serializationStrategy.serialize(container);
try {
// Configure the InputSources such that external entities can be resolved
String systemId = new URL(file.getUrl(), "dummy.xml").toString();
control[0].setSystemId(systemId);
InputSource actualIS = actual.getInputSource();
actualIS.setSystemId(systemId);
assertAbout(xml()).that(actualIS).ignoringElementContentWhitespace().hasSameContentAs(control[0]);
} catch (Throwable ex) {
System.out.println("Control:");
dumpInputSource(control[1]);
System.out.println("Actual:");
actual.dump(System.out);
throw ex;
}
if (serializationStrategy.isCaching()) {
assertTrue(container.isComplete());
} else {
// TODO: need to investigate why assertConsumed is not working here
assertFalse(container.isComplete());
// assertConsumed(element);
}
} finally {
builder.close();
}
}
use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.
the class DocumentNavigator method getNamespaceAxisIterator.
/**
* Retrieves an <code>Iterator</code> matching the <code>namespace</code> XPath axis.
*
* @param contextNode the original context node
* @return Returns an Iterator capable of traversing the axis, not null.
* @throws UnsupportedAxisException if the semantics of the namespace axis are not supported by
* this object model
*/
@Override
public Iterator<?> getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException {
if (!(contextNode instanceof OMContainer && contextNode instanceof OMElement)) {
return JaxenConstants.EMPTY_ITERATOR;
}
OMContainer omContextNode = (OMContainer) contextNode;
List<OMNamespaceEx> nsList = new ArrayList<OMNamespaceEx>();
Set<String> prefixes = new HashSet<String>();
for (OMContainer context = omContextNode; context != null && !(context instanceof OMDocument); context = ((OMElement) context).getParent()) {
OMElement element = (OMElement) context;
List<OMNamespace> declaredNS = new ArrayList<OMNamespace>();
Iterator<OMNamespace> i = element.getAllDeclaredNamespaces();
while (i != null && i.hasNext()) {
declaredNS.add(i.next());
}
declaredNS.add(element.getNamespace());
for (Iterator<OMAttribute> iter = element.getAllAttributes(); iter != null && iter.hasNext(); ) {
OMAttribute attr = iter.next();
OMNamespace namespace = attr.getNamespace();
if (namespace != null) {
declaredNS.add(namespace);
}
}
for (OMNamespace namespace : declaredNS) {
if (namespace != null) {
String prefix = namespace.getPrefix();
if (prefix != null && !prefixes.contains(prefix)) {
prefixes.add(prefix);
nsList.add(new OMNamespaceEx(namespace, context));
}
}
}
}
nsList.add(new OMNamespaceEx(omContextNode.getOMFactory().createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml"), omContextNode));
return nsList.iterator();
}
Aggregations