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
|
15
|
14 our %CTOR = (
|
|
15 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument)
|
|
16 );
|
11
|
17
|
|
18 sub CTOR {
|
|
19 my ($this,$domDocument,$schema) = @_;
|
|
20
|
|
21 $this->{$Document} = $domDocument;
|
|
22 $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema);
|
|
23 }
|
|
24
|
|
25 sub NavigateCreate {
|
|
26 my ($this,$nodeName,%props) = @_;
|
|
27
|
14
|
28 if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) {
|
15
|
29 my $class = delete $props{type} || $nodeSchema->type || $nodeName;
|
11
|
30
|
15
|
31 my $node = $this->{$Document}->Create(delete $props{nodeName} || $nodeName, $class, \%props);
|
14
|
32
|
|
33 $this->Current()->appendNode($node);
|
|
34 $this->Current($node);
|
11
|
35
|
|
36 } else {
|
|
37 die new IMPL::InvalidOperationException("Requested elemnt not found in the schema");
|
|
38 }
|
|
39 }
|
|
40
|
15
|
41 sub Back {
|
|
42 my ($this) = @_;
|
|
43
|
|
44 $this->{$_navigatorSchema}->Back;
|
|
45 return $this->SUPER::Back();
|
|
46 }
|
|
47
|
11
|
48 1;
|
15
|
49
|
|
50 __END__
|
|
51 =pod
|
|
52
|
|
53 =head1 SYNOPSIS
|
|
54
|
|
55 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
|
|
56 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
|
|
57
|
|
58 $reader->ParseFile("document.xml");
|
|
59
|
|
60 my @errors = $schema->Validate($builder->Document);
|
|
61
|
|
62 =head1 DESCRIPTION
|
|
63
|
|
64 DOM .
|
|
65 C<IMPL::DOM::XMLReader>.
|
|
66
|
|
67 =head1 METHODS
|
|
68
|
|
69 =over
|
|
70
|
|
71 =item C<CTOR($domDocument,$schema)>
|
|
72
|
|
73 , ( )
|
|
74 .
|
|
75
|
|
76 =item C<< $obj->NavigateCreate($nodeName) >>
|
|
77
|
|
78 .
|
|
79 , .
|
|
80
|
|
81 ,
|
|
82 ,
|
|
83
|
|
84 =over
|
|
85
|
|
86 =item C<type> ,
|
|
87
|
|
88 =item C<type> , ,
|
|
89 .
|
|
90
|
|
91 =item
|
|
92
|
|
93 =back
|
|
94
|
|
95 C<nodeName>.
|
|
96
|
|
97 .. C<< <ComplexNode nodeName="Box" type="Container"> >>
|
|
98 C<< Container->new(nodeName => 'Box') >>.
|
|
99
|
|
100 =back
|
|
101
|
|
102 =cut |