annotate Lib/IMPL/DOM/Schema/Property.pm @ 46:75148ccd732d

Upgrading resources
author Sergey
date Tue, 02 Feb 2010 17:09:49 +0300
parents 9dd67fa91ee3
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
1 package IMPL::DOM::Schema::Property;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
2 use strict;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
3 use warnings;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
4
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
5 use base qw(IMPL::DOM::Schema::SimpleNode);
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
6 require IMPL::DOM::Schema;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
7 require IMPL::DOM::Node;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
9
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
10 __PACKAGE__->PassThroughArgs;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
11
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
12 BEGIN {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
13 public property RequiredMessage => prop_all;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
14 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
15
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
16 our %CTOR = (
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
17 'IMPL::DOM::Schema::SimpleNode' => sub {
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
18 my %args = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
19
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
20 $args{maxOccur} = 1;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
21 $args{minOccur} = delete $args{optional} ? 0 : 1;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
22 $args{nodeName} ||= 'Property';
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
23
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
24 return %args;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
25 }
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
26 );
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
27
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
28 sub CTOR {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
29 my ($this,%args) = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
30
25
9dd67fa91ee3 small fix in the dom schema
Sergey
parents: 24
diff changeset
31 $this->RequiredMessage($args{RequiredMessage} || 'A property %Schema.name% is required in the %Node.qname%');
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
32 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
33
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
34 sub Validate {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
35 my ($this,$node) = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
36
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
37 if ($this->minOccur) {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
38 my $prop = $this->name;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
39 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => $node->$prop() || $node->nodePropety($prop));
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
40
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
41 if (! $nodeProp->nodeValue) {
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
42 return new IMPL::DOM::Schema::ValidationError(
25
9dd67fa91ee3 small fix in the dom schema
Sergey
parents: 24
diff changeset
43 Message => $this->RequiredMessage,
9dd67fa91ee3 small fix in the dom schema
Sergey
parents: 24
diff changeset
44 Node => $node,
9dd67fa91ee3 small fix in the dom schema
Sergey
parents: 24
diff changeset
45 Schema => $this
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
46 );
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
47 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
48 return $this->SUPER::Validate($nodeProp);
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
49 } else {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
50 return ();
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
51 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
52 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
53
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
54 1;