annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 16:75d55f4ee263

Окончательная концепция описания схем и построения DOM документов
author Sergey
date Tue, 08 Sep 2009 17:29:07 +0400
parents 16795016e70b
children 7f00786f8210
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
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
14 our %CTOR = (
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
15 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument)
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
16 );
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
17
75980091813b DOM и навигация
Sergey
parents:
diff changeset
18 sub CTOR {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
19 my ($this,$domDocument,$schema) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
20
75980091813b DOM и навигация
Sergey
parents:
diff changeset
21 $this->{$Document} = $domDocument;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
22 $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
23 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
24
75980091813b DOM и навигация
Sergey
parents:
diff changeset
25 sub NavigateCreate {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
26 my ($this,$nodeName,%props) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
27
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
28 if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) {
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
29 my $class = delete $props{type} || $nodeSchema->type || $nodeName;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
30
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
31 my $node = $this->{$Document}->Create(delete $props{nodeName} || $nodeName, $class, \%props);
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
32
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
33 $this->Current()->appendNode($node);
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
34 $this->Current($node);
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
35
75980091813b DOM и навигация
Sergey
parents:
diff changeset
36 } else {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
37 die new IMPL::InvalidOperationException("Requested elemnt not found in the schema");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
38 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
39 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
40
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
41 sub Back {
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
42 my ($this) = @_;
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
43
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
44 $this->{$_navigatorSchema}->Back;
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
45 return $this->SUPER::Back();
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
46 }
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
47
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
48 1;
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
49
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
50 __END__
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
51 =pod
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
52
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
53 =head1 SYNOPSIS
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
54
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
55 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
56 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
57
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
58 $reader->ParseFile("document.xml");
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
59
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
60 my @errors = $schema->Validate($builder->Document);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
61
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
62 =head1 DESCRIPTION
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
63
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
64 DOM .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
65 C<IMPL::DOM::XMLReader>.
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
66
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
67 =head1 METHODS
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
68
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
69 =over
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
70
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
71 =item C<CTOR($domDocument,$schema)>
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
72
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
73 , ( )
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
74 .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
75
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
76 =item C<< $obj->NavigateCreate($nodeName) >>
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
77
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
78 .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
79 , .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
80
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
81 ,
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
82 ,
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
83
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
84 =over
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
85
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
86 =item C<type> ,
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
87
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
88 =item C<type> , ,
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
89 .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
90
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
91 =item
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
92
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
93 =back
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
94
16
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 15
diff changeset
95 C<nodeName>.
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
96
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
97 .. C<< <ComplexNode nodeName="Box" type="Container"> >>
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
98 C<< Container->new(nodeName => 'Box') >>.
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
99
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
100 =back
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
101
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
102 =cut