49
|
1 package IMPL::DOM::Navigator::Builder;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Object);
|
|
6 use IMPL::Class::Property;
|
|
7 use IMPL::Class::Property::Direct;
|
|
8 require IMPL::DOM::Navigator::SchemaNavigator;
|
|
9
|
|
10 BEGIN {
|
|
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
|
|
15 public _direct property Document => prop_get | owner_set;
|
|
16 }
|
|
17
|
|
18 sub CTOR {
|
|
19 my ($this,$docClass,$schema) = @_;
|
|
20
|
|
21 $this->{$_docClass} = $docClass;
|
|
22 $this->{$_schemaNavi} = $schema ? IMPL::DOM::Navigator::SchemaNavigator->new($schema) : undef;
|
|
23 }
|
|
24
|
|
25 sub NavigateCreate {
|
|
26 my ($this,$nodeName,%props) = @_;
|
|
27
|
|
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') unless $this->{$_nodeCurrent};
|
|
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 }
|
|
47 }
|
|
48
|
|
49 sub Back {
|
|
50 my ($this) = @_;
|
|
51
|
|
52 $this->{$_schemaNavi}->SchemaBack();
|
|
53 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}};
|
|
54 }
|
|
55
|
|
56 1;
|
|
57
|
|
58 __END__
|
64
|
59
|
49
|
60 =pod
|
|
61
|
64
|
62 =head1 NAME
|
|
63
|
|
64 C< IMPL::DOM::Navigator::Builder > - ���������, �������� �������� �� ��������� �����.
|
|
65
|
49
|
66 =head1 SYNOPSIS
|
|
67
|
64
|
68 =begin code
|
|
69
|
49
|
70 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
|
|
71 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
|
|
72
|
|
73 $reader->ParseFile("document.xml");
|
|
74
|
|
75 my @errors = $schema->Validate($builder->Document);
|
|
76
|
64
|
77 =end code
|
|
78
|
49
|
79 =head1 DESCRIPTION
|
|
80
|
|
81 ����������� DOM ���������� �� ��������� �����. ������ ������������ � ������
|
|
82 � ��������� ��� ������ ������ ��� C<IMPL::DOM::XMLReader>.
|
|
83
|
|
84 =head1 METHODS
|
|
85
|
|
86 =over
|
|
87
|
64
|
88 =item C< CTOR($classDocument,$schema) >
|
49
|
89
|
64
|
90 ������� ����� ������, ��������� �� ���� ����� ��������� (��� �������, ��������
|
|
91 L<IMPL::Object::Factory>) � �����. � �������� ��������� ���������� ���������
|
|
92 ����� ������ ������ ���������.
|
49
|
93
|
64
|
94 =item C< NavigateCreate($nodeName,\%props) >
|
49
|
95
|
|
96 ������� ����� ���� � ��������� ������ � ��������� � ����. � ������ ���� � �����
|
|
97 ���������� ���� �� ������, �� ���������� ����������.
|
|
98
|
|
99 ��� ���� �� ����� ���� ������ ��� �����, ����� ���� ������������ ����� ���
|
64
|
100 �������� ���������� � ��������� ���� ���������� � ��������. ��� ��������
|
|
101 ������ ���� ������������ ����� ��������� C<< IMPL::DOM::Document->Create >>
|
49
|
102
|
64
|
103 �������� ���� ���������� ��� �������� ����� �������� C<props>, �� ��� ������������
|
|
104 ���� �� ����� ���� �������������� ��������� C<nodeName>, ��� ����� ���������������.
|
|
105
|
|
106 =item C< Document >
|
|
107
|
|
108 ��������, ������� �������� �������� �� ��������� ��������� ����������.
|
49
|
109
|
|
110 =back
|
|
111
|
|
112 =cut
|