1 |
wakaba |
1.1 |
Module: |
2 |
|
|
@QName: |
3 |
|
|
Util:ManakaiNode |
4 |
|
|
@FullName: |
5 |
|
|
@@lang: en |
6 |
|
|
@@@: |
7 |
|
|
Manakai Generic Node Implementation |
8 |
|
|
@Namespace: |
9 |
|
|
http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ManakaiNode# |
10 |
|
|
|
11 |
|
|
@Description: |
12 |
|
|
@@lang:en |
13 |
|
|
@@@: |
14 |
|
|
The <Module::Util:ManakaiNode> module provides a basic |
15 |
|
|
implementation for glaph (perhaps tree) structures. |
16 |
|
|
|
17 |
|
|
@Author: |
18 |
|
|
@@FullName: Wakaba |
19 |
|
|
@@Mail: w@suika.fam.cx |
20 |
|
|
@License: |
21 |
|
|
license:Perl+MPL |
22 |
|
|
@Date: |
23 |
|
|
@@@: |
24 |
wakaba |
1.5 |
$Date: 2005/02/27 14:27:56 $ |
25 |
wakaba |
1.1 |
@@ContentType: |
26 |
|
|
dis:Date.RCS |
27 |
|
|
|
28 |
|
|
@Require: |
29 |
|
|
@@Module: |
30 |
|
|
@@@Name: DISPerl |
31 |
wakaba |
1.4 |
@@@QName: |
32 |
|
|
DISlib:DISPerl |
33 |
wakaba |
1.1 |
@@@WithFor: |
34 |
|
|
ManakaiDOM:all |
35 |
wakaba |
1.2 |
@@Module: |
36 |
|
|
@@@Name: ManakaiNode |
37 |
|
|
@@@WithFor: |
38 |
|
|
ManakaiDOM:Perl |
39 |
|
|
|
40 |
|
|
@DefaultFor: |
41 |
|
|
ManakaiDOM:Perl |
42 |
wakaba |
1.1 |
|
43 |
|
|
Namespace: |
44 |
|
|
@dis: |
45 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-- |
46 |
|
|
@dis2pm: |
47 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm# |
48 |
wakaba |
1.4 |
@DISlib: |
49 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/dis/ |
50 |
wakaba |
1.1 |
@lang: |
51 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/8/18/lang# |
52 |
|
|
@license: |
53 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/8/18/license# |
54 |
|
|
@ManakaiDOM: |
55 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom# |
56 |
|
|
@owl: |
57 |
|
|
http://www.w3.org/2002/07/owl# |
58 |
|
|
@Perl: |
59 |
|
|
http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl-- |
60 |
|
|
@rdf: |
61 |
|
|
http://www.w3.org/1999/02/22-rdf-syntax-ns# |
62 |
|
|
@rdfs: |
63 |
|
|
http://www.w3.org/2000/01/rdf-schema# |
64 |
|
|
@TreeCore:\ |
65 |
|
|
@Util: |
66 |
|
|
http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ |
67 |
|
|
|
68 |
|
|
ResourceDef: |
69 |
|
|
@QName: |
70 |
|
|
Util: |
71 |
|
|
@rdf:type: |
72 |
|
|
dis:ModuleGroup |
73 |
|
|
@FullName: |
74 |
|
|
@@lang:en |
75 |
|
|
@@@: |
76 |
|
|
The manakai support modules |
77 |
|
|
@AppName: |
78 |
|
|
Message::Util:: |
79 |
|
|
|
80 |
|
|
## -- Internal node object |
81 |
|
|
|
82 |
|
|
ClassDef: |
83 |
|
|
@QName: |
84 |
|
|
ManakaiDOM:ManakaiDOMNodeObject |
85 |
|
|
@Description: |
86 |
|
|
@@lang:en |
87 |
|
|
@@@: |
88 |
|
|
Internal (actual) node objects that is accessed via |
89 |
|
|
<Class::ManakaiDOM:ManakaiDOMNodeReference> objects referring it. |
90 |
|
|
@ImplNote: |
91 |
|
|
@@lang:en |
92 |
|
|
@@@: |
93 |
|
|
No public interface should be defined for any class inheriting |
94 |
|
|
this class - applications should access to nodes only via |
95 |
|
|
<Class::ManakaiDOM:ManakaiDOMNodeReference> objects. |
96 |
|
|
@ImplNote: |
97 |
|
|
@@lang:en |
98 |
|
|
@@@: |
99 |
|
|
A <Class::ManakaiDOM:ManakaiDOMNodeObject> is a blessed hash |
100 |
|
|
reference. Each hash key and value pair is called as a |
101 |
|
|
<DFN::property>. Currently, several core properties |
102 |
|
|
are defined as listed below. Applications for this class, |
103 |
|
|
including <Class::DOMCore:ManakaiDOMNode>, defines additional |
104 |
|
|
properties for their purpose and scope. |
105 |
|
|
\ |
106 |
|
|
{FIG:: Core node properties |
107 |
|
|
\ |
108 |
|
|
- <CODE::TreeCore:nodeID>::: The global-unique identifier for |
109 |
|
|
this node object. |
110 |
|
|
\ |
111 |
|
|
- <CODE::TreeCore:treeID>::: The global-unique identifier for the |
112 |
|
|
tree containing this node object. |
113 |
|
|
\ |
114 |
|
|
- <CODE::TreeCore:rc>::: The number that denotes how many reference |
115 |
|
|
to this node there are. |
116 |
|
|
\ |
117 |
|
|
- <CODE::TreeCore:origin>::: An array reference, containing |
118 |
|
|
hash key names of <DFN::origin> |
119 |
|
|
properties for this node. |
120 |
|
|
\ |
121 |
wakaba |
1.3 |
- <CODE::TreeCore:subnode0>::: An array reference, containing |
122 |
|
|
hash key names of <DFN::subnode> |
123 |
|
|
properties for this node. |
124 |
|
|
\ |
125 |
wakaba |
1.1 |
- <CODE::TreeCore:subnode>::: An array reference, containing |
126 |
wakaba |
1.3 |
hash key names of <DFN::subnode> list |
127 |
wakaba |
1.1 |
properties for this node. |
128 |
|
|
\ |
129 |
|
|
- <CODE::TreeCore:subnode2>::: An array reference, containing |
130 |
wakaba |
1.3 |
hash key names of <DFN::subnode> (two steps) list |
131 |
wakaba |
1.1 |
properties for this node. |
132 |
|
|
\ |
133 |
|
|
- <CODE::TreeCore:irefnode>::: An array reference, containing |
134 |
|
|
hash key names of <DFN::irefnode> |
135 |
|
|
properties for this node. |
136 |
|
|
\ |
137 |
|
|
- <CODE::TreeCore:anydata>::: An array reference, containing |
138 |
wakaba |
1.3 |
hash key names of <DFN::anydata> list |
139 |
|
|
properties for this node. |
140 |
wakaba |
1.1 |
\ |
141 |
|
|
- <CODE::TreeCore:anydata2>::: An array reference, containing |
142 |
wakaba |
1.3 |
hash key names of <DFN::anydata> (two steps) list properties |
143 |
wakaba |
1.1 |
for this node. |
144 |
|
|
\ |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
@IntMethod: |
148 |
|
|
@@Name: new |
149 |
|
|
@@Description: |
150 |
|
|
@@@lang:en |
151 |
|
|
@@@@: |
152 |
|
|
Constructs a new instance of |
153 |
|
|
<Class::ManakaiDOM:ManakaiDOMNodeObject> and returns it. |
154 |
|
|
@@Return: |
155 |
|
|
@@@Type: |
156 |
|
|
ManakaiDOM:ManakaiDOMNodeObject |
157 |
|
|
@@@Description: |
158 |
|
|
@@@@lang:en |
159 |
|
|
@@@@@: |
160 |
|
|
The newly created <Class::ManakaiDOM:ManakaiDOMNodeObject> instance. |
161 |
|
|
@@@PerlDef: |
162 |
|
|
$r = bless { |
163 |
|
|
<Q::TreeCore:origin> => [], |
164 |
wakaba |
1.3 |
<Q::TreeCore:subnode0> => [], |
165 |
wakaba |
1.1 |
<Q::TreeCore:subnode> => [], |
166 |
|
|
<Q::TreeCore:subnode2> => [], |
167 |
|
|
<Q::TreeCore:irefnode> => [], |
168 |
|
|
<Q::TreeCore:anydata> => [], |
169 |
|
|
<Q::TreeCore:anydata2> => [], |
170 |
|
|
<Q::TreeCore:rc> => 0, |
171 |
|
|
<Q::TreeCore:treeID> => <Code::ManakaiDOM:generateUniqueID>, |
172 |
|
|
<Q::TreeCore:nodeID> => <Code::ManakaiDOM:generateUniqueID>, |
173 |
|
|
}, ref $self || $self; |
174 |
|
|
@IntMethod: |
175 |
|
|
@@Name: newReference |
176 |
|
|
@@Description: |
177 |
|
|
@@@lang:en |
178 |
|
|
@@@@: |
179 |
|
|
Creates a new reference to this node and returns it. |
180 |
|
|
@@Param: |
181 |
|
|
@@@Name: class |
182 |
|
|
@@@Type: |
183 |
|
|
Perl:package-name |
184 |
|
|
@@@Description: |
185 |
|
|
@@@@lang:en |
186 |
|
|
@@@@@: |
187 |
|
|
A Perl class package name with which the newly created |
188 |
|
|
reference is blessed. The <P::class> class must be a |
189 |
|
|
subclass of <Class::ManakaiDOM:ManakaiDOM:ManakaiDOMNodeReference>. |
190 |
|
|
@@Return: |
191 |
|
|
@@@Type: |
192 |
|
|
ManakaiDOM:ManakaiDOMNodeReference |
193 |
|
|
@@@Description: |
194 |
|
|
@@@@lang:en |
195 |
|
|
@@@@@: |
196 |
|
|
The newly created node reference. |
197 |
|
|
@@@PerlDef: |
198 |
|
|
$r = bless { |
199 |
|
|
<Q::TreeCore:node> => $self, |
200 |
|
|
}, ref $class ? ref $class : $class ? $class : |
201 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeReference>; |
202 |
|
|
$self->{<Q::TreeCore:rc>}++; |
203 |
|
|
@IntMethod: |
204 |
|
|
@@Name: isExternallyReferred |
205 |
|
|
@@Description: |
206 |
|
|
@@@lang:en |
207 |
|
|
@@@@: |
208 |
|
|
Checks whether the tree containing this node has been referred |
209 |
|
|
from the outside of the tree or not. |
210 |
|
|
@@Return: |
211 |
|
|
@@@Type: |
212 |
|
|
DISPerl:Boolean |
213 |
|
|
@@@InCase: |
214 |
|
|
@@@@Value: true |
215 |
|
|
@@@@Type: |
216 |
|
|
DISPerl:Boolean |
217 |
|
|
@@@@Description: |
218 |
|
|
@@@@@lang:en |
219 |
|
|
@@@@@@: |
220 |
|
|
There is one or more nodes in the tree that has been |
221 |
|
|
referred via <Class::ManakaiDOM:ManakaiDOMNodeReference> objects. |
222 |
|
|
@@@InCase: |
223 |
|
|
@@@@Value: false |
224 |
|
|
@@@@Type: |
225 |
|
|
DISPerl:Boolean |
226 |
|
|
@@@@Description: |
227 |
|
|
@@@@@lang:en |
228 |
|
|
@@@@@@: No external reference found. |
229 |
|
|
@@@PerlDef: |
230 |
|
|
if ($self->{<Q::TreeCore:rc>}) { |
231 |
|
|
$r = true; |
232 |
|
|
} else { |
233 |
|
|
my @node = ($self); |
234 |
|
|
my %checked; |
235 |
|
|
NODES: while (my $node = shift @node) { |
236 |
wakaba |
1.5 |
next unless ref $node eq |
237 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject>; |
238 |
wakaba |
1.1 |
if ($node->{<Q::TreeCore:rc>}) { |
239 |
|
|
$r = true; |
240 |
|
|
last NODES; |
241 |
|
|
} elsif ($checked{$node->{<Q::TreeCore:nodeID>}}) { |
242 |
|
|
next NODES; |
243 |
|
|
} |
244 |
|
|
my @n; |
245 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:subnode2>}}) { |
246 |
|
|
if (ref $node->{$p} eq 'ARRAY') { |
247 |
|
|
push @n, @{$node->{$p}}; |
248 |
|
|
} elsif (ref $node->{$p} eq 'HASH') { |
249 |
|
|
push @n, values %{$node->{$p}}; |
250 |
wakaba |
1.1 |
} |
251 |
|
|
} |
252 |
wakaba |
1.3 |
for my $p (@n, |
253 |
|
|
map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) { |
254 |
|
|
if (ref $p eq 'ARRAY') { |
255 |
|
|
push @node, @$p; |
256 |
|
|
} elsif (ref $p eq 'HASH') { |
257 |
|
|
push @node, values %$p; |
258 |
wakaba |
1.1 |
} |
259 |
|
|
} |
260 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:origin>}}, |
261 |
|
|
\ @{$node->{<Q::TreeCore:subnode0>}}) { |
262 |
|
|
push @node, $node->{$p} if $node->{$p}; |
263 |
wakaba |
1.1 |
} |
264 |
|
|
$checked{$node->{<Q::TreeCore:nodeID>}} = 1; |
265 |
|
|
} |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
@IntMethod: |
269 |
|
|
@@Name: destroy |
270 |
|
|
@@Description: |
271 |
|
|
@@@lang:en |
272 |
|
|
@@@@: |
273 |
|
|
Destructs the tree containing this node. |
274 |
|
|
@@Return: |
275 |
|
|
@@@PerlDef: |
276 |
|
|
my @node = ($self); |
277 |
|
|
NODES: while (my $node = shift @node) { |
278 |
wakaba |
1.5 |
next unless ref $node eq <ClassName::ManakaiDOM:ManakaiDOMNodeObject>; |
279 |
wakaba |
1.1 |
my @n; |
280 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:subnode2>}}) { |
281 |
|
|
if (ref $node->{$p} eq 'ARRAY') { |
282 |
|
|
push @n, @{$node->{$p}}; |
283 |
|
|
} elsif (ref $node->{$p} eq 'HASH') { |
284 |
|
|
push @n, values %{$node->{$p}}; |
285 |
wakaba |
1.1 |
} |
286 |
|
|
} |
287 |
wakaba |
1.3 |
for my $p (@n, |
288 |
|
|
map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) { |
289 |
|
|
if (ref $p eq 'ARRAY') { |
290 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
291 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
292 |
|
|
and defined $_->{<Q::TreeCore:nodeID>}} @$p; |
293 |
wakaba |
1.3 |
} elsif (ref $p eq 'HASH') { |
294 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
295 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
296 |
|
|
and defined $_->{<Q::TreeCore:nodeID>}} |
297 |
wakaba |
1.3 |
values %$p; |
298 |
wakaba |
1.1 |
} |
299 |
|
|
} |
300 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:origin>}}, |
301 |
|
|
\ @{$node->{<Q::TreeCore:subnode0>}}) { |
302 |
|
|
push @node, $node->{$p} |
303 |
|
|
if defined $node->{$p} and |
304 |
|
|
defined $node->{$p}->{<Q::TreeCore:nodeID>}; |
305 |
wakaba |
1.1 |
} |
306 |
|
|
%$node = (); |
307 |
|
|
} |
308 |
|
|
@@ImplNote: |
309 |
|
|
@@@lang:en |
310 |
|
|
@@@@: |
311 |
|
|
This method is different from Perl <Perl::DESTROY> special |
312 |
|
|
purpose method. |
313 |
|
|
\ |
314 |
|
|
An <QUOTE::uninitialized> warning in this method might mean |
315 |
|
|
some method puts an <Perl::undef> into a list of nodes. |
316 |
|
|
|
317 |
|
|
@IntMethod: |
318 |
|
|
@@Name: importTree |
319 |
|
|
@@Description: |
320 |
|
|
@@@lang:en |
321 |
|
|
@@@@: |
322 |
|
|
Changes the tree identifier of the nodes belong to another tree |
323 |
|
|
to be same as this node's tree identifier. |
324 |
|
|
@@Param: |
325 |
|
|
@@@Name: node |
326 |
|
|
@@@Type: |
327 |
|
|
ManakaiDOM:ManakaiDOMNodeObject |
328 |
|
|
@@@Description: |
329 |
|
|
@@@@lang:en |
330 |
|
|
@@@@@: |
331 |
|
|
Any node from the tree to change its identifier. |
332 |
|
|
@@Return: |
333 |
|
|
@@@PerlDef: |
334 |
|
|
unless ($node->{<Q::TreeCore:treeID>} eq |
335 |
|
|
$self->{<Q::TreeCore:treeID>}) { |
336 |
|
|
my @node = ($node); |
337 |
|
|
NODES: while (my $node = shift @node) { |
338 |
wakaba |
1.5 |
next unless ref $node eq |
339 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject>; |
340 |
wakaba |
1.1 |
my @n; |
341 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:subnode2>}}) { |
342 |
|
|
if (ref $node->{$p} eq 'ARRAY') { |
343 |
|
|
push @n, @{$node->{$p}}; |
344 |
|
|
} elsif (ref $node->{$p} eq 'HASH') { |
345 |
|
|
push @n, values %{$node->{$p}}; |
346 |
wakaba |
1.1 |
} |
347 |
|
|
} |
348 |
wakaba |
1.3 |
for my $p (@n, |
349 |
|
|
map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) { |
350 |
|
|
if (ref $p eq 'ARRAY') { |
351 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
352 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
353 |
|
|
and $_->{<Q::TreeCore:treeID>} ne |
354 |
wakaba |
1.3 |
$self->{<Q::TreeCore:treeID>}} @$p; |
355 |
|
|
} elsif (ref $p eq 'HASH') { |
356 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
357 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
358 |
|
|
and $_->{<Q::TreeCore:treeID>} ne |
359 |
wakaba |
1.1 |
$self->{<Q::TreeCore:treeID>}} |
360 |
wakaba |
1.3 |
values %$p; |
361 |
wakaba |
1.1 |
} |
362 |
|
|
} |
363 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:origin>}}, |
364 |
|
|
\ @{$node->{<Q::TreeCore:subnode0>}}) { |
365 |
|
|
push @node, $node->{$p} |
366 |
|
|
if defined $node->{$p} and |
367 |
|
|
$node->{$p}->{<Q::TreeCore:treeID>} ne |
368 |
wakaba |
1.1 |
$self->{<Q::TreeCore:treeID>}; |
369 |
|
|
} |
370 |
|
|
$node->{<Q::TreeCore:treeID>} = $self->{<Q::TreeCore:treeID>}; |
371 |
|
|
} |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
@IntMethod: |
375 |
|
|
@@Name: changeTreeID |
376 |
|
|
@@Description: |
377 |
|
|
@@@lang:en |
378 |
|
|
@@@@: |
379 |
|
|
Changes tree identifier of all nodes traversable from this node. |
380 |
|
|
@@Param: |
381 |
|
|
@@@Name: treeID |
382 |
|
|
@@@Type: |
383 |
|
|
DISPerl:String |
384 |
|
|
@@@Description: |
385 |
|
|
@@@@lang:en |
386 |
|
|
@@@@@: |
387 |
|
|
The new tree identifier. |
388 |
|
|
@@Return: |
389 |
|
|
@@@PerlDef: |
390 |
|
|
unless ($self->{<Q::TreeCore:treeID>} eq $treeID) { |
391 |
|
|
my @node = ($self); |
392 |
|
|
NODES: while (my $node = shift @node) { |
393 |
wakaba |
1.5 |
next unless ref $node eq |
394 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject>; |
395 |
wakaba |
1.1 |
my @n; |
396 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:subnode2>}}) { |
397 |
|
|
if (ref $node->{$p} eq 'ARRAY') { |
398 |
|
|
push @n, @{$node->{$p}}; |
399 |
|
|
} elsif (ref $node->{$p} eq 'HASH') { |
400 |
|
|
push @n, values %{$node->{$p}}; |
401 |
wakaba |
1.1 |
} |
402 |
|
|
} |
403 |
wakaba |
1.3 |
for my $p (@n, |
404 |
|
|
map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) { |
405 |
|
|
if (ref $p eq 'ARRAY') { |
406 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
407 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
408 |
|
|
and |
409 |
|
|
$_->{<Q::TreeCore:treeID>} ne $treeID} @$p; |
410 |
wakaba |
1.3 |
} elsif (ref $p eq 'HASH') { |
411 |
wakaba |
1.5 |
push @node, grep {ref $_ eq |
412 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject> |
413 |
|
|
and $_->{<Q::TreeCore:treeID>} ne $treeID} |
414 |
wakaba |
1.3 |
values %$p; |
415 |
wakaba |
1.1 |
} |
416 |
|
|
} |
417 |
wakaba |
1.3 |
for my $p (@{$node->{<Q::TreeCore:origin>}}, |
418 |
|
|
\ @{$node->{<Q::TreeCore:subnode0>}}) { |
419 |
|
|
push @node, $node->{$p} |
420 |
|
|
if defined $node->{$p} and |
421 |
|
|
$node->{$p}->{<Q::TreeCore:treeID>} ne $treeID; |
422 |
wakaba |
1.1 |
} |
423 |
|
|
$node->{<Q::TreeCore:treeID>} = $treeID; |
424 |
|
|
} |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
@IntMethod: |
428 |
|
|
@@Name: getRootNodes |
429 |
|
|
@@Description: |
430 |
|
|
@@@lang:en |
431 |
|
|
@@@@: |
432 |
|
|
Gets root nodes in the tree to which this node belongs, |
433 |
|
|
at <QUOTE::higher> level than this node. |
434 |
|
|
\ |
435 |
|
|
{NOTE:: The manakai internal tree structure may have more than |
436 |
|
|
one tree root node - it is a set of tree sharing their |
437 |
|
|
nodes rather than a single tree. In this method |
438 |
|
|
<DFN::root nodes> is defined as the nodes that |
439 |
|
|
have no their <QUOTE::origin> node. There is at least |
440 |
|
|
one such node by definition of the manakai tree structure. |
441 |
|
|
<QUOTE::Higher> in this context means that the node is reachable |
442 |
|
|
by only traversing <QUOTE::origin> relationships from this node. |
443 |
|
|
\ |
444 |
|
|
} |
445 |
|
|
@@Return: |
446 |
|
|
@@@Type: |
447 |
|
|
Perl:ARRAY |
448 |
|
|
@@@PerlDef: |
449 |
|
|
my %result; |
450 |
|
|
my @node = ($self); |
451 |
|
|
NODES: while (my $node = shift @node) { |
452 |
|
|
my $i = 0; |
453 |
wakaba |
1.3 |
ORIGINS: for my $o (@{$node->{<Q::TreeCore:origin>}}) { |
454 |
|
|
next ORIGINS unless $node->{$o}; |
455 |
wakaba |
1.1 |
$i++; |
456 |
wakaba |
1.3 |
push @node, $node->{$o}; |
457 |
wakaba |
1.1 |
} |
458 |
|
|
if ($i == 0) { |
459 |
|
|
$result{$node->{<Q::TreeCore:nodeID>}} = $node; |
460 |
|
|
} |
461 |
|
|
} |
462 |
|
|
\ @$r = (grep {defined $_->{<Q::TreeCore:nodeID>}} values %result); |
463 |
|
|
|
464 |
|
|
@IntMethod: |
465 |
|
|
@@Name: isSameNode |
466 |
|
|
@@Description: |
467 |
|
|
@@@lang:en |
468 |
|
|
@@@@: |
469 |
|
|
Returns whether a node is the same as this node or not. |
470 |
|
|
\ |
471 |
|
|
{NOTE:: The sameness is different from the equality; |
472 |
|
|
two nodes are same iff they are same hash reference. |
473 |
|
|
\ |
474 |
|
|
} |
475 |
|
|
@@Operator: |
476 |
|
|
@@@ContentType: |
477 |
|
|
lang:Perl |
478 |
|
|
@@@@: eq |
479 |
|
|
@@Param: |
480 |
|
|
@@@Name: node |
481 |
|
|
@@@Type: |
482 |
|
|
ManakaiDOM:ManakaiDOMNodeObject |
483 |
|
|
@@@Description: |
484 |
|
|
@@@@lang:en |
485 |
|
|
@@@@@: |
486 |
|
|
A node to compare with. |
487 |
|
|
@@Return: |
488 |
|
|
@@@Type: |
489 |
|
|
DISPerl:Boolean |
490 |
|
|
@@@Description: |
491 |
|
|
@@@@lang:en |
492 |
|
|
@@@@@: Whether the two nodes are same or not. |
493 |
|
|
@@@PerlDef: |
494 |
|
|
if (ref $node and |
495 |
|
|
UNIVERSAL::isa ($node, |
496 |
|
|
<ClassName::ManakaiDOM:ManakaiDOMNodeObject>) and |
497 |
|
|
$node->{<Q::TreeCore:nodeID>} eq $self->{<Q::TreeCore:nodeID>}) { |
498 |
|
|
$r = true; |
499 |
|
|
} |
500 |
|
|
@IntMethod: |
501 |
|
|
@@Name: orphanate |
502 |
|
|
@@Description: |
503 |
|
|
@@@lang:en |
504 |
|
|
@@@@: |
505 |
|
|
Notifies that this node (and its neibors if any) is no longer |
506 |
|
|
part of the main tree. If the new tree containing this node |
507 |
|
|
has been referred yet, then the tree is preserved except its |
508 |
|
|
tree identifier has changed. Otherwise, i.e. the tree is |
509 |
|
|
useless any more, then it is destructed. |
510 |
|
|
\ |
511 |
|
|
{NOTE:: Interaction on deleting a relationship from multiply |
512 |
|
|
organized <QUOTE::trees> (such as DOM tree and |
513 |
|
|
styled displaying tree) is less studied. This |
514 |
|
|
method might be modified or addition of another method(s) |
515 |
|
|
might be required when style sheet, XBL, or other |
516 |
|
|
technologies has been implemented. |
517 |
|
|
\ |
518 |
|
|
} |
519 |
|
|
@@Return: |
520 |
|
|
@@@PerlDef: |
521 |
|
|
if ($self-><M::ManakaiDOM:ManakaiDOMNodeObject.isExternallyReferred>) { |
522 |
|
|
$self-><M::ManakaiDOM:ManakaiDOMNodeObject.changeTreeID> |
523 |
|
|
(<Code::ManakaiDOM:generateUniqueID>); |
524 |
|
|
} else { |
525 |
|
|
$self-><M::ManakaiDOM:ManakaiDOMNodeObject.destroy>; |
526 |
|
|
} |
527 |
|
|
##Class:ManakaiDOMNodeObject |
528 |
|
|
|
529 |
|
|
## -- Public node object |
530 |
|
|
|
531 |
|
|
ClassDef: |
532 |
|
|
@QName: |
533 |
|
|
ManakaiDOM:ManakaiDOMNodeReference |
534 |
|
|
@Description: |
535 |
|
|
@@lang:en |
536 |
|
|
@@@: |
537 |
|
|
References to the node object corresponding to it. From |
538 |
|
|
applications' view, any node object is hidden and |
539 |
|
|
<Class::ManakaiDOM:ManakaiDOMNodeReference> seems as if |
540 |
|
|
the node itself. |
541 |
|
|
@ImplNote: |
542 |
|
|
@@lang:en |
543 |
|
|
@@@: |
544 |
|
|
A <Class::ManakaiDOM:ManakaiDOMNodeReference> is a blessed hash |
545 |
|
|
reference; currently there is a hash key defined: |
546 |
|
|
\ |
547 |
|
|
- <CODE::TreeCore:node>::: A node object |
548 |
|
|
(<Class::ManakaiDOM:ManakaiDOMNodeObject>) to which |
549 |
|
|
this is referring. |
550 |
|
|
|
551 |
|
|
@IntMethod: |
552 |
|
|
@@Name: destroy |
553 |
|
|
@@Description: |
554 |
|
|
@@@lang:en |
555 |
|
|
@@@@: Destroy this reference object. |
556 |
|
|
@@Operator: |
557 |
|
|
@@@ContentType: |
558 |
|
|
lang:Perl |
559 |
|
|
@@@@: DESTROY |
560 |
|
|
@@Return: |
561 |
|
|
@@@PerlDef: |
562 |
|
|
@@@@@: |
563 |
|
|
my $node = $self->{<Q::TreeCore:node>}; |
564 |
|
|
if ($node) { |
565 |
|
|
CORE::delete $self->{<Q::TreeCore:node>}; |
566 |
|
|
$node->{<Q::TreeCore:rc>}--; |
567 |
|
|
unless ($node-><M::ManakaiDOM:ManakaiDOMNodeObject |
568 |
|
|
.isExternallyReferred>) { |
569 |
|
|
$node-><M::ManakaiDOM:ManakaiDOMNodeObject.destroy>; |
570 |
|
|
} |
571 |
|
|
} else { |
572 |
|
|
warn ref ($self) . q{->DESTROY: there is no associated }. |
573 |
|
|
q{node object - you have a global variable or }. |
574 |
|
|
qq{potential memory-leak detected\n}; |
575 |
|
|
} |
576 |
|
|
@@@@ImplNote: |
577 |
|
|
@@@@@lang:en |
578 |
|
|
@@@@@@: |
579 |
|
|
{P::Warning during the global destruction might mean: |
580 |
|
|
\ |
581 |
|
|
- there be a loop in the manakai internal implementation - |
582 |
|
|
it should be a bug. |
583 |
|
|
\ |
584 |
|
|
- there be a loop created by application, e.g. |
585 |
|
|
event handler containing a reference to any node |
586 |
|
|
belonging to the same tree. |
587 |
|
|
\ |
588 |
|
|
- there be a global variable that contains a node reference |
589 |
|
|
and it is not altered or <Perl::undef>ed until the global |
590 |
|
|
destruction. |
591 |
|
|
\ |
592 |
|
|
- or other unknown bad situation. |
593 |
|
|
\ |
594 |
|
|
} |
595 |
|
|
@@ImplNote: |
596 |
|
|
@@@lang:en |
597 |
|
|
@@@@: |
598 |
|
|
Don't override this method unintentionally - for example, |
599 |
|
|
inheritting <PerlModule::Tie::Array> would hide this method |
600 |
|
|
from that class, since that module defines its own |
601 |
|
|
destructor. |
602 |
|
|
##Class:ManakaiDOMNodeReference |
603 |
|
|
|
604 |
|
|
## -- Frequently used code fragments |
605 |
|
|
|
606 |
|
|
ResourceDef: |
607 |
|
|
@QName: |
608 |
|
|
ManakaiDOM:generateUniqueID |
609 |
|
|
@rdf:type: |
610 |
|
|
dis2pm:InlineCode |
611 |
|
|
@Description: |
612 |
|
|
@@lang:en |
613 |
|
|
@@@: |
614 |
|
|
Generates a global-unique opaque string. |
615 |
|
|
\ |
616 |
|
|
{NOTE:: A URI reference is generated by this code. |
617 |
|
|
\ |
618 |
|
|
} |
619 |
|
|
@AliasFor: |
620 |
|
|
@@@: |
621 |
|
|
::ManakaiDOM:all |
622 |
|
|
@@For: |
623 |
|
|
!=ManakaiDOM:all |
624 |
|
|
@PerlDef: |
625 |
|
|
( |
626 |
|
|
sprintf 'mid:%d.%d.%s.dom.manakai@suika.fam.cx#', |
627 |
|
|
time, $$, |
628 |
|
|
['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] . |
629 |
|
|
['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] . |
630 |
|
|
['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] . |
631 |
|
|
['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] . |
632 |
|
|
['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] |
633 |
|
|
) |
634 |
|
|
##ManakaiDOM:generateUniqueID |
635 |
|
|
|
636 |
|
|
## -- lang:dis vocabulary |
637 |
|
|
|
638 |
|
|
TreeElementType: |
639 |
|
|
@QName: |
640 |
|
|
dis:GetProp |
641 |
|
|
@dataType: |
642 |
|
|
dis:TypeQName |
643 |
|
|
@rdfs:range: |
644 |
|
|
rdf:Property |
645 |
|
|
@Description: |
646 |
|
|
@@lang:en |
647 |
|
|
@@@: |
648 |
|
|
Gets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference> |
649 |
|
|
property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property). |
650 |
|
|
|
651 |
|
|
TreeElementType: |
652 |
|
|
@QName: |
653 |
|
|
dis:SetProp |
654 |
|
|
@dataType: |
655 |
|
|
dis:TypeQName |
656 |
|
|
@rdfs:range: |
657 |
|
|
rdf:Property |
658 |
|
|
@Description: |
659 |
|
|
@@lang:en |
660 |
|
|
@@@: |
661 |
|
|
Sets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference> |
662 |
|
|
property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property). |
663 |
|
|
|
664 |
|
|
## -- Syntax sugar |
665 |
|
|
|
666 |
|
|
ElementTypeBinding: |
667 |
|
|
@Name: TreeElementType |
668 |
|
|
@ElementType: |
669 |
|
|
dis:ResourceDef |
670 |
|
|
@ShadowContent: |
671 |
|
|
@@rdf:type: |
672 |
|
|
DISLang:TreeElementType |
673 |
|
|
@@AliasFor: |
674 |
|
|
@@@@: |
675 |
|
|
::ManakaiDOM:all |
676 |
|
|
@@@For: |
677 |
|
|
!=ManakaiDOM:all |
678 |
|
|
|
679 |
|
|
ElementTypeBinding: |
680 |
|
|
@Name: ClassDef |
681 |
|
|
@ElementType: |
682 |
|
|
dis:ResourceDef |
683 |
|
|
@ShadowContent: |
684 |
|
|
@@rdf:type: |
685 |
|
|
ManakaiDOM:Class |
686 |
|
|
@@AliasFor: |
687 |
|
|
@@@@: |
688 |
wakaba |
1.2 |
::ManakaiDOM:Perl |
689 |
wakaba |
1.1 |
@@@For: |
690 |
wakaba |
1.2 |
!=ManakaiDOM:Perl |
691 |
|
|
@@ForCheck: |
692 |
|
|
ManakaiDOM:Perl |
693 |
wakaba |
1.1 |
|
694 |
|
|
ElementTypeBinding: |
695 |
|
|
@Name: IntMethod |
696 |
|
|
@ElementType: |
697 |
|
|
dis:ResourceDef |
698 |
|
|
@ShadowContent: |
699 |
|
|
@@rdf:type: |
700 |
|
|
DISLang:Method |
701 |
|
|
@@ManakaiDOM:isForInternal:1 |
702 |
|
|
|
703 |
|
|
ElementTypeBinding: |
704 |
|
|
@Name: Return |
705 |
|
|
@ElementType: |
706 |
|
|
dis:ResourceDef |
707 |
|
|
@ShadowContent: |
708 |
|
|
@@rdf:type: |
709 |
|
|
DISLang:MethodReturn |
710 |
|
|
|
711 |
|
|
ElementTypeBinding: |
712 |
|
|
@Name: Param |
713 |
|
|
@ElementType: |
714 |
|
|
dis:ResourceDef |
715 |
|
|
@ShadowContent: |
716 |
|
|
@@rdf:type: |
717 |
|
|
DISLang:MethodParameter |
718 |
|
|
|
719 |
|
|
ElementTypeBinding: |
720 |
|
|
@Name: PerlDef |
721 |
|
|
@ElementType: |
722 |
|
|
dis:Def |
723 |
|
|
@ShadowContent: |
724 |
|
|
@@ContentType: |
725 |
|
|
lang:Perl |
726 |
|
|
|
727 |
|
|
ElementTypeBinding: |
728 |
|
|
@Name: InCase |
729 |
|
|
@ElementType: |
730 |
|
|
dis:ResourceDef |
731 |
|
|
@ShadowContent: |
732 |
|
|
@@rdf:type: |
733 |
|
|
ManakaiDOM:InCase |
734 |
|
|
|
735 |
|
|
## ManakaiNode.dis ends here |