package tutorial.sample5.client;

import java.io.IOException;

import java.awt.*;
import javax.swing.*;

import javax.activation.DataHandler;
import javax.xml.rpc.ServiceException;

public class Main{

  public static void main( String[] args ){

    if( args.length == 1 ){
      new Main( args[0] );
    }else{
      throw new IllegalArgumentException( "URL of the service not specified" );
    }
  }

  private void displayImage( Image image ){
    JFrame frame = new JFrame( "Attachment Sample" );
    frame.setSize( 300, 100 );
    frame.getContentPane().setLayout( new FlowLayout() );
    frame.getContentPane().add( new JLabel( new ImageIcon( image ) ) );
    frame.setVisible( true );

    try{
      Thread.sleep( 5000 );
    }catch( Exception e ){}

    frame.setVisible( false );
    System.exit(0);
  }

  public Main( String wsdlUrl ){
    try{
      HelloWorldService service = new HelloWorldService_Impl( wsdlUrl );
      HelloWorldServicePort port = service.getHelloWorldServicePort();
      Image image = port.helloAttachmentWorld( "Attachment World" );
      Image[] images = port.echoImageArray( new Image[]{image} );
      weblogic.utils.Debug.say( "(manoj):images" +images );
      weblogic.utils.Debug.say( "(manoj):images" +images.length );
      DataHandler handler = new DataHandler( "Hi there", "text/plain" );
      DataHandler result = port.echoDataHandler( handler );
      weblogic.utils.Debug.say( "(manoj):result" +result );

      DataHandler[] arrayResult = port.echoDataHandlerArray( 
          new DataHandler[]{ handler, result, handler} );

      weblogic.utils.Debug.say( "(manoj):arrayResult.length" + 
          arrayResult.length );
    }catch( IOException e ){
      System.out.println( "Failed to create web service client:" + e );
    }catch( ServiceException e ){
      System.out.println( "Failed to create web service client:" + e );
    }catch( Throwable e ){
      e.printStackTrace();
    }
  }
}

