The code segment in Example 7-1, creates a Solaris instance provider class that routes requests for instance data from the CIM Object Manager to one or more specialized providers. These specialized providers service requests for dynamic data for a particular type of Solaris object. For example, the Solaris_Package provider services requests for instances of the Solaris_Package class.
An instance provider must implement all methods in the InstanceProvider interface. The code segment in Example 7-1 shows only two methods:
enumInstances - Calls the appropriate provider to enumerate Solaris packages and patches. This method does a deep enumeration, which returns the class instances and all instances of its subclasses.
getInstances - Calls the appropriate provider to get instances of Solaris packages and patches.
public class Solaris implements InstanceProvider
{
/**
* Top-level provider class routes requests from the CIM
* Object Manager to the appropriate provider.
*/
public void initialize(CIMONHandle, ch)
throws CIMException {
}
public void cleanup()
throws CIMException {
}
/* This class returns a vector of enumerated instances of the
specified object in the specified class. If the object is a
Solaris package, it calls the Solaris_Package provider to return
a list of the Solaris packages on the system. If the object is a
Solaris patch, it calls the Solaris_Patch provider to return a
list of the Solaris patches on the system. */
public Vector enumInstances(CIMObjectPath op, CIMClient.DEEP, CIMClass cc)
throws CIMException {
if (op.getObjectName().equalsIgnoreCase("solaris_package")) {
Solaris_Package sp = new Solaris_Package();
return sp.enumerateInstances(op);
}
if (op.getObjectName().equalsIgnoreCase("solaris_patch")) {
Solaris_Patch sp = new Solaris_Patch();
return sp.enumerateInstances(op);
}
return new Vector();
}
/* This class returns an instance of the specified object in the
specified class. If the object is a Solaris package, it
calls the Solaris_Package provider to return the data for the
specified Solaris package. If the object is a Solaris patch, it
calls the Solaris_Patch provider to return the data for the
specified Solaris patch. */
public CIMInstance getInstance(CIMObjectPath op, CIMClass cc)
throws CIMException {
if (op.getObjectName().equalsIgnoreCase("solaris_package")) {
Solaris_Package sp = new Solaris_Package();
return sp.getInstance(op,cc);
}
if (op.getObjectName().equalsIgnoreCase("solaris_patch")) {
Solaris_Patch sp = new Solaris_Patch();
return sp.getInstance(op,cc);
}
}
|
The specialized Solaris instance providers use the API to get and set instances of objects. These providers also declare native methods that call C functions to get Solaris-specific values, such as host name, serial number, release, machine, architecture, and manufacturer.
The code segment in Example 7-2 shows the solaris_package class, which is called in Example 7-1. This code segment implements the getInstance method. This method creates a new instance of the specified class and then fills it with properties returned from native C functions, such as GetPkgArchitecture().
public class Solaris_Package
{
public CIMInstance getInstance(CIMObjectPath op, CIMClass cc) {
String pkgName = "";
for (Enumeration e = op.getKeys().elements(); e.hasMoreElements();) {
CIMProperty cp = (CIMProperty)e.nextElement();
if (cp.getName().equalsIgnoreCase("name")) {
pkgName = (String) ((CIMValue)(cp.getValue())).getValue();
}
}
CIMInstance ci = cc.newInstance();
ci.setProperty("Name", new CIMValue(pkgName));
ci.setProperty("TargetOperatingSystem",
new CIMValue(new UnsignedInt16(29)));
ci.setProperty("Status",
new CIMValue(GetPkgStatus(pkgName)));
ci.setProperty("Architecture",
new CIMValue(GetPkgArchitecture(pkgName)));
ci.setProperty("Description", new CIMValue(GetPkgDescription(pkgName)));
ci.setProperty("Caption", new CIMValue(GetPkgDescription(pkgName)));
ci.setProperty("Manufacturer", new CIMValue(GetPkgVendor(pkgName)));
ci.setProperty("Category", new CIMValue(GetPkgCategory(pkgName)));
ci.setProperty("Basedir", new CIMValue(GetPkgBasedir(pkgName)));
return ci;
}
native String GetPkgDescription(String pkgName);
native String GetPkgArchitecture(String pkgName);
native String GetPkgVersion(String pkgName);
native String GetPkgVendor(String pkgName);
native String GetPkgBasedir(String pkgName);
native String GetPkgCategory(String pkgName);
native String GetPkgStatus(String pkgName);
static {
System.loadLibrary("NativeUnix");
}
}
|