/*
 * Copyright (c) 2004, 2005, ADAPT project partners (IST-2001-37126).
 *
 * ManufacturerUser.java
 */

package org.eu.adapt.demonstrator.client;

import java.net.URL;

import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_10.ManufacturerPO_xsd.*;
import org.eu.adapt.services.demo_1_1.manufacturer.PurchaseOrderBasicService_wsdl.PurchaseOrderBasicServicePortType;
import org.eu.adapt.services.demo_1_1.manufacturer.PurchaseOrderBasicService_wsdl.PurchaseOrderBasicServiceLocator;
import org.eu.adapt.services.demo_1_1.manufacturer.ProductionLineBasicService_wsdl.ProductionLineBasicServicePortType;
import org.eu.adapt.services.demo_1_1.manufacturer.ProductionLineBasicService_wsdl.ProductionLineBasicServiceLocator;
import org.eu.adapt.services.demo_1_1.manufacturer.ProductionLineBasicService_wsdl.types.ProductionLineState;

public class ManufacturerUser
{
    public static void main(String[] args)
    {
        try
        {
            String                            purchaseOrderBasicServiceURLString = args[0];
            PurchaseOrderBasicServiceLocator  purchaseOrderBasicServiceLocator   = new PurchaseOrderBasicServiceLocator();
            PurchaseOrderBasicServicePortType purchaseOrderBasicService          = purchaseOrderBasicServiceLocator.getPurchaseOrder(new URL(purchaseOrderBasicServiceURLString));

            PurchOrdType purchOrd = new PurchOrdType();
            purchOrd.setCustomerRef("TTN");
            purchOrd.setOrderNum("TTN00010");
            purchOrd.setTotal(100.00f);
            Item[] items = new Item[2];
            items[0] = new Item();
            items[0].setID("100");
            items[0].setQty(100);
            items[0].setPrice(100.00f);
            items[1] = new Item();
            items[1].setID("101");
            items[1].setQty(101);
            items[1].setPrice(101.00f);
            ItemList itemList = new ItemList();
            itemList.setItem(items);
            purchOrd.setItems(itemList);

            if (purchaseOrderBasicService.checkPurchaseOrder(purchOrd))
            {
                System.out.println("Purchase Order: OK");
                
                purchaseOrderBasicService.addPurchaseOrder(purchOrd);
                
                System.out.println("Purchase Order: Added");
                
                purchaseOrderBasicService.removePurchaseOrder(purchOrd);
                
                System.out.println("Purchase Order: Removed");
            }
            else
                System.out.println("Purchase Order: Invalid");

            String                             productionLineBasicServiceURLString = args[1];
            ProductionLineBasicServiceLocator  productionLineBasicServiceLocator   = new ProductionLineBasicServiceLocator();
            ProductionLineBasicServicePortType productionLineBasicServicePortType  = productionLineBasicServiceLocator.getProductionLine(new URL(productionLineBasicServiceURLString));

            ProductionLineState state = productionLineBasicServicePortType.getProductionLineState("Test");

            System.out.println("Storehouse: " + state.getStorehouseName());

            for (int finishedProductIndex = 0; finishedProductIndex < state.getFinishedGoodsNames().length; finishedProductIndex++)
                System.out.println("Finished Product " + finishedProductIndex + ": " + state.getFinishedGoodsNames(finishedProductIndex));
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
        catch (Error error)
        {
            error.printStackTrace();
        }
    }
}
