Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/ValidationError.pm @ 245:7c517134c42f
Added Unsupported media type Web exception
corrected resourceLocation setting in the resource
Implemented localizable resources for text messages
fixed TT view scopings, INIT block in controls now sets globals correctly.
author | sergey |
---|---|
date | Mon, 29 Oct 2012 03:15:22 +0400 |
parents | 2904da230022 |
children | 6b6d4b2275a1 |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::ValidationError; |
2 use strict; | |
3 use warnings; | |
4 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
5 use overload |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
6 '""' => \&toString, |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
7 'fallback' => 1; |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
8 |
165 | 9 use parent qw(IMPL::Object); |
49 | 10 use IMPL::Class::Property; |
11 use IMPL::Class::Property::Direct; | |
12 use IMPL::Resources::Format qw(FormatMessage); | |
13 | |
14 BEGIN { | |
236 | 15 public _direct property node => prop_get; # target document node (if exists) |
16 public _direct property schema => prop_get; # a schema for the target node (if exists) | |
17 public _direct property source => prop_get; # a schema which triggered this error (can be equal to the Schema) | |
18 public _direct property parent => prop_get; | |
19 public _direct property message => prop_get; # displayable message | |
49 | 20 } |
21 | |
22 sub CTOR { | |
23 my ($this,%args) = @_; | |
24 | |
236 | 25 $this->{$node} = $args{node}; |
26 $this->{$schema} = $args{schema} if $args{schema}; | |
27 $this->{$source} = $args{source} if $args{source}; | |
28 if ($args{parent}) { | |
29 $this->{$parent} = $args{parent}; | |
30 } elsif ($args{node}) { | |
31 $this->{$parent} = $args{node}->parentNode; | |
125 | 32 } else { |
236 | 33 die new IMPL::InvalidArgumentException("A 'parent' or a 'node' parameter is required"); |
125 | 34 } |
236 | 35 $this->{$message} = FormatMessage(delete $args{message}, \%args) if $args{message}; |
49 | 36 } |
37 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
38 sub toString { |
194 | 39 (my $this) = @_; |
236 | 40 return $this->message; |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
41 } |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
102
diff
changeset
|
42 |
49 | 43 1; |
125 | 44 |
45 __END__ | |
46 | |
47 =pod | |
48 | |
49 =head1 NAME | |
50 | |
180 | 51 C<IMPL::DOM::Schema::ValidationError> - Описывает ошибку в документе. |
125 | 52 |
53 =head1 DESCRIPTION | |
54 | |
180 | 55 При проверке документа на ошибки формирования возвращается массив с объектами |
56 C<IMPL::DOM::Schema::ValidationError>, каждая из которых описывает одну ошибку | |
57 в документе. | |
125 | 58 |
180 | 59 С помощью данного объекта осущетсвляется привязка элемента схемы, элемента документа |
60 и сообщения о причине возникновения ошибки. | |
125 | 61 |
236 | 62 Часть ошибок, таких как проверка содержимого на регулярные выражения, привязаны |
63 непосредственно к элементу. Но есть ошибки которые привязываются к родительскому | |
64 контейнеру, например отсутсвие обязательного элемента. В таком случае ошибка | |
65 содержит свойство C<parent> и по свойству C<source> можно определить элемент | |
66 (например его имя), к которому относится ошибка. | |
67 | |
125 | 68 =head1 MEMBERS |
69 | |
70 =over | |
230 | 71 |
125 | 72 =item C<[get] Node> |
73 | |
180 | 74 Узел в документе который привел к ошибке. Как правило это либо простые узлы, либо |
75 узлы, которые не могут присутствоать в данном месте по схеме. | |
125 | 76 |
180 | 77 Данное свойство может быть C<undef>. |
125 | 78 |
79 =item C<[get] Parent> | |
80 | |
180 | 81 Родительский узел в котором произошла ошибка. Используется в случаях, когда C<Node> |
82 не указан, например, если по схеме должен существовать дочерний узел с определенным | |
83 именем, а в реальном документе его нет. | |
125 | 84 |
180 | 85 Также это свойство может использоваться при формировании сообщения. |
125 | 86 |
87 =item C<[get] Schema> | |
88 | |
180 | 89 Схема для C<Node> или узла который должен присутсвовать если C<Node> не задан. |
125 | 90 |
91 =item C<[get] Source> | |
92 | |
180 | 93 Схема, проверка которой привела к возникновению ошибки. Поскольку схемы могут |
94 использовать ссылки, то данное свойство нужно для получения схемы узла, а не | |
95 схемы его типа. | |
125 | 96 |
180 | 97 Тоесть проверка схемы узла C<IMPL::DOM::Schema::Node> приводит к проверке схемы |
98 типа, например, C<IMPL::DOM::Schema::ComplexType>, а свойство C<Source> будет | |
99 указывать именно на C<IMPL::DOM::Schema::Node>. | |
125 | 100 |
101 =item C<[get] Message> | |
102 | |
180 | 103 Возвращает форматированное сообщение об ошибке. |
125 | 104 |
105 =item C<toString()> | |
106 | |
180 | 107 Преобразует ошибку к строке, возвращает значение свойства C<Message> |
125 | 108 |
109 =back | |
110 | |
111 =head1 REMARKS | |
112 | |
113 =begin code | |
114 | |
115 my $doc = IMPL::DOM::XMLReader->LoadDocument('data.xml'); | |
116 my $schema = IMPL::DOM::Schema->LoadSchema('schema.xml'); | |
117 | |
118 my @errors = $schema->Validate($doc); | |
119 | |
120 my $node = $doc->selectSingleNode('user','name'); | |
121 | |
180 | 122 # Получаем все ошибки относящиеся к данному узлу |
125 | 123 my @nodeErrors = grep { ($_->Node || $_->Parent) == $node } @errors; |
124 | |
125 =end code | |
126 | |
127 =cut |