annotate Lib/IMPL/DOM/Schema/ValidationError.pm @ 148:e6447ad85cb4

DOM objects now have a schema and schemaSource properties RegExp now can launder data Improved post to DOM transformation (multiple values a now supported) Added new axes to navigation queries: ancestor and descendant minor changes and bug fixes
author wizard
date Mon, 16 Aug 2010 08:26:44 +0400
parents a4b0a819bbda
children 76515373dac0
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
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
9 use base qw(IMPL::Object);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
10 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
11 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
12 use IMPL::Resources::Format qw(FormatMessage);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
14 BEGIN {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
15 public _direct property Node => prop_get; # target document node (if exists)
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
16 public _direct property Schema => prop_get; # a schema for the target node (if exists)
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
17 public _direct property Source => prop_get; # a schema which triggered this error (can be equal to the Schema)
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
18 public _direct property Parent => prop_get;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
19 public _direct property Message => prop_get; # displayable message
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
20 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
21
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
22 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
23 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
24
100
df6b4f054957 Schema in progress
wizard
parents: 49
diff changeset
25 $this->{$Node} = $args{Node};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
26 $this->{$Schema} = $args{Schema} if $args{Schema};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
27 $this->{$Source} = $args{Source} if $args{Source};
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
28 if ($args{Parent}) {
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
29 $this->{$Parent} = $args{Parent};
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
30 } elsif ($args{Node}) {
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
31 $this->{$Parent} = $args{Node}->parentNode;
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
32 } else {
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
33 die new IMPL::InvalidArgumentException("A 'Parent' or a 'Node' parameter is required");
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
34 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
35 $this->{$Message} = FormatMessage(delete $args{Message}, \%args) if $args{Message};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
37
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
38 sub toString {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
39 (my $this) = @_;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
40 return $this->Message;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
43 1;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
44
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
45 __END__
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
46
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
47 =pod
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
48
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
49 =head1 NAME
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
50
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
51 C<IMPL::DOM::Schema::ValidationError> - Описывает ошибку в документе.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
52
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
53 =head1 DESCRIPTION
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
54
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 C<IMPL::DOM::Schema::ValidationError>, каждая из которых описывает одну ошибку
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
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 и сообщения о причине возникновения ошибки.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
61
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
62 =head1 MEMBERS
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 =over
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
65 =item C<[get] Node>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
66
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
67
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
68 Узел в документе который привел к ошибке. Как правило это либо простые узлы, либо
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
69 узлы, которые не могут присутствоать в данном месте по схеме.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
70
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
71 Данное свойство может быть C<undef>.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
72
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
73 =item C<[get] Parent>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
74
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
75 Родительский узел в котором произошла ошибка. Используется в случаях, когда C<Node>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
76 не указан, например, если по схеме должен существовать дочерний узел с определенным
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
77 именем, а в реальном документе его нет.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
78
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
79 Также это свойство может использоваться при формировании сообщения.
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 =item C<[get] Schema>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
82
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
83 Схема для C<Node> или узла который должен присутсвовать если C<Node> не задан.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
84
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
85 =item C<[get] Source>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
86
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
87 Схема, проверка которой привела к возникновению ошибки. Поскольку схемы могут
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
88 использовать ссылки, то данное свойство нужно для получения схемы узла, а не
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
89 схемы его типа.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
90
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
91 Тоесть проверка схемы узла C<IMPL::DOM::Schema::Node> приводит к проверке схемы
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
92 типа, например, C<IMPL::DOM::Schema::ComplexType>, а свойство C<Source> будет
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
93 указывать именно на C<IMPL::DOM::Schema::Node>.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
94
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
95 =item C<[get] Message>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
96
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
97 Возвращает форматированное сообщение об ошибке.
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
98
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
99 =item C<toString()>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
100
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
101 Преобразует ошибку к строке, возвращает значение свойства C<Message>
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
102
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
103 =back
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
104
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
105 =head1 REMARKS
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
106
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
107 =begin code
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
108
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
109 my $doc = IMPL::DOM::XMLReader->LoadDocument('data.xml');
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
110 my $schema = IMPL::DOM::Schema->LoadSchema('schema.xml');
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
111
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
112 my @errors = $schema->Validate($doc);
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
113
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
114 my $node = $doc->selectSingleNode('user','name');
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 # Получаем все ошибки относящиеся к данному узлу
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
117 my @nodeErrors = grep { ($_->Node || $_->Parent) == $node } @errors;
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
118
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
119 =end code
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
120
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 104
diff changeset
121 =cut