< prev index next >
jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/impl/BodyImpl.java
Print this page
@@ -28,25 +28,34 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.logging.Level;
import javax.xml.namespace.QName;
-import javax.xml.soap.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
-import org.w3c.dom.*;
-import org.w3c.dom.Node;
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
import com.sun.xml.internal.messaging.saaj.soap.StaxBridge;
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* The implementation of SOAP-ENV:BODY or the SOAPBody abstraction.
*
* @author Anil Vijendran (anil@sun.com)
@@ -70,10 +79,11 @@
protected abstract SOAPBodyElement createBodyElement(Name name);
protected abstract SOAPBodyElement createBodyElement(QName name);
protected abstract SOAPFault createFaultElement();
protected abstract QName getDefaultFaultCode();
+ @Override
public SOAPFault addFault() throws SOAPException {
if (hasFault()) {
log.severe("SAAJ0110.impl.fault.already.exists");
throw new SOAPExceptionImpl("Error: Fault already exists");
}
@@ -86,10 +96,11 @@
fault.setFaultString("Fault string, and possibly fault code, not set");
return fault;
}
+ @Override
public SOAPFault addFault(
Name faultCode,
String faultString,
Locale locale)
throws SOAPException {
@@ -98,10 +109,11 @@
fault.setFaultCode(faultCode);
fault.setFaultString(faultString, locale);
return fault;
}
+ @Override
public SOAPFault addFault(
QName faultCode,
String faultString,
Locale locale)
throws SOAPException {
@@ -110,19 +122,21 @@
fault.setFaultCode(faultCode);
fault.setFaultString(faultString, locale);
return fault;
}
+ @Override
public SOAPFault addFault(Name faultCode, String faultString)
throws SOAPException {
SOAPFault fault = addFault();
fault.setFaultCode(faultCode);
fault.setFaultString(faultString);
return fault;
}
+ @Override
public SOAPFault addFault(QName faultCode, String faultString)
throws SOAPException {
SOAPFault fault = addFault();
fault.setFaultCode(faultCode);
@@ -145,19 +159,21 @@
}
return null;
}
+ @Override
public boolean hasFault() {
QName payloadQName = getPayloadQName();
return getFaultQName().equals(payloadQName);
}
private Object getFaultQName() {
return new QName(getNamespaceURI(), "Fault");
}
+ @Override
public SOAPFault getFault() {
if (hasFault()) {
if (fault == null) {
//initialize fault member
fault = (SOAPFault) getSoapDocument().find(getFirstChildElement());
@@ -165,10 +181,11 @@
return fault;
}
return null;
}
+ @Override
public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
SOAPBodyElement newBodyElement =
(SOAPBodyElement) ElementFactory.createNamedElement(
((SOAPDocument) getOwnerDocument()).getDocument(),
name.getLocalName(),
@@ -179,10 +196,11 @@
}
addNode(newBodyElement);
return newBodyElement;
}
+ @Override
public SOAPBodyElement addBodyElement(QName qname) throws SOAPException {
SOAPBodyElement newBodyElement =
(SOAPBodyElement) ElementFactory.createNamedElement(
((SOAPDocument) getOwnerDocument()).getDocument(),
qname.getLocalPart(),
@@ -193,23 +211,26 @@
}
addNode(newBodyElement);
return newBodyElement;
}
+ @Override
public void setParentElement(SOAPElement element) throws SOAPException {
if (!(element instanceof SOAPEnvelope)) {
log.severe("SAAJ0111.impl.body.parent.must.be.envelope");
throw new SOAPException("Parent of SOAPBody has to be a SOAPEnvelope");
}
super.setParentElement(element);
}
+ @Override
protected SOAPElement addElement(Name name) throws SOAPException {
return addBodyElement(name);
}
+ @Override
protected SOAPElement addElement(QName name) throws SOAPException {
return addBodyElement(name);
}
// public Node insertBefore(Node newElement, Node ref) throws DOMException {
@@ -224,10 +245,11 @@
// newElement = new ElementWrapper((ElementImpl) newElement);
// }
// return super.replaceChild(newElement, ref);
// }
+ @Override
public SOAPBodyElement addDocument(Document document)
throws SOAPException {
/*
Element rootNode =
@@ -250,21 +272,22 @@
// This copies the whole tree which could be very big so it's slow.
// However, it does have the advantage of actually working.
org.w3c.dom.Node replacingNode = ownerDoc.importNode(docFrag, true);
// Adding replacingNode at the last of the children list of body
addNode(replacingNode);
- Iterator<Node> i =
+ Iterator<javax.xml.soap.Node> i =
getChildElements(NameImpl.copyElementName(rootElement));
// Return the child element with the required name which is at the
// end of the list
while(i.hasNext())
newBodyElement = (SOAPBodyElement) i.next();
}
return newBodyElement;
//*/
}
+ @Override
protected SOAPElement convertToSoapElement(Element element) {
final Node soapNode = getSoapDocument().findIfPresent(element);
if ((soapNode instanceof SOAPBodyElement) &&
//this check is required because ElementImpl currently
// implements SOAPBodyElement
@@ -276,23 +299,25 @@
(ElementImpl) createBodyElement(NameImpl
.copyElementName(element)));
}
}
+ @Override
public SOAPElement setElementQName(QName newName) throws SOAPException {
log.log(Level.SEVERE,
"SAAJ0146.impl.invalid.name.change.requested",
new Object[] {elementQName.getLocalPart(),
newName.getLocalPart()});
throw new SOAPException("Cannot change name for "
+ elementQName.getLocalPart() + " to "
+ newName.getLocalPart());
}
+ @Override
public Document extractContentAsDocument() throws SOAPException {
- Iterator<Node> eachChild = getChildElements();
+ Iterator<javax.xml.soap.Node> eachChild = getChildElements();
javax.xml.soap.Node firstBodyElement = null;
while (eachChild.hasNext() &&
!(firstBodyElement instanceof SOAPElement))
firstBodyElement = (javax.xml.soap.Node) eachChild.next();
< prev index next >