annotate Lib/IMPL/DOM/Transform/ObjectToDOM.pm @ 283:2f06250bab5f

*IMPL::SQL::MySQL fixed issues with foreign keys and drop table
author sergey
date Tue, 12 Feb 2013 18:43:32 +0400
parents c9c2ec29793f
children 50ff1595bd62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
1 package IMPL::DOM::Transform::ObjectToDOM;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
2 use strict;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
3
2904da230022 DOM refactoring
sergey
parents:
diff changeset
4 use IMPL::Const qw(:prop :access);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
5 use IMPL::declare {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
6 require => {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
7 PropertyInfo => 'IMPL::Class::PropertyInfo',
2904da230022 DOM refactoring
sergey
parents:
diff changeset
8 Builder => 'IMPL::DOM::Navigator::Builder',
2904da230022 DOM refactoring
sergey
parents:
diff changeset
9 Exception => 'IMPL::Exception',
2904da230022 DOM refactoring
sergey
parents:
diff changeset
10 ArgumentException => '-IMPL::InvalidArgumentException',
2904da230022 DOM refactoring
sergey
parents:
diff changeset
11 OperationException => '-IMPL::InvalidOperationException'
2904da230022 DOM refactoring
sergey
parents:
diff changeset
12 },
2904da230022 DOM refactoring
sergey
parents:
diff changeset
13 base => [
2904da230022 DOM refactoring
sergey
parents:
diff changeset
14 'IMPL::Transform' => sub {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
15 -plain => 'TransformPlain',
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
16 HASH => 'TransformHash',
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
17 -default => 'TransformDefault'
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
18 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
19 ],
2904da230022 DOM refactoring
sergey
parents:
diff changeset
20 props => [
2904da230022 DOM refactoring
sergey
parents:
diff changeset
21 documentSchema => PROP_RO,
2904da230022 DOM refactoring
sergey
parents:
diff changeset
22 _schema => PROP_RW,
2904da230022 DOM refactoring
sergey
parents:
diff changeset
23 _navi => PROP_RW
2904da230022 DOM refactoring
sergey
parents:
diff changeset
24 ]
2904da230022 DOM refactoring
sergey
parents:
diff changeset
25 };
2904da230022 DOM refactoring
sergey
parents:
diff changeset
26
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 237
diff changeset
27 use constant {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
28 SchemaNode => 'IMPL::DOM::Schema::Node',
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
29 ComplexNode => 'IMPL::DOM::Schema::ComplexNode'
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 237
diff changeset
30 };
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 237
diff changeset
31
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
32 sub CTOR {
237
61db68166c37 refactoring QueryToDOM
sergey
parents: 236
diff changeset
33 my ($this,$docName,$docSchema,$transforms) = @_;
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
34
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 237
diff changeset
35 my $docNodeSchema = $docSchema->selectSingleNode(sub { $_->isa(SchemaNode) and $_->name eq $docName } )
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
36 or die OperationException->new("Can't find a node schema for the document '$docName'");
2904da230022 DOM refactoring
sergey
parents:
diff changeset
37
2904da230022 DOM refactoring
sergey
parents:
diff changeset
38 my $docClass = ($docNodeSchema->can('nativeType') ? $docNodeSchema->nativeType : undef) || 'IMPL::DOM::Document';
2904da230022 DOM refactoring
sergey
parents:
diff changeset
39
2904da230022 DOM refactoring
sergey
parents:
diff changeset
40 $this->documentSchema($docNodeSchema);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
41
2904da230022 DOM refactoring
sergey
parents:
diff changeset
42 $this->_navi(
2904da230022 DOM refactoring
sergey
parents:
diff changeset
43 Builder->new(
2904da230022 DOM refactoring
sergey
parents:
diff changeset
44 $docClass,
2904da230022 DOM refactoring
sergey
parents:
diff changeset
45 $docSchema,
2904da230022 DOM refactoring
sergey
parents:
diff changeset
46 ignoreUndefined => 1
2904da230022 DOM refactoring
sergey
parents:
diff changeset
47 )
2904da230022 DOM refactoring
sergey
parents:
diff changeset
48 );
2904da230022 DOM refactoring
sergey
parents:
diff changeset
49 $this->_schema($docSchema);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
50
2904da230022 DOM refactoring
sergey
parents:
diff changeset
51 $this->_navi->NavigateCreate($docName);
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
52 $this->currentNode->nodeProperty(schemaDocument => $docSchema);
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
53 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
54
2904da230022 DOM refactoring
sergey
parents:
diff changeset
55 sub TransformPlain {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
56 my ($this,$data) = @_;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
57
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
58 $this->_navi->Current->nodeValue( $data );
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
59 return $this->_navi->Current;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
60 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
61
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
62 sub currentNode {
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
63 shift->_navi->Current;
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
64 }
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
65
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
66 sub inflateNodeValue {
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
67 shift->_navi->inflateValue(shift);
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
68 }
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
69
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
70 sub TransformHash {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
71 my ($this,$data) = @_;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
72
2904da230022 DOM refactoring
sergey
parents:
diff changeset
73 die ArgumentException->new(data => 'A HASH reference is required')
2904da230022 DOM refactoring
sergey
parents:
diff changeset
74 unless ref $data eq 'HASH';
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
75
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
76 return $this->StoreObject($this->currentNode,$data)
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
77 if !$this->currentNode->schema->isa(ComplexNode);
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
78
2904da230022 DOM refactoring
sergey
parents:
diff changeset
79 KEYLOOP: foreach my $key (keys %$data) {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
80 my $value = $data->{$key};
2904da230022 DOM refactoring
sergey
parents:
diff changeset
81
2904da230022 DOM refactoring
sergey
parents:
diff changeset
82 if (ref $value eq 'ARRAY') {
257
299af584c05f collapse empty array elements in POSTed data
sergey
parents: 250
diff changeset
83 #TODO: collapse empty values only if needed
299af584c05f collapse empty array elements in POSTed data
sergey
parents: 250
diff changeset
84 foreach my $subval (grep $_, @$value) {
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
85
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
86 $this->_navi->saveState();
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
87
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
88 my $node = $this->_navi->NavigateCreate($key);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
89
2904da230022 DOM refactoring
sergey
parents:
diff changeset
90 unless(defined $node) {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
91 #$this->_navi->Back();
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
92 $this->_navi->restoreState();
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
93 next KEYLOOP;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
94 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
95
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
96 $this->_navi->applyState();
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
97
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
98 $this->Transform($subval);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
99
2904da230022 DOM refactoring
sergey
parents:
diff changeset
100 $this->_navi->Back();
2904da230022 DOM refactoring
sergey
parents:
diff changeset
101 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
102 } else {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
103 $this->_navi->saveState();
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
104 my $node = $this->_navi->NavigateCreate($key);
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
105
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
106 unless(defined $node) {
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
107 #$this->_navi->Back();
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
108 $this->_navi->restoreState();
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
109 next KEYLOOP;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
110 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
111
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
112 $this->_navi->applyState();
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
113
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
114 $this->Transform($value);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
115
2904da230022 DOM refactoring
sergey
parents:
diff changeset
116 $this->_navi->Back();
2904da230022 DOM refactoring
sergey
parents:
diff changeset
117 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
118 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
119 return $this->_navi->Current;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
120 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
121
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
122 # this method handles situatuions when a complex object must be stored in a
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
123 # simple node.
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
124 sub StoreObject {
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
125 my ($this,$node,$data) = @_;
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
126
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
127 $node->nodeValue($data);
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
128
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
129 return $node;
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
130 }
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
131
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
132 sub TransformDefault {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
133 my ($this,$data) = @_;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
134
250
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
135 return $this->StoreObject($this->currentNode,$data)
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
136 if !$this->currentNode->schema->isa(ComplexNode);
129e48bb5afb DOM refactoring
sergey
parents: 246
diff changeset
137
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
138 if ( ref $data and eval { $data->can('GetMeta') } ) {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
139 my %props = map {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
140 $_->name, 1
2904da230022 DOM refactoring
sergey
parents:
diff changeset
141 } $data->GetMeta(PropertyInfo, sub { $_->access == ACCESS_PUBLIC }, 1 );
2904da230022 DOM refactoring
sergey
parents:
diff changeset
142
2904da230022 DOM refactoring
sergey
parents:
diff changeset
143 my %values = map {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
144 $_,
2904da230022 DOM refactoring
sergey
parents:
diff changeset
145 $data->$_();
2904da230022 DOM refactoring
sergey
parents:
diff changeset
146 } keys %props;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
147
2904da230022 DOM refactoring
sergey
parents:
diff changeset
148 return $this->Transform(\%values);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
149 } else {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
150 die OperationException->new("Don't know how to transform $data");
2904da230022 DOM refactoring
sergey
parents:
diff changeset
151 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
152
2904da230022 DOM refactoring
sergey
parents:
diff changeset
153 return $this->_navi->Current;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
154 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
155
2904da230022 DOM refactoring
sergey
parents:
diff changeset
156 sub buildErrors {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
157 my ($this) = @_;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
158
2904da230022 DOM refactoring
sergey
parents:
diff changeset
159 return $this->_navi->buildErrors;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
160 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
161
2904da230022 DOM refactoring
sergey
parents:
diff changeset
162 1;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
163
2904da230022 DOM refactoring
sergey
parents:
diff changeset
164 __END__
2904da230022 DOM refactoring
sergey
parents:
diff changeset
165
2904da230022 DOM refactoring
sergey
parents:
diff changeset
166 =pod
2904da230022 DOM refactoring
sergey
parents:
diff changeset
167
2904da230022 DOM refactoring
sergey
parents:
diff changeset
168 =head1 NAME
2904da230022 DOM refactoring
sergey
parents:
diff changeset
169
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
170 C<IMPL::DOM::Transform::ObjectToDOM> -преобразование объекта в DOM документ.
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
171
2904da230022 DOM refactoring
sergey
parents:
diff changeset
172 =head1 SYNOPSIS
2904da230022 DOM refactoring
sergey
parents:
diff changeset
173
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
174 =begin code
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
175
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
176 use IMPL::require {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
177 Schema => 'IMPL::DOM::Schema',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
178 Config => 'IMPL::Config'
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
179 }
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
180
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
181 my $data = {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
182 id => '12313-232',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
183 name => 'Peter',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
184 age => 20
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
185 };
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
186
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
187 my $schema = Schema->LoadSchema(Config->AppBase('schemas','person.xml'));
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
188 my $transorm = IMPL::DOM::Transform::ObjectToDOM->new('edit', $schema);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
189
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
190 my $form = $transform->Transform($data);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
191
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
192 my @errors;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
193
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
194 push @errors, $transform->buildErrors;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
195 push @errors, $schema->Validate($doc);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
196
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
197 =end code
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
198
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
199 =head1 DESCRIPTION
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
200
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
201 Наследует C<IMPL::Transform>. Определяет базовые преобразования для хешей и
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
202 объектов, поддерживающих метаданные.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
203
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
204 Результатом выполнения преобразования является DOM документ. При построении
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
205 документа используется навигатор C<IMPL::DOM::Navigator::Builder> для
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
206 сопоставления схемы и свойств преобразуемого объекта. Элементы полученного
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
207 документа имеют ссылки на соответствующие им элементы схемы.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
208
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
209 После того, как документ построен и преобразование будет очищено, не останется
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
210 объектов, которые бы ссылались на документ со схемой, поскольку элементы схемы
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
211 имеют слабые ссылки на саму схему и не могут предотвратить ее удаление.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
212 Для предотвращения очитски документа схемы, ссылка на него сохраняется в
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
213 атрибуте документа C<schemaDocument>, что обеспечит жизнь схемы на протяжении
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
214 жизни документа.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
215
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
216 Преобразование происходит рекурсивно, сначала используется метод
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
217 C<NavigateCreate> для создания элемента соответсвующего свойству объекта,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
218 затем вызывается метод C<Transform> для преобразования значения свойства, при
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
219 этом C<currentNode> указывает на только что созданный элемент документа.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
220
264
c9c2ec29793f *IMPL::DOM::Transform: updated documentation
sergey
parents: 263
diff changeset
221 Для изменения поведения преобразования можно добавлять новые обработчики, как
c9c2ec29793f *IMPL::DOM::Transform: updated documentation
sergey
parents: 263
diff changeset
222 в случае со стандартным преобразованием, а также можно унаследовать текущий
c9c2ec29793f *IMPL::DOM::Transform: updated documentation
sergey
parents: 263
diff changeset
223 класс для переопределения его некоторых методов.
c9c2ec29793f *IMPL::DOM::Transform: updated documentation
sergey
parents: 263
diff changeset
224
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
225 =head1 MEMBERS
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
226
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
227 =head2 C<CTOR($docName,$schema)>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
228
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
229 Создает преобразование, при этом будет создан документ состоящий только из
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
230 корневого элемента с именем C<$docName> и будет найдена подходящий для него
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
231 элемент схемы C<$schema>.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
232
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
233 =over
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
234
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
235 =item * C<$docName>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
236
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
237 Имя корневого узла документа, которое будет использовано для поиска
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
238 соответствующего элемента схемы C<$schema>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
239
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
240 =item * C<$schema>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
241
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
242 Схема, содержащая описание документа. Если в данной схеме нет описания корневого
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
243 элемента с именем C<$docName>, будет вызвано исключение.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
244
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
245 =back
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
246
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
247 =head2 C<[get]documentSchema>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
248
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
249 Элемент схемы C<ComplexNode> соответствующий документу. Определяется в
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
250 конструкторе исходя из имени документа.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
251
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
252 =head2 C<[get]currentNode>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
253
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
254 Текущий элемент документа. После создания преобразования - это сам документ.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
255 Данное свойство использется внутри преобразования для работы с текущим
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
256 элементом.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
257
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
258 =head2 C<[virtual]StoreObject($node,$data)>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
259
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
260 Метод, который вызывается преобразованием в случае если текущий узел документа
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
261 является простым, а значени которое ему соответсвует является объектом (ссылкой).
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
262
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
263 По-умолчанию будет выполнено присваивание C<< $node->nodeValue($data) >>, однако
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
264 это можно заменить, например, на преобразование в строку.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
265
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
266 =head2 C<inflateNodeValue($data)>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
267
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
268 Метод который используется для преобразования значений к правильным типам,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
269 используя атрибут C<inflator> элемента схемы. Этот метод можно использовать для
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
270 C<TransformPlain>, однако по-умолчанию он не используется, поскольку
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
271 предполагается, что входной объект имеет уже преобразованные значения в своих
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
272 свойствах.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
273
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
274 =cut