/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* {@link Message} implementation backed by {@link XMLStreamReader}.
*
* TODO: we need another message class that keeps {@link XMLStreamReader} that points
* at the start of the envelope element.
*/
/**
* The reader will be positioned at
* the first child of the SOAP body
*/
// lazily created
/**
* infoset about the SOAP envelope, header, and body.
*
* <p>
* If the creater of this object didn't care about those,
* we use stock values.
*/
/**
* Creates a {@link StreamMessage} from a {@link XMLStreamReader}
* that points at the start element of the payload, and headers.
*
* <p>
* This method creaets a {@link Message} from a payload.
*
* @param headers
* if null, it means no headers. if non-null,
* it will be owned by this message.
* @param reader
* if there's no payload)
*/
public StreamMessage(@Nullable HeaderList headers, @NotNull AttachmentSet attachmentSet, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
super(soapVersion);
this.attachmentSet = attachmentSet;
//if the reader is pointing to the end element </soapenv:Body> then its empty message
// or no payload
//if its not soapenv:Body then throw exception, we received malformed stream
this.payloadLocalName = null;
this.payloadNamespaceURI = null;
}else{ //TODO: i18n and also we should be throwing better message that this
}
}else{
}
// use the default infoset representation for headers
}
/**
* Creates a {@link StreamMessage} from a {@link XMLStreamReader}
* and the complete infoset of the SOAP envelope.
*
* <p>
* See {@link #StreamMessage(HeaderList, AttachmentSet, XMLStreamReader, SOAPVersion)} for
* the description of the basic parameters.
*
* @param headerTag
* Null if the message didn't have a header tag.
*
*/
public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable HeaderList headers, @NotNull TagInfoset bodyTag, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
if(envelopeTag == null ) {
throw new IllegalArgumentException("EnvelopeTag TagInfoset cannot be null");
}
throw new IllegalArgumentException("BodyTag TagInfoset cannot be null");
}
this.envelopeTag = envelopeTag;
}
public boolean hasHeaders() {
}
headers = new HeaderList();
}
return headers;
}
return payloadLocalName;
}
return payloadNamespaceURI;
}
public boolean hasPayload() {
return payloadLocalName!=null;
}
if(hasPayload()) {
assert unconsumed();
} else
return null;
}
/**
* There is no way to enumerate inscope namespaces for XMLStreamReader. That means
* namespaces declared in envelope, and body tags need to be computed using their
* {@link TagInfoset}s.
*
* @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }
*/
nss.pushContext();
}
nss.pushContext();
}
}
}
if(!hasPayload())
return null;
assert unconsumed();
// TODO: How can the unmarshaller process this as a fragment?
if(hasAttachments())
try {
} finally{
}
}
if(!hasPayload())
return null;
assert unconsumed();
return r;
}
public void consume() {
assert unconsumed();
}
if(!hasPayload())
return null;
// TODO: What about access at and beyond </soap:Body>
assert unconsumed();
return this.reader;
}
if(payloadLocalName==null)
return; // no body
assert unconsumed();
//after previous conv.bridge() call the cursor will be at
//END_ELEMENT. Check if its not soapenv:Body then move to next
// ELEMENT
break;
}
}
if(name.equals("Body") && nsUri.equals(soapVersion.nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
break;
}
}
}
/**
* This method should be called when the StreamMessage is created with a payload
* @param writer
*/
//write headers
}
}
if(hasPayload())
}
public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
assert unconsumed();
try {
if(payloadLocalName==null)
return; // no body
//after previous conv.bridge() call the cursor will be at
//END_ELEMENT. Check if its not soapenv:Body then move to next
// ELEMENT
break;
}
}
if(name.equals("Body") && nsUri.equals(soapVersion.nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
break;
}
} catch (XMLStreamException e) {
SAXParseException x = new SAXParseException(
errorHandler.error(x);
}
}
try {
assert unconsumed();
// preserving inscope namespaces from envelope, and body. Other option
// would be to create a filtering XMLStreamReader from reader+envelopeTag+bodyTag
if (hasPayload()) {
// Loop all the way for multi payload case
if(name.equals("Body") && nsUri.equals(soapVersion.nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
break;
// Skip whitespaces in between payload and </Body> or between elements
if (reader.isWhiteSpace()) {
}
}
}
c.storeEndElement(); // create structure element for </Body>
c.storeEndElement(); // create structure element for </Envelope>
c.storeEndElement(); // create structure element for END_DOCUMENT
// advance to the start tag of the <Body> first child element
return new StreamMessage(envelopeTag, headerTag, attachmentSet, HeaderList.copy(headers), bodyTag, clone, soapVersion);
} catch (XMLStreamException e) {
throw new WebServiceException("Failed to copy a message",e);
}
}
}
public void writeTo( ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException {
if(hasHeaders()) {
for( int i=0; i<len; i++ ) {
// shouldn't JDK be smart enough to use array-style indexing for this foreach!?
}
}
}
/**
* Used for an assertion. Returns true when the message is unconsumed,
* or otherwise throw an exception.
*
* <p>
* Calling this method also marks the stream as 'consumed'
*/
private boolean unconsumed() {
if(payloadLocalName==null)
return true; // no payload. can be consumed multiple times.
AssertionError error = new AssertionError("StreamMessage has been already consumed. See the nested exception for where it's consumed");
throw error;
}
return true;
}
/**
* Used only for debugging. This records where the message was consumed.
*/
/**
* Default s:Envelope, s:Header, and s:Body tag infoset definitions.
*
* We need 3 for SOAP 1.1, 3 for SOAP 1.2.
*/
static {
}
}
}