/** * isValidOpType * * @param opType a {@link java.lang.String} object. * @return a boolean. */ public static boolean isValidOpType(final String opType) { try { WmiMgrOperation.valueOf(opType); return true; } catch (IllegalArgumentException e) { return false; } }
private void performResultCheck(final WmiResult wmiResult, final WmiParams params) throws WmiException { final ArrayList<Object> wmiObjects = wmiResult.getResponse(); int matches = 0; final int total = wmiObjects.size(); for (int i = 0; i < total; i++) { final Object wmiObj = wmiObjects.get(i); final WmiMgrOperation op = WmiMgrOperation.valueOf(params.getCompareOperation()); if (op.compareString(wmiObj, (String) params.getCompareValue())) { matches++; } } /* * Check that we meet the match requirements: * - all: all objects must match, one or more. * - none: no objects must match * - one: only one object must match * - some: one or more objects but not all objects must match. */ if (m_MatchType.equals("all") && matches == total && matches > 0) { wmiResult.setResultCode(WmiResult.RES_STATE_OK); } else if (m_MatchType.equals("none") && matches == 0) { wmiResult.setResultCode(WmiResult.RES_STATE_OK); } else if (m_MatchType.equals("one") && matches == 1) { wmiResult.setResultCode(WmiResult.RES_STATE_OK); } else if (m_MatchType.equals("some") && matches >= 1) { // we want to match more than one but not all. if (matches != total) { wmiResult.setResultCode(WmiResult.RES_STATE_OK); } else { wmiResult.setResultCode(WmiResult.RES_STATE_CRIT); } } else { wmiResult.setResultCode(WmiResult.RES_STATE_CRIT); } }