public ValidationInfo validate(String mdPrefix, String xml) {
        ValidationInfo validationInfo = new ValidationInfo();
        StringReader toValidate = new StringReader(xml);
        long retrievalDelay = 0;
        Schema schema = schemaCache.get(mdPrefix);
        if (schema == null) {
            if (malformedSchemaUrl.containsKey(mdPrefix)) {
                validationInfo.setFailReason(malformedSchemaUrl.get(mdPrefix));
                validationInfo.setResult(ValidationResult.wrongSchemaLocation);
            }
            else if (wrongTargetNamespaceCache.containsKey(mdPrefix)) {
                validationInfo.setFailReason(wrongTargetNamespaceCache
                    .get(mdPrefix));
                validationInfo.setResult(ValidationResult.wrongSchemaLocation);
            }
            else if (failedConnectCache.containsKey(mdPrefix)) {
                validationInfo.setFailReason(failedConnectCache.get(mdPrefix));
                validationInfo.setResult(ValidationResult.connectionFailure);
            }
            else if (failedFileNotFoundCache.containsKey(mdPrefix)) {
                validationInfo.setFailReason(failedFileNotFoundCache
                    .get(mdPrefix));
                validationInfo.setResult(ValidationResult.wrongSchemaLocation);
            }
            else if (failedParseSchemaCache.containsKey(mdPrefix)) {
                validationInfo.setFailReason(failedParseSchemaCache
                    .get(mdPrefix));
                validationInfo.setResult(ValidationResult.wrongSchemaLocation);
            }
            return validationInfo;
        }
        else {

            try {
                Validator validator = schema.newValidator();
                long startValidationTime = System.currentTimeMillis();
                validator.validate(new SAXSource(new InputSource(toValidate)));
                long endValidationTime = System.currentTimeMillis();
                retrievalDelay = endValidationTime - startValidationTime;
                validationInfo.setResult(ValidationResult.valid);
                validationInfo.setValidationDelay(retrievalDelay);
            }
            catch (SAXException e) {
                validationInfo.setFailReason(e);
                validationInfo.setResult(ValidationResult.invalid);
            }
            catch (IOException e) {
                validationInfo.setFailReason(e);
                validationInfo.setResult(ValidationResult.invalid);
            }
            return validationInfo;
        }

    }