Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Navigator/Builder.pm @ 24:7f00786f8210
Первая рабочая реазизация схемы и навигаторов
author | Sergey |
---|---|
date | Mon, 05 Oct 2009 00:48:49 +0400 |
parents | 75d55f4ee263 |
children | a8086f85a571 |
comparison
equal
deleted
inserted
replaced
23:716b287d4795 | 24:7f00786f8210 |
---|---|
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::DOM::Navigator); | 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 | 9 |
9 BEGIN { | 10 BEGIN { |
10 protected _direct property _navigatorSchema => prop_all; | 11 protected _direct property _schemaNavi => prop_all; |
11 public _direct property Document => prop_get | owner_set; | 12 public _direct property Document => prop_get | owner_set; |
12 } | 13 } |
13 | 14 |
14 our %CTOR = ( | 15 our %CTOR = ( |
15 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument) | 16 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument) |
17 | 18 |
18 sub CTOR { | 19 sub CTOR { |
19 my ($this,$domDocument,$schema) = @_; | 20 my ($this,$domDocument,$schema) = @_; |
20 | 21 |
21 $this->{$Document} = $domDocument; | 22 $this->{$Document} = $domDocument; |
22 $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema); | 23 $this->{$_schemaNavi} = $schema; |
23 } | 24 } |
24 | 25 |
25 sub NavigateCreate { | 26 sub NavigateCreate { |
26 my ($this,$nodeName,%props) = @_; | 27 my ($this,$nodeName,%props) = @_; |
27 | 28 |
28 if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) { | 29 |
29 my $class = delete $props{type} || $nodeSchema->type || $nodeName; | |
30 | |
31 my $node = $this->{$Document}->Create(delete $props{nodeName} || $nodeName, $class, \%props); | |
32 | |
33 $this->Current()->appendNode($node); | |
34 $this->Current($node); | |
35 | |
36 } else { | |
37 die new IMPL::InvalidOperationException("Requested elemnt not found in the schema"); | |
38 } | |
39 } | 30 } |
40 | 31 |
41 sub Back { | 32 sub Back { |
42 my ($this) = @_; | 33 my ($this) = @_; |
43 | 34 |
44 $this->{$_navigatorSchema}->Back; | |
45 return $this->SUPER::Back(); | |
46 } | 35 } |
47 | 36 |
48 1; | 37 1; |
49 | 38 |
50 __END__ | 39 __END__ |