comparison Lib/IMPL/DOM/Navigator/Builder.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
comparison
equal deleted inserted replaced
102:cf3b6ef2be22 103:c289ed9662ca
9 9
10 BEGIN { 10 BEGIN {
11 private _direct property _schemaNavi => prop_all; 11 private _direct property _schemaNavi => prop_all;
12 private _direct property _nodesPath => prop_all; 12 private _direct property _nodesPath => prop_all;
13 private _direct property _nodeCurrent => prop_all; 13 private _direct property _nodeCurrent => prop_all;
14 private _direct property _docClass => prop_all 14 private _direct property _docClass => prop_all;
15 public _direct property Document => prop_get | owner_set; 15 public _direct property Document => prop_get | owner_set;
16 } 16 }
17 17
18 sub CTOR { 18 sub CTOR {
19 my ($this,$docClass,$schema) = @_; 19 my ($this,$docClass,$schema) = @_;
25 sub NavigateCreate { 25 sub NavigateCreate {
26 my ($this,$nodeName,%props) = @_; 26 my ($this,$nodeName,%props) = @_;
27 27
28 if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) { 28 if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) {
29 my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType : 'IMPL::DOM::Node'; 29 my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType : 'IMPL::DOM::Node';
30 $this->inflateProperties($schemaNode,\%props);
30 31
31 my $node; 32 my $node;
32 if (! $this->{$Document}) { 33 if (! $this->{$Document}) {
33 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props); 34 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
34 } else { 35 } else {
40 41
41 $this->{$_nodeCurrent} = $node; 42 $this->{$_nodeCurrent} = $node;
42 43
43 return $node; 44 return $node;
44 } else { 45 } else {
45 warn $nodeName;
46 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName); 46 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName);
47 } 47 }
48 }
49
50 sub inflateProperties {
51 my ($this,$schemaNode,$refProps) = @_;
52
53 $refProps->{$_->name} = $_->inflator->new($refProps->{$_->name})
54 foreach $schemaNode->selectNodes(
55 sub {
56 $_->nodeName eq 'Property' and exists $refProps->{$_->name} and $_->inflator
57 }
58 );
59 }
60
61 sub inflateValue {
62 my ($this,$value) = @_;
63 my $schemaNode = $this->{$_schemaNavi}->Current;
64 if ($schemaNode->can('inflator') and my $inflator = $schemaNode->inflator) {
65 return $inflator->new($value);
66 } else {
67 return $value;
68 }
48 } 69 }
49 70
50 sub Back { 71 sub Back {
51 my ($this) = @_; 72 my ($this) = @_;
52 73