use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestLookupPrefix method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element element = document.createElementNS("urn:test", "ns:root");
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:ns", "urn:test");
fragment.appendChild(element);
assertNull(fragment.lookupPrefix("urn:test"));
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestReplaceChildFirstWithDocumentFragment method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element x = document.createElementNS(null, "x");
Element y = document.createElementNS(null, "y");
fragment.appendChild(x);
fragment.appendChild(y);
Element element = document.createElementNS(null, "parent");
Element a = document.createElementNS(null, "a");
Element b = document.createElementNS(null, "b");
element.appendChild(a);
element.appendChild(b);
element.replaceChild(fragment, a);
NodeList children = element.getChildNodes();
assertEquals(3, children.getLength());
assertSame(x, children.item(0));
assertSame(y, children.item(1));
assertSame(b, children.item(2));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
assertSame(x, element.getFirstChild());
assertSame(b, element.getLastChild());
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestReplaceChildMiddleWithDocumentFragment method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element x = document.createElementNS(null, "x");
Element y = document.createElementNS(null, "y");
fragment.appendChild(x);
fragment.appendChild(y);
Element element = document.createElementNS(null, "parent");
Element a = document.createElementNS(null, "a");
Element b = document.createElementNS(null, "b");
Element c = document.createElementNS(null, "c");
element.appendChild(a);
element.appendChild(b);
element.appendChild(c);
element.replaceChild(fragment, b);
NodeList children = element.getChildNodes();
assertEquals(4, children.getLength());
assertSame(a, children.item(0));
assertSame(x, children.item(1));
assertSame(y, children.item(2));
assertSame(c, children.item(3));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
assertSame(a, element.getFirstChild());
assertSame(c, element.getLastChild());
}
use of org.w3c.dom.DocumentFragment in project cxf by apache.
the class ProviderImpl method convertToInternal.
/**
* Convert from EndpointReference to CXF internal 2005/08 EndpointReferenceType
*
* @param external the javax.xml.ws.EndpointReference
* @return CXF internal 2005/08 EndpointReferenceType
*/
public static EndpointReferenceType convertToInternal(EndpointReference external) {
if (external instanceof W3CEndpointReference) {
Unmarshaller um = null;
try {
DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment();
DOMResult result = new DOMResult(frag);
external.writeTo(result);
W3CDOMStreamReader reader = new W3CDOMStreamReader(frag);
// CXF internal 2005/08 EndpointReferenceType should be
// compatible with W3CEndpointReference
// jaxContext = ContextUtils.getJAXBContext();
JAXBContext context = JAXBContext.newInstance(new Class[] { org.apache.cxf.ws.addressing.ObjectFactory.class });
um = context.createUnmarshaller();
return um.unmarshal(reader, EndpointReferenceType.class).getValue();
} catch (JAXBException e) {
throw new IllegalArgumentException("Could not unmarshal EndpointReference", e);
} finally {
JAXBUtils.closeUnmarshaller(um);
}
}
return null;
}
use of org.w3c.dom.DocumentFragment in project cxf by apache.
the class LogicalMessageImpl method getPayload.
public Object getPayload(JAXBContext arg0) {
try {
Source s = getPayload();
if (s instanceof DOMSource) {
DOMSource ds = (DOMSource) s;
ds.setNode(org.apache.cxf.helpers.DOMUtils.getDomElement(ds.getNode()));
Node parent = ds.getNode().getParentNode();
Node next = ds.getNode().getNextSibling();
if (parent instanceof DocumentFragment) {
parent.removeChild(ds.getNode());
}
try {
return JAXBUtils.unmarshall(arg0, ds);
} finally {
if (parent instanceof DocumentFragment) {
parent.insertBefore(ds.getNode(), next);
}
}
}
return JAXBUtils.unmarshall(arg0, getPayload());
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
Aggregations