001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import java.lang.reflect.Method;
004:
005: import javax.xml.datatype.Duration;
006:
007: import org.objectweb.celtix.bindings.AbstractBindingBase;
008: import org.objectweb.celtix.bindings.DataBindingCallback;
009: import org.objectweb.celtix.bindings.Request;
010: import org.objectweb.celtix.bus.configuration.wsrm.SourcePolicyType;
011: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
012: import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
013: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
014: import org.objectweb.celtix.bus.ws.addressing.VersionTransformer;
015: import org.objectweb.celtix.transports.Transport;
016: import org.objectweb.celtix.ws.addressing.AddressingProperties;
017: import org.objectweb.celtix.ws.addressing.AttributedURIType;
018: import org.objectweb.celtix.ws.addressing.RelatesToType;
019: import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType;
020: import org.objectweb.celtix.ws.rm.CreateSequenceType;
021: import org.objectweb.celtix.ws.rm.Expires;
022: import org.objectweb.celtix.ws.rm.OfferType;
023:
024: public class CreateSequenceRequest extends Request {
025:
026: private static final String METHOD_NAME = "createSequence";
027: private static final String OPERATION_NAME = "CreateSequence";
028:
029: public CreateSequenceRequest(
030: AbstractBindingBase b,
031: Transport t,
032: RMSource source,
033: org.objectweb.celtix.ws.addressing.EndpointReferenceType to,
034: EndpointReferenceType acksTo, RelatesToType relatesTo) {
035:
036: super (b, t, b.createObjectContext());
037:
038: if (to != null) {
039: ContextUtils.storeTo(to, getObjectMessageContext());
040: ContextUtils.storeReplyTo(VersionTransformer
041: .convert(acksTo), getObjectMessageContext());
042: }
043:
044: ContextUtils.storeUsingAddressing(true,
045: getObjectMessageContext());
046:
047: getObjectMessageContext().setRequestorRole(true);
048:
049: AddressingProperties maps = new AddressingPropertiesImpl();
050: AttributedURIType actionURI = ContextUtils.WSA_OBJECT_FACTORY
051: .createAttributedURIType();
052: actionURI.setValue(RMUtils.getRMConstants()
053: .getCreateSequenceAction());
054: maps.setAction(actionURI);
055: maps.setRelatesTo(relatesTo);
056: ContextUtils.storeMAPs(maps, getObjectMessageContext(), true,
057: true, true, true);
058:
059: setMessageParameters(source, acksTo);
060:
061: // this request is sent as the initial request in a pair of
062: // correlated oneways - setting the oneway flag to false is
063: // simply to ensure that the WS-Addressing RelpyTo property
064: // is included
065: setOneway(false);
066: expectRelatedRequest();
067: }
068:
069: public static Method getMethod() {
070: Method method = null;
071: try {
072: method = OutOfBandProtocolMessages.class.getMethod(
073: METHOD_NAME,
074: new Class[] { CreateSequenceType.class });
075: } catch (NoSuchMethodException ex) {
076: ex.printStackTrace();
077: }
078: return method;
079: }
080:
081: public static String getOperationName() {
082: return OPERATION_NAME;
083: }
084:
085: public static DataBindingCallback createDataBindingCallback() {
086: return new JAXBDataBindingCallback(getMethod(),
087: DataBindingCallback.Mode.PARTS, null);
088: }
089:
090: protected OfferType getIncludedOffer() {
091: Object[] params = getObjectMessageContext().getMessageObjects();
092: if (null == params || params.length < 1) {
093: return null;
094: }
095: return ((CreateSequenceType) params[0]).getOffer();
096: }
097:
098: private void setMessageParameters(RMSource source,
099: EndpointReferenceType defaultAcksTo) {
100: SourcePolicyType sourcePolicies = source.getSourcePolicies();
101: assert null != sourcePolicies;
102:
103: CreateSequenceType cs = RMUtils.getWSRMFactory()
104: .createCreateSequenceType();
105:
106: String address = sourcePolicies.getAcksTo();
107: EndpointReferenceType acksTo = null;
108: if (null != address) {
109: acksTo = RMUtils.createReference(address);
110: } else {
111: acksTo = defaultAcksTo;
112: }
113: cs.setAcksTo(acksTo);
114:
115: Duration d = sourcePolicies.getSequenceExpiration();
116: if (null != d) {
117: Expires expires = RMUtils.getWSRMFactory().createExpires();
118: expires.setValue(d);
119: cs.setExpires(expires);
120: }
121:
122: if (sourcePolicies.isIncludeOffer()) {
123: OfferType offer = RMUtils.getWSRMFactory()
124: .createOfferType();
125: d = sourcePolicies.getOfferedSequenceExpiration();
126: if (null != d) {
127: Expires expires = RMUtils.getWSRMFactory()
128: .createExpires();
129: expires.setValue(d);
130: offer.setExpires(expires);
131: }
132: offer.setIdentifier(source.generateSequenceIdentifier());
133: cs.setOffer(offer);
134: }
135:
136: getObjectMessageContext()
137: .setMessageObjects(new Object[] { cs });
138: }
139: }
|