annotate Lib/IMPL/DOM/Schema/Property.pm @ 216:e9fd7ff3f54c

sync
author sergey
date Thu, 09 Aug 2012 17:24:07 +0400
parents 4d0e1962161c
children 2904da230022
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: 25
diff changeset
1 package IMPL::DOM::Schema::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
4
165
76515373dac0 Added Class::Template,
wizard
parents: 152
diff changeset
5 use parent qw(IMPL::DOM::Schema::SimpleNode);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
6 require IMPL::DOM::Schema;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
7 require IMPL::DOM::Node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
8 use IMPL::Class::Property;
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 104
diff changeset
9 use IMPL::DOM::Property qw(_dom);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
10
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
11 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
13 BEGIN {
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 104
diff changeset
14 public _dom property messageRequired => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
15 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
17 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
18 'IMPL::DOM::Schema::SimpleNode' => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
19 my %args = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
21 $args{maxOccur} = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
22 $args{minOccur} = delete $args{optional} ? 0 : 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
23 $args{nodeName} ||= 'Property';
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
24 $args{messageInflateError} ||= "Failed to inflate a property '%Schema.name%' of a node '%Node.path%': %Error.Message%";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
26 return %args;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
28 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
30 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
31 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
32
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
33 $this->messageRequired($args{messageRequired} || 'A property %Schema.name% is required in the %Node.qname%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
34 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
36 sub Validate {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
37 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
38
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
39 my $prop = $this->name;
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
40
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
41 # buld a pseudo node for the property value
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
42 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop));
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
43
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
44 if ($nodeProp->nodeValue) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
45 # we have a value so validate it
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
46 return $this->SUPER::Validate($nodeProp,$ctx);
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
47 } elsif($this->minOccur) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
48 # we don't have a value but it's a mandatory property
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
49 return new IMPL::DOM::Schema::ValidationError(
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
50 Message => $this->messageRequired,
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
51 Node => $node,
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
52 Schema => $this,
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
53 Source => $ctx && $ctx->{Source} || $this
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
54 );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
55 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
56 return ();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
57 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
58
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
59 1;