annotate Lib/IMPL/DOM/Schema/SimpleType.pm @ 103:c289ed9662ca

Schema beta 2 More strict validation, support for inflating a simple nodes and properties
author wizard
date Fri, 07 May 2010 18:17:40 +0400
parents cf3b6ef2be22
children 196bf443b5e1
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: 20
diff changeset
1 package IMPL::DOM::Schema::SimpleType;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
5 use base qw(IMPL::DOM::Schema::SimpleNode);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
7 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
9 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
10 public _direct property nativeType => prop_get;
103
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
11 public _direct property messageWrongType => prop_get;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
12 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
14 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
15 'IMPL::DOM::Schema::SimpleNode' => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
16 my %args = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
17 $args{nodeName} = 'SimpleType';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
18 $args{minOccur} = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
19 $args{maxOccur} = 'unbounded';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
20 $args{name} ||= 'SimpleType';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
21 %args
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
22 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
23 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
25 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
26 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
28 $this->{$nativeType} = $args{nativeType};
103
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
29 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%Node.path%' is expected to be %Schema.nativeType%";
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
30 }
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
31
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
32 sub Validate {
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
33 my ($this, $node) = @_;
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
34
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
35 if ($this->{$nativeType}) {
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
36 return new IMPL::DOM::Schema::ValidationError(
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
37 Node => $node,
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
38 Source => $this,
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
39 Schema => $this,
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
40 Message => $this->messageWrongType
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
41 ) unless $node->isa($this->{$nativeType});
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
42 }
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
43 return $this->SUPER::Validate($node);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
44 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
45
102
cf3b6ef2be22 Schema beta version
wizard
parents: 49
diff changeset
46 sub qname {
103
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
47 $_[0]->nodeName.'[type='.$_[0]->type.']';
102
cf3b6ef2be22 Schema beta version
wizard
parents: 49
diff changeset
48 }
cf3b6ef2be22 Schema beta version
wizard
parents: 49
diff changeset
49
103
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
50 1;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 20
diff changeset
51
103
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
52 __END__
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
53
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
54 =pod
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
55
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
56 =head1 NAME
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
57
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
58 C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов.
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
59
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
60 =head1 DESCRIPTION
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
61
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
62 Используется для описания простых узлов, которые можно отобразить в узлы
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
63 определенного типа при построении DOM документа.
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
64
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
65 =head1 MEMBERS
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
66
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
67 =over
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
68
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
69 =item C<nativeType>
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
70
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
71 Имя класса который будет представлять узел в DOM модели.
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
72
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
73 =item C<messageWrongType>
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
74
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
75 Формат сообщения которое будет выдано, если узел в дом модели не будет
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
76 соответствовать свойству C<nativeType>.
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
77
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
78 =back
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
79
c289ed9662ca Schema beta 2
wizard
parents: 102
diff changeset
80 =cut