Author: richard.opalka(a)jboss.com
Date: 2007-09-10 10:13:48 -0400 (Mon, 10 Sep 2007)
New Revision: 4537
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceResponseSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceResponseSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/SerializationHelper.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceResponseSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceSerializer.java
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/spi/protocol/CreateSequenceResponse.java
Log:
implementing other serializers + little optimization
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceResponseSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceResponseSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceResponseSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,10 +21,18 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
+import org.jboss.ws.extensions.wsrm.spi.Constants;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.CloseSequenceResponse;
@@ -49,7 +57,25 @@
public static void deserialize(CloseSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ Constants wsrmConstants = provider.getConstants();
+
+ // read wsrm:CloseSequenceResponse
+ QName closeSequenceResponseQName =
wsrmConstants.getCloseSequenceResponseQName();
+ SOAPElement closeSequenceResponseElement = getRequiredElement(soapBody,
closeSequenceResponseQName, "soap body");
+
+ // read wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+ SOAPElement identifierElement = getRequiredElement(closeSequenceResponseElement,
identifierQName, closeSequenceResponseQName);
+ String identifier = getRequiredTextContent(identifierElement, identifierQName);
+ object.setIdentifier(identifier);
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to deserialize RM
message", se);
+ }
}
/**
@@ -61,7 +87,26 @@
public static void serialize(CloseSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
+ Constants wsrmConstants = provider.getConstants();
+
+ // Add xmlns:wsrm declaration
+ soapEnvelope.addNamespaceDeclaration(wsrmConstants.getPrefix(),
wsrmConstants.getNamespaceURI());
+
+ // write wsrm:CloseSequenceResponse
+ QName closeSequenceResponseQName =
wsrmConstants.getCloseSequenceResponseQName();
+ SOAPElement closeSequenceResponseElement =
soapEnvelope.getBody().addChildElement(closeSequenceResponseQName);
+
+ // write wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+
closeSequenceResponseElement.addChildElement(identifierQName).setValue(object.getIdentifier());
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to serialize RM message",
se);
+ }
}
}
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CloseSequenceSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,10 +21,19 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getOptionalElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
+import org.jboss.ws.extensions.wsrm.spi.Constants;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.CloseSequence;
@@ -49,7 +58,40 @@
public static void deserialize(CloseSequence object, Provider provider, SOAPMessage
soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ Constants wsrmConstants = provider.getConstants();
+
+ // read wsrm:CloseSequence
+ QName closeSequenceQName = wsrmConstants.getCloseSequenceQName();
+ SOAPElement closeSequenceElement = getRequiredElement(soapBody,
closeSequenceQName, "soap body");
+
+ // read wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+ SOAPElement identifierElement = getRequiredElement(closeSequenceElement,
identifierQName, closeSequenceQName);
+ String identifier = getRequiredTextContent(identifierElement, identifierQName);
+ object.setIdentifier(identifier);
+
+ // read wsrm:LastMsgNumber
+ QName lastMsgNumberQName = wsrmConstants.getLastMsgNumberQName();
+ SOAPElement lastMsgNumberElement = getOptionalElement(closeSequenceElement,
lastMsgNumberQName, closeSequenceQName);
+ if (lastMsgNumberElement != null)
+ {
+ try
+ {
+ long lastMsgNumber =
Long.valueOf(getRequiredTextContent(lastMsgNumberElement, lastMsgNumberQName));
+ object.setLastMsgNumber(lastMsgNumber);
+ } catch (NumberFormatException nfe)
+ {
+ throw new ReliableMessagingException("Unable to parse LastMsgNumber
element text content", nfe);
+ }
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to deserialize RM
message", se);
+ }
}
/**
@@ -61,7 +103,34 @@
public static void serialize(CloseSequence object, Provider provider, SOAPMessage
soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
+ Constants wsrmConstants = provider.getConstants();
+
+ // Add xmlns:wsrm declaration
+ soapEnvelope.addNamespaceDeclaration(wsrmConstants.getPrefix(),
wsrmConstants.getNamespaceURI());
+
+ // write wsrm:CloseSequence
+ QName closeSequenceQName = wsrmConstants.getCloseSequenceQName();
+ SOAPElement closeSequenceElement =
soapEnvelope.getBody().addChildElement(closeSequenceQName);
+
+ // write wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+
closeSequenceElement.addChildElement(identifierQName).setValue(object.getIdentifier());
+
+ if (object.getLastMsgNumber() != 0)
+ {
+ // write wsrm:LastMsgNumber
+ QName lastMsgNumberQName = wsrmConstants.getLastMsgNumberQName();
+ SOAPElement lastMsgNumberElement =
closeSequenceElement.addChildElement(lastMsgNumberQName);
+ lastMsgNumberElement.setValue(String.valueOf(object.getLastMsgNumber()));
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to serialize RM message",
se);
+ }
}
}
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceResponseSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceResponseSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceResponseSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,12 +21,24 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getOptionalElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.addressing.AddressingBuilder;
+import javax.xml.ws.addressing.AddressingConstants;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
+import org.jboss.ws.extensions.wsrm.spi.Constants;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.CreateSequenceResponse;
+import org.jboss.ws.extensions.wsrm.spi.protocol.IncompleteSequenceBehavior;
/**
* <b>CreateSequenceResponse</b> object de/serializer
@@ -35,6 +47,9 @@
final class CreateSequenceResponseSerializer
{
+ private static final AddressingConstants ADDRESSING_CONSTANTS =
+ AddressingBuilder.getAddressingBuilder().newAddressingConstants();
+
private CreateSequenceResponseSerializer()
{
// no instances
@@ -49,7 +64,61 @@
public static void deserialize(CreateSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ Constants wsrmConstants = provider.getConstants();
+
+ // read wsrm:CreateSequenceResponse
+ QName createSequenceResponseQName =
wsrmConstants.getCreateSequenceResponseQName();
+ SOAPElement createSequenceResponseElement = getRequiredElement(soapBody,
createSequenceResponseQName, "soap body");
+
+ // read wsrm:identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+ SOAPElement identifierElement =
getRequiredElement(createSequenceResponseElement, identifierQName,
createSequenceResponseQName);
+ String identifier = getRequiredTextContent(identifierElement, identifierQName);
+ object.setIdentifier(identifier);
+
+ // read wsrm:Expires
+ QName expiresQName = wsrmConstants.getExpiresQName();
+ SOAPElement expiresElement = getOptionalElement(createSequenceResponseElement,
expiresQName, createSequenceResponseQName);
+ if (expiresElement != null)
+ {
+ String duration = getRequiredTextContent(expiresElement, expiresQName);
+ object.setExpires(duration);
+ }
+
+ // read wsrm:IncompleteSequenceBehavior
+ QName behaviorQName = wsrmConstants.getIncompleteSequenceBehaviorQName();
+ SOAPElement behaviorElement = getOptionalElement(createSequenceResponseElement,
behaviorQName, createSequenceResponseQName);
+ if (behaviorElement != null)
+ {
+ String behaviorString = getRequiredTextContent(behaviorElement,
behaviorQName);
+
object.setIncompleteSequenceBehavior(IncompleteSequenceBehavior.getValue(behaviorString));
+ }
+
+ // read wsrm:Accept
+ QName acceptQName = wsrmConstants.getAcceptQName();
+ SOAPElement acceptElement = getOptionalElement(createSequenceResponseElement,
acceptQName, createSequenceResponseQName);
+ if (acceptElement != null)
+ {
+ CreateSequenceResponse.Accept accept = object.newAccept();
+
+ // read wsrm:AcksTo
+ QName acksToQName = wsrmConstants.getAcksToQName();
+ SOAPElement acksToElement = getRequiredElement(acceptElement, acksToQName,
acceptQName);
+ QName addressQName = ADDRESSING_CONSTANTS.getAddressQName();
+ SOAPElement acksToAddressElement = getRequiredElement(acksToElement,
addressQName, acksToQName);
+ String acksToAddress = getRequiredTextContent(acksToAddressElement,
addressQName);
+ accept.setAcksTo(acksToAddress);
+
+ object.setAccept(accept);
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to deserialize RM
message", se);
+ }
}
/**
@@ -61,7 +130,56 @@
public static void serialize(CreateSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
+ Constants wsrmConstants = provider.getConstants();
+
+ // Add xmlns:wsrm declaration
+ soapEnvelope.addNamespaceDeclaration(wsrmConstants.getPrefix(),
wsrmConstants.getNamespaceURI());
+
+ // write wsrm:CreateSequenceResponse
+ QName createSequenceResponseQName =
wsrmConstants.getCreateSequenceResponseQName();
+ SOAPElement createSequenceResponseElement =
soapEnvelope.getBody().addChildElement(createSequenceResponseQName);
+
+ // write wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+
createSequenceResponseElement.addChildElement(identifierQName).setValue(object.getIdentifier());
+
+ if (object.getExpires() != null)
+ {
+ // write wsrm:Expires
+ QName expiresQName = wsrmConstants.getExpiresQName();
+
createSequenceResponseElement.addChildElement(expiresQName).setValue(object.getExpires());
+ }
+
+ if (object.getIncompleteSequenceBehavior() != null)
+ {
+ // write wsrm:IncompleteSequenceBehavior
+ IncompleteSequenceBehavior behavior =
object.getIncompleteSequenceBehavior();
+ QName behaviorQName = wsrmConstants.getIncompleteSequenceBehaviorQName();
+ SOAPElement behaviorElement =
createSequenceResponseElement.addChildElement(behaviorQName);
+ behaviorElement.setValue(behavior.toString());
+ }
+
+ if (object.getAccept() != null)
+ {
+ // write wsrm:Accept
+ QName acceptQName = wsrmConstants.getAcceptQName();
+ SOAPElement acceptElement =
createSequenceResponseElement.addChildElement(acceptQName);
+
+ // write wsrm:AcksTo
+ QName acksToQName = wsrmConstants.getAcksToQName();
+ QName addressQName = ADDRESSING_CONSTANTS.getAddressQName();
+ acceptElement.addChildElement(acksToQName)
+ .addChildElement(addressQName)
+ .setValue(object.getAccept().getAcksTo());
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to serialize RM message",
se);
+ }
}
}
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/CreateSequenceSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,7 +21,9 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
-import static org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.*;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getOptionalElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPBody;
@@ -37,7 +39,6 @@
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.CreateSequence;
import org.jboss.ws.extensions.wsrm.spi.protocol.IncompleteSequenceBehavior;
-import org.w3c.dom.Element;
/**
* <b>CreateSequence</b> object de/serializer
@@ -70,19 +71,19 @@
// read wsrm:CreateSequence
QName createSequenceQName = wsrmConstants.getCreateSequenceQName();
- Element createSequenceElement = getRequiredElement(soapBody,
createSequenceQName, "soap body");
+ SOAPElement createSequenceElement = getRequiredElement(soapBody,
createSequenceQName, "soap body");
// read wsrm:AcksTo
QName acksToQName = wsrmConstants.getAcksToQName();
- Element acksToElement = getRequiredElement(createSequenceElement, acksToQName,
createSequenceQName);
+ SOAPElement acksToElement = getRequiredElement(createSequenceElement,
acksToQName, createSequenceQName);
QName addressQName = ADDRESSING_CONSTANTS.getAddressQName();
- Element acksToAddressElement = getRequiredElement(acksToElement, addressQName,
acksToQName);
+ SOAPElement acksToAddressElement = getRequiredElement(acksToElement,
addressQName, acksToQName);
String acksToAddress = getRequiredTextContent(acksToAddressElement,
addressQName);
object.setAcksTo(acksToAddress);
// read wsrm:Expires
QName expiresQName = wsrmConstants.getExpiresQName();
- Element expiresElement = getOptionalElement(createSequenceElement, expiresQName,
createSequenceQName);
+ SOAPElement expiresElement = getOptionalElement(createSequenceElement,
expiresQName, createSequenceQName);
if (expiresElement != null)
{
String duration = getRequiredTextContent(expiresElement, expiresQName);
@@ -91,29 +92,29 @@
// read wsrm:Offer
QName offerQName = wsrmConstants.getOfferQName();
- Element offerElement = getOptionalElement(createSequenceElement, offerQName,
createSequenceQName);
+ SOAPElement offerElement = getOptionalElement(createSequenceElement, offerQName,
createSequenceQName);
if (offerElement != null)
{
CreateSequence.Offer offer = object.newOffer();
- // read wsrm:identifier
+ // read wsrm:Identifier
QName identifierQName = wsrmConstants.getIdentifierQName();
- Element identifierElement = getRequiredElement(offerElement, identifierQName,
offerQName);
+ SOAPElement identifierElement = getRequiredElement(offerElement,
identifierQName, offerQName);
String identifier = getRequiredTextContent(identifierElement,
identifierQName);
offer.setIdentifier(identifier);
// read wsrm:Endpoint
QName endpointQName = wsrmConstants.getEndpointQName();
- Element endpointElement = getOptionalElement(offerElement, endpointQName,
offerQName);
+ SOAPElement endpointElement = getOptionalElement(offerElement, endpointQName,
offerQName);
if (endpointElement != null)
{
- Element endpointAddressElement = getRequiredElement(endpointElement,
addressQName, endpointQName);
+ SOAPElement endpointAddressElement = getRequiredElement(endpointElement,
addressQName, endpointQName);
String endpointAddress = getRequiredTextContent(endpointAddressElement,
addressQName);
offer.setEndpoint(endpointAddress);
}
// read wsrm:Expires
- Element offerExpiresElement = getOptionalElement(offerElement, expiresQName,
offerQName);
+ SOAPElement offerExpiresElement = getOptionalElement(offerElement,
expiresQName, offerQName);
if (offerExpiresElement != null)
{
String duration = getRequiredTextContent(offerExpiresElement,
expiresQName);
@@ -122,7 +123,7 @@
// read wsrm:IncompleteSequenceBehavior
QName behaviorQName = wsrmConstants.getIncompleteSequenceBehaviorQName();
- Element behaviorElement = getOptionalElement(offerElement, behaviorQName,
offerQName);
+ SOAPElement behaviorElement = getOptionalElement(offerElement, behaviorQName,
offerQName);
if (behaviorElement != null)
{
String behaviorString = getRequiredTextContent(behaviorElement,
behaviorQName);
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/SerializationHelper.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/SerializationHelper.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/SerializationHelper.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.ws.extensions.wsrm.common.serialization;
import java.util.List;
@@ -4,8 +25,13 @@
import javax.xml.namespace.QName;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
import org.jboss.wsf.common.DOMUtils;
+import javax.xml.soap.SOAPElement;
import org.w3c.dom.Element;
+/**
+ * Serialization helper - TODO: optimize it to minimize usage of org.w3c.dom.Element
class
+ * @author richard.opalka(a)jboss.com
+ */
final class SerializationHelper
{
@@ -14,7 +40,7 @@
// no instances
}
- public static String getRequiredTextContent(Element element, QName nodeName)
+ public static String getRequiredTextContent(SOAPElement element, QName nodeName)
{
if (!DOMUtils.hasTextChildNodesOnly(element))
throw new ReliableMessagingException(
@@ -33,24 +59,39 @@
return getRequiredElementFromList(list, requiredQName.getLocalPart(), context);
}
- public static Element getRequiredElement(Element element, QName requiredQName, QName
contextQName)
+ private static Element getRequiredElement(Element element, QName requiredQName, QName
contextQName)
{
List<Element> list = DOMUtils.getChildElementsAsList(element,
requiredQName);
return getRequiredElementFromList(list, requiredQName, contextQName);
}
- public static Element getRequiredElement(Element element, QName requiredQName, String
context)
+ public static SOAPElement getRequiredElement(SOAPElement element, QName requiredQName,
QName contextQName)
{
+ return (SOAPElement)getRequiredElement((Element)element, requiredQName,
contextQName);
+ }
+
+ private static Element getRequiredElement(Element element, QName requiredQName, String
context)
+ {
List<Element> list = DOMUtils.getChildElementsAsList(element,
requiredQName);
return getRequiredElementFromList(list, requiredQName, context);
}
- public static Element getOptionalElement(Element element, QName optionalQName, QName
contextQName)
+ public static SOAPElement getRequiredElement(SOAPElement element, QName requiredQName,
String context)
{
+ return (SOAPElement)getRequiredElement((Element)element, requiredQName, context);
+ }
+
+ private static Element getOptionalElement(Element element, QName optionalQName, QName
contextQName)
+ {
List<Element> list = DOMUtils.getChildElementsAsList(element,
optionalQName);
return getOptionalElementFromList(list, optionalQName, contextQName);
}
+ public static SOAPElement getOptionalElement(SOAPElement element, QName optionalQName,
QName contextQName)
+ {
+ return (SOAPElement)getOptionalElement((Element)element, optionalQName,
contextQName);
+ }
+
private static Element getOptionalElementFromList(List<Element> list, QName
requiredQName, QName contextQName)
{
return getOptionalElementFromList(list, requiredQName.getLocalPart(),
contextQName.getLocalPart());
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceResponseSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceResponseSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceResponseSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,10 +21,18 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
+import org.jboss.ws.extensions.wsrm.spi.Constants;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.TerminateSequenceResponse;
@@ -49,7 +57,25 @@
public static void deserialize(TerminateSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ Constants wsrmConstants = provider.getConstants();
+
+ // read wsrm:TerminateSequenceResponse
+ QName terminateSequenceResponseQName =
wsrmConstants.getTerminateSequenceResponseQName();
+ SOAPElement terminateSequenceResponseElement = getRequiredElement(soapBody,
terminateSequenceResponseQName, "soap body");
+
+ // read wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+ SOAPElement identifierElement =
getRequiredElement(terminateSequenceResponseElement, identifierQName,
terminateSequenceResponseQName);
+ String identifier = getRequiredTextContent(identifierElement, identifierQName);
+ object.setIdentifier(identifier);
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to deserialize RM
message", se);
+ }
}
/**
@@ -61,7 +87,26 @@
public static void serialize(TerminateSequenceResponse object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
+ Constants wsrmConstants = provider.getConstants();
+
+ // Add xmlns:wsrm declaration
+ soapEnvelope.addNamespaceDeclaration(wsrmConstants.getPrefix(),
wsrmConstants.getNamespaceURI());
+
+ // write wsrm:TerminateSequenceResponse
+ QName terminateSequenceResponseQName =
wsrmConstants.getTerminateSequenceResponseQName();
+ SOAPElement terminateSequenceResponseElement =
soapEnvelope.getBody().addChildElement(terminateSequenceResponseQName);
+
+ // write wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+
terminateSequenceResponseElement.addChildElement(identifierQName).setValue(object.getIdentifier());
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to serialize RM message",
se);
+ }
}
}
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceSerializer.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceSerializer.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/common/serialization/TerminateSequenceSerializer.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -21,10 +21,19 @@
*/
package org.jboss.ws.extensions.wsrm.common.serialization;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getOptionalElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredElement;
+import static
org.jboss.ws.extensions.wsrm.common.serialization.SerializationHelper.getRequiredTextContent;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.extensions.wsrm.ReliableMessagingException;
+import org.jboss.ws.extensions.wsrm.spi.Constants;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.TerminateSequence;
@@ -49,7 +58,40 @@
public static void deserialize(TerminateSequence object, Provider provider,
SOAPMessage soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ Constants wsrmConstants = provider.getConstants();
+
+ // read wsrm:TerminateSequence
+ QName terminateSequenceQName = wsrmConstants.getTerminateSequenceQName();
+ SOAPElement terminateSequenceElement = getRequiredElement(soapBody,
terminateSequenceQName, "soap body");
+
+ // read wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+ SOAPElement identifierElement = getRequiredElement(terminateSequenceElement,
identifierQName, terminateSequenceQName);
+ String identifier = getRequiredTextContent(identifierElement, identifierQName);
+ object.setIdentifier(identifier);
+
+ // read wsrm:LastMsgNumber
+ QName lastMsgNumberQName = wsrmConstants.getLastMsgNumberQName();
+ SOAPElement lastMsgNumberElement = getOptionalElement(terminateSequenceElement,
lastMsgNumberQName, terminateSequenceQName);
+ if (lastMsgNumberElement != null)
+ {
+ try
+ {
+ long lastMsgNumber =
Long.valueOf(getRequiredTextContent(lastMsgNumberElement, lastMsgNumberQName));
+ object.setLastMsgNumber(lastMsgNumber);
+ } catch (NumberFormatException nfe)
+ {
+ throw new ReliableMessagingException("Unable to parse LastMsgNumber
element text content", nfe);
+ }
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to deserialize RM
message", se);
+ }
}
/**
@@ -61,7 +103,34 @@
public static void serialize(TerminateSequence object, Provider provider, SOAPMessage
soapMessage)
throws ReliableMessagingException
{
- throw new NotImplementedException();
+ try
+ {
+ SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
+ Constants wsrmConstants = provider.getConstants();
+
+ // Add xmlns:wsrm declaration
+ soapEnvelope.addNamespaceDeclaration(wsrmConstants.getPrefix(),
wsrmConstants.getNamespaceURI());
+
+ // write wsrm:TerminateSequence
+ QName terminateSequenceQName = wsrmConstants.getTerminateSequenceQName();
+ SOAPElement terminateSequenceElement =
soapEnvelope.getBody().addChildElement(terminateSequenceQName);
+
+ // write wsrm:Identifier
+ QName identifierQName = wsrmConstants.getIdentifierQName();
+
terminateSequenceElement.addChildElement(identifierQName).setValue(object.getIdentifier());
+
+ if (object.getLastMsgNumber() != 0)
+ {
+ // write wsrm:LastMsgNumber
+ QName lastMsgNumberQName = wsrmConstants.getLastMsgNumberQName();
+ SOAPElement lastMsgNumberElement =
terminateSequenceElement.addChildElement(lastMsgNumberQName);
+ lastMsgNumberElement.setValue(String.valueOf(object.getLastMsgNumber()));
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new ReliableMessagingException("Unable to serialize RM message",
se);
+ }
}
}
Modified:
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/spi/protocol/CreateSequenceResponse.java
===================================================================
---
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/spi/protocol/CreateSequenceResponse.java 2007-09-10
08:33:00 UTC (rev 4536)
+++
stack/native/branches/ropalka/trunk/src/main/java/org/jboss/ws/extensions/wsrm/spi/protocol/CreateSequenceResponse.java 2007-09-10
14:13:48 UTC (rev 4537)
@@ -83,9 +83,9 @@
/**
* This element, if present, specifies the behavior that the destination will exhibit
upon the closure or
* termination of an incomplete Sequence.
- * @param incompletSequenceBehaviour
+ * @param incompleteSequenceBehavior
*/
- void setIncompleteSequenceBehavior(IncompleteSequenceBehavior
incompletSequenceBehaviour);
+ void setIncompleteSequenceBehavior(IncompleteSequenceBehavior
incompleteSequenceBehavior);
/**
* Getter