annotate Lib/IMPL/DOM/Schema/NodeSet.pm @ 383:2f16f13b000c

DOM localization
author cin
date Thu, 23 Jan 2014 17:26:34 +0400
parents b8c724f6de36
children 5aff94ba842f
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::NodeSet;
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
165
76515373dac0 Added Class::Template,
wizard
parents: 152
diff changeset
5 use parent qw(IMPL::DOM::Node);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
6 use IMPL::Class::Property;
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
7 use IMPL::DOM::Property qw(_dom);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
9 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
10 'IMPL::DOM::Node' => sub { nodeName => 'NodeSet' }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
11 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
13 BEGIN {
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
14 public _dom property messageUnexpected => prop_all;
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
15 public _dom property messageMax => prop_all;
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
16 public _dom property messageMin => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
17 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
18
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
19 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
20 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
21
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
22 $this->messageMax( $args{messageMax} || 'Too many %node.nodeName% nodes');
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
23 $this->messageMin( $args{messageMin} || '%schema.name% nodes expected');
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
24 $this->messageUnexpected( $args{messageUnexpected} || 'A %node.nodeName% isn\'t allowed in %node.parentNode.path%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
25 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
26
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
27 sub Validate {
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
28 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
30 my @errors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
32 my %nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
33 my $anyNode;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
34 my $sourceSchema = $ctx->{Source} || $this->parentNode;
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
35
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36 foreach (@{$this->childNodes}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
37 if ($_->isa('IMPL::DOM::Schema::AnyNode')) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
38 $anyNode = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
39 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
40 $nodes{$_->name} = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
41 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
42 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
43
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
44 foreach my $child ( @{$node->childNodes} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
45 if (my $info = $nodes{$child->nodeName} || $anyNode) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
46 $info->{Seen}++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47 push @errors,new IMPL::DOM::Schema::ValidationError (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
48 source => $sourceSchema,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
49 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
50 parent => $node,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
51 schema => $info->{Schema},
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
52 message => $this->messageMax
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
53 ) if ($info->{Max} and $info->{Seen} > $info->{Max});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
55 if (my @localErrors = $info->{Schema}->Validate($child)) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
56 push @errors,@localErrors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
58 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
59 push @errors, new IMPL::DOM::Schema::ValidationError (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
60 source => $sourceSchema,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
61 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
62 parent => $node,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
63 message => $this->messageUnexpected
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
64 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
65 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
66 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
68 foreach my $info (values %nodes) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
69 push @errors, new IMPL::DOM::Schema::ValidationError (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
70 source => $sourceSchema,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
71 schema => $info->{Schema},
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
72 parent => $node,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
73 message => $this->messageMin
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
74 ) if $info->{Min} > $info->{Seen};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
75 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
76
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
77 return @errors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
78 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
80 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
81
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
82 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
84 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
85
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
86 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
87
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
88 Содержимое для сложного узла. Порядок не важен. Дочерними элементами могут быть
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
89 только C<IMPL::DOM::Schema::ComplexNode> и C<IMPL::DOM::Schema::SimpleNode>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
90
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
91 При проверке данного правила, проверяются имеющиеся элементы на соответсие схемы
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
92 и количества встречаемости, после чего проверяются количественные ограничения
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
93 для несуществующих элементов.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
94
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
95 =cut