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

package org.eu.adapt.demonstrator.client;

import java.net.URL;
import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_08.LoggingFacility_xsd.GetEventsRequestType;
import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_08.LoggingFacility_xsd.GetEventsResponseType_LogEntry;
import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_08.LoggingFacility_xsd.LogEventRequestType;
import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_08.LoggingFacility_xsd.GetEventsResponseType;
import org.ws_i.www.SampleApplications.SupplyChainManagement._2002_08.LoggingFacility_wsdl.LoggingFacilityLogPortType;
import org.eu.adapt.services.demo_1_1.DemoService_wsdl.DemoServiceLocator;

public class LogUser
{
    public static void main(String[] args)
    {
        try
        {
            String                     demoServiceURLString = args[0];
            DemoServiceLocator         demoServiceLocator   = new DemoServiceLocator();
            LoggingFacilityLogPortType logingFacility       = demoServiceLocator.getLogging(new URL(demoServiceURLString));

            LogEventRequestType logEventRequestType1 = new LogEventRequestType();
            logEventRequestType1.setDemoUserID("12345");
            logEventRequestType1.setServiceID("54321");
            logEventRequestType1.setEventDescription("Event Description 1");
            logEventRequestType1.setEventID("112345");

            LogEventRequestType logEventRequestType2 = new LogEventRequestType();
            logEventRequestType2.setDemoUserID("12345");
            logEventRequestType2.setServiceID("54321");
            logEventRequestType2.setEventDescription("Event Description 2");
            logEventRequestType2.setEventID("212345");

            LogEventRequestType logEventRequestType3 = new LogEventRequestType();
            logEventRequestType3.setDemoUserID("12345");
            logEventRequestType3.setServiceID("54321");
            logEventRequestType3.setEventDescription("Event Description 3");
            logEventRequestType3.setEventID("312345");

            LogEventRequestType logEventRequestType4 = new LogEventRequestType();
            logEventRequestType4.setDemoUserID("12345");
            logEventRequestType4.setServiceID("54321");
            logEventRequestType4.setEventDescription("Event Description 4");
            logEventRequestType4.setEventID("412345");

            logingFacility.logEvent(logEventRequestType1);
            logingFacility.logEvent(logEventRequestType2);
            logingFacility.logEvent(logEventRequestType3);
            logingFacility.logEvent(logEventRequestType4);

            Thread.sleep(5000);

            GetEventsRequestType getEventsRequestType = new GetEventsRequestType();
            getEventsRequestType.setDemoUserID("12345");

            GetEventsResponseType            getEventsResponseType = logingFacility.getEvents(getEventsRequestType);
            GetEventsResponseType_LogEntry[] logEnties             = getEventsResponseType.getLogEntry();

            for (int index = 0; index < logEnties.length; index++)
            {
                System.out.print("[" + logEnties[index].getTimestamp() + "] ");
                System.out.print(logEnties[index].getServiceID() + " ");
                System.out.print(logEnties[index].getEventID() + " ");
                System.out.println(" \"" + logEnties[index].getEventDescription() + "\"");
            }
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
        catch (Error error)
        {
            error.printStackTrace();
        }
    }
}
