annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 102:cf3b6ef2be22

Schema beta version
author wizard
date Fri, 07 May 2010 08:05:23 +0400
parents 259cd3df6e53
children c289ed9662ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
1 package IMPL::DOM::Navigator::Builder;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
5 use base qw(IMPL::Object);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
7 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
8 require IMPL::DOM::Navigator::SchemaNavigator;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
10 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
11 private _direct property _schemaNavi => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
12 private _direct property _nodesPath => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
13 private _direct property _nodeCurrent => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
14 private _direct property _docClass => prop_all
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
15 public _direct property Document => prop_get | owner_set;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
16 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
17
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
18 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
19 my ($this,$docClass,$schema) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
21 $this->{$_docClass} = $docClass;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
22 $this->{$_schemaNavi} = $schema ? IMPL::DOM::Navigator::SchemaNavigator->new($schema) : undef;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
23 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
25 sub NavigateCreate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
26 my ($this,$nodeName,%props) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
28 if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
29 my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType : 'IMPL::DOM::Node';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
31 my $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
32 if (! $this->{$Document}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
33 $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
34 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
35 die new IMPL::InvalidOperationException('Can\t create a second top level element') unless $this->{$_nodeCurrent};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
36 $node = $this->{$Document}->Create($nodeName,$class,\%props);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
37 push @{$this->{$_nodesPath}}, $this->{$_nodeCurrent};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
38 $this->{$_nodeCurrent}->appendChild($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
39 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
41 $this->{$_nodeCurrent} = $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
42
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
43 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
44 } else {
102
cf3b6ef2be22 Schema beta version
wizard
parents: 64
diff changeset
45 warn $nodeName;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
46 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
47 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
48 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
50 sub Back {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
51 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
52
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
53 $this->{$_schemaNavi}->SchemaBack();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
54 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
55 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
56
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
57 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
58
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
59 __END__
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
60
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
61 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
62
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
63 =head1 NAME
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
65 C< IMPL::DOM::Navigator::Builder > - Навигатор, строящий документ по указанной схеме.
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
66
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
67 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
68
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
69 =begin code
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
70
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
71 my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
72 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
73
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
74 $reader->ParseFile("document.xml");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
76 my @errors = $schema->Validate($builder->Document);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
77
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
78 =end code
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
79
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
80 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
81
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
82 Построитель DOM документов по указанной схеме. Обычно используется в связке
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
83 с объектами для чтения такими как C<IMPL::DOM::XMLReader>.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
84
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
85 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
86
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
87 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
88
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
89 =item C< CTOR($classDocument,$schema) >
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
90
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
91 Создает новый объект, принимает на вход класс документа (или фабрику, например
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
92 L<IMPL::Object::Factory>) и схему. В процессе процедуры построения документа
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
93 будет создан объект документа.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
94
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
95 =item C< NavigateCreate($nodeName,\%props) >
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
96
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
97 Создает новый узел с указанным именем и переходит в него. В случае если в схеме
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
98 подходящий узел не найден, то вызывается исключение.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
99
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
100 При этом по имени узла ищется его схема, после чего определяется класс для
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
101 создания экземпляра и созданный узел доавляется в документ. При создании
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
102 нового узла используется метод документа C<< IMPL::DOM::Document->Create >>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
103
64
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
104 Свойства узла передаются при создании через параметр C<props>, но имя создаваемого
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
105 узла НЕ может быть переопределено свойством C<nodeName>, оно будет проигнорировано.
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
106
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
107 =item C< Document >
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
108
259cd3df6e53 Doc generation
wizard
parents: 49
diff changeset
109 Свойство, которое содержит документ по окончании процедурв построения.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
110
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
111 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
112
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
113 =cut