annotate Lib/IMPL/DOM/Navigator/Builder.pm @ 58:a35b60b16a99

Configuration, late activation
author wizard
date Fri, 05 Mar 2010 20:14:45 +0300
parents 16ada169ca75
children 259cd3df6e53
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 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
45 die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
46 }
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 sub Back {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
50 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
51
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
52 $this->{$_schemaNavi}->SchemaBack();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
53 $this->{$_nodeCurrent} = pop @{$this->{$_nodesPath}};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
54 }
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 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
58 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
59 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
60
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
61 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
62
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
63 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
64 my $reader = new IMPL::DOM::XMLReader(Navigator => $builder);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
65
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
66 $reader->ParseFile("document.xml");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
68 my @errors = $schema->Validate($builder->Document);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
69
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
70 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
71
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
72 Построитель DOM документов по указанной схеме. Обычно используется в связке
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
73 с объектами для чтения такими как C<IMPL::DOM::XMLReader>.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
74
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
75 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
76
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
77 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
78
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
79 =item C<CTOR($domDocument,$schema)>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
80
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 схему.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
84 =item C<< $obj->NavigateCreate($nodeName) >>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
85
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 подходящий узел не найден, то вызывается исключение.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
88
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
89 При этом по имени узла ищется его схема, после чего определяется класс для
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
90 создания экземпляра и созданный узел доавляется в документ.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
91
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
92 Также имя создаваемого узла НЕ может быть переопределено свойством nodeName, оно
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
93 будет проигнорировано.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
94
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 35
diff changeset
95 =back
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 =cut