annotate Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 302:673581380e79

Added templates provider functionality to controls minor fixes
author cin
date Mon, 01 Apr 2013 00:41:48 +0400
parents 4ddb27ff4a0b
children 70658970af15
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
78 if ($node->nodeName eq 'Node') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
79 # if we navigate to a reference
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
80 # resolve it
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
81 $node = $this->{$Schema}->resolveType($node->type);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
82 $this->internalNavigateNodeSet($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
83 $steps++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
84 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
85
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
86 push @{$this->{$_historySteps}},$steps;
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 # return found node schema
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
89 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
90 } else {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
91 return; # abort navigation
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
92 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
93 #}
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 sub SchemaBack {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
97 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
98
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
99 $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps};
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
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
102 sub SourceSchemaNode {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
103 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
104
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
105 if ($this->Current->isa('IMPL::DOM::Schema::SimpleType') or
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
106 $this->Current->isa('IMPL::DOM::Schema::ComplexType')
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
107 ) {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 194
diff changeset
108 # we are redirected
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
109 return $this->GetNodeFromHistory(-1);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
110 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
111 return $this->Current;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
112 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
113 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
114
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
115 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
116 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
117
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
118 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
119
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
120 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
121
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
122 Помимо стандартных методов навигации позволяет переходить по элементам документа,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
123 который данной схемой описывается.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
124
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
125 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
126
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
127 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
128
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
129 =item C<NavigateName($name)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
130
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
131 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
132
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
133 =item C<SchemaBack>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
134
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
135 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
136 посокольку операция навигации по элементам описываемым схемой может приводить к
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
137 нескольким операциям навигации по самой схеме.
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<SourceSchemaNode>
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
140
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
141 Получает схему узла из которого было выполнено перенаправление, например, C<IMPL::DOM::Schema::Node>.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
142 В остальных случаях совпадает со свойством C<Current>.
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
143
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
144 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
145
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
146 =cut