Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/SimpleType.pm @ 406:f23fcb19d3c1 ref20150831
implemented ServicesBag
author | cin |
---|---|
date | Mon, 31 Aug 2015 20:22:16 +0300 |
parents | 5aff94ba842f |
children |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::SimpleType; |
2 use strict; | |
3 use warnings; | |
4 | |
389 | 5 use IMPL::declare { |
6 require => { | |
7 Label => 'IMPL::DOM::Schema::Label', | |
8 ValidationError => 'IMPL::DOM::Schema::ValidationError' | |
9 }, | |
10 base => [ | |
11 'IMPL::DOM::Schema::SimpleNode' => sub { | |
12 my %args = @_; | |
13 $args{nodeName} = 'SimpleType'; | |
14 $args{minOccur} = 0; | |
15 $args{maxOccur} = 'unbounded'; | |
16 $args{name} ||= 'SimpleType'; | |
17 delete @args{qw(nativeType messageWrongType)}; | |
18 %args | |
19 } | |
20 ], | |
21 props => [ | |
22 nativeType => { get => 1, set => 1, direct => 1, dom => 1}, | |
23 messageWrongType => { get => 1, set => 1, direct => 1, dom => 1 } | |
24 ] | |
25 }; | |
49 | 26 |
27 sub CTOR { | |
28 my ($this,%args) = @_; | |
29 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
30 $this->{$nativeType} = $args{nativeType} if $args{nativeType}; |
389 | 31 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%node.path%' is expected to be %schemaType.nativeType%"; |
103 | 32 } |
33 | |
34 sub Validate { | |
194 | 35 my ($this, $node, $ctx) = @_; |
36 | |
37 if ($this->{$nativeType}) { | |
389 | 38 return ValidationError->new( |
236 | 39 node => $node, |
389 | 40 schemaNode => $ctx->{schemaNode} || $this, |
41 schemaType => $this, | |
42 message => $this->_MakeLabel($this->messageWrongType) | |
194 | 43 ) unless $node->isa($this->{$nativeType}); |
44 } | |
45 return $this->SUPER::Validate($node,$ctx); | |
49 | 46 } |
47 | |
102 | 48 sub qname { |
194 | 49 $_[0]->nodeName.'[type='.$_[0]->type.']'; |
102 | 50 } |
51 | |
389 | 52 sub _MakeLabel { |
53 my ($this,$label) = @_; | |
54 | |
55 if ($label =~ /^ID:(\w+)$/) { | |
56 return Label->new($this->document->stringMap, $1); | |
57 } else { | |
58 return $label; | |
59 } | |
60 } | |
61 | |
103 | 62 1; |
49 | 63 |
103 | 64 __END__ |
65 | |
66 =pod | |
67 | |
68 =head1 NAME | |
69 | |
180 | 70 C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов. |
103 | 71 |
72 =head1 DESCRIPTION | |
73 | |
180 | 74 Используется для описания простых узлов, которые можно отобразить в узлы |
75 определенного типа при построении DOM документа. | |
103 | 76 |
77 =head1 MEMBERS | |
78 | |
79 =over | |
80 | |
81 =item C<nativeType> | |
82 | |
180 | 83 Имя класса который будет представлять узел в DOM модели. |
103 | 84 |
85 =item C<messageWrongType> | |
86 | |
180 | 87 Формат сообщения которое будет выдано, если узел в дом модели не будет |
88 соответствовать свойству C<nativeType>. | |
103 | 89 |
90 =back | |
91 | |
92 =cut |