Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Navigator/Builder.pm @ 106:83e356614c1e
DOM Builder now is a navigator like SimpleBuilder
PostToDOM transformation
author | wizard |
---|---|
date | Wed, 12 May 2010 17:52:12 +0400 |
parents | 196bf443b5e1 |
children | 0ed8e2541b1c |
comparison
equal
deleted
inserted
replaced
105:a6e9759ff88a | 106:83e356614c1e |
---|---|
1 package IMPL::DOM::Navigator::Builder; | 1 package IMPL::DOM::Navigator::Builder; |
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::Object); | 5 use base qw(IMPL::DOM::Navigator); |
6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
7 use IMPL::Class::Property::Direct; | 7 use IMPL::Class::Property::Direct; |
8 require IMPL::DOM::Navigator::SchemaNavigator; | 8 require IMPL::DOM::Navigator::SchemaNavigator; |
9 require IMPL::DOM::Schema::ValidationError; | 9 require IMPL::DOM::Schema::ValidationError; |
10 use IMPL::DOM::Document; | |
10 | 11 |
11 BEGIN { | 12 BEGIN { |
12 private _direct property _schemaNavi => prop_all; | 13 private _direct property _schemaNavi => prop_all; |
13 private _direct property _nodesPath => prop_all; | |
14 private _direct property _nodeCurrent => prop_all; | |
15 private _direct property _docClass => prop_all; | 14 private _direct property _docClass => prop_all; |
16 public _direct property BuildErrors => prop_get | prop_list; | 15 public _direct property BuildErrors => prop_get | prop_list; |
17 public _direct property Document => prop_get | owner_set; | 16 public _direct property Document => prop_get | owner_set; |
18 } | 17 } |
18 | |
19 our %CTOR = ( | |
20 'IMPL::DOM::Navigator' => sub { IMPL::DOM::Document::Empty; } | |
21 ); | |
19 | 22 |
20 sub CTOR { | 23 sub CTOR { |
21 my ($this,$docClass,$schema) = @_; | 24 my ($this,$docClass,$schema) = @_; |
22 | 25 |
23 $this->{$_docClass} = $docClass; | 26 $this->{$_docClass} = $docClass; |
33 my @errors = $this->inflateProperties($schemaNode,\%props); | 36 my @errors = $this->inflateProperties($schemaNode,\%props); |
34 | 37 |
35 my $node; | 38 my $node; |
36 if (! $this->{$Document}) { | 39 if (! $this->{$Document}) { |
37 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props); | 40 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props); |
41 $this->_initNavigator($node); | |
38 } else { | 42 } else { |
39 die new IMPL::InvalidOperationException('Can\t create a second top level element') unless $this->{$_nodeCurrent}; | 43 die new IMPL::InvalidOperationException('Can\t create a second top level element') unless $this->Current; |
40 $node = $this->{$Document}->Create($nodeName,$class,\%props); | 44 $node = $this->{$Document}->Create($nodeName,$class,\%props); |
41 push @{$this->{$_nodesPath}}, $this->{$_nodeCurrent}; | 45 $this->Current->appendChild($node); |
42 $this->{$_nodeCurrent}->appendChild($node); | 46 $this->internalNavigateNodeSet($node); |
43 } | 47 } |
44 | |
45 $this->{$_nodeCurrent} = $node; | |
46 | 48 |
47 if (@errors) { | 49 if (@errors) { |
48 $this->BuildErrors->Append( | 50 $this->BuildErrors->Append( |
49 map { | 51 map { |
50 IMPL::DOM::Schema::ValidationError->new( | 52 IMPL::DOM::Schema::ValidationError->new( |
101 | 103 |
102 sub Back { | 104 sub Back { |
103 my ($this) = @_; | 105 my ($this) = @_; |
104 | 106 |
105 $this->{$_schemaNavi}->SchemaBack(); | 107 $this->{$_schemaNavi}->SchemaBack(); |
106 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}}; | 108 $this->SUPER::Back(); |
107 } | 109 } |
108 | 110 |
109 1; | 111 1; |
110 | 112 |
111 __END__ | 113 __END__ |