//
// Test02C.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//	http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is Test02C.java
// 
// The Initial Developers of the Original Code are Bapu Patil 
//
//
// Revision 1.1  2002/05/15 09:36:59 bpatil
// Initial revision
//


package tests.ClientUnitTests;

import java.util.Enumeration;
import java.util.Vector;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.Naming;
import java.rmi.Remote;
import java.net.*;
import org.snia.wbemcmd.utils.SimpleEnum;
import org.snia.wbem.client.CIMClient;
import org.snia.wbem.cim.CIMNameSpace;
import org.snia.wbem.cim.CIMObjectPath;
import org.snia.wbem.cim.CIMClass;
import org.snia.wbem.cim.CIMProperty;
import org.snia.wbem.cim.CIMInstance;
import org.snia.wbem.cim.CIMValue;
import org.snia.wbem.cim.CIMQualifierType;
import org.snia.wbem.cim.CIMException;

public class Test02C {

    public void example(String args[])
    {

	CIMNameSpace clientNameSpace;
	String hostName = "localhost";		// host for cimom
	String nameSpace = "root/cimv2";		// namespace
	CIMClient cc=null;
	int portNo=CIMNameSpace.DEFAULT_PORT;
	String hostURL;
	String nsName = "nameSP2";
        String isSSL=null;
		
	if (args.length>=4) {
	    hostName=args[0];
	    nameSpace=args[1];
            portNo=Integer.parseInt(args[2]);
            nsName=args[3];
	} else if (args.length!=0) {
	    System.err.println("Test02C [hostname namespace portNo nameSpace [ssl]]");
	    System.exit(1);
	}

        if (args.length==5 && args[4].equalsIgnoreCase("ssl") )
        {
            isSSL=args[4];
        }
        if ( isSSL != null )
            hostURL="https://"+hostName+":"+portNo;
        else
            hostURL="http://"+hostName+":"+portNo;
	
	System.err.println("Connecting to "+hostName+
			    " for namespace "+nameSpace);
	try {
	    clientNameSpace = new CIMNameSpace(hostURL, nameSpace);  
	    cc = new CIMClient(clientNameSpace, "guest", "guest", CIMClient.XML);
	} catch (CIMException e) {
	    System.err.println("Failed to access CIMOM: "+e);
	    System.exit(1);
	}
	
	System.err.println("Client created");


     //
     // should return an instance
     //   - Gets an instance for the specified object path
     //
     //
System.err.println("\n **********create Namespace ");
     try 
     {
	 
	CIMNameSpace ns = new CIMNameSpace(hostName, "root/"+nsName);
        cc.createNameSpace(ns);

	CIMNameSpace ns2 = new CIMNameSpace(hostName, "root/"+nsName+"/one");
        cc.createNameSpace(ns2);
     }
     catch (CIMException ce) 
     {
	 System.err.println("Failed to create a namespace:"+ce);
	  //ce.printStackTrace();
	 System.exit(1);
     }
     
     try 
     {

System.err.println("\n **********list Namespaces ");
        CIMObjectPath pa1=new CIMObjectPath("root", (Vector)null);
        Enumeration enum = cc.enumNameSpace(pa1, true);

        while (enum.hasMoreElements()) 
        {
	   String nsString = (String) enum.nextElement();
           System.out.println("NameSpace:"+ nsString);
        }
     }
     catch (CIMException ce) {
	 System.err.println("Failed to fetch namespaces:"+ce);
	 System.exit(1);
    }
     
     System.out.println("done:");
   }

   
   public Test02C() {
   }
   
    public static void main(String args[]){
	Test02C ea=new Test02C();
	ea.example(args);
    }
}
