/*
 * "@(#)SimpleInstanceProvider.java	1.0 SMI"
 *
 * Copyright 1998-1999 Sun Microsystems, Inc.,
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 * 
 */

import com.sun.wbem.cim.*;
import com.sun.wbem.client.*;
import com.sun.wbem.provider.CIMProvider;
import com.sun.wbem.provider20.InstanceProvider;
import com.sun.wbem.provider.MethodProvider;
import java.util.*;
import java.io.*;


    /**
     * @author	Sun Microsystems, Inc.
     * @version    1.0, 12/5/99
     * @since      WBEM 1.0
     */
public class SimpleInstanceProvider implements InstanceProvider {
static int loop = 0;

    public void initialize(CIMOMHandle cimom) 
    throws CIMException {
    }

    public void cleanup() 
    throws CIMException {
    }

    public Vector enumInstances(CIMObjectPath op, boolean deep, CIMClass cc,
    boolean localOnly)
    throws CIMException {
        return null;
    }

    /*
     * enumInstances:
     * The entire instances and not just the names are returned.
     * Deep or shallow enumeration is possible, however
     * currently the CIMOM only asks for shallow enumeration.
     */
    public Vector enumInstances(CIMObjectPath op, boolean deep, CIMClass cc)
    throws CIMException {
        if (op.getObjectName().equalsIgnoreCase("Ex_SimpleInstanceProvider")) {

	    Vector instances = new Vector();
	    CIMObjectPath cop = new CIMObjectPath(op.getObjectName(),
                                                 op.getNameSpace());
	    if (loop == 0) {
		cop.addKey("First", new CIMValue("red"));
		cop.addKey("Last", new CIMValue("apple"));
	    // To delete this class, comment this following line and compile it.
		instances.addElement(cop);
		loop += 1;
	    } else {
		cop.addKey("First", new CIMValue("red"));
		cop.addKey("Last", new CIMValue("apple"));
	    // To delete this class, comment this following line and compile it.
		instances.addElement(cop);

		cop = new CIMObjectPath(op.getObjectName(),
                                                 op.getNameSpace());
		cop.addKey("First", new CIMValue("green"));
		cop.addKey("Last", new CIMValue("apple"));
	    // To delete this class, comment this following line and compile it.
		instances.addElement(cop);
	    }
        return instances;
        }
        return new Vector();
    }

    public CIMInstance getInstance(CIMObjectPath op, 
				   CIMClass cc, 
				   boolean localOnly)
    throws CIMException {
        if (op.getObjectName().equalsIgnoreCase("Ex_SimpleInstanceProvider")) {
            CIMInstance ci = cc.newInstance();
            ci.setProperty("First", new CIMValue("yellow"));
            ci.setProperty("Last", new CIMValue("apple"));
            return ci;
        }
        return new CIMInstance();
    }

    public Vector execQuery(CIMObjectPath op, String query, int ql, CIMClass cc)
                throws CIMException {
        throw(new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED));
    }

    public void setInstance(CIMObjectPath op, CIMInstance ci)
                throws CIMException {
        throw(new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED));
    }

    public CIMObjectPath createInstance(CIMObjectPath op, CIMInstance ci)
                throws CIMException {
        throw(new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED));
    }

    public void deleteInstance(CIMObjectPath cp)
	        throws CIMException {
        throw(new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED));
    }
}
