#!/usr/bin/perl
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# this is the script validates an RDF model against an RDF schemas

use Carp;
use RDFStore::NodeFactory;
use RDFStore::Model;
use RDFStore::SchemaModel;
use RDFStore::Parser::SiRPAC;

my $Usage =<<EOU;
Usage is:
    $0 <instance URL> <schema URL>

Validates a given RDF URL against a RDF Schema (URL)

EOU

# Process options
print $Usage and exit if ($#ARGV<1);

my @schemas = ();

my ($outputDirectory, $packageClass, $namespace, $factoryStr);

my $f = new RDFStore::NodeFactory();
my $rawSchema = new RDFStore::Model();

my $fileNameOrURL = shift @ARGV;
print STDERR "READING INSTANCE: ". $fileNameOrURL.".....";

my $p=new RDFStore::Parser::SiRPAC(
				ErrorContext => 3,
                                Style => 'RDFStore::Parser::Styles::RDFStore::Model',
                                NodeFactory     => $f,
                                Source  => $fileNameOrURL,
                                );
my $m = $p->parsefile($fileNameOrURL);

print STDERR "DONE\n";

my $schemaURL = shift @ARGV;
print STDERR "READING SCHEMA: ". $schemaURL.".....";

my $ps=new RDFStore::Parser::SiRPAC(
				ErrorContext => 3,
                                Style => 'RDFStore::Parser::Styles::RDFStore::Model',
                                NodeFactory     => $f,
                                Source  => $schemaURL,
                                );
my $ms = $ps->parsefile($schemaURL);

print STDERR "DONE\n";

my $schema_validator = new RDFStore::SchemaModel( $m, $ms );

my $valid = $schema_validator->validateRawSchema($m, $ms);

print "Model is ";
print "NOT "
	if(!(defined $valid));
print "valid\n";
