annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 394:2c14f66efa08

minor changes
author cin
date Tue, 18 Feb 2014 18:17:20 +0400
parents 4edd36025051
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
1 package IMPL::DOM::Navigator::Builder;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
4
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
5 use IMPL::Const qw(:prop);
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
6
165
76515373dac0 Added Class::Template,
wizard
parents: 148
diff changeset
7 use parent qw(IMPL::DOM::Navigator);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
8 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
9 require IMPL::DOM::Navigator::SchemaNavigator;
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
10 require IMPL::DOM::Schema::ValidationError;
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
11 use IMPL::DOM::Document;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
13 BEGIN {
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
14 private _direct property _schemaNavi => PROP_RW;
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
15 private _direct property _docClass => PROP_RW;
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
16 public _direct property Document => PROP_RO;
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
17 public _direct property ignoreUndefined => PROP_RO;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
18 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
19
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
20 our %CTOR = (
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
21 'IMPL::DOM::Navigator' => sub { IMPL::DOM::Document->Empty; }
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
22 );
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
23
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
24 sub CTOR {
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
25 my ($this,$docClass,$schema,%opts) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
26
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
27 $this->{$_docClass} = $docClass;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
28 $this->{$_schemaNavi} = $schema ? IMPL::DOM::Navigator::SchemaNavigator->new($schema) : undef;
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
29
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
30 $this->{$ignoreUndefined} = $opts{ignoreUndefined} if $opts{ignoreUndefined};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
33 sub NavigateCreate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
34 my ($this,$nodeName,%props) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
35
384
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
36 if (my $schemaType = $this->{$_schemaNavi}->NavigateName($nodeName)) {
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
37 my $class = $schemaType->can('nativeType') ? $schemaType->nativeType || 'IMPL::DOM::Node' : 'IMPL::DOM::Node';
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 113
diff changeset
38
384
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
39 my $schemaNode = $this->{$_schemaNavi}->SourceSchemaNode;
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
40
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
41 $props{schemaType} = $schemaType;
4edd36025051 DOM schema refactoring
cin
parents: 368
diff changeset
42 $props{schemaNode} = $schemaNode;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
43
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
44 my $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
45 if (! $this->{$Document}) {
368
010ceafd0c5a form metadata + tests
cin
parents: 278
diff changeset
46 # keep reference to the schema document
010ceafd0c5a form metadata + tests
cin
parents: 278
diff changeset
47 $props{schemaDocument} = $this->{$_schemaNavi}->schema;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
48 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
49 $this->_initNavigator($node);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
50 } else {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
51 die new IMPL::InvalidOperationException('Can\'t create a second top level element') unless $this->Current;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
52 $node = $this->{$Document}->Create($nodeName,$class,\%props);
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
53 $this->Current->appendChild($node);
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
54 $this->internalNavigateNodeSet($node);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
55 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
56
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
57 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
58 } else {
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
59 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName)
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
60 if !$this->ignoreUndefined;
236
2904da230022 DOM refactoring
sergey
parents: 206
diff changeset
61 return;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
62 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
63 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
64
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
65 sub Back {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
66 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
68 $this->{$_schemaNavi}->SchemaBack();
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 104
diff changeset
69 $this->SUPER::Back();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
70 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
71
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
72 sub saveState {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
75 $this->{$_schemaNavi}->saveState;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
76 $this->SUPER::saveState;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
77 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
78
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
79 sub restoreState {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
80 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
81
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
82 $this->{$_schemaNavi}->restoreState;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
83 $this->SUPER::restoreState;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
84 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
85
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
86 sub document {
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
87 goto &Document;
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
88 }
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
89
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
90 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
91
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
92 __END__
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
93
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
94 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
95
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
96 =head1 NAME
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
97
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
98 C< IMPL::DOM::Navigator::Builder > - Навигатор, строящий документ по указанной схеме.
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
99
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
100 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
101
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
102 =begin code
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
103
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
104 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
105 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
106
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
107 $reader->ParseFile("document.xml");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
108
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
109 my @errors = $schema->Validate($builder->Document);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
110
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
111 =end code
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
112
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
113 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
114
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
115 Построитель DOM документов по указанной схеме. Обычно используется в связке
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
116 с объектами для чтения такими как C<IMPL::DOM::XMLReader>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
117
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
118 =head1 MEMBERS
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
119
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
120 =head2 C< CTOR($classDocument,$schema, %opts) >
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
121
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
122 Создает новый объект, принимает на вход класс документа (или фабрику, например
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
123 L<IMPL::Object::Factory>) и схему. В процессе процедуры построения документа
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
124 будет создан объект документа.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
125
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
126 Необязательные именованные параметры
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
127
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
128 =over
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
129
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
130 =item C<ignoreUndefined>
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
131
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
132 C<NavigateCreate> не будет вызывать исключение, если запрашиваемый узел не
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
133 найден в схеме, но будет возвращать C<undef>.
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
134
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
135 =back
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
136
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
137 =head2 C< NavigateCreate($nodeName,%props) >
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
138
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
139 Создает новый узел с указанным именем и переходит в него. В случае если в схеме
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
140 подходящий узел не найден, то вызывается исключение или будет возвращено
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
141 C<undef> см. C<ignoreUndefined>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
142
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
143 При этом по имени узла ищется его схема, после чего определяется класс для
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
144 создания экземпляра узла и созданный узел доавляется в документ. При создании
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
145 нового узла используется метод документа C<< IMPL::DOM::Document->Create >>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
146
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
147 Свойства узла передаются при создании через параметр C<%props>, но имя
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
148 создаваемого узла НЕ может быть переопределено свойством C<nodeName>, оно будет
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
149 проигнорировано.
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
150
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
151 Свойства узла будут преобразованы при помощи заданных в схеме заполнителей
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
152 C<inflator>.
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
153
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
154 =head2 C<[get]document >
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
155
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
156 Свойство, которое содержит документ по окончании процедуры построения.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
157
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
158 =head2 C<[get]buildErrors>
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
159
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
160 Ошибки, возникшие в процессе построения документа.
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
161
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
162 =head2 C<[get]ignoreUndefined>
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
163
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
164 Опция, заданная при создании построителя, отвечающая за обработку узлов
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
165 не найденных в схеме.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
166
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
167 =cut