annotate Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 394:2c14f66efa08

minor changes
author cin
date Tue, 18 Feb 2014 18:17:20 +0400
parents 010ceafd0c5a
children
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: 36
diff changeset
1 package IMPL::DOM::Navigator::SchemaNavigator;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
5 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
6
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
7 require IMPL::DOM::Schema::ComplexType;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
8 require IMPL::DOM::Schema::NodeSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
9 require IMPL::DOM::Schema::AnyNode;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
10
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
11 use IMPL::declare {
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
12 base => [
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
13 'IMPL::DOM::Navigator' => '@_'
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
14 ]
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
15 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
17 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
18 public _direct property Schema => prop_get;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
19 private _direct property _historySteps => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
20 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
21
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
22 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
23 my ($this,$schema) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
24
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
25 $this->{$Schema} = $schema->isa('IMPL::DOM::Schema::ComplexNode') ? $schema->document : $schema;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
26
246
2746a8e5a6c4 Fixed regressions in DOM due previous refactorings
sergey
parents: 236
diff changeset
27 die new IMPL::InvalidArgumentException("A schema object is required") unless ref $this->{$Schema} && eval { $this->{$Schema}->isa('IMPL::DOM::Schema') };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
28 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
30 my $schemaAnyNode = IMPL::DOM::Schema::ComplexType->new(type => '::AnyNodeType', nativeType => 'IMPL::DOM::ComplexNode')->appendRange(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
31 IMPL::DOM::Schema::NodeSet->new()->appendRange(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
32 IMPL::DOM::Schema::AnyNode->new()
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
33 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
34 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
36 sub NavigateName {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
37 my ($this,$name) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
38
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
39 die new IMPL::InvalidArgumentException('name is required') unless defined $name;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
41 # perform a safe navigation
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
42 #return dosafe $this sub {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
43 my $steps = 0;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
44 # if we are currently in a ComplexNode, first go to it's content
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
45 if ($this->Current->isa('IMPL::DOM::Schema::ComplexNode')) {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
46 # navigate to it's content
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
47 # ComplexNode
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
48 $this->internalNavigateNodeSet($this->Current->content);
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
49 $steps ++;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
50 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
51
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
52 # navigate to node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
53 if (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
54 my $node = $this->Navigate( sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
55 $_->isa('IMPL::DOM::Schema::Node') and (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
56 $_->name eq $name
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
57 or
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
58 $_->nodeName eq 'AnyNode'
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
59 or
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
60 ( $_->nodeName eq 'SwitchNode' and $_->selectNodes( sub { $_->name eq $name } ) )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
61 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
62 })
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
63 ) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
64 $steps ++;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
65 if ($node->nodeName eq 'AnyNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
66 # if we navigate to the anynode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
67 # assume it to be ComplexType by default
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
68 $node = $node->type ? $this->{$Schema}->resolveType($node->type) : $schemaAnyNode;
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
69 $this->internalNavigateNodeSet($node);
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
70 $steps ++;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
71 } elsif ($node->nodeName eq 'SwitchNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
72 # if we are in the switchnode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
73 # navigate to the target node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
74 $node = $this->Navigate(sub { $_->name eq $name });
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
75 $steps ++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
76 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
77
341
70658970af15 small fixes
cin
parents: 278
diff changeset
78 die IMPL::Exception->new("A node is expected")
70658970af15 small fixes
cin
parents: 278
diff changeset
79 unless $node;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
80 if ($node->nodeName eq 'Node') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
81 # if we navigate to a reference
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
82 # resolve it
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
83 $node = $this->{$Schema}->resolveType($node->type);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
84 $this->internalNavigateNodeSet($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
85 $steps++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
86 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
87
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
88 push @{$this->{$_historySteps}},$steps;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
89
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
90 # return found node schema
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
91 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
92 } else {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
93 return; # abort navigation
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
94 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
95 #}
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
96 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
97
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
98 sub SchemaBack {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
99 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
100
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
101 $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
102 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
103
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
104 sub SourceSchemaNode {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
105 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
106
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
107 if ($this->Current->isa('IMPL::DOM::Schema::SimpleType') or
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
108 $this->Current->isa('IMPL::DOM::Schema::ComplexType')
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
109 ) {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
110 # we are redirected
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
111 return $this->GetNodeFromHistory(-1);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
112 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
113 return $this->Current;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
114 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
115 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
116
368
010ceafd0c5a form metadata + tests
cin
parents: 341
diff changeset
117 sub schema {
010ceafd0c5a form metadata + tests
cin
parents: 341
diff changeset
118 goto &Schema;
010ceafd0c5a form metadata + tests
cin
parents: 341
diff changeset
119 }
010ceafd0c5a form metadata + tests
cin
parents: 341
diff changeset
120
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
121 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
122 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
123
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
124 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
125
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
126 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
127
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
128 Помимо стандартных методов навигации позволяет переходить по элементам документа,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
129 который данной схемой описывается.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
130
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
131 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
132
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
133 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
134
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
135 =item C<NavigateName($name)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
136
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
137 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
138
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
139 =item C<SchemaBack>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
140
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
141 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
142 посокольку операция навигации по элементам описываемым схемой может приводить к
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
143 нескольким операциям навигации по самой схеме.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
144
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
145 =item C<SourceSchemaNode>
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
146
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
147 Получает схему узла из которого было выполнено перенаправление, например, C<IMPL::DOM::Schema::Node>.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
148 В остальных случаях совпадает со свойством C<Current>.
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
149
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
150 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
151
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
152 =cut