annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 34:a8086f85a571

Dom Builder
author Sergey
date Mon, 16 Nov 2009 18:39:25 +0300
parents 7f00786f8210
children f25d021780b3
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
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
5 use base qw(IMPL::Object);
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
6 use IMPL::Class::Property;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
7 use IMPL::Class::Property::Direct;
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 16
diff changeset
8 require IMPL::DOM::Navigator::SchemaNavigator;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
9
75980091813b DOM и навигация
Sergey
parents:
diff changeset
10 BEGIN {
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
11 private _direct property _schemaNavi => prop_all;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
12 private _direct property _nodesPath => prop_all;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
13 private _direct property _nodeCurrent => prop_all;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
14 private _direct property _docClass => prop_all
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
15 public _direct property Document => prop_get | owner_set;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
16 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
17
75980091813b DOM и навигация
Sergey
parents:
diff changeset
18 sub CTOR {
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
19 my ($this,$docClass,$schema) = @_;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
20
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
21 $this->{$_docClass} = $docClass;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
22 $this->{$_schemaNavi} = IMPL::DOM::Navigator::SchemaNavigator->new($schema);
11
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
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
28 if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) {
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
29 my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType : 'IMPL::DOM::Node';
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
30
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
31 my $node;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
32 if (! $this->{$Document}) {
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
33 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
34 } else {
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
35 die new IMPL::InvalidOperationException('Can\t create a second top level element');
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
36 $node = $this->{$Document}->Create($nodeName,$class,\%props);
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
37 push @{$this->{$_nodesPath}}, $this->{$_nodeCurrent};
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
38 $this->{$_nodeCurrent}->appendChild($node);
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
39 }
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
40
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
41 $this->{$_nodeCurrent} = $node;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
42
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
43 return $node;
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
44 } else {
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
45 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName);
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
46 }
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
47 }
75980091813b DOM и навигация
Sergey
parents:
diff changeset
48
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
49 sub Back {
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
50 my ($this) = @_;
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
51
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
52 $this->{$_schemaNavi}->SchemaBack();
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
53 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}};
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
54 }
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
55
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
56 1;
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
57
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
58 __END__
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
59 =pod
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
60
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
61 =head1 SYNOPSIS
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
62
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
63 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
64 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
65
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
66 $reader->ParseFile("document.xml");
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
67
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
68 my @errors = $schema->Validate($builder->Document);
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
69
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
70 =head1 DESCRIPTION
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
71
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
72 DOM .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
73 C<IMPL::DOM::XMLReader>.
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
74
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
75 =head1 METHODS
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
76
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
77 =over
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
78
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
79 =item C<CTOR($domDocument,$schema)>
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 =item C<< $obj->NavigateCreate($nodeName) >>
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
85
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
86 .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
87 , .
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
88
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
89 ,
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
90 .
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
91
34
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
92 nodeName,
a8086f85a571 Dom Builder
Sergey
parents: 24
diff changeset
93 .
15
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
94
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
95 =back
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
96
16795016e70b Dom schema in progress
Sergey
parents: 14
diff changeset
97 =cut