/*
 * {ClassName}Impl.java
 *
 * Generated by {productTitle}  {versionName} - {utilityTitle}
 *
 * {copywrite}
 */
package {packageName}.implementation;

import static {packageName}.schema.{schemaName}.{SchemaName}_{ClassName}Constants.*;

import javax.cim.*;
import javax.wbem.*;

import {packageName}.abstractImpl.{ClassName}AbstractImpl;
import {packageName}.data.{ClassName}Data;
import com.ws.wbem.CloseableAddableIterator;
import com.ws.wbem.query.fql.FQLParser;

public class {ClassName}Impl extends {ClassName}AbstractImpl {

	public {ClassName}Impl() {
		super(CCN_NAME);
	}
	
	@Override
	public void getAllInstances(CloseableAddableIterator<CIMInstance> iter,
			CIMObjectPath op, String[] propertyList,
			final FQLParser fqlParser,
			final WBEMOperation wbemOperation) throws WBEMException {

		try {
			// This example code generates a single instance with dummy values.
			// TODO: Provider writers should modify this code.
			{ClassName}Data inst = new {ClassName}Data();
			
			// set key values			
			{prop_key_value_setters}			
			// set other pertinent values
			{prop_value_setters}
			final CIMInstance instance = inst.generateCIMInstance(op,
					propertyList, fqlParser);

			// if instance is not null (FQLParser did not reject instance) then
			// add it to the return iterator
			if (null != instance) {
				iter.add(instance);
			}
		} finally {
			if (null != iter && !iter.isClosed()) {
				iter.done();
			}
		}
	}
    
    @Override
	public void initialize() throws WBEMException {
		// Add one time initialization code here

	}
    
    @Override
	public CIMInstance getInstance(final CIMObjectPath op,
			final String[] propertyList) throws WBEMException {
		// TODO: This function is very inefficient as it enumerates all
		// instances and then tries to match the passed in objectpath to what
		// is returned. If the provider has more then a couple of instances then
		// this implementation should be changed to be more efficient
		CIMInstance ret = null;
		// Create an instance iterator
		final CloseableAddableIterator<CIMInstance> iter = new CloseableAddableIterator<CIMInstance>();
		// Get all of the instances from the implementation
		getAllInstances(iter, op, propertyList, null, 
				WBEMOperation.GETINSTANCE);
		// iterate all instances until we find a match
		while (iter.hasNext() && null == ret) {
			final CIMInstance inst = iter.next();
			final CIMObjectPath obj = inst.getObjectPath();
			// see if the instance matches what is being searched for
			if (op.equalsModelPath(obj)) {
				// set the return value, will cause while loop to exit
				ret = inst;
			}
		}
		// if not found, throw exception
		if (null == ret) {
			// not found
			throw WBEMOperationErrors.getInstanceNotFoundException(op,
					WBEMOperation.GETINSTANCE, op.getObjectName());
		}
		// found instance, return it
		return ret;
	}
	
	// Code below implements the various functions supported by this CIM Class
	// The default behavior is to return a method not supported exception.
	// No changes should be needed below this line unless one (or more) of these
	// methods is being implemented.
			
    {extrinsicMethod2}
	
}
