package ebxml.roundtrip;

import com.bea.control.EBXMLControl;
import com.bea.control.ServiceBrokerControl;
import com.bea.jpd.JpdContext;
import com.bea.data.RawData;
import com.bea.wli.control.broker.MessageBroker;
import com.bea.wli.jpd.Callback;
import com.bea.wli.jpd.CallbackInterface;
import com.bea.xml.XmlObjectList;
import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.api.events.EventHandler;
import org.apache.xmlbeans.XmlObject;

@com.bea.wli.common.XQuery(version = com.bea.wli.common.XQuery.Version.v2002)
@com.bea.wli.jpd.Process(process = "<process name=\"RoundtripBuyer\"> " +
                                   "  <clientRequest name=\"Client Request\" method=\"startBuyer\"/> " +
                                   "  <controlSend name=\"processOrder\" method=\"roundtripSellerControlProcessOrder\"/> " +
                                   "  <controlReceive name=\"onInvoice\" method=\"roundtripSellerControl_onInvoice\"/> " +
                                   "  <clientCallback name=\"Client Response\" method=\"clientResponseCallbackHandler\"/> " +
                                   "</process>")
public class RoundtripBuyer implements com.bea.jpd.ProcessDefinition
{
    public com.bea.tutorial.invoice.InvoiceDocument invoice;

    public com.bea.tutorial.order.OrderDocument order;

    static final long serialVersionUID = 1L;

    @com.bea.wli.jpd.Callback()
    public Callback callback;

    /*
     * The area above this comment contains Variable Declarations created from the Design View.
     * The area below this comment contains Control Declarations created from the Design View.
     *
     * Code in these areas is generated automatically.
     *
     * 2-Way editing is fully supported in these areas of code.
     * Warning: changing Process Variables and Control Declarations already in use by your application
     * may generate errors in your application if you do not update these declarations
     * in all locations where they are used.
     */

    /**
     * @common:control
     * @jc:ebxml ebxml-service-name="RoundtripSeller"
     * @jc:tp-selector to-selector::
     * declare namespace ns0="bea.com/tutorial/order"
     *
     *
     *
     * data($order/ns0:Supplier_ID)::
     */
    @Control()
    @EBXMLControl.EbXML(serviceName = "RoundtripSeller")
    @com.bea.wli.jpd.TPSelector(toSelector = "declare namespace ns0=\"bea.com/tutorial/order\"" +
                                             "" +
                                             "" +
                                             "" +
                                             "data($order/ns0:Supplier_ID)")
    private ebxml.roundtrip.RoundtripSellerControl roundtripSellerControl;

    /**
     * @common:context
     */
    @com.bea.wli.jpd.Context()
    JpdContext context; //(..control insertion marker - do not modify this line)

    /*
     * The area below this comment contains java methods referenced by communication nodes in the Process Language.
     *
     * Code in this area is generated automatically.
     *
     * 2-Way editing is partially supported in this area of code.
     * Warning: you can safely add code inside a method body but it must be outside of any PROTECTED SECTION
     * block comments. Modifications to code within these comments will prevent you from viewing information
     * in the Design View builder that generated this code.
     */

    public void startBuyer(com.bea.tutorial.order.OrderDocument x0)
    {
        //#START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.order = x0;
        //#END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }




    public void roundtripSellerControlProcessOrder() throws Exception
    {
        //#START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // method call
        roundtripSellerControl.processOrder(this.order);
        // output transform
        // output assignments
        //#END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }

    @EventHandler(field = "roundtripSellerControl",
                  eventSet = RoundtripSellerControl.Callback.class,
                  eventName = "onInvoice")
    public void roundtripSellerControl_onInvoice(com.bea.tutorial.invoice.InvoiceDocument payload)
    {
        //#START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.invoice = payload;
        //#END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }




    public void clientResponseCallbackHandler()
    {
        //#START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // method call
        callback.onBuyerComplete(this.invoice);
        // output transform
        // output assignments
        //#END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }

	@CallbackInterface()
    public interface Callback extends ServiceBrokerControl //(..region end marker - do not modify this line)
    {

        void onBuyerComplete(com.bea.tutorial.invoice.InvoiceDocument x0);
    }

    /*
     * Code inserted below this comment is for methods corresponding to Perform or Condition nodes
     * created in the Design View.
     *
     * Feel free to make modifications or add new code here.
     */

}
