annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 14:65a7bb156fb7

Дом модель и схема
author Sergey
date Fri, 04 Sep 2009 16:38:15 +0400
parents bb8d67f811ea
children 16795016e70b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
1 package IMPL::DOM::Navigator::Builder;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
2 use strict;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
3 use warnings;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
4
75980091813b DOM и навигация
Sergey
parents:
diff changeset
5 use base qw(IMPL::DOM::Navigator);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
6 use IMPL::Class::Property;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
7 use IMPL::Class::Property::Direct;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
8
75980091813b DOM и навигация
Sergey
parents:
diff changeset
9 BEGIN {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
10 protected _direct property _navigatorSchema => prop_all;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
11 public _direct property Document => prop_get | owner_set;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
12 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
13
75980091813b DOM и навигация
Sergey
parents:
diff changeset
14 __PACKAGE__->PassThroughArgs;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
15
75980091813b DOM и навигация
Sergey
parents:
diff changeset
16 sub CTOR {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
17 my ($this,$domDocument,$schema) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
18
75980091813b DOM и навигация
Sergey
parents:
diff changeset
19 $this->{$Document} = $domDocument;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
20 $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
21 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
22
75980091813b DOM и навигация
Sergey
parents:
diff changeset
23 sub NavigateCreate {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
24 my ($this,$nodeName,%props) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
25
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
26 if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) {
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
27 my $class = $nodeSchema->type;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
28
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
29 my $node = $this->{$Document}->Create($nodeName, $class, \%props);
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
30
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
31 $this->Current()->appendNode($node);
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
32 $this->Current($node);
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
33
75980091813b DOM и навигация
Sergey
parents:
diff changeset
34 } else {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
35 die new IMPL::InvalidOperationException("Requested elemnt not found in the schema");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
36 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
37 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
38
75980091813b DOM и навигация
Sergey
parents:
diff changeset
39 1;