# 
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (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.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 
# The Original Code is the RDF::Core module
# 
# The Initial Developer of the Original Code is Ginger Alliance Ltd.
# Portions created by Ginger Alliance are 
# Copyright (C) 2001 Ginger Alliance Ltd.
# All Rights Reserved.
# 
# Contributor(s):
# 
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable 
# instead of those above.  If you wish to allow use of your 
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL.  If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
# 

package RDF::Core::Model;

use strict;
require Exporter;


use Carp;

sub new {
    my ($pkg,%options) = @_;
    $pkg = ref $pkg || $pkg;
    my $self = {};
    $self->{_options} = \%options;
    bless $self, $pkg;
}
sub setOptions {
    my ($self,$options) = @_;
    $self->{_options} = $options;
}
sub getOptions {
    my $self = shift;
    return $self->{_options};
}
sub addStmt {
    my $self = shift;
    carp "No storage defined"
      unless exists $self->{_options}->{Storage} &&
	defined $self->{_options}->{Storage} &&
	  ref  $self->{_options}->{Storage};
     $self->{_options}->{Storage}->addStmt(@_);
}
sub removeStmt {
    my $self = shift;
    carp "No storage defined"
      unless exists $self->{_options}->{Storage} &&
	defined $self->{_options}->{Storage} &&
	  ref  $self->{_options}->{Storage};
     $self->{_options}->{Storage}->removeStmt(@_);
}
sub existsStmt {
    my $self = shift;
    carp "No storage defined"
      unless exists $self->{_options}->{Storage} &&
	defined $self->{_options}->{Storage} &&
	  ref  $self->{_options}->{Storage};
     $self->{_options}->{Storage}->existsStmt(@_);
}
sub getStmts {
    my $self = shift;
    carp "No storage defined"
      unless exists $self->{_options}->{Storage} &&
	defined $self->{_options}->{Storage} &&
	  ref  $self->{_options}->{Storage};
     $self->{_options}->{Storage}->getStmts(@_);
}
sub countStmts {
    my $self = shift;
    carp "No storage defined"
      unless exists $self->{_options}->{Storage} &&
	defined $self->{_options}->{Storage} &&
	  ref  $self->{_options}->{Storage};
     $self->{_options}->{Storage}->countStmts(@_);
}
1;
__END__

=head1 NAME

RDF::Core::Model - RDF model

=head1 SYNOPSIS

  use RDF::Core::Model;
  use RDF::Core::Storage::Memory;
  use RDF::Core::Statement;

  my $storage = new RDF::Core::Storage::Memory;
  my $model = new RDF::Core::Model (Storage => $storage);
  my $subject = new RDF::Core::Resource('http://www.gingerall.cz/employees/Jim');
  my $predicate = $subject->new('http://www.gingerall.cz/rdfns#name');
  my $object = new RDF::Core::Literal('Jim Brown');
  my $statement = new RDF::Core::Statement($subject, $predicate, $object);

  $model->addStmt($statement);

  print "Model contains ".$model->countStmts."statement(s).\n"

=head1 DESCRIPTION

Model provides interface to store RDF statements, ask about them and retrieve them back.

=head2 Interface

=over 4

=item * new(%options)

$options is a hash reference, available options are 

=over 4

=item * Storage 

a reference to a RDF::Core::Storage implementation

=back

=item * getOptions

=item * setOptions(\%options)

=item * addStmt($statement)

Add RDF::Core::Statement instance to Model, unless it already exists there.

=item * removeStmt($statement)

Remove statement from Model, if it's there.

=item * existsStmt($subject,$predicate,$object)

Check if statement exists, that matches given mask. Parameters can be undefined, every value matches undefined parameter.

=item * countStmts($subject,$predicate,$object)

Count matching statements.

=item * getStmts($subject,$predicate,$object)

Retrieve matching statements. Returns RDF::Core::Enumerator object.

=back



=head1 LICENSE

This package is subject to the MPL (or the GPL alternatively).

=head1 AUTHOR

Ginger Alliance, rdf@gingerall.cz

=head1 SEE ALSO

RDF::Core::Statement, RDF::Core::Storage, RDF::Core::Serializer, RDF::Core::Parser, RDF::Core::Enumerator

=cut
