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
|
|
28 $this->{$nativeType} = $args{nativeType};
|
103
|
29 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%Node.path%' is expected to be %Schema.nativeType%";
|
|
30 }
|
|
31
|
|
32 sub Validate {
|
|
33 my ($this, $node) = @_;
|
|
34
|
|
35 if ($this->{$nativeType}) {
|
|
36 return new IMPL::DOM::Schema::ValidationError(
|
|
37 Node => $node,
|
|
38 Source => $this,
|
|
39 Schema => $this,
|
|
40 Message => $this->messageWrongType
|
|
41 ) unless $node->isa($this->{$nativeType});
|
|
42 }
|
|
43 return $this->SUPER::Validate($node);
|
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
|