private static SOAPEnvelope configureCloseSequence()

in modules/core/src/main/java/org/apache/sandesha2/client/SandeshaClient.java [973:1052]


	private static SOAPEnvelope configureCloseSequence(Options options, ConfigurationContext configurationContext)
			throws SandeshaException {

		if (options == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.optionsObjectNotSet));

		EndpointReference epr = options.getTo();
		if (epr == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.toEPRNotValid, null));

		//first see if the cliet has told us which sequence to close
		String internalSequenceID = 
			(String)options.getProperty(SandeshaClientConstants.INTERNAL_SEQUENCE_ID);
		
		if(internalSequenceID==null){
			//lookup the internal seq id based on to EPR and sequenceKey
			String to = epr.getAddress();
			String sequenceKey = (String) options.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
			internalSequenceID = SandeshaUtil.getInternalSequenceID(to, sequenceKey);
		}

		StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
		
		// Get a transaction for getting the sequence properties
		Transaction transaction = null;
		String sequenceID = null;
		SOAPEnvelope dummyEnvelope = null;
		try
		{
			transaction = storageManager.getTransaction();
			sequenceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(internalSequenceID, storageManager);
			if (sequenceID == null)
				sequenceID = Sandesha2Constants.TEMP_SEQUENCE_ID;	

			String rmSpecVersion = (String) options.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);

			if (rmSpecVersion == null)
				rmSpecVersion = SpecSpecificConstants.getDefaultSpecVersion();

			if (!SpecSpecificConstants.isSequenceClosingAllowed(rmSpecVersion))
				throw new SandeshaException(SandeshaMessageHelper.getMessage(
						SandeshaMessageKeys.closeSequenceSpecLevel, rmSpecVersion));
			
			SOAPFactory factory = null;
			String soapNamespaceURI = options.getSoapVersionURI();
			if (soapNamespaceURI == null) 
				soapNamespaceURI = getSOAPNamespaceURI(storageManager, internalSequenceID);

			if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNamespaceURI)) {
				factory = OMAbstractFactory.getSOAP12Factory();
				dummyEnvelope = factory.getDefaultEnvelope();
			} else {
				factory = OMAbstractFactory.getSOAP11Factory();
				dummyEnvelope = factory.getDefaultEnvelope();
			}

			String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmSpecVersion);

			CloseSequence closeSequence = new CloseSequence(rmNamespaceValue);
			Identifier identifier = new Identifier(rmNamespaceValue);
			identifier.setIndentifer(sequenceID);
			closeSequence.setIdentifier(identifier);
			if(closeSequence.isLastMsgNumberRequired(rmNamespaceValue)){
				LastMessageNumber lastMsgNumber = new LastMessageNumber(rmNamespaceValue);
				lastMsgNumber.setMessageNumber(SandeshaUtil.getLastMessageNumber(internalSequenceID, storageManager));
				closeSequence.setLastMessageNumber(lastMsgNumber);
			}
			closeSequence.toSOAPEnvelope(dummyEnvelope);

		}
		finally
		{
			// Commit the tran whatever happened
			if(transaction != null) transaction.commit();
		}
		
		return dummyEnvelope;
	}