Beispiel #1
0
  private ParamsValidator getParamsValidator(
      Class<? extends ParamsValidator> validatorClass, String[] customParams) throws ApiException {

    // use cache only if there is no custom parameters
    boolean useCache = customParams == null || customParams.length == 0;

    if (useCache) {
      ParamsValidator validator = paramsValidatorsMap.get(validatorClass);
      if (validator != null) {
        return validator;
      }
    }

    try {
      ParamsValidator validator = validatorClass.newInstance();
      validator.setCustomParams(customParams);

      if (useCache) {
        paramsValidatorsMap.put(validatorClass, validator);
      }
      return validator;
    } catch (Exception e) {
      throw new ApiException("Failed to instantiate a validator: " + validatorClass.getName());
    }
  }
Beispiel #2
0
  private ModelValidator getModelValidator(Class<? extends ModelValidator> validatorClass)
      throws ApiException {
    ModelValidator validator = modelValidatorsMap.get(validatorClass);
    if (validator != null) {
      return validator;
    }

    try {
      validator = validatorClass.newInstance();
      modelValidatorsMap.put(validatorClass, validator);
    } catch (Exception e) {
      throw new ApiException("Failed to instantiate a validator: " + validatorClass.getName());
    }

    return validator;
  }