Validates a given value against this rule.

@param path    a dot notation path to the value.
@param schema  a schema this rule is called from
@param value   a value to be validated.
@param results a list with validation results to add new results.
978805
public void validate(String path, Schema schema, Object value, List<ValidationResult> results) {
		if (_rules == null || _rules.length == 0)
			return;

		List<ValidationResult> localResults = new ArrayList<ValidationResult>();

		for (IValidationRule rule : _rules) {
			int resultsCount = localResults.size();
			rule.validate(path, schema, value, localResults);
			if (resultsCount == localResults.size())
				return;
		}

		results.addAll(localResults);
	}
809508
public static boolean validate(final Source input, final Source[] schemas) {
        boolean isValid = true;
        try {
            final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            factory.setResourceResolver(new SchemaLSResourceResolver());
            final Validator val = factory.newSchema(schemas).newValidator();
            final ParserErrorHandler eh = new ParserErrorHandler();
            val.setErrorHandler(eh);
            val.validate(input);
            if (eh.didErrorOccur()) {
                isValid = false;
                eh.logErrors(LOGGER);
            }
        } catch (final Exception ex) {
            LOGGER.error("Problem validating the given process definition.", ex);
            isValid = false;
        }

        return isValid;
    }
1360370
public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename)
        throws Exception
    {
        final ParserOptions.Builder optionsBuilder = ParserOptions.builder()
            .xsdFilename(System.getProperty(VALIDATION_XSD))
            .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE)))
            .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR)))
            .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL)))
            .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT)));

        final Path path = Paths.get(sbeSchemaFilename);
        try (InputStream in = new BufferedInputStream(Files.newInputStream(path)))
        {
            final InputSource inputSource = new InputSource(in);
            if (path.toAbsolutePath().getParent() != null)
            {
                inputSource.setSystemId(path.toUri().toString());
            }

            XmlSchemaParser.validate(xsdFilename, inputSource, optionsBuilder.build());
        }
    }
454218
public static void validateXMLSchema(InputStream xsdStream, InputStream xmlStream) throws IOException, SAXException {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(xmlStream));
    }
320329
public void setValue(List<P> path, V value) {

        ensureNode(path).setValue(value);

    }
824806
protected function validateItems(&$value, $schema = null, JsonPointer $path = null, $i = null)
    {
        if (is_object($schema->items)) {
            // just one type definition for the whole array
            foreach ($value as $k => &$v) {
                $initErrors = $this->getErrors();

                // First check if its defined in "items"
                $this->checkUndefined($v, $schema->items, $path, $k);

                // Recheck with "additionalItems" if the first test fails
                if (count($initErrors) < count($this->getErrors()) && (isset($schema->additionalItems) && $schema->additionalItems !== false)) {
                    $secondErrors = $this->getErrors();
                    $this->checkUndefined($v, $schema->additionalItems, $path, $k);
                }

                // Reset errors if needed
                if (isset($secondErrors) && count($secondErrors) < count($this->getErrors())) {
                    $this->errors = $secondErrors;
                } elseif (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
                    $this->errors = $initErrors;
                }
            }
            unset($v); /* remove dangling reference to prevent any future bugs
                        * caused by accidentally using $v elsewhere */
        } else {
            // Defined item type definitions
            foreach ($value as $k => &$v) {
                if (array_key_exists($k, $schema->items)) {
                    $this->checkUndefined($v, $schema->items[$k], $path, $k);
                } else {
                    // Additional items
                    if (property_exists($schema, 'additionalItems')) {
                        if ($schema->additionalItems !== false) {
                            $this->checkUndefined($v, $schema->additionalItems, $path, $k);
                        } else {
                            $this->addError(
                                ConstraintError::ADDITIONAL_ITEMS(),
                                $path,
                                array(
                                    'item' => $i,
                                    'property' => $k,
                                    'additionalItems' => $schema->additionalItems
                                )
                            );
                        }
                    } else {
                        // Should be valid against an empty schema
                        $this->checkUndefined($v, new \stdClass(), $path, $k);
                    }
                }
            }
            unset($v); /* remove dangling reference to prevent any future bugs
                        * caused by accidentally using $v elsewhere */

            // Treat when we have more schema definitions than values, not for empty arrays
            if (count($value) > 0) {
                for ($k = count($value); $k < count($schema->items); $k++) {
                    $undefinedInstance = $this->factory->createInstanceFor('undefined');
                    $this->checkUndefined($undefinedInstance, $schema->items[$k], $path, $k);
                }
            }
        }
    }
1246406
public static boolean validatePath(String path) {
        if(path == null) {
            Log.w(TAG, "Uploading path not set");
            return false;
        }

        try {
            uriFromString(path);
            return true;
        } catch(DataSinkException e) {
            return false;
        }
    }
482859
def _perform_validation(self, path, value, results):
        
        name = path if path != None else "value"

        if value == None:
            # Check for required values
            if self.required:
                results.append(
                    ValidationResult(
                        path,
                        ValidationResultType.Error,
                        "VALUE_IS_NULL",
                        name + " cannot be null",
                        "NOT NULL",
                        None
                    )
                )
        else:
            value = ObjectReader.get_value(value)

            # Check validation rules
            if self.rules != None:
                for rule in self.rules:
                    rule.validate(path, self, value, results)
276613
def validate(schema):
    """"""
    try:
        tableschema.validate(schema)
        click.echo("Schema is valid")
        sys.exit(0)
    except tableschema.exceptions.ValidationError as exception:
        click.echo("Schema is not valid")
        click.echo(exception.errors)
        sys.exit(1)
1205904
def validate(self, value, add_comments=False, schema_name="map"):
        
        validator = self.get_schema_validator(schema_name)

        error_messages = []

        if isinstance(value, list):
            for d in value:
                error_messages += self._validate(d, validator, add_comments, schema_name)
        else:
            error_messages = self._validate(value, validator, add_comments, schema_name)

        return error_messages
945536
public static ValidationResult isValidAddOn(Path file) {
		if (file == null || file.getNameCount() == 0) {
			return new ValidationResult(ValidationResult.Validity.INVALID_PATH);
		}

		if (!isAddOnFileName(file.getFileName().toString())) {
			return new ValidationResult(ValidationResult.Validity.INVALID_FILE_NAME);
		}

		if (!Files.isRegularFile(file) || !Files.isReadable(file)) {
			return new ValidationResult(ValidationResult.Validity.FILE_NOT_READABLE);
		}

		try (ZipFile zip = new ZipFile(file.toFile())) {
			ZipEntry manifest = zip.getEntry(MANIFEST_FILE_NAME);
			if (manifest == null) {
				return new ValidationResult(ValidationResult.Validity.MISSING_MANIFEST);
			}

			try (InputStream zis = zip.getInputStream(manifest)) {
				try {
					return new ValidationResult(new ZapAddOnXmlFile(zis));
				} catch (Exception e) {
					return new ValidationResult(ValidationResult.Validity.INVALID_MANIFEST, e);
				}
			}
		} catch (ZipException e) {
			return new ValidationResult(ValidationResult.Validity.UNREADABLE_ZIP_FILE, e);
		} catch (Exception e) {
			return new ValidationResult(ValidationResult.Validity.IO_ERROR_FILE, e);
		}
	}
1019966
public void validate(String path, Schema schema, Object value, List<ValidationResult> results) {
		String name = path != null ? path : "value";

		if (!ObjectComparator.compare(value, _operation, _value)) {
			results.add(new ValidationResult(path, ValidationResultType.Error, "BAD_VALUE",
					name + " must " + _operation + " " + _value + " but found " + value, _operation + " " + _value,
					value));
		}
	}
445530
public static void main(String[] args) {
        if(args.length != 2) {
            System.out.println("Usage: SchemaEvolutionValidator pathToOldSchema pathToNewSchema");
            return;
        }

        Schema oldSchema;
        Schema newSchema;

        try {
            oldSchema = Schema.parse(new File(args[0]));
        } catch(Exception ex) {
            oldSchema = null;
            System.out.println("Could not open or parse the old schema (" + args[0] + ") due to "
                               + ex);
        }

        try {
            newSchema = Schema.parse(new File(args[1]));
        } catch(Exception ex) {
            newSchema = null;
            System.out.println("Could not open or parse the new schema (" + args[1] + ") due to "
                               + ex);
        }

        if(oldSchema == null || newSchema == null) {
            return;
        }

        System.out.println("Comparing: ");
        System.out.println("\t" + args[0]);
        System.out.println("\t" + args[1]);

        List<Message> messages = SchemaEvolutionValidator.checkBackwardCompatibility(oldSchema,
                                                                                     newSchema,
                                                                                     oldSchema.getName());
        Level maxLevel = Level.ALL;
        for(Message message: messages) {
            System.out.println(message.getLevel() + ": " + message.getMessage());
            if(message.getLevel().isGreaterOrEqual(maxLevel)) {
                maxLevel = message.getLevel();
            }
        }

        if(maxLevel.isGreaterOrEqual(Level.ERROR)) {
            System.out.println(Level.ERROR
                               + ": The schema is not backward compatible. New clients will not be able to read existing data.");
        } else if(maxLevel.isGreaterOrEqual(Level.WARN)) {
            System.out.println(Level.WARN
                               + ": The schema is partially backward compatible, but old clients will not be able to read data serialized in the new format.");
        } else {
            System.out.println(Level.INFO
                               + ": The schema is backward compatible. Old and new clients will be able to read records serialized by one another.");
        }
    }
742882
private void validate(Source src, Result res) throws XMLStreamException {
        try {
            Validator v = schemaFactory.newSchema().newValidator();
            v.setResourceResolver(schemaFactory.getResourceResolver());
            v.validate(src, res);
        } catch (SAXException | IOException e) {
            throw new XMLStreamException(e);
        }
    }
1034642
public void validate() {
    Validator validator = this.schema.newValidator();
    InputStream in = null;
    try {
      if(this.xmlFile != null) {
        in = this.xmlFile.openStream();
      } else {
        // TODO: check if we need to specify the encoding
        in = new ByteArrayInputStream(this.serializedRule.getBytes()) ;
      }
      validator.validate(new StreamSource(in));
    } catch (SAXException e) {
      throw new RulesException("Rules file does not conform to the schema", e);
    } catch (IOException e) {
      if(this.xmlFile != null) {
        throw new RulesException("Could not read file " + this.xmlFile, e);
      } else {
        throw new RulesException("Could not read serialized rule " + this.serializedRule, e);
      }
        
    } finally {
      Closeables.closeQuietly(in);
    }
  }
244616
@Override
    protected void validate(List<TableInfo> tableInfos)
    {
        for (TableInfo tableInfo : tableInfos)
        {
            try
            {
                if (!client.tableExists(tableInfo.getTableName()))
                {
                    throw new SchemaGenerationException("Table: " + tableInfo.getTableName() + " does not exist ");
                }
            }
            catch (Exception e)
            {
                logger.error("Error while validating tables, Caused by: " + e.getMessage());
                throw new KunderaException("Error while validating tables, Caused by: " + e.getMessage());
            }
        }
    }
1215767
public void validateWithXmlSchema(String filename, String xmlSchemaPath) throws IOException {
    try (InputStream xmlStream = this.getClass().getResourceAsStream(filename)) {
      if (xmlStream == null) {
        throw new IOException("File not found in classpath: " + filename);
      }
      URL schemaUrl = this.getClass().getResource(xmlSchemaPath);
      if (schemaUrl == null) {
        throw new IOException("XML schema not found in classpath: " + xmlSchemaPath);
      }
      validateInternal(new StreamSource(xmlStream), schemaUrl);
    } catch (Exception e) {
      throw new IOException("Cannot load or parse '" + filename + "'", e);
    }
  }