📄 commoninstanceprovider.java
字号:
return null; } } } CIMObjectPath ret = new CIMObjectPath (instanceClassname, namespace); for (int i = 0, is = INDICATION_KEYS.length; i < is; i++) { CIMProperty cp = cimInstance.getProperty (INDICATION_KEYS[i]); if (cp != null) { ret.addKey (INDICATION_KEYS[i], cp.getValue ()); } else { if (DEBUG) { System.err.println (providerName + "::validatePropertyTypeInstance: Bad3: " + INDICATION_KEYS[i]); } return null; } } return ret; } private int findCOPInPropertyTypes (CIMObjectPath cop1) { String path1 = cop1.toString (); for (int i = 0; i < paths.size (); i++) { CIMObjectPath cop2 = (CIMObjectPath)paths.elementAt (i); String path2 = cop2.toString (); if (DEBUG) { System.err.println (providerName + "::findCOPInPropertyTypes: \"" + path1 + "\" == \"" + path2 + "\""); } if (path2.equalsIgnoreCase (path1)) { if (DEBUG) { System.err.println (providerName + "::findCOPInPropertyTypes: found!"); } return i; } } return -1; } private int findCOPInPropertyTypesNew (CIMObjectPath cop1) { HashMap hashPaths = new HashMap (); if (DEBUG) { System.out.println (providerName + "::findCOPInPropertyTypesNew: comparing \"" + cop1 + "\""); } // Iterate through each ObjectPath in our ObjectPaths for (int i = 0; i < paths.size (); i++) { CIMObjectPath cop2 = (CIMObjectPath)paths.elementAt (i); Vector keysCop1 = cop1.getKeys (); HashMap hashCop1 = new HashMap (); if (DEBUG) { System.out.println (providerName + "::findCOPInPropertyTypesNew: to \"" + cop2 + "\""); } // Iterate though each property in the ObjectPath for (int idxPath = 0; idxPath < keysCop1.size (); idxPath++) { CIMProperty cp = (CIMProperty)keysCop1.elementAt (idxPath); String cpKeyValue = cp.getValue ().toString (); String copKeyValue = cop2.getKeyValue (cp.getName ()); if (DEBUG) { System.out.println (providerName + "::findCOPInPropertyTypesNew: cpKeyValue \"" + cpKeyValue + "\""); System.out.println (providerName + "::findCOPInPropertyTypesNew: copKeyValue \"" + copKeyValue + "\""); } // Compare the property values and save it for later hashCop1.put (cp.toString (), new Boolean (cpKeyValue.equals (copKeyValue))); } // Save the result of all of the property comparisons hashPaths.put (cop2, hashCop1); } if (DEBUG) { System.out.println (providerName + "::findCOPInPropertyTypesNew: 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 (providerName + "::findCOPInPropertyTypesNew: found = " + found + ", key = " + key); } // Were they all equal? if (found) { // Return the index of it return paths.indexOf (key); } } return -1; } private void testPropertyTypeInstance (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.UINT8: { if (!(value instanceof UnsignedInt8)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((UnsignedInt8)value).intValue () >= 255) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.UINT16: { if (!(value instanceof UnsignedInt16)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((UnsignedInt16)value).intValue () >= 10000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.UINT32: { if (!(value instanceof UnsignedInt32)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((UnsignedInt32)value).intValue () >= 10000000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } 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; } case CIMDataType.SINT8: { if (!(value instanceof Byte)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Byte)value).intValue () <= -120) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.SINT16: { if (!(value instanceof Short)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Short)value).intValue () < -10000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.SINT32: { if (!(value instanceof Integer)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Integer)value).intValue () <= -10000000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.SINT64: { if (!(value instanceof Long)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Long)value).intValue () <= -1000000000) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.REAL32: { if (!(value instanceof Float)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Float)value).floatValue () >= 10000000.32) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } case CIMDataType.REAL64: { if (!(value instanceof Double)) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); if (((Double)value).doubleValue () >= 1000000000.64) throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); break; } default: { break; } } } } private interface Compare { abstract boolean lessThan (Object lhs, Object rhs); abstract boolean lessThanOrEqual (Object lhs, Object rhs); } private class SortableVector extends Vector { private Compare compare; public SortableVector (Compare compare) { this.compare = compare; } public void sort () { quickSort (0, size() - 1); } private void quickSort (int left, int right) { if (right > left) { Object o1 = elementAt (right); int i = left - 1; int j = right; while (true) { while (compare.lessThan (elementAt (++i), o1)) ; while (j > 0) if(compare.lessThanOrEqual (elementAt (--j), o1)) break; if (i >= j) break; swap (i, j); } swap (i , right); quickSort (left, i - 1); quickSort (i + 1, right); } } private void swap (int loc1, int loc2) { Object tmp = elementAt(loc1); setElementAt (elementAt (loc2), loc1); setElementAt (tmp, loc2); } } private class CIMInstanceComparer implements Compare { private int getInstanceId (Object o) { try { CIMInstance ci = (CIMInstance)o; CIMProperty cp = ci.getProperty ("InstanceId"); UnsignedInt64 id = (UnsignedInt64)cp.getValue ().getValue (); return id.intValue (); } catch (Exception e) { return 0; } } public boolean lessThan (Object lhs, Object rhs) { return getInstanceId (lhs) < getInstanceId (rhs); } public boolean lessThanOrEqual (Object lhs, Object rhs) { return getInstanceId (lhs) <= getInstanceId (rhs); } } private class CIMObjectPathComparer implements Compare { private int getInstanceId (Object o) { try { CIMObjectPath cop = (CIMObjectPath)o; String value = cop.getKeyValue ("InstanceId"); UnsignedInt64 id = new UnsignedInt64 (value); return id.intValue (); } catch (Exception e) { return 0; } } public boolean lessThan (Object lhs, Object rhs) { return getInstanceId (lhs) < getInstanceId (rhs); } public boolean lessThanOrEqual (Object lhs, Object rhs) { return getInstanceId (lhs) <= getInstanceId (rhs); } } // private String providerName = ""; private String namespace = ""; private String instanceClassname = ""; private CIMOMHandle ch = null; private SortableVector paths = new SortableVector (new CIMObjectPathComparer ()); private SortableVector instances = new SortableVector (new CIMInstanceComparer ()); private boolean fEnableModifications = true; private final boolean DEBUG = true; private final String[] INDICATION_KEYS = { "InstanceId" }; private final String[] INDICATION_PROPS = { "InstanceId", "PropertyString", };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -