Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/ValidationError.pm @ 217:bfce101e0a5a
Слияние
| author | cin |
|---|---|
| date | Mon, 20 Aug 2012 10:27:20 +0400 |
| parents | 4d0e1962161c |
| children | 6d8092d8ce1b |
| 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 { | |
|
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 | 20 } |
| 21 | |
| 22 sub CTOR { | |
| 23 my ($this,%args) = @_; | |
| 24 | |
| 100 | 25 $this->{$Node} = $args{Node}; |
| 49 | 26 $this->{$Schema} = $args{Schema} if $args{Schema}; |
| 27 $this->{$Source} = $args{Source} if $args{Source}; | |
| 125 | 28 if ($args{Parent}) { |
| 194 | 29 $this->{$Parent} = $args{Parent}; |
| 125 | 30 } elsif ($args{Node}) { |
| 194 | 31 $this->{$Parent} = $args{Node}->parentNode; |
| 125 | 32 } else { |
| 194 | 33 die new IMPL::InvalidArgumentException("A 'Parent' or a 'Node' parameter is required"); |
| 125 | 34 } |
| 49 | 35 $this->{$Message} = FormatMessage(delete $args{Message}, \%args) if $args{Message}; |
| 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) = @_; |
| 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 |
| 62 =head1 MEMBERS | |
| 63 | |
| 64 =over | |
| 65 =item C<[get] Node> | |
| 66 | |
| 67 | |
| 180 | 68 Узел в документе который привел к ошибке. Как правило это либо простые узлы, либо |
| 69 узлы, которые не могут присутствоать в данном месте по схеме. | |
| 125 | 70 |
| 180 | 71 Данное свойство может быть C<undef>. |
| 125 | 72 |
| 73 =item C<[get] Parent> | |
| 74 | |
| 180 | 75 Родительский узел в котором произошла ошибка. Используется в случаях, когда C<Node> |
| 76 не указан, например, если по схеме должен существовать дочерний узел с определенным | |
| 77 именем, а в реальном документе его нет. | |
| 125 | 78 |
| 180 | 79 Также это свойство может использоваться при формировании сообщения. |
| 125 | 80 |
| 81 =item C<[get] Schema> | |
| 82 | |
| 180 | 83 Схема для C<Node> или узла который должен присутсвовать если C<Node> не задан. |
| 125 | 84 |
| 85 =item C<[get] Source> | |
| 86 | |
| 180 | 87 Схема, проверка которой привела к возникновению ошибки. Поскольку схемы могут |
| 88 использовать ссылки, то данное свойство нужно для получения схемы узла, а не | |
| 89 схемы его типа. | |
| 125 | 90 |
| 180 | 91 Тоесть проверка схемы узла C<IMPL::DOM::Schema::Node> приводит к проверке схемы |
| 92 типа, например, C<IMPL::DOM::Schema::ComplexType>, а свойство C<Source> будет | |
| 93 указывать именно на C<IMPL::DOM::Schema::Node>. | |
| 125 | 94 |
| 95 =item C<[get] Message> | |
| 96 | |
| 180 | 97 Возвращает форматированное сообщение об ошибке. |
| 125 | 98 |
| 99 =item C<toString()> | |
| 100 | |
| 180 | 101 Преобразует ошибку к строке, возвращает значение свойства C<Message> |
| 125 | 102 |
| 103 =back | |
| 104 | |
| 105 =head1 REMARKS | |
| 106 | |
| 107 =begin code | |
| 108 | |
| 109 my $doc = IMPL::DOM::XMLReader->LoadDocument('data.xml'); | |
| 110 my $schema = IMPL::DOM::Schema->LoadSchema('schema.xml'); | |
| 111 | |
| 112 my @errors = $schema->Validate($doc); | |
| 113 | |
| 114 my $node = $doc->selectSingleNode('user','name'); | |
| 115 | |
| 180 | 116 # Получаем все ошибки относящиеся к данному узлу |
| 125 | 117 my @nodeErrors = grep { ($_->Node || $_->Parent) == $node } @errors; |
| 118 | |
| 119 =end code | |
| 120 | |
| 121 =cut |
