annotate Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 96:4c55aed00ff2

Minor changes
author wizard
date Fri, 30 Apr 2010 15:03:38 +0400
parents 16ada169ca75
children c289ed9662ca
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 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
41 my $steps = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
42 # navigate to node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
43 if (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
44 my $node = $this->Navigate( sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
45 $_->isa('IMPL::DOM::Schema::Node') and (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
46 $_->name eq $name
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
47 or
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
48 $_->nodeName eq 'AnyNode'
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
49 or
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
50 ( $_->nodeName eq 'SwitchNode' and $_->selectNodes( sub { $_->name eq $name } ) )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
51 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
52 })
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
53 ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
54 if ($node->nodeName eq 'AnyNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
55 # if we navigate to the anynode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
56 # assume it to be ComplexType by default
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
57 $node = $node->type ? $this->{$Schema}->resolveType($node->type) : $schemaAnyNode;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
58 } elsif ($node->nodeName eq 'SwitchNode') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
59 # if we are in the switchnode
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
60 # navigate to the target node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
61 $node = $this->Navigate(sub { $_->name eq $name });
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
62 $steps ++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
63 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
64
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
65 if ($node->nodeName eq 'Node') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
66 # if we navigate to a reference
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
67 # resolve it
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
68 $node = $this->{$Schema}->resolveType($node->type);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
69 $this->internalNavigateNodeSet($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
70 $steps++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
71 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
72
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
73 # if target node is a complex node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
74 if ($node->isa('IMPL::DOM::Schema::ComplexNode')) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
75 # navigate to it's content
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
76 $this->internalNavigateNodeSet($node->content);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
77 $steps ++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
78 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
80 push @{$this->{$_historySteps}},$steps;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
81
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
82 # return found node schema
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
83 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
84 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
85 return undef; # abort navigation
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 }
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 sub SchemaBack {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
91 my ($this) = @_;
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 $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps};
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 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
97 __END__
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 =pod
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 =head1 DESCRIPTION
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 Помимо стандартных методов навигации позволяет переходить по элементам документа,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
104 который данной схемой описывается.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
105
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
106 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
107
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
108 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
109
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
110 =item C<< $navi->NavigateName($name) >>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
111
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
112 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
113 В данном случае всегда происходит безопасная навигация, тоесть в случае неудачи,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 36
diff changeset
114 навигатор останется на прежней позиции.
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 =item C<< $navi->SchemaBack >>
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 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен
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 =back
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 =cut