11
|
1 package IMPL::DOM::Navigator::Builder;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::DOM::Navigator);
|
|
6 use IMPL::Class::Property;
|
|
7 use IMPL::Class::Property::Direct;
|
|
8
|
|
9 BEGIN {
|
|
10 protected _direct property _navigatorSchema => prop_all;
|
|
11 public _direct property Document => prop_get | owner_set;
|
|
12 }
|
|
13
|
|
14 __PACKAGE__->PassThroughArgs;
|
|
15
|
|
16 sub CTOR {
|
|
17 my ($this,$domDocument,$schema) = @_;
|
|
18
|
|
19 $this->{$Document} = $domDocument;
|
|
20 $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema);
|
|
21 }
|
|
22
|
|
23 sub NavigateCreate {
|
|
24 my ($this,$nodeName,%props) = @_;
|
|
25
|
14
|
26 if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) {
|
|
27 my $class = $nodeSchema->type;
|
11
|
28
|
14
|
29 my $node = $this->{$Document}->Create($nodeName, $class, \%props);
|
|
30
|
|
31 $this->Current()->appendNode($node);
|
|
32 $this->Current($node);
|
11
|
33
|
|
34 } else {
|
|
35 die new IMPL::InvalidOperationException("Requested elemnt not found in the schema");
|
|
36 }
|
|
37 }
|
|
38
|
|
39 1;
|