annotate Lib/IMPL/DOM/Schema/ValidationError.pm @ 404:9ef75f2029be default

sync
author cin
date Fri, 28 Aug 2015 19:54:53 +0300
parents 5aff94ba842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
1 package IMPL::DOM::Schema::ValidationError;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
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
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
9 use IMPL::lang qw(is);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
10 use IMPL::Const qw(:prop);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
11 use IMPL::declare {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
12 require => {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
13 Label => '-IMPL::DOM::Schema::Label'
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
14 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
15 base => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
16 'IMPL::Object' => undef
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
17 ],
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
18 props => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
19 node => PROP_RO | PROP_DIRECT,
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
20 schemaNode => PROP_RO | PROP_DIRECT,
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
21 schemaType => PROP_RO | PROP_DIRECT,
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
22 parent => PROP_RO | PROP_DIRECT,
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
23 message => PROP_RO | PROP_DIRECT
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
24 ]
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
25 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
26 use IMPL::Resources::Format qw(FormatMessage);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
28 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
29 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
30
236
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
31 $this->{$node} = $args{node};
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
32 $this->{$schemaNode} = $args{schemaNode} if $args{schemaNode};
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
33 $this->{$schemaType} = $args{schemaType} if $args{schemaType};
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
34
236
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
35 if ($args{parent}) {
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
36 $this->{$parent} = $args{parent};
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
37 } elsif ($args{node}) {
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
38 $this->{$parent} = $args{node}->parentNode;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
39 } else {
236
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
40 die new IMPL::InvalidArgumentException("A 'parent' or a 'node' parameter is required");
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
41 }
383
2f16f13b000c DOM localization
cin
parents: 278
diff changeset
42
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
43 if ($args{message}) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
44 $this->{$message} = is($args{message},Label) ? $args{message}->Format(\%args) : FormatMessage($args{message}, \%args) ;
383
2f16f13b000c DOM localization
cin
parents: 278
diff changeset
45 }
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 383
diff changeset
46
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
48
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
49 sub toString {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 (my $this) = @_;
236
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
51 return $this->message;
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
52 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
53
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
54 1;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
55
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
56 __END__
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
57
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
58 =pod
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
59
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
60 =head1 NAME
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
61
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
62 C<IMPL::DOM::Schema::ValidationError> - Описывает ошибку в документе.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
63
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
64 =head1 DESCRIPTION
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
65
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
66 При проверке документа на ошибки формирования возвращается массив с объектами
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
67 C<IMPL::DOM::Schema::ValidationError>, каждая из которых описывает одну ошибку
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
68 в документе.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
69
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
70 С помощью данного объекта осущетсвляется привязка элемента схемы, элемента документа
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
71 и сообщения о причине возникновения ошибки.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
72
236
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
73 Часть ошибок, таких как проверка содержимого на регулярные выражения, привязаны
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
74 непосредственно к элементу. Но есть ошибки которые привязываются к родительскому
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
75 контейнеру, например отсутсвие обязательного элемента. В таком случае ошибка
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
76 содержит свойство C<parent> и по свойству C<source> можно определить элемент
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
77 (например его имя), к которому относится ошибка.
2904da230022 DOM refactoring
sergey
parents: 230
diff changeset
78
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
79 =head1 MEMBERS
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
80
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
81 =over
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
82
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
83 =item C<[get] node>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
84
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
85 Узел в документе который привел к ошибке. Как правило это либо простые узлы, либо
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
86 узлы, которые не могут присутствоать в данном месте по схеме.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
87
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
88 Данное свойство может быть C<undef>.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
89
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
90 =item C<[get] parent>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
91
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
92 Родительский узел в котором произошла ошибка. Используется в случаях, когда C<node>
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
93 не указан, например, если по схеме должен существовать дочерний узел с определенным
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
94 именем, а в реальном документе его нет.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
95
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
96 Также это свойство может использоваться при формировании сообщения.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
97
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
98 =item C<[get] schema>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
99
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
100 Схема для C<Node> или узла который должен присутсвовать если C<Node> не задан.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
101
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
102 =item C<[get] source>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
103
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
104 Схема, проверка которой привела к возникновению ошибки. Поскольку схемы могут
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
105 использовать ссылки, то данное свойство нужно для получения схемы узла, а не
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
106 схемы его типа.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
107
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
108 Тоесть проверка схемы узла C<IMPL::DOM::Schema::Node> приводит к проверке схемы
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
109 типа, например, C<IMPL::DOM::Schema::ComplexType>, а свойство C<Source> будет
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
110 указывать именно на C<IMPL::DOM::Schema::Node>.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
111
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
112 =item C<[get] message>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
113
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
114 Возвращает форматированное сообщение об ошибке.
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
115
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
116 =item C<toString()>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
117
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
118 Преобразует ошибку к строке, возвращает значение свойства C<Message>
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
119
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
120 =back
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
121
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
122 =head1 REMARKS
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
123
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
124 =begin code
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
126 my $doc = IMPL::DOM::XMLReader->LoadDocument('data.xml');
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
127 my $schema = IMPL::DOM::Schema->LoadSchema('schema.xml');
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
128
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
129 my @errors = $schema->Validate($doc);
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
130
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
131 my $node = $doc->selectSingleNode('user','name');
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
132
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
133 # Получаем все ошибки относящиеся к данному узлу
265
6b6d4b2275a1 improved documentation
cin
parents: 236
diff changeset
134 my @nodeErrors = grep { ($_->node || $_->parent) == $node } @errors;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
135
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
136 =end code
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
137
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
138 =cut