/**
***************************************************************************
 myTestConsumer.java
 This is a test program to receive Indications sent by Indication clients.
 This program start the CIM Indication Listener on port 8190.

 The Initial Developer of the Original Code :
     Bapu Patil ( bapu_patil@hp.com)
     Hewlett-Packard Company.

 Modified by:

***************************************************************************
*/


package tests.IndTests;

import org.snia.wbem.client.*;
import org.snia.wbem.cim.*;
import org.snia.wbem.listener.*;
import org.snia.wbemcmd.xml.*;
import java.net.*;
import java.util.*;

public class myTestConsumer  extends CIMHTTPListener
{
    int proto=CIMClient.XML;
    String hostName="sequoia";
    String nameSpace="root/cimv2";
    int portNo=5988;
    String classText="";
    String username="guest";
    String password="guest";
    String attachName=hostName;

    boolean cleanupOnly=false;
    boolean delete=true;
    CIMClient cc=null;
    CIMNameSpace clientNameSpace=null;
    CIMListener crl=null;
    boolean monitorMode=false;

    String localHostName=null;
    String sysCreationName="primary";

    static final String FCCN="CIM_IndicationFilter";
    static final String SCCN="CIM_IndicationSubscription";

    myTestConsumer(int portNo, boolean isSSL)  throws CIMException
    {
       super(portNo, isSSL);
    }


    private void handleIndication(CIMInstance ind, String indURL) 
    {
       System.out.println("---------- Begin of event data ----------");
       System.out.println("--- Indication URL : "+indURL);
       System.out.println("--- Indication : "+ind.toString());
       try 
       {
          Object o=null;
          if (ind.getClassName().startsWith("CIM_Class"))
             o=(Object)ind.getProperty("classdefinition").getValue().getValue();
          if (ind.getClassName().startsWith("CIM_Inst"))
            o=(Object) ind.getProperty("sourceinstance").getValue().getValue();

          if (o instanceof CIMInstance) 
	  {
             CIMInstance eo=(CIMInstance)o;
             System.out.println("--- Embedded Instance: "+eo);
          }
          else if (o instanceof CIMClass) {
             CIMClass eo=(CIMClass)o;
             System.out.println("--- Embedded Class: "+eo);
          }
          System.out.println("----------- End of event data -----------\n");
       }
       catch (Exception ee) 
       {
          ee.printStackTrace();
       }
    }

    public void indicationOccured(CIMIndication e, String indURL) 
    {
          handleIndication(e.getIndication(), indURL);
    }

    public static void main(String args[]) throws CIMException 
    {
      boolean enableSSL=false;
      int listenerPortNo=8190;

      if ( args.length != 0 )
      {
        if ( args[0].equals("-ssl") )
        {
          System.out.println("SSL Enabled Indication Listener ");
          enableSSL = true;
        }

      }

      try
      {
         myTestConsumer myi= new myTestConsumer(listenerPortNo, enableSSL);
         myi.startCIMHTTPListener();
       }
       catch (Exception e) {
          System.out.println(e);
          e.printStackTrace();
       }
       System.out.println("Ok -  waiting for events ");
    }
}

