/*
 * {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}.common.BaseAssociatorImpl;
import {packageName}.common.BaseProviderImpl;
import {packageName}.common.ImplementationRegistry;
import {packageName}.data.{ClassName}Data;
import com.ws.wbem.CloseableAddableIterator;
import com.ws.wbem.query.fql.FQLParser;

public class {ClassName}Impl extends BaseAssociatorImpl {

	public {ClassName}Impl() throws Exception{
		super(CCN_NAME, (BaseProviderImpl) ImplementationRegistry
				.getImplementation({Ref1ClassName}Impl.class),
				CPN_{REF1}, (BaseProviderImpl) ImplementationRegistry
						.getImplementation({Ref2ClassName}Impl.class),
				CPN_{REF2});
	}
	
	@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);
			}
					
		} catch (WBEMException we) {
			iter.setException(we);
			throw we;
		} catch (Throwable t) {
			iter.setException(WBEMOperationErrors.getOtherFailureException(op,
					t, wbemOperation, op.getObjectName()));
		} 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;
	}
	
	@Override
	public void assocEnumerate(
	    final CloseableAddableIterator<CIMInstance> iter,
	    final CIMObjectPath assocName, final CIMObjectPath objectName,
	    final String resultClass, final String role,
	    final String resultRole, final String[] propertyList,
	    final FQLParser fqlParser,
	    final boolean continueOnError, final WBEMOperation wbemOperation)
	        throws WBEMException {
	    // TODO: The superclasses implementation is extremely inefficient,
	    // It is provided for basic associations such as 1-to-1 or
	    // 1-to-many. if this provider is for a many-to-many association
	    // (e.g. StoragePool to StorageVolume) this provider should
	    // provide it's own implementation.
	    super.assocEnumerate(iter, assocName, objectName, resultClass, role, resultRole,
	        propertyList, fqlParser,
	        continueOnError, wbemOperation);
	}
	
	
	@Override
	public void refEnumerate(final CloseableAddableIterator<CIMInstance> iter,
	    final CIMObjectPath assocName, final CIMObjectPath objectName,
	    final String role, final String[] propertyList,
	    final FQLParser fqlParser,
	    final boolean continueOnError, final WBEMOperation wbemOperation)
	    throws WBEMException {
	    // TODO: The superclasses implementation is extremely inefficient,
	    // It is provided for basic associations such as 1-to-1 or
	    // 1-to-many. if this provider is for a many-to-many association
	    // (e.g. StoragePool to StorageVolume) this provider should
	    // provide it's own implementation.
	    super.refEnumerate(iter, assocName, objectName, role, propertyList,
	        fqlParser, continueOnError,
	        wbemOperation);
	}
	
	// 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}

}
