📄 jmpipropertyprovider.java
字号:
} else { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } } public void deleteInstance (CIMObjectPath cop) throws CIMException { if (DEBUG) System.err.println ("JMPIPropertyProvider::deleteInstance: cop = " + cop); // ensure the Namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE)) throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); // ensure the class existing in the specified namespace if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES)) throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); // ensure the request object exists int index = findObjectPath (cop); if (index < 0) throw new CIMException (CIMException.CIM_ERR_NOT_FOUND); if (fEnableModifications) { paths.removeElementAt (index); instances.removeElementAt (index); paths.sort (); instances.sort (); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } } public Vector enumInstances (CIMObjectPath cop, boolean deep, CIMClass cimClass) throws CIMException { if (DEBUG) { System.err.println ("JMPIPropertyProvider::enumInstances: cop = " + cop); System.err.println ("JMPIPropertyProvider::enumInstances: deep = " + deep); System.err.println ("JMPIPropertyProvider::enumInstances: cimClass = " + cimClass); } // ensure the Namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE)) throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); // ensure the class existing in the specified namespace if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES)) throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); return paths; } public Vector enumInstances (CIMObjectPath cop, boolean deep, CIMClass cimClass, boolean localOnly) throws CIMException { if (DEBUG) { System.err.println ("JMPIPropertyProvider::enumInstances: cop = " + cop); System.err.println ("JMPIPropertyProvider::enumInstances: deep = " + deep); System.err.println ("JMPIPropertyProvider::enumInstances: cimClass = " + cimClass); System.err.println ("JMPIPropertyProvider::enumInstances: localOnly = " + localOnly); } // ensure the Namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE)) throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); // ensure the class existing in the specified namespace if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES)) throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); return instances; } public Vector execQuery (CIMObjectPath cop, String queryStatement, int queryLanguage, CIMClass cimClass) throws CIMException { if (DEBUG) { System.err.println ("JMPIPropertyProvider::execQuery: cop = " + cop); System.err.println ("JMPIPropertyProvider::execQuery: queryStatement = " + queryStatement); System.err.println ("JMPIPropertyProvider::execQuery: queryLanguage = " + queryLanguage); System.err.println ("JMPIPropertyProvider::execQuery: cimClass = " + cimClass); } // ensure the Namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE)) throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); // ensure the class existing in the specified namespace if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES)) throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); throw new CIMException (CIMException.CIM_ERR_NOT_SUPPORTED); } public void setPropertyValue (CIMObjectPath cop, String oclass, String pName, CIMValue val) { if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cop = " + cop ); System.err.println ("JMPIPropertyProvider::setPropertyValue: oclass = " + oclass); System.err.println ("JMPIPropertyProvider::setPropertyValue: pName = " + pName ); System.err.println ("JMPIPropertyProvider::setPropertyValue: val = " + val ); } try { CIMInstance cimInstance = getInstance (cop, new CIMClass (oclass), true); if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cimInstance = " + cimInstance); } CIMProperty cp = cimInstance.getProperty (pName); if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cp = " + cp); } cp.setValue (val); if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cp = " + cp); } } catch (Exception e) { System.err.println ("JMPIPropertyProvider::setPropertyValue: caught = " + e); } } public CIMValue getPropertyValue (CIMObjectPath cop, String oclass, String pName) { CIMValue cv = null; if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cop = " + cop ); System.err.println ("JMPIPropertyProvider::setPropertyValue: oclass = " + oclass); System.err.println ("JMPIPropertyProvider::setPropertyValue: pName = " + pName ); } try { CIMInstance cimInstance = getInstance (cop, new CIMClass (oclass), true); if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cimInstance = " + cimInstance); } CIMProperty cp = cimInstance.getProperty (pName); if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cp = " + cp); } if (cp != null) { cv = cp.getValue (); } if (DEBUG) { System.err.println ("JMPIPropertyProvider::setPropertyValue: cv = " + cv); } } catch (Exception e) { System.err.println ("JMPIPropertyProvider::setPropertyValue: caught = " + e); } return cv; } private CIMObjectPath validateInstance (CIMInstance cimInstance, boolean fStrict) { if (cimInstance.getPropertyCount () != PROPERTYTYPES_PROPS.length) { if (DEBUG) { System.err.println ("JMPIPropertyProvider::validateInstance: Bad1: " + cimInstance.getPropertyCount () + " != " + PROPERTYTYPES_PROPS.length); } if (fStrict) { return null; } } for (int i = 0, m = PROPERTYTYPES_PROPS.length; i < m; i++) { CIMProperty cp = cimInstance.getProperty (PROPERTYTYPES_PROPS[i]); if (cp == null) { if (DEBUG) { System.err.println ("JMPIPropertyProvider::validateInstance: Bad2: " + PROPERTYTYPES_PROPS[i]); } if (fStrict) { return null; } } } CIMObjectPath ret = new CIMObjectPath (CLASS_PROPERTYTYPES, NAMESPACE); for (int i = 0, m = PROPERTYTYPES_KEYS.length; i < m; i++) { CIMProperty cp = cimInstance.getProperty (PROPERTYTYPES_KEYS[i]); if (cp != null) { ret.addKey (PROPERTYTYPES_KEYS[i], cp.getValue ()); } else { if (DEBUG) { System.err.println ("JMPIPropertyProvider::validateInstance: Bad3: " + PROPERTYTYPES_KEYS[i]); } return null; } } return ret; } private int findObjectPath (CIMObjectPath path) { HashMap hashPaths = new HashMap (); String p = path.toString (); if (DEBUG) { System.out.println ("JMPIPropertyProvider::findObjectPath: comparing \"" + p + "\""); } // Iterate through each ObjectPath in our ObjectPaths for (int i = 0; i < paths.size (); i++) { HashMap hashCop = new HashMap (); CIMObjectPath cop = (CIMObjectPath)paths.elementAt (i); Vector keysPath = path.getKeys (); if (DEBUG) { System.out.println ("JMPIPropertyProvider::findObjectPath: to \"" + cop + "\""); } // Iterate though each property in the ObjectPath for (int idxPath = 0; idxPath < keysPath.size (); idxPath++) { CIMProperty cp = (CIMProperty)keysPath.elementAt (idxPath); String cpKeyValue = cp.getValue ().toString (); String copKeyValue = cop.getKeyValue (cp.getName ()); if (DEBUG) { System.out.println ("JMPIPropertyProvider::findObjectPath: cpKeyValue \"" + cpKeyValue + "\""); System.out.println ("JMPIPropertyProvider::findObjectPath: copKeyValue \"" + copKeyValue + "\""); } // Compare the property values and save it for later hashCop.put (cp.toString (), new Boolean (cpKeyValue.equals (copKeyValue))); } // Save the result of all of the property comparisons hashPaths.put (cop, hashCop); } if (DEBUG) { System.out.println ("JMPIPropertyProvider::findObjectPath: hashPaths = " + hashPaths); } Iterator itrHashPaths = hashPaths.keySet ().iterator (); // Iterate through all of our results while (itrHashPaths.hasNext ()) { Object key = itrHashPaths.next (); HashMap hash = (HashMap)hashPaths.get (key); boolean found = true; Iterator itrHash = hash.values ().iterator (); while (itrHash.hasNext ()) { if (!((Boolean)itrHash.next ()).booleanValue ()) { found = false; } } if (DEBUG) { System.out.println ("JMPIPropertyProvider::findObjectPath: found = " + found + ", key = " + key); } // Were they all equal? if (found) { // Return the index of it return paths.indexOf (key); } } return -1; } private void testPropertyTypesValue (CIMInstance instanceObject) throws CIMException { Vector properties = instanceObject.getProperties (); int iPropertyCount = properties.size (); for (int j = 0; j < iPropertyCount; j++) { CIMProperty property = (CIMProperty)properties.elementAt (j); String propertyName = property.getName (); CIMValue propertyValue = property.getValue (); Object value = propertyValue.getValue (); int type = property.getType ().getType (); switch (type) { case CIMDataType.UINT64: if (!(value instanceof UnsignedInt64)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((UnsignedInt64)value).longValue () >= 1000000000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; default: break; } } } private static final String NAMESPACE = "root/SampleProvider"; private static final String NAMESPACE_INTEROP = "root/PG_InterOp"; // Class names private static final String CLASS_PROPERTYTYPES = "JMPIProperty_TestPropertyTypes"; private final String[] PROPERTYTYPES_KEYS = { "CreationClassName", "InstanceId" }; private final String[] PROPERTYTYPES_PROPS = { "CreationClassName", "InstanceId", "PropertyString", };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -