Mercurial > pub > Impl
view Lib/IMPL/DOM/Schema/SimpleType.pm @ 103:c289ed9662ca
Schema beta 2
More strict validation, support for inflating a simple nodes and properties
author | wizard |
---|---|
date | Fri, 07 May 2010 18:17:40 +0400 |
parents | cf3b6ef2be22 |
children | 196bf443b5e1 |
line wrap: on
line source
package IMPL::DOM::Schema::SimpleType; use strict; use warnings; use base qw(IMPL::DOM::Schema::SimpleNode); use IMPL::Class::Property; use IMPL::Class::Property::Direct; BEGIN { public _direct property nativeType => prop_get; public _direct property messageWrongType => prop_get; } our %CTOR = ( 'IMPL::DOM::Schema::SimpleNode' => sub { my %args = @_; $args{nodeName} = 'SimpleType'; $args{minOccur} = 0; $args{maxOccur} = 'unbounded'; $args{name} ||= 'SimpleType'; %args } ); sub CTOR { my ($this,%args) = @_; $this->{$nativeType} = $args{nativeType}; $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%Node.path%' is expected to be %Schema.nativeType%"; } sub Validate { my ($this, $node) = @_; if ($this->{$nativeType}) { return new IMPL::DOM::Schema::ValidationError( Node => $node, Source => $this, Schema => $this, Message => $this->messageWrongType ) unless $node->isa($this->{$nativeType}); } return $this->SUPER::Validate($node); } sub qname { $_[0]->nodeName.'[type='.$_[0]->type.']'; } 1; __END__ =pod =head1 NAME C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов. =head1 DESCRIPTION Используется для описания простых узлов, которые можно отобразить в узлы определенного типа при построении DOM документа. =head1 MEMBERS =over =item C<nativeType> Имя класса который будет представлять узел в DOM модели. =item C<messageWrongType> Формат сообщения которое будет выдано, если узел в дом модели не будет соответствовать свойству C<nativeType>. =back =cut