static void check(OpenMBeanParameterInfo info) throws OpenDataException { OpenType<?> openType = info.getOpenType(); if (openType == null) throw new IllegalArgumentException("OpenType cannot be null"); if (info.getName() == null || info.getName().trim().equals("")) throw new IllegalArgumentException("Name cannot be null or empty"); if (info.getDescription() == null || info.getDescription().trim().equals("")) throw new IllegalArgumentException("Description cannot be null or empty"); // Check and initialize defaultValue // if (info.hasDefaultValue()) { // Default value not supported for ArrayType and TabularType // Cast to Object because "OpenType<T> instanceof" is illegal if (openType.isArray() || (Object) openType instanceof TabularType) { throw new OpenDataException( "Default value not supported " + "for ArrayType and TabularType"); } // Check defaultValue's class if (!openType.isValue(info.getDefaultValue())) { final String msg = "Argument defaultValue's class [\"" + info.getDefaultValue().getClass().getName() + "\"] does not match the one defined in openType[\"" + openType.getClassName() + "\"]"; throw new OpenDataException(msg); } } // Check that we don't have both legalValues and min or max // if (info.hasLegalValues() && (info.hasMinValue() || info.hasMaxValue())) { throw new OpenDataException("cannot have both legalValue and " + "minValue or maxValue"); } // Check minValue and maxValue if (info.hasMinValue() && !openType.isValue(info.getMinValue())) { final String msg = "Type of minValue [" + info.getMinValue().getClass().getName() + "] does not match OpenType [" + openType.getClassName() + "]"; throw new OpenDataException(msg); } if (info.hasMaxValue() && !openType.isValue(info.getMaxValue())) { final String msg = "Type of maxValue [" + info.getMaxValue().getClass().getName() + "] does not match OpenType [" + openType.getClassName() + "]"; throw new OpenDataException(msg); } // Check that defaultValue is a legal value // if (info.hasDefaultValue()) { Object defaultValue = info.getDefaultValue(); if (info.hasLegalValues() && !info.getLegalValues().contains(defaultValue)) { throw new OpenDataException("defaultValue is not contained " + "in legalValues"); } // Check that minValue <= defaultValue <= maxValue // if (info.hasMinValue()) { if (compare(info.getMinValue(), defaultValue) > 0) { throw new OpenDataException("minValue cannot be greater " + "than defaultValue"); } } if (info.hasMaxValue()) { if (compare(info.getMaxValue(), defaultValue) < 0) { throw new OpenDataException("maxValue cannot be less " + "than defaultValue"); } } } // Check legalValues // if (info.hasLegalValues()) { // legalValues not supported for TabularType and arrays if ((Object) openType instanceof TabularType || openType.isArray()) { throw new OpenDataException("Legal values not supported " + "for TabularType and arrays"); } // Check legalValues are valid with openType for (Object v : info.getLegalValues()) { if (!openType.isValue(v)) { final String msg = "Element of legalValues [" + v + "] is not a valid value for the specified openType [" + openType.toString() + "]"; throw new OpenDataException(msg); } } } // Check that, if both specified, minValue <= maxValue // if (info.hasMinValue() && info.hasMaxValue()) { if (compare(info.getMinValue(), info.getMaxValue()) > 0) { throw new OpenDataException("minValue cannot be greater " + "than maxValue"); } } }