Implementing the Provider Interfaces
When you write a provider, you must determine the interfaces that your provider will support. You must implement all the methods of each interface that your provider supports. In addition, every provider must implement the CIMProvider interface, which has two methods:
initialize(CIMOMHandle cimom) - If your provider stores data in the CIM Object Manager Repository, it must assign the passed CIM Object Manager handle to the CIM Object Manager handle that it will use to contact the CIM Object Manager. For example:
private CIMOMHandle cimom = null; ... public void initialize(CIMOMHandle cimom) throws CIMException { this.cimom = (CIMOMHandle) cimom;
The provider creates instances or manipulates associations in the CIM Object Manager Repository, it must first cast the passed CIM Object Manager handle to the subclass ProviderCIMOMHandle, and then fetch an internal instance or association provider. For example:
private ProviderCIMOMHandle cimom = null; private CIMAssociatorProvider ap = null; ... public void initialize(CIMOMHandle cimom) throws CIMException { this.cimom = (ProviderCIMOMHandle) cimom; ap = pcimom.getInternalProvider();
Note - The initialize command automatically runs each time a provider is initialized after the CIM Object Manager restarts.
cleanup() - Currently acts as a placeholder.
Writing an Instance Provider
This following sample code implements the enumerateInstances and getInstance interfaces for the Ex_SimpleCIMInstanceProvider class. For brevity, this example implements the deleteInstance, createInstance, setInstance, and execQuery interfaces by throwing a CIMException.
Note - For information on implementing the execQuery method, see "Parsing Queries".
Example 4-1 CIMInstance Provider
/* * "@(#)SimpleCIMInstanceProvider.java" */ import javax.wbem.cim.*; import javax.wbem.client.*; import javax.wbem.provider.CIMProvider; import javax.wbem.provider.CIMInstanceProvider; import javax.wbem.provider.MethodProvider; import java.util.*; import java.io.*; public class SimpleCIMInstanceProvider implements CIMInstanceProvider{ static int loop = 0; public void initialize(CIMOMHandle cimom) throws CIMException { } public void cleanup() throws CIMException { } public CIMObjectPath[] enumerateInstanceNames(CIMObjectPath op, CIMClass cc) throws CIMException { return null; } /* * enumerateInstances: * The entire instances and not just the names are returned. */ public CIMInstance[] enumerateInstances(CIMObjectPath op, boolean localOnly,boolean includeQualifiers, boolean includeClassOrigin,String[] propertyList, CIMClass cc) throws CIMException { if (op.getObjectName().equalsIgnoreCase\ ("Ex_SimpleCIMInstanceProvider")) { Vector instances = new Vector(); CIMInstance ci = cc.newInstance(); if (loop == 0){ ci.setProperty("First", new CIMValue("red")); ci.setProperty("Last", new CIMValue("apple")); // only include the properties that were requested ci = ci.filterProperties(propertyList, includeQualifier, includeClassOrigin); instances.addElement(ci); loop += 1; } else { ci.setProperty("First", new CIMValue("red")); ci.setProperty("Last", new CIMValue("apple")); // only include the properties that were requested ci = ci.filterProperties(propertyList, includeQualifier, includeClassOrigin); instances.addElement(ci); ci = cc.newInstance(); ci.setProperty("First", new CIMValue("green")); ci.setProperty("Last", new CIMValue("apple")); // only include the properties that were requested ci = ci.filterProperties(propertyList, includeQualifier, includeClassOrigin); instances.addElement(ci); } return (CIMInstance[])instances.toArray(); } throw new CIMException(CIM_ERR_INVALID_CLASS); } public CIMInstance getInstance(CIMObjectPath op, boolean localOnly, boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList, CIMClass cc) ) throws CIMException { if (op.getObjectName().equalsIgnoreCase ("Ex_SimpleCIMInstanceProvider")) { CIMInstance ci = cc.newInstance(); // we need to get the keys from the passed in object path, this // will uniqeuly identify the instance we want to get java.util.Vector keys = cop.getKeys(); // Since this is a contrived example we will simply place the keys // into the instance and be done. ci.setProperties(keys); // if we had other non-key properties we should add them here. // only include the properties that were requested ci = ci.filterProperties(propertyList, includeQualifiers, includeClassOrigin); return ci; } throw new CIMException(CIM_ERR_INVALID_CLASS); } public CIMInstance[] execQuery(CIMObjectPath op, \ String query, String ql, CIMClass cc) throws CIMException { throw(new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED)); } public void setInstance(CIMObjectPath op, CIMInstance ci, boolean includeQualifiers, String[] propertyList) 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)); } } |