11
|
1 package IMPL::DOM::Navigator::Builder;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
34
|
5 use base qw(IMPL::Object);
|
11
|
6 use IMPL::Class::Property;
|
|
7 use IMPL::Class::Property::Direct;
|
24
|
8 require IMPL::DOM::Navigator::SchemaNavigator;
|
11
|
9
|
|
10 BEGIN {
|
34
|
11 private _direct property _schemaNavi => prop_all;
|
|
12 private _direct property _nodesPath => prop_all;
|
|
13 private _direct property _nodeCurrent => prop_all;
|
|
14 private _direct property _docClass => prop_all
|
11
|
15 public _direct property Document => prop_get | owner_set;
|
|
16 }
|
|
17
|
|
18 sub CTOR {
|
34
|
19 my ($this,$docClass,$schema) = @_;
|
11
|
20
|
34
|
21 $this->{$_docClass} = $docClass;
|
|
22 $this->{$_schemaNavi} = IMPL::DOM::Navigator::SchemaNavigator->new($schema);
|
11
|
23 }
|
|
24
|
|
25 sub NavigateCreate {
|
|
26 my ($this,$nodeName,%props) = @_;
|
|
27
|
34
|
28 if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) {
|
|
29 my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType : 'IMPL::DOM::Node';
|
|
30
|
|
31 my $node;
|
|
32 if (! $this->{$Document}) {
|
|
33 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
|
|
34 } else {
|
|
35 die new IMPL::InvalidOperationException('Can\t create a second top level element');
|
|
36 $node = $this->{$Document}->Create($nodeName,$class,\%props);
|
|
37 push @{$this->{$_nodesPath}}, $this->{$_nodeCurrent};
|
|
38 $this->{$_nodeCurrent}->appendChild($node);
|
|
39 }
|
|
40
|
|
41 $this->{$_nodeCurrent} = $node;
|
|
42
|
|
43 return $node;
|
|
44 } else {
|
|
45 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName);
|
|
46 }
|
11
|
47 }
|
|
48
|
15
|
49 sub Back {
|
|
50 my ($this) = @_;
|
|
51
|
34
|
52 $this->{$_schemaNavi}->SchemaBack();
|
|
53 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}};
|
15
|
54 }
|
|
55
|
11
|
56 1;
|
15
|
57
|
|
58 __END__
|
|
59 =pod
|
|
60
|
|
61 =head1 SYNOPSIS
|
|
62
|
|
63 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
|
|
64 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
|
|
65
|
|
66 $reader->ParseFile("document.xml");
|
|
67
|
|
68 my @errors = $schema->Validate($builder->Document);
|
|
69
|
|
70 =head1 DESCRIPTION
|
|
71
|
|
72 DOM .
|
|
73 C<IMPL::DOM::XMLReader>.
|
|
74
|
|
75 =head1 METHODS
|
|
76
|
|
77 =over
|
|
78
|
|
79 =item C<CTOR($domDocument,$schema)>
|
|
80
|
|
81 , ( )
|
|
82 .
|
|
83
|
|
84 =item C<< $obj->NavigateCreate($nodeName) >>
|
|
85
|
|
86 .
|
|
87 , .
|
|
88
|
34
|
89 ,
|
|
90 .
|
15
|
91
|
34
|
92 nodeName,
|
|
93 .
|
15
|
94
|
|
95 =back
|
|
96
|
|
97 =cut |