Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/SimpleType.pm @ 114:7084af955c57
minor changes, more strict code, no bugs fixed, no features added
author | wizard |
---|---|
date | Tue, 25 May 2010 01:26:42 +0400 |
parents | a6e9759ff88a |
children | e30bdd040fe3 |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::SimpleType; |
2 use strict; | |
3 use warnings; | |
4 | |
5 use base qw(IMPL::DOM::Schema::SimpleNode); | |
6 use IMPL::Class::Property; | |
7 use IMPL::Class::Property::Direct; | |
8 | |
9 BEGIN { | |
10 public _direct property nativeType => prop_get; | |
103 | 11 public _direct property messageWrongType => prop_get; |
49 | 12 } |
13 | |
14 our %CTOR = ( | |
15 'IMPL::DOM::Schema::SimpleNode' => sub { | |
16 my %args = @_; | |
17 $args{nodeName} = 'SimpleType'; | |
18 $args{minOccur} = 0; | |
19 $args{maxOccur} = 'unbounded'; | |
20 $args{name} ||= 'SimpleType'; | |
21 %args | |
22 } | |
23 ); | |
24 | |
25 sub CTOR { | |
26 my ($this,%args) = @_; | |
27 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
28 $this->{$nativeType} = $args{nativeType} if $args{nativeType}; |
103 | 29 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%Node.path%' is expected to be %Schema.nativeType%"; |
30 } | |
31 | |
32 sub Validate { | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
33 my ($this, $node, $ctx) = @_; |
103 | 34 |
35 if ($this->{$nativeType}) { | |
36 return new IMPL::DOM::Schema::ValidationError( | |
37 Node => $node, | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
38 Source => $ctx && $ctx->{Source} || $this, |
103 | 39 Schema => $this, |
40 Message => $this->messageWrongType | |
41 ) unless $node->isa($this->{$nativeType}); | |
42 } | |
105 | 43 return $this->SUPER::Validate($node,$ctx); |
49 | 44 } |
45 | |
102 | 46 sub qname { |
103 | 47 $_[0]->nodeName.'[type='.$_[0]->type.']'; |
102 | 48 } |
49 | |
103 | 50 1; |
49 | 51 |
103 | 52 __END__ |
53 | |
54 =pod | |
55 | |
56 =head1 NAME | |
57 | |
58 C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов. | |
59 | |
60 =head1 DESCRIPTION | |
61 | |
62 Используется для описания простых узлов, которые можно отобразить в узлы | |
63 определенного типа при построении DOM документа. | |
64 | |
65 =head1 MEMBERS | |
66 | |
67 =over | |
68 | |
69 =item C<nativeType> | |
70 | |
71 Имя класса который будет представлять узел в DOM модели. | |
72 | |
73 =item C<messageWrongType> | |
74 | |
75 Формат сообщения которое будет выдано, если узел в дом модели не будет | |
76 соответствовать свойству C<nativeType>. | |
77 | |
78 =back | |
79 | |
80 =cut |