Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 338:c78dfbe658bd
improved string maps loading for TT documents
author | cin |
---|---|
date | Sat, 15 Jun 2013 02:32:11 +0400 |
parents | 4ddb27ff4a0b |
children | 70658970af15 |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Navigator::SchemaNavigator; |
2 use strict; | |
3 use warnings; | |
4 | |
5 use IMPL::Class::Property; | |
6 | |
7 require IMPL::DOM::Schema::ComplexType; | |
8 require IMPL::DOM::Schema::NodeSet; | |
9 require IMPL::DOM::Schema::AnyNode; | |
10 | |
246 | 11 use IMPL::declare { |
12 base => [ | |
13 'IMPL::DOM::Navigator' => '@_' | |
14 ] | |
15 }; | |
49 | 16 |
17 BEGIN { | |
18 public _direct property Schema => prop_get; | |
19 private _direct property _historySteps => prop_all; | |
20 } | |
21 | |
22 sub CTOR { | |
23 my ($this,$schema) = @_; | |
24 | |
246 | 25 $this->{$Schema} = $schema->isa('IMPL::DOM::Schema::ComplexNode') ? $schema->document : $schema; |
49 | 26 |
246 | 27 die new IMPL::InvalidArgumentException("A schema object is required") unless ref $this->{$Schema} && eval { $this->{$Schema}->isa('IMPL::DOM::Schema') }; |
49 | 28 } |
29 | |
30 my $schemaAnyNode = IMPL::DOM::Schema::ComplexType->new(type => '::AnyNodeType', nativeType => 'IMPL::DOM::ComplexNode')->appendRange( | |
31 IMPL::DOM::Schema::NodeSet->new()->appendRange( | |
32 IMPL::DOM::Schema::AnyNode->new() | |
33 ) | |
34 ); | |
35 | |
36 sub NavigateName { | |
37 my ($this,$name) = @_; | |
38 | |
39 die new IMPL::InvalidArgumentException('name is required') unless defined $name; | |
40 | |
41 # perform a safe navigation | |
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 | 52 # navigate to node |
53 if ( | |
54 my $node = $this->Navigate( sub { | |
55 $_->isa('IMPL::DOM::Schema::Node') and ( | |
56 $_->name eq $name | |
57 or | |
58 $_->nodeName eq 'AnyNode' | |
59 or | |
60 ( $_->nodeName eq 'SwitchNode' and $_->selectNodes( sub { $_->name eq $name } ) ) | |
61 ) | |
62 }) | |
63 ) { | |
194 | 64 $steps ++; |
49 | 65 if ($node->nodeName eq 'AnyNode') { |
66 # if we navigate to the anynode | |
67 # assume it to be ComplexType by default | |
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 | 71 } elsif ($node->nodeName eq 'SwitchNode') { |
72 # if we are in the switchnode | |
73 # navigate to the target node | |
74 $node = $this->Navigate(sub { $_->name eq $name }); | |
75 $steps ++; | |
76 } | |
77 | |
78 if ($node->nodeName eq 'Node') { | |
79 # if we navigate to a reference | |
80 # resolve it | |
81 $node = $this->{$Schema}->resolveType($node->type); | |
82 $this->internalNavigateNodeSet($node); | |
83 $steps++; | |
84 } | |
85 | |
86 push @{$this->{$_historySteps}},$steps; | |
87 | |
88 # return found node schema | |
89 return $node; | |
90 } else { | |
230 | 91 return; # abort navigation |
49 | 92 } |
93 #} | |
94 } | |
95 | |
96 sub SchemaBack { | |
97 my ($this) = @_; | |
98 | |
99 $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps}; | |
100 } | |
101 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
102 sub SourceSchemaNode { |
194 | 103 my ($this) = @_; |
104 | |
105 if ($this->Current->isa('IMPL::DOM::Schema::SimpleType') or | |
106 $this->Current->isa('IMPL::DOM::Schema::ComplexType') | |
107 ) { | |
230 | 108 # we are redirected |
194 | 109 return $this->GetNodeFromHistory(-1); |
110 } else { | |
111 return $this->Current; | |
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 | 115 1; |
116 __END__ | |
117 | |
118 =pod | |
119 | |
120 =head1 DESCRIPTION | |
121 | |
180 | 122 Помимо стандартных методов навигации позволяет переходить по элементам документа, |
123 который данной схемой описывается. | |
49 | 124 |
125 =head1 METHODS | |
126 | |
127 =over | |
128 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
129 =item C<NavigateName($name)> |
49 | 130 |
180 | 131 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>. |
49 | 132 |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
133 =item C<SchemaBack> |
49 | 134 |
180 | 135 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен |
136 посокольку операция навигации по элементам описываемым схемой может приводить к | |
137 нескольким операциям навигации по самой схеме. | |
49 | 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 | 141 Получает схему узла из которого было выполнено перенаправление, например, C<IMPL::DOM::Schema::Node>. |
142 В остальных случаях совпадает со свойством C<Current>. | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
143 |
49 | 144 =back |
145 | |
146 =cut |