view Lib/IMPL/DOM/Schema/SwitchNode.pm @ 24:7f00786f8210

Первая рабочая реазизация схемы и навигаторов
author Sergey
date Mon, 05 Oct 2009 00:48:49 +0400
parents
children 16ada169ca75
line wrap: on
line source

package IMPL::DOM::Schema::SwitchNode;
use strict;
use warnings;

use base qw(IMPL::DOM::Schema::AnyNode);
use IMPL::Class::Property;
require IMPL::DOM::Schema::ValidationError;

our %CTOR = (
    'IMPL::DOM::Schema::AnyNode' => sub {
        my %args = @_;
        
        $args{nodeName} ||= 'SwitchNode';
        
        %args;
    }
);

BEGIN {
    public property messageNoMatch => prop_all;
}

sub CTOR {
    my ($this,%args) = @_;
    
    $this->messageNoMatch($args{messageNoMatch} || 'A node %Node.nodeName% isn\'t expected in the %Node.parentNode.path%');
}

sub Validate {
    my ($this,$node) = @_;
    
    if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) {
        return $schema->Validate($node);
    } else {
        return new IMPL::DOM::Schema::ValidationError(
            Node => $node,
            Source => $this,
            Message => $this->messageNoMatch
        );
    }
}

1;

__END__

=pod

=head1 DESCRIPTION

 ,      ,    .
    C<IMPL::DOM::Schema::AnyNode>.

=cut