Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
102:cf3b6ef2be22 | 103:c289ed9662ca |
---|---|
6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
7 use IMPL::Class::Property::Direct; | 7 use IMPL::Class::Property::Direct; |
8 | 8 |
9 BEGIN { | 9 BEGIN { |
10 public _direct property nativeType => prop_get; | 10 public _direct property nativeType => prop_get; |
11 public _direct property messageWrongType => prop_get; | |
11 } | 12 } |
12 | 13 |
13 our %CTOR = ( | 14 our %CTOR = ( |
14 'IMPL::DOM::Schema::SimpleNode' => sub { | 15 'IMPL::DOM::Schema::SimpleNode' => sub { |
15 my %args = @_; | 16 my %args = @_; |
23 | 24 |
24 sub CTOR { | 25 sub CTOR { |
25 my ($this,%args) = @_; | 26 my ($this,%args) = @_; |
26 | 27 |
27 $this->{$nativeType} = $args{nativeType}; | 28 $this->{$nativeType} = $args{nativeType}; |
29 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%Node.path%' is expected to be %Schema.nativeType%"; | |
30 } | |
31 | |
32 sub Validate { | |
33 my ($this, $node) = @_; | |
34 | |
35 if ($this->{$nativeType}) { | |
36 return new IMPL::DOM::Schema::ValidationError( | |
37 Node => $node, | |
38 Source => $this, | |
39 Schema => $this, | |
40 Message => $this->messageWrongType | |
41 ) unless $node->isa($this->{$nativeType}); | |
42 } | |
43 return $this->SUPER::Validate($node); | |
28 } | 44 } |
29 | 45 |
30 sub qname { | 46 sub qname { |
31 $_[0]->nodeName.'[name='.$_[0]->type.']'; | 47 $_[0]->nodeName.'[type='.$_[0]->type.']'; |
32 } | 48 } |
33 | 49 |
50 1; | |
34 | 51 |
35 1; | 52 __END__ |
53 | |
54 =pod | |
55 | |
56 =head1 NAME | |
57 | |
58 C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов. | |
59 | |
60 =head1 DESCRIPTION | |
61 | |
62 Используется для описания простых узлов, которые можно отобразить в узлы | |
63 определенного типа при построении DOM документа. | |
64 | |
65 =head1 MEMBERS | |
66 | |
67 =over | |
68 | |
69 =item C<nativeType> | |
70 | |
71 Имя класса который будет представлять узел в DOM модели. | |
72 | |
73 =item C<messageWrongType> | |
74 | |
75 Формат сообщения которое будет выдано, если узел в дом модели не будет | |
76 соответствовать свойству C<nativeType>. | |
77 | |
78 =back | |
79 | |
80 =cut |