annotate Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 117:0475eb382085

Controls support (RC1)
author wizard
date Thu, 03 Jun 2010 02:41:44 +0400
parents 196bf443b5e1
children 76515373dac0
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 base qw(IMPL::DOM::Navigator);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
7 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
9 require IMPL::DOM::Schema::ComplexType;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
10 require IMPL::DOM::Schema::NodeSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
11 require IMPL::DOM::Schema::AnyNode;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
13 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
14
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
15 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
16 public _direct property Schema => prop_get;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
17 private _direct property _historySteps => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
18 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
20 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
21 my ($this,$schema) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
22
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
23 $this->{$Schema} = $schema;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
25 die new IMPL::InvalidArgumentException("A schema object is required") unless $schema->isa('IMPL::DOM::Schema');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
26 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
28 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
29 IMPL::DOM::Schema::NodeSet->new()->appendRange(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
30 IMPL::DOM::Schema::AnyNode->new()
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
31 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
32 );
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 sub NavigateName {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
35 my ($this,$name) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
37 die new IMPL::InvalidArgumentException('name is required') unless defined $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 # perform a safe navigation
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
40 #return dosafe $this sub {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
41 my $steps = 0;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
42 # 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
43 if ($this->Current->isa('IMPL::DOM::Schema::ComplexNode')) {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
44 # navigate to it's content
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
45 # ComplexNode
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
46 $this->internalNavigateNodeSet($this->Current->content);
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
47 $steps ++;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
48 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
49
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
50 # navigate to node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
51 if (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
52 my $node = $this->Navigate( sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
53 $_->isa('IMPL::DOM::Schema::Node') and (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
54 $_->name eq $name
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
55 or
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
56 $_->nodeName eq 'AnyNode'
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 'SwitchNode' and $_->selectNodes( sub { $_->name eq $name } ) )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
59 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
60 })
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
61 ) {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
62 $steps ++;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
63 if ($node->nodeName eq 'AnyNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
64 # if we navigate to the anynode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
65 # assume it to be ComplexType by default
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
66 $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
67 $this->internalNavigateNodeSet($node);
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
68 $steps ++;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
69 } elsif ($node->nodeName eq 'SwitchNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
70 # if we are in the switchnode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
71 # navigate to the target node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
72 $node = $this->Navigate(sub { $_->name eq $name });
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
73 $steps ++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
74 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
76 if ($node->nodeName eq 'Node') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
77 # if we navigate to a reference
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
78 # resolve it
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
79 $node = $this->{$Schema}->resolveType($node->type);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
80 $this->internalNavigateNodeSet($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
81 $steps++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
82 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
84 push @{$this->{$_historySteps}},$steps;
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 # return found node schema
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
87 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
88 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
89 return undef; # abort navigation
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
90 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
91 #}
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 sub SchemaBack {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
95 my ($this) = @_;
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 $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps};
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
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
100 sub SourceSchemaNode {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
101 my ($this) = @_;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
102
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
103 if ($this->Current->isa('IMPL::DOM::Schema::SimpleType') or
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
104 $this->Current->isa('IMPL::DOM::Schema::ComplexType')
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
105 ) {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
106 # we a redirected
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
107 return $this->GetNodeFromHistory(-1);
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
108 } else {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
109 return $this->Current;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
110 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
111 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
112
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
113 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
114 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
115
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
116 =pod
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 =head1 DESCRIPTION
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 Помимо стандартных методов навигации позволяет переходить по элементам документа,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
121 который данной схемой описывается.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
122
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
123 =head1 METHODS
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 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
126
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
127 =item C<NavigateName($name)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
128
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
129 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
130
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
131 =item C<SchemaBack>
49
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 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
134 посокольку операция навигации по элементам описываемым схемой может приводить к
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
135 нескольким операциям навигации по самой схеме.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
136
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
137 =item C<SourceSchemaNode>
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
138
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
139 Получает схему узла из которого было выполнено перенаправление, например, C<IMPL::DOM::Schema::Node>.
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
140 В остальных случаях совпадает со свойством C<Current>.
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
141
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
142 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
143
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
144 =cut