annotate Lib/IMPL/DOM/Node.pm @ 250:129e48bb5afb

DOM refactoring ObjectToDOM methods are virtual QueryToDOM uses inflators Fixed transform for the complex values in the ObjectToDOM QueryToDOM doesn't allow to use complex values (HASHes) as values for nodes (overpost problem)
author sergey
date Wed, 07 Nov 2012 04:17:53 +0400
parents a8db61d0ed33
children 6253872024a4
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: 38
diff changeset
1 package IMPL::DOM::Node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
4
165
76515373dac0 Added Class::Template,
wizard
parents: 152
diff changeset
5 use parent qw(IMPL::Object);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
6
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
7 use IMPL::Object::List;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
8 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
9 use IMPL::Class::Property::Direct;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
10 use Scalar::Util qw(weaken);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
12 use IMPL::Exception;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
14 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
15 public _direct property nodeName => prop_get;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
16 public _direct property document => prop_get;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
17 public _direct property isComplex => { get => \&_getIsComplex } ;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
18 public _direct property nodeValue => prop_all;
102
cf3b6ef2be22 Schema beta version
wizard
parents: 75
diff changeset
19 public _direct property childNodes => { get => \&_getChildNodes }; # prop_list
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
20 public _direct property parentNode => prop_get | owner_set;
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
21 public _direct property schema => prop_get | owner_set;
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
22 public _direct property schemaSource => prop_get | owner_set;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
23 private _direct property _propertyMap => prop_all ;
116
1722ca51537c minor changes.
wizard
parents: 113
diff changeset
24
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
25 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
26
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
27 our %Axes = (
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
28 parent => \&selectParent,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
29 siblings => \&selectSiblings,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
30 child => \&childNodes,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
31 document => \&selectDocument,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
32 ancestor => \&selectAncestors,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
33 descendant => \&selectDescendant
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
34 );
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
35
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
36 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
37 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
38
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
39 $this->{$nodeName} = delete $args{nodeName} or die new IMPL::InvalidArgumentException("A name is required");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
40 $this->{$nodeValue} = delete $args{nodeValue} if exists $args{nodeValue};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
41 if ( exists $args{document} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
42 $this->{$document} = delete $args{document};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
43 weaken($this->{$document});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
44 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
45
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
46 while ( my ($key,$value) = each %args ) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
47 $this->nodeProperty($key,$value);
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
48 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
49 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
50
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
51 sub insertNode {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
52 my ($this,$node,$pos) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
53
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
54 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
55
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
56 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
58 $this->childNodes->InsertAt($pos,$node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
60 $node->_setParent( $this );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
62 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
63 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
64
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
65 sub appendChild {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
66 my ($this,$node) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
68 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
69
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
70 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
71
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
72 my $children = $this->childNodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
73 $children->Append($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
74
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
75 $node->_setParent( $this );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
76
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
77 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
78 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
80 sub appendNode {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
81 goto &appendChild;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
82 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
84 sub appendRange {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
85 my ($this,@range) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
86
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
87 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if grep $_ == $this, @range;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
88
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
89 foreach my $node (@range) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
90 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
91 $node->_setParent( $this );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
92 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
93
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
94 $this->childNodes->Append(@range);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
95
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
96 return $this;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
97 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
98
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
99 sub _getChildNodes {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
100 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
101
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
102 $this->{$childNodes} = new IMPL::Object::List() unless $this->{$childNodes};
102
cf3b6ef2be22 Schema beta version
wizard
parents: 75
diff changeset
103 return wantarray ? @{ $this->{$childNodes} } : $this->{$childNodes};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
104 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
105
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
106 sub childNodesRef {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
107 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
108 return scalar $this->_getChildNodes;
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
109 }
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
110
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
111 sub removeNode {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
112 my ($this,$node) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
113
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
114 if ($this == $node->{$parentNode}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
115 $this->childNodes->RemoveItem($node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
116 $node->_setParent(undef);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
117 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
118 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
119 die new IMPL::InvalidOperationException("The specified node isn't belong to this node");
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
120 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
121 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
122
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
123 sub replaceNodeAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
124 my ($this,$index,$node) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
125
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
126 my $nodeOld = $this->childNodes->[$index];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
127
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
128 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
129
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
130 # unlink node from previous parent
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
131 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
132
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
133 # replace (or set) old node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
134 $this->childNodes->[$index] = $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
135
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
136 # set new parent
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
137 $node->_setParent( $this );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
138
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
139 # unlink old node if we have one
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
140 $nodeOld->_setParent(undef) if $nodeOld;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
141
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
142 # return old node
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
143 return $nodeOld;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
144 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
145
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
146 sub removeAt {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
147 my ($this,$pos) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
148
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
149 if ( my $node = $this->childNodes->RemoveAt($pos) ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
150 $node->_setParent(undef);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
151 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
152 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
153 return undef;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
154 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
155 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
156
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
157 sub removeLast {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
158 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
159
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
160 if ( my $node = $this->{$childNodes} ? $this->{$childNodes}->RemoveLast() : undef) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
161 $node->_setParent(undef);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
162 return $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
163 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
164 return undef;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
165 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
166 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
167
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
168 sub removeSelected {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
169 my ($this,$query) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
170
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
171 my @newSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
172 my @result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
173
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
174 if (ref $query eq 'CODE') {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
175 &$query($_) ? push @result, $_ : push @newSet, $_ foreach @{$this->childNodes};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
176 } elsif (defined $query) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
177 $_->nodeName eq $query ? push @result, $_ : push @newSet, $_ foreach @{$this->childNodes};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
178 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
179 my $children = $this->childNodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
180 $_->_setParent(undef) foreach @$children;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
181 delete $this->{$childNodes};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
182 return wantarray ? @$children : $children;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
183 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
184
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
185 $_->_setParent(undef) foreach @result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
186
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
187 $this->{$childNodes} = @newSet ? bless \@newSet ,'IMPL::Object::List' : undef;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
188
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
189 return wantarray ? @result : \@result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
190 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
191
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
192 sub resolveAxis {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
193 my ($this,$axis) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
194 return $Axes{$axis}->($this)
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
195 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
196
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
197 sub selectNodes {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
198 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
199 my $path;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
200
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
201 if (@_ == 1) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
202 $path = $this->translatePath($_[0]);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
203 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
204 $path = [@_];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
205 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
206
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
207 my @set = ($this);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
208
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
209 while (@$path) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
210 my $query = shift @$path;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
211 @set = map $_->selectNodesAxis($query), @set;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
212 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
213
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
214 return wantarray ? @set : \@set;
108
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
215 }
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
216
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 109
diff changeset
217 sub selectSingleNode {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
218 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
219 my @result = $this->selectNodes(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
220 return $result[0];
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 109
diff changeset
221 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 109
diff changeset
222
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
223 sub selectNodesRef {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
224 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
225
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
226 my @result = $this->selectNodes(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
227 return \@result;
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
228 }
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
229
108
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
230 sub translatePath {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
231 my ($this,$path) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
232
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
233 # TODO: Move path compilation here from IMPL::DOM::Schema::Validator::Compare
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
234 return [$path];
108
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
235 }
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
236
c6fb6964de4c Removed absolute modules
wizard
parents: 104
diff changeset
237 sub selectNodesAxis {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
238 my ($this,$query,$axis) = @_;
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
239
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
240 $axis ||= 'child';
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
241
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
242 die new IMPL::InvalidOperationException('Unknown axis',$axis) unless exists $Axes{$axis};
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
243
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
244 my $nodes = $this->resolveAxis($axis);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
245
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
246 my @result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
247
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
248 if (ref $query eq 'CODE') {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
249 @result = grep &$query($_), @{$nodes};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
250 } elsif (ref $query eq 'ARRAY' ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
251 my %keys = map (($_,1),@$query);
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
252 @result = grep $keys{$_->nodeName}, @{$nodes};
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
253 } elsif (ref $query eq 'HASH') {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
254 while( my ($axis,$filter) = each %$query ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
255 push @result, $this->selectNodesAxis($filter,$axis);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
256 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
257 } elsif (defined $query) {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
258 @result = grep $_->nodeName eq $query, @{$nodes};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
259 } else {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
260 return wantarray ? @{$nodes} : $nodes;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
261 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
262
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
263 return wantarray ? @result : \@result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
264 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
265
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
266 sub selectParent {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
267 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
268
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
269 if ($this->parentNode) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
270 return wantarray ? $this->parentNode : [$this->parentNode];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
271 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
272 return wantarray ? () : [];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
273 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
274 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
275
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
276 sub selectSiblings {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
277 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
278
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
279 if ($this->parentNode) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
280 return $this->parentNode->selectNodes( sub { $_ != $this } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
281 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
282 return wantarray ? () : [];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
283 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
284 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
285
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
286 sub selectDocument {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
287 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
288
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
289 if ($this->document) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
290 return wantarray ? $this->document : [$this->document];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
291 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
292 return wantarray ? () : [];
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
293 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
294 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 102
diff changeset
295
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
296 sub selectDescendant {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
297 wantarray ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
298 map $_->selectAll(), $_[0]->childNodes :
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
299 [map $_->selectAll(), $_[0]->childNodes]
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
300 }
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
301
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
302 sub selectAll {
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
303 map(selectAll($_),@{$_[0]->childNodes}) , $_[0]
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
304 }
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
305
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
306 sub selectAncestors {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
307 my $parent = $_[0]->parentNode;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
308
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
309 wantarray ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
310 ($parent ? ($parent->selectAncestors,$parent) : ()) :
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
311 [$parent ? ($parent->selectAncestors,$parent) : ()]
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
312 }
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
313
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
314 sub firstChild {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
315 @_ >=2 ? $_[0]->replaceNodeAt(0,$_[1]) : $_[0]->childNodes->[0];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
316 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
317
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
318 sub _getIsComplex {
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
319 ($_[0]->{$childNodes} and $_[0]->{$childNodes}->Count) ? 1 : 0;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
320 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
321
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
322 sub _updateDocRefs {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
323 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
324
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
325 # this method is called by the parent node on his children, so we need no to check parent
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
326 $this->{$document} = $this->{$parentNode}->document;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
327
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
328 # prevent cyclic
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
329 weaken($this->{$document}) if $this->{$document};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
330
173
aaab45153411 minor bugfixes
sourcer
parents: 165
diff changeset
331 map $_->_updateDocRefs, @{$this->{$childNodes}} if $this->{$childNodes};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
332 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
333
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
334 sub _setParent {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
335 my ($this,$node) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
336
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
337
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
338 if (($node || 0) != ($this->{$parentNode} || 0)) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
339 my $newOwner;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
340 if ($node) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
341 $this->{$parentNode} = $node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
342 $newOwner = $node->document || 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
343
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
344 # prevent from creating cyclicreferences
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
345 weaken($this->{$parentNode});
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
346
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
347 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
348 delete $this->{$parentNode};
75
wizard
parents: 49
diff changeset
349
wizard
parents: 49
diff changeset
350 #keep document
wizard
parents: 49
diff changeset
351 $newOwner = $this->{$document};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
352 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
353
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
354 if (($this->{$document}||0) != $newOwner) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
355 $this->{$document} = $newOwner;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
356 weaken($this->{$document}) if $newOwner;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
357 $_->_updateDocRefs foreach @{$this->childNodes};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
358 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
359 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
360 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
361
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
362 sub text {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
363 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
364
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
365 join ('', $this->nodeValue || '', map ($_->text || '', @{$this->childNodes}));
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
366 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
367
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
368 sub nodeProperty {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
369 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
370 my $name = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
371
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 180
diff changeset
372 return unless defined $name;
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 180
diff changeset
373
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents: 116
diff changeset
374 if (my $method = $this->can($name)) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
375 unshift @_,$this;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
376 # use goto to preserve calling context
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
377 goto &$method;
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents: 116
diff changeset
378 }
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
379 # dynamic property
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
380 if (@_) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
381 # set
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
382 return $this->{$_propertyMap}{$name} = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
383 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
384 return $this->{$_propertyMap}{$name};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
385 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
386 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
387
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents: 116
diff changeset
388 sub listProperties {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
389 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
390
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
391 my %props = map {$_->Name, 1} $this->get_meta(typeof IMPL::Class::PropertyInfo, sub { $_->Attributes->{domProperty}},1);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
392
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
393 return (keys %props,keys %{$this->{$_propertyMap}});
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents: 116
diff changeset
394 }
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents: 116
diff changeset
395
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
396 sub save {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
397 my ($this,$writer) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
398
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
399 if ( not ( $this->isComplex or defined $this->{$nodeValue} ) ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
400 $writer->emptyTag(
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
401 $this->{$nodeName},
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
402 map {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
403 $_,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
404 $this->nodeProperty($_)
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
405 } grep defined $this->nodeProperty($_), $this->listProperties
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
406 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
407 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
408 $writer->startTag(
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
409 $this->{$nodeName},
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
410 map {
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
411 $_,
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
412 $this->nodeProperty($_)
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
413 } grep defined $this->nodeProperty($_), $this->listProperties
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
414 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
415 $writer->characters($this->{$nodeValue}) if $this->{$nodeValue};
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
416
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
417 $_->save($writer) foreach $this->childNodes;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
418
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
419 $writer->endTag($this->{$nodeName});
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
420 }
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
421 }
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
422
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
423 sub qname {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
424 $_[0]->{$nodeName};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
425 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
426
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
427 sub path {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
428 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
429
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
430 if ($this->parentNode) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
431 return $this->parentNode->path.'.'.$this->qname;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
432 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
433 return $this->qname;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
434 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
435 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
436
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 38
diff changeset
437 1;
75
wizard
parents: 49
diff changeset
438
wizard
parents: 49
diff changeset
439 __END__
wizard
parents: 49
diff changeset
440
wizard
parents: 49
diff changeset
441 =pod
wizard
parents: 49
diff changeset
442
wizard
parents: 49
diff changeset
443 =head1 NAME
wizard
parents: 49
diff changeset
444
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
445 C<IMPL::DOM::Node> Элемент DOM модели
75
wizard
parents: 49
diff changeset
446
wizard
parents: 49
diff changeset
447 =head1 DESCRIPTION
wizard
parents: 49
diff changeset
448
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
449 Базовый узел DOM модели. От него можно наследовать другие элементы DOM модели.
75
wizard
parents: 49
diff changeset
450
wizard
parents: 49
diff changeset
451 =head1 MEMBERS
wizard
parents: 49
diff changeset
452
wizard
parents: 49
diff changeset
453 =head2 PROPERTIES
wizard
parents: 49
diff changeset
454
wizard
parents: 49
diff changeset
455 =over
wizard
parents: 49
diff changeset
456
wizard
parents: 49
diff changeset
457 =item C<[get] nodeName>
wizard
parents: 49
diff changeset
458
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
459 Имя узла. Задается при создании.
75
wizard
parents: 49
diff changeset
460
wizard
parents: 49
diff changeset
461 =item C<[get] document>
wizard
parents: 49
diff changeset
462
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
463 Документ к которому принадлежит узел. Задается при поздании узла.
75
wizard
parents: 49
diff changeset
464
wizard
parents: 49
diff changeset
465 =item C<[get] isComplex>
wizard
parents: 49
diff changeset
466
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
467 Определяет является ли узел сложным (тоесть есть ли дети).
75
wizard
parents: 49
diff changeset
468
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
469 C<true> - есть, C<false> - нет.
75
wizard
parents: 49
diff changeset
470
wizard
parents: 49
diff changeset
471 =item C<[get,set] nodeValue>
wizard
parents: 49
diff changeset
472
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
473 Значение узла, обычно простой скаляр, но ничто не мешает туда
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
474 устанавливать любое значение.
75
wizard
parents: 49
diff changeset
475
wizard
parents: 49
diff changeset
476 =item C<[get,list] childNodes>
wizard
parents: 49
diff changeset
477
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
478 Список детей, является списокм C<IMPL::Object::List>.
75
wizard
parents: 49
diff changeset
479
wizard
parents: 49
diff changeset
480 =item C<[get] parentNode>
wizard
parents: 49
diff changeset
481
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
482 Ссылка на родительский элемент, если таковой имеется.
75
wizard
parents: 49
diff changeset
483
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
484 =item C<[get] schema>
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
485
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
486 Ссылка на узел из C<IMPL::DOM::Schema>, представляющий схему данных текущего узла. Может быть C<undef>.
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
487
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
488 =item C<[get] schema>
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
489
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
490 Ссылка на узел из C<IMPL::DOM::Schema>, представляющий элемент схемы, объявляющий данный узел. Может быть C<undef>.
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
491
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
492 Отличается от свойства C<schema> тем, что узел в случае ссылки на тип узла, данной свойство будет содержать
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
493 описание ссылки C<IMPL::DOM::Schema::Node>, а свойство C<schema> например будет ссылаться на
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
494 C<IMPL::DOM::Schema::ComplexType>.
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
495
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
496 =back
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 124
diff changeset
497
75
wizard
parents: 49
diff changeset
498 =head2 METHODS
wizard
parents: 49
diff changeset
499
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
500 =cut