annotate Lib/IMPL/DOM/Schema/Property.pm @ 379:a471e8b77544

sync
author cin
date Thu, 16 Jan 2014 18:10:50 +0400
parents 0f59b2de72af
children ced5937ff21a
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::Node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
7 use IMPL::Class::Property;
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 104
diff changeset
8 use IMPL::DOM::Property qw(_dom);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
10 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
12 BEGIN {
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 104
diff changeset
13 public _dom property messageRequired => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
14 }
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 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
17 'IMPL::DOM::Schema::SimpleNode' => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
18 my %args = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
20 $args{maxOccur} = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
21 $args{minOccur} = delete $args{optional} ? 0 : 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
22 $args{nodeName} ||= 'Property';
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
23 $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
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
25 return %args;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
26 }
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 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
30 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
31
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
32 $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
33 }
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 sub Validate {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
36 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
37
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
38 my $prop = $this->name;
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
39
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
40 # buld a pseudo node for the property value
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
41 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
42
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
43 if ($nodeProp->nodeValue) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
44 # we have a value so validate it
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
45 return $this->SUPER::Validate($nodeProp,$ctx);
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
46 } elsif($this->minOccur) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
47 # we don't have a value but it's a mandatory property
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
48 return new IMPL::DOM::Schema::ValidationError(
236
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
49 message => $this->messageRequired,
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
50 node => $node,
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
51 schema => $this,
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
52 source => $ctx && $ctx->{Source} || $this
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
53 );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
54 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
55 return ();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
56 }
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 1;