annotate Lib/IMPL/DOM/Transform/ObjectToDOM.pm @ 337:f4e14f32cf54

fixed bugs with string and local $_ added support for localized labels
author cin
date Fri, 14 Jun 2013 15:37:34 +0400
parents 50ff1595bd62
children f116cd9fe7d9
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
329
50ff1595bd62 fixed bug when transforming list properties
sergey
parents: 264
diff changeset
143
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
144 my %values = map {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
145 $_,
329
50ff1595bd62 fixed bug when transforming list properties
sergey
parents: 264
diff changeset
146 scalar($data->$_())
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
147 } keys %props;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
148
2904da230022 DOM refactoring
sergey
parents:
diff changeset
149 return $this->Transform(\%values);
2904da230022 DOM refactoring
sergey
parents:
diff changeset
150 } else {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
151 die OperationException->new("Don't know how to transform $data");
2904da230022 DOM refactoring
sergey
parents:
diff changeset
152 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
153
2904da230022 DOM refactoring
sergey
parents:
diff changeset
154 return $this->_navi->Current;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
155 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
156
2904da230022 DOM refactoring
sergey
parents:
diff changeset
157 sub buildErrors {
2904da230022 DOM refactoring
sergey
parents:
diff changeset
158 my ($this) = @_;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
159
2904da230022 DOM refactoring
sergey
parents:
diff changeset
160 return $this->_navi->buildErrors;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
161 }
2904da230022 DOM refactoring
sergey
parents:
diff changeset
162
2904da230022 DOM refactoring
sergey
parents:
diff changeset
163 1;
2904da230022 DOM refactoring
sergey
parents:
diff changeset
164
2904da230022 DOM refactoring
sergey
parents:
diff changeset
165 __END__
2904da230022 DOM refactoring
sergey
parents:
diff changeset
166
2904da230022 DOM refactoring
sergey
parents:
diff changeset
167 =pod
2904da230022 DOM refactoring
sergey
parents:
diff changeset
168
2904da230022 DOM refactoring
sergey
parents:
diff changeset
169 =head1 NAME
2904da230022 DOM refactoring
sergey
parents:
diff changeset
170
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
171 C<IMPL::DOM::Transform::ObjectToDOM> -преобразование объекта в DOM документ.
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
172
2904da230022 DOM refactoring
sergey
parents:
diff changeset
173 =head1 SYNOPSIS
2904da230022 DOM refactoring
sergey
parents:
diff changeset
174
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
175 =begin code
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
176
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
177 use IMPL::require {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
178 Schema => 'IMPL::DOM::Schema',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
179 Config => 'IMPL::Config'
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
182 my $data = {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
183 id => '12313-232',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
184 name => 'Peter',
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
185 age => 20
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
188 my $schema = Schema->LoadSchema(Config->AppBase('schemas','person.xml'));
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
189 my $transorm = IMPL::DOM::Transform::ObjectToDOM->new('edit', $schema);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
190
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
191 my $form = $transform->Transform($data);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
192
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
193 my @errors;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
194
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
195 push @errors, $transform->buildErrors;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
196 push @errors, $schema->Validate($doc);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
197
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
198 =end code
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
199
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
200 =head1 DESCRIPTION
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
201
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
202 Наследует C<IMPL::Transform>. Определяет базовые преобразования для хешей и
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
205 Результатом выполнения преобразования является DOM документ. При построении
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
206 документа используется навигатор C<IMPL::DOM::Navigator::Builder> для
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 Для предотвращения очитски документа схемы, ссылка на него сохраняется в
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
214 атрибуте документа C<schemaDocument>, что обеспечит жизнь схемы на протяжении
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 Преобразование происходит рекурсивно, сначала используется метод
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
218 C<NavigateCreate> для создания элемента соответсвующего свойству объекта,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
219 затем вызывается метод C<Transform> для преобразования значения свойства, при
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
220 этом C<currentNode> указывает на только что созданный элемент документа.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
221
264
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 класс для переопределения его некоторых методов.
c9c2ec29793f *IMPL::DOM::Transform: updated documentation
sergey
parents: 263
diff changeset
225
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
226 =head1 MEMBERS
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
227
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
228 =head2 C<CTOR($docName,$schema)>
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 Создает преобразование, при этом будет создан документ состоящий только из
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
231 корневого элемента с именем C<$docName> и будет найдена подходящий для него
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
232 элемент схемы C<$schema>.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
233
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
234 =over
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
235
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
236 =item * C<$docName>
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 Имя корневого узла документа, которое будет использовано для поиска
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
239 соответствующего элемента схемы C<$schema>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
240
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
241 =item * C<$schema>
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 Схема, содержащая описание документа. Если в данной схеме нет описания корневого
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
244 элемента с именем C<$docName>, будет вызвано исключение.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
245
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
246 =back
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
247
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
248 =head2 C<[get]documentSchema>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
249
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
250 Элемент схемы C<ComplexNode> соответствующий документу. Определяется в
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
253 =head2 C<[get]currentNode>
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
259 =head2 C<[virtual]StoreObject($node,$data)>
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
264 По-умолчанию будет выполнено присваивание C<< $node->nodeValue($data) >>, однако
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
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
267 =head2 C<inflateNodeValue($data)>
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 Метод который используется для преобразования значений к правильным типам,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
270 используя атрибут C<inflator> элемента схемы. Этот метод можно использовать для
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
271 C<TransformPlain>, однако по-умолчанию он не используется, поскольку
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 свойствах.
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 257
diff changeset
274
236
2904da230022 DOM refactoring
sergey
parents:
diff changeset
275 =cut