package com.ebmwebsourcing.easybpel.usecase.seinedemo;

import javax.xml.namespace.QName;

import com.ebmwebsourcing.easybpel.model.bpel.api.BPELException;
import com.ebmwebsourcing.easybpel.model.bpel.api.message.BPELExternalMessage;
import com.ebmwebsourcing.easybpel.model.bpel.impl.message.BPELExternalMessageImpl;
import com.ebmwebsourcing.easyviper.core.api.CoreException;
import com.ebmwebsourcing.easyviper.environment.test.env.api.Operation;
import com.ebmwebsourcing.easyviper.environment.test.env.api.ProviderEndpoint;
import com.ebmwebsourcing.easyviper.environment.test.env.api.Service;
import com.ebmwebsourcing.easyviper.environment.test.env.impl.AbstractServiceImpl;
import com.ebmwebsourcing.easyviper.environment.test.env.impl.OperationImpl;

public class AP214AP239Service extends AbstractServiceImpl implements Service {


	public AP214AP239Service(ProviderEndpoint pep) throws BPELException {
		super(pep);
		this.setName(new QName("http://seinedemo.ebmwebsourcing.com/AP239/", "AP214AP239Service"));

		// Create operation
		this.createPutEnvelopeOperation();
	}

	
	private void createPutEnvelopeOperation() throws BPELException {
		try {
			Operation putEnvelope = new OperationImpl("PutEnvelope", Operation.IN_OUT, this);

			BPELExternalMessage in = new BPELExternalMessageImpl();
			in.setService(this.getName());
			in.setEndpoint(this.getProviderEndpoint().getName());
			in.setQName(new QName("http://seinedemo.ebmwebsourcing.com/AP239/", "PutEnvelope"));
			in.setMessage("" +
					"<tns:PutEnvelopeRequest_AP239Envelope xmlns:tns=\"http://seinedemo.ebmwebsourcing.com/AP239/\" xmlns:ap239=\"http://AP239/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ap239:AP239_Envelope_Type\">" +
						"<ap2:datasetId xmlns:ap2=\"http://AP239/\">45</ap2:datasetId>" +
						"<ap2:envelopeId xmlns:ap2=\"http://AP239/\">99</ap2:envelopeId>" +
						"<ap2:receivers xmlns:ap2=\"http://AP239/\">dassault</ap2:receivers>" +
						"<ap2:sender xmlns:ap2=\"http://AP239/\">thales</ap2:sender>" +
					"</tns:PutEnvelopeRequest_AP239Envelope>"
			);
			
			BPELExternalMessage out = new BPELExternalMessageImpl();
			out.setService(this.getName());
			out.setEndpoint(this.getProviderEndpoint().getName());
			out.setQName(new QName("http://seinedemo.ebmwebsourcing.com/AP239/", "PutEnvelope"));
			out.setMessage("" +
					"<tns:AP239Boolean xmlns:tns=\"http://seinedemo.ebmwebsourcing.com/AP239/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xsd:string\">" +
					"true" +
					"</tns:AP239Boolean>" 
			);
			putEnvelope.addMessageExchangeInstances(in, out, null);

			this.addOperation(putEnvelope);
		} catch (CoreException e) {
			throw new BPELException(e);
		}
	}
}
