1 PACKAGE BODY ecx_inbound as
2 --$Header: ECXINBB.pls 120.4 2006/06/07 07:33:43 susaha ship $
3
4 l_procedure PLS_INTEGER := ecx_debug.g_procedure;
5 l_statement PLS_INTEGER := ecx_debug.g_statement;
6 l_unexpected PLS_INTEGER := ecx_debug.g_unexpected;
7 l_procedureEnabled boolean := ecx_debug.g_procedureEnabled;
8 l_statementEnabled boolean := ecx_debug.g_statementEnabled;
9 l_unexpectedEnabled boolean := ecx_debug.g_unexpectedEnabled;
10
11 TYPE l_stack is table of pls_integer index by binary_integer;
12 i_stack l_stack;
13 i_current_depth pls_integer;
14 i_xmlclob clob;
15
16 /**
17 stage 10 - Pre-Processing
18 stage 20 - In-Processing
19 stage 30 - Post-Processing
20 **/
21
22 /**
23 Updates the DOM for any mappings by refering to the g_node_tbl
24 **/
25 procedure updateDOM
26 (
27 i_target IN pls_integer
28 )
29 is
30
31 i_method_name varchar2(2000) := 'ecx_inbound.updatedom';
32
33 p_node xmlDOM.DOMNode;
34 l_text_node xmldom.DOMNode;
35
36 begin
37 if (l_procedureEnabled) then
38 ecx_debug.push(i_method_name);
39 end if;
40 for j in ecx_utils.g_target_levels(i_target).file_start_pos..ecx_utils.g_target_levels(i_target).file_end_pos
41 loop
42 -- update the DOM for each element of this level
43 -- get the DOM id for the current attribute
44 if ecx_utils.g_target(j).map_attribute_id is not null
45 then
46 p_node := ecx_utils.g_node_tbl(ecx_utils.g_target(j).attribute_id);
47
48 if (xmlDOM.getNodeType(p_node) = 2)
49 then
50 l_text_node := p_node;
51 else
52 l_text_node := xmldom.getFirstChild(p_node);
53 end if;
54
55 -- Update the DOM only if the node and its value are not null
56 if not (xmldom.isnull(l_text_node))
57 then
58 if (ecx_utils.g_target(j).value is not null)
59 then
60 xmlDOM.setNodeValue(l_text_node,ecx_utils.g_target(j).value);
61 end if;
62 if(l_statementEnabled) then
63 ecx_debug.log(l_statement,'updating dom node', xmlDOM.getNodeValue(l_text_node),
64 i_method_name);
65 ecx_debug.log(l_statement, 'with value', ecx_utils.g_target(j).value,i_method_name);
66 end if;
67 end if;
68 end if;
69 end loop;
70
71 if (l_procedureEnabled) then
72 ecx_debug.pop(i_method_name);
73 end if;
74 exception
75 when others then
76 ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_INBOUND.updateDOM');
77 if(l_statementEnabled) then
78 ecx_debug.log(l_statement,'ECX', SQLERRM || ' - ECX_INBOUND.updateDOM',
79 i_method_name);
80 end if;
81 if (l_procedureEnabled) then
82 ecx_debug.pop(i_method_name);
83 end if;
84 raise ecx_utils.program_exit;
85 end updateDOM;
86
87 procedure processTarget
88 (
89 i_target in pls_integer
90 )
91 is
92
93 i_method_name varchar2(2000) := 'ecx_inbound.processTarget';
94 begin
95 if (l_procedureEnabled) then
96 ecx_debug.push(i_method_name);
97 end if;
98 if(l_statementEnabled) then
99 ecx_debug.log(l_statement,'i_target',i_target,i_method_name);
100 end if;
101
102 -- don't need t execute stage 10, level 0 action for target as this is
103 -- already done in the initilization phase
104 if (i_target <> 0)
105 then
106 /** Execute the Pre-processing for the Target **/
107 ecx_actions.execute_stage_data (10,i_target, 'T');
108 end if;
109
110 /** Move the Data from Source to the Target **/
111 for j in ecx_utils.g_target_levels(i_target).file_start_pos..ecx_utils.g_target_levels(i_target).file_end_pos
112 loop
113
114 if ecx_utils.g_target(j).map_attribute_id is not null
115 then
116 /* Just assign the source data as it is to target */
117 ecx_utils.g_target(j).clob_value :=
118 ecx_utils.g_source(ecx_utils.g_target(j).map_attribute_id).clob_value;
119 ecx_utils.g_target(j).clob_length :=
120 ecx_utils.g_source(ecx_utils.g_target(j).map_attribute_id).clob_length;
121 ecx_utils.g_target(j).is_clob :=
122 ecx_utils.g_source(ecx_utils.g_target(j).map_attribute_id).is_clob;
123 ecx_utils.g_target(j).value :=
124 ecx_utils.g_source(ecx_utils.g_target(j).map_attribute_id).value;
125 end if;
126
127 If ecx_utils.g_target(j).clob_value is not null Then
128 if(l_statementEnabled) then
129 ecx_debug.log(l_statement,j||'=>'||ecx_utils.g_target(j).parent_attribute_id||'=>'||
130 ecx_utils.g_target(j).attribute_type||'=>'||
131 ecx_utils.g_target(j).attribute_name,ecx_utils.g_target(j).clob_value,
132 i_method_name);
133 end if;
134 else
135 -- if clob_value is null this means that it is varchar2
136 /** If the value is null then assign the target default value **/
137 If ecx_utils.g_target(j).value is null
138 then
139 ecx_utils.g_target(j).value := ecx_utils.g_target(j).default_value;
140 End if;
141 if(l_statementEnabled) then
142 ecx_debug.log(l_statement,j||'=>'||ecx_utils.g_target(j).parent_attribute_id||'=>'||
143 ecx_utils.g_target(j).attribute_type||'=>'||
144 ecx_utils.g_target(j).attribute_name,ecx_utils.g_target(j).value,
145 i_method_name);
146 end if;
147 End If;
148 if(l_statementEnabled) then
149 ecx_debug.log(l_statement,'ecx_utils.g_target('||j||') is_clob variable' ,ecx_utils.g_target(j).is_clob,
150 i_method_name);
151 end if;
152
153 end loop;
154
155
156 /** Execute the In-processing for the Target **/
157 if (i_target <> 0)
158 then
159 ecx_actions.execute_stage_data (20,i_target, 'T');
160 end if;
161
162 -- check if the data needs to be printed
163 if (ecx_utils.dom_printing)
164 then
165 -- update the DOM
166 updateDOM(i_target);
167 else
168 if (ecx_utils.structure_printing)
169 then
170 -- call the printing program
171 ecx_print_local.print_new_level
172 (
173 i_target,
174 ecx_utils.g_target_levels(i_target).dtd_node_index
175 );
176 end if;
177 end if;
178
179 /** Execute the Post-processing for the Target **/
180 if (i_target <> 0)
181 then
182 ecx_actions.execute_stage_data (30,i_target, 'T');
183 end if;
184 if (l_procedureEnabled) then
185 ecx_debug.pop(i_method_name);
186 end if;
187 exception
188 when ecx_utils.program_exit then
189 if (l_procedureEnabled) then
190 ecx_debug.pop(i_method_name);
191 end if;
192 raise ecx_utils.program_exit;
193 when others then
194 /* Start of bug# 2186635*/
195 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || ' - ECX_INBOUND.processTarget');
196 /* End of bug# 2186635 */
197 if(l_statementEnabled) then
198 ecx_debug.log(l_statement,'ECX', ecx_utils.i_errbuf || ' - ECX_INBOUND.processTarget',
199 i_method_name);
200 end if;
201 if (l_procedureEnabled) then
202 ecx_debug.pop(i_method_name);
203 end if;
204 raise ecx_utils.program_exit;
205 end processTarget;
206
207 procedure process_data
208 (
209 i IN pls_integer,
210 i_stage in pls_integer ,
211 i_next IN pls_integer
212 )
213 is
214 i_method_name varchar2(2000) := 'ecx_inbound. process_data';
215 begin
216
217 if (l_procedureEnabled) then
218 ecx_debug.push(i_method_name);
219 end if;
220
221 if(l_statementEnabled) then
222 ecx_debug.log(l_statement,'i',i,i_method_name);
223 ecx_debug.log(l_statement,'i_stage',i_stage,i_method_name);
224 ecx_debug.log(l_statement,'i_next',i_next,i_method_name);
225 end if;
226
227 if (i < 0)
228 then
229 if (l_procedureEnabled) then
230 ecx_debug.pop(i_method_name);
231 end if;
232 return;
233 end if;
234
235 if i_stage = 10
236 then
237 /** Should clean up the Current Source and the down levels first**/
238 for k in i..ecx_utils.g_source_levels.last
239 loop
240 for j in ecx_utils.g_source_levels(k).file_start_pos..ecx_utils.g_source_levels(k).file_end_pos
241 loop
242 ecx_utils.g_source(j).clob_value := null;
243 ecx_utils.g_source(j).is_clob := null;
244 ecx_utils.g_source(j).clob_length := null;
245 if ecx_utils.g_source(j).default_value is null
246 then
247 ecx_utils.g_source(j).value := null;
248 else
249 ecx_utils.g_source(j).value := ecx_utils.g_source(j).default_value;
250 end if;
251
252 if(l_statementEnabled) then
253 ecx_debug.log(l_statement,'Source '||ecx_utils.g_source(j).attribute_name,
254 ecx_utils.g_source(j).value,i_method_name);
255 end if;
256 end loop;
257 end loop;
258
259
260 -- For level 0 this is already done in Initialization
261 if (i <> 0)
262 then
263 /** Execute the pre-processing for the Source **/
264 ecx_actions.execute_stage_data (i_stage, i, 'S');
265 end if;
266 end if;
267
268 if i_stage = 20
269 then
270 -- For level 0 this is already done in Initialization
271 if (i <> 0)
272 then
273 /** Execute the In-processing for the Source **/
274 ecx_actions.execute_stage_data (i_stage, i, 'S');
275 end if;
276
277 for j in ecx_utils.g_source_levels(i).first_target_level .. ecx_utils.g_source_levels(i).last_target_level
278 loop
279 /** Initialize the Target **/
280 for k in ecx_utils.g_target_levels(j).file_start_pos..ecx_utils.g_target_levels(j).file_end_pos
281 loop
282 ecx_utils.g_target(k).clob_value := null;
283 ecx_utils.g_target(k).clob_length := null;
284 ecx_utils.g_target(k).is_clob := null;
285
286 if ecx_utils.g_target(k).default_value is null
287 then
288 ecx_utils.g_target(k).value := null;
289 else
290 ecx_utils.g_target(k).value := ecx_utils.g_target(k).default_value;
291 end if;
292
293 if(l_statementEnabled) then
294 ecx_debug.log(l_statement,'target '||ecx_utils.g_target(k).attribute_name,
295 ecx_utils.g_target(k).value,i_method_name);
296 end if;
297 end loop;
298
299 end loop;
300
301
302 /** Check for Collapsion. Do depth checking for Collapsion only **/
303 if(l_statementEnabled) then
304 ecx_debug.log(l_statement,'Previous Level',i,i_method_name);
305 ecx_debug.log(l_statement,'Current Level',i_next,I_method_name);
306 end if;
307 if ( ecx_utils.g_source_levels(i).last_source_level -
308 ecx_utils.g_source_levels(i).first_source_level > 0 )
309 then
310 if i_next > i
311 then
312 if ( i_next >= ecx_utils.g_source_levels(i).first_source_level )
313 and
314 ( i_next <= ecx_utils.g_source_levels(i).last_source_level )
315 then
316 if(l_statementEnabled) then
317 ecx_debug.log(l_statement,'Skipping Source',i,i_method_name);
318 end if;
319 else
320 processTarget(ecx_utils.g_source_levels(i).first_target_level);
321 end if;
322 end if;
323
324 if i_next <= i
325 then
326 processTarget(ecx_utils.g_source_levels(i).first_target_level);
327 end if;
328 else
329 /** Else Expansion or 1-1 mapping **/
330 for j in ecx_utils.g_source_levels(i).first_target_level .. ecx_utils.g_source_levels(i).last_target_level
331 loop
332 processTarget(j);
333 end loop;
334 end if;
335 end if;
336
337 if i_stage = 30
338 then
339 -- For level 0 this is will be done in the end
340 if (i <> 0)
341 then
342 /** Execute the Post-processing for the Source **/
343 ecx_actions.execute_stage_data (30, i, 'S');
344 end if;
345 end if;
346
347 if (l_procedureEnabled) then
348 ecx_debug.pop(i_method_name);
349 end if;
350 exception
351 when ecx_utils.program_exit then
352 if (l_procedureEnabled) then
353 ecx_debug.pop(i_method_name);
354 end if;
355 raise ecx_utils.program_exit;
356
357 when others then
358 if(l_statementEnabled) then
359 ecx_debug.log(l_statement,SQLERRM,i_method_name);
360 end if;
361 if (l_procedureEnabled) then
362 ecx_debug.pop(i_method_name);
363 end if;
364 raise ecx_utils.program_exit;
365 end process_data;
366
367
368 procedure print_stack
369 is
370 i_method_name varchar2(2000) := 'ecx_inbound.print_stack';
371 begin
372 if(l_statementEnabled) then
373 ecx_debug.log(l_statement,'Stack Status','====',i_method_name);
374 for i in 1..i_stack.COUNT
375 loop
376 ecx_debug.log(l_statement,i_stack(i),i_method_name);
377 end loop;
378 end if;
379 exception
380 when others then
381 if(l_statementEnabled) then
382 ecx_debug.log(l_statement,SQLERRM,i_method_name);
383 end if;
384 raise ecx_utils.program_exit;
385 end print_stack;
386
387 procedure pop
388 (
389 i_next in pls_integer
390 )
391 is
392 i_method_name varchar2(2000) := 'ecx_inbound.pop';
393 begin
394 if (l_procedureEnabled) then
395 ecx_debug.push(i_method_name);
396 end if;
397 if(l_statementEnabled) then
398 ecx_debug.log(l_statement,i_next,i_method_name);
399 print_stack;
400 end if;
401
402 if i_stack.COUNT = 0
403 then
404 if(l_statementEnabled) then
405 ecx_debug.log(l_statement,'Stack Error. Nothing to pop','xxxxx',i_method_name);
406 end if;
407 if (l_procedureEnabled) then
408 ecx_debug.pop(i_method_name);
409 end if;
410 return;
411 end if;
412
413 /** Post Process and then pop. **/
414 process_data(i_stack(i_stack.COUNT),30,i_next);
415
416 i_stack.delete(i_stack.COUNT);
417
418 if(l_statementEnabled) then
419 print_stack;
420 end if;
421
422 if (l_procedureEnabled) then
423 ecx_debug.pop(i_method_name);
424 end if;
425 exception
426 when ecx_utils.program_exit then
427 if (l_procedureEnabled) then
428 ecx_debug.pop(i_method_name);
429 end if;
430 raise ecx_utils.program_exit;
431 when others then
432 if(l_statementEnabled) then
433 ecx_debug.log(l_statement,SQLERRM,i_method_name);
434 end if;
435 if (l_procedureEnabled) then
436 ecx_debug.pop(i_method_name);
437 end if;
438 raise ecx_utils.program_exit;
439 end pop;
440
441 procedure push
442 (
443 i in pls_integer
444 )
445 is
446 i_method_name varchar2(2000) := 'ecx_inbound.push';
447 begin
448 if (l_procedureEnabled) then
449 ecx_debug.push(i_method_name);
450 end if;
451 if(l_statementEnabled) then
452 ecx_debug.log(l_statement,i,i_method_name);
453 print_stack;
454 end if;
455
456 if i_stack.COUNT = 0
457 then
458 -- Nothing on the Stack. Push the value
459 i_stack(i_stack.COUNT+1):=i;
460
461 /** pre stage processing **/
462 process_data(i_stack(i_stack.COUNT),10,i);
463
464 if(l_statementEnabled) then
465 print_stack;
466 end if;
467
468 if (l_procedureEnabled) then
469 ecx_debug.pop(i_method_name);
470 end if;
471 return;
472 end if;
473
474 if i > i_stack(i_stack.COUNT)
475 then
476
477 /** In stage processing **/
478 process_data(i_stack(i_stack.COUNT),20,i);
479
480 -- Push
481 i_stack(i_stack.COUNT+1):=i;
482
483 /** pre stage processing **/
484 process_data(i_stack(i_stack.COUNT),10,i);
485
486 if(l_statementEnabled) then
487 print_stack;
488 end if;
489
490 if (l_procedureEnabled) then
491 ecx_debug.pop(i_method_name);
492 end if;
493 return;
494 end if;
495
496 if i = i_stack(i_stack.COUNT)
497 then
498 /** In-Processing and then pop the Top Entry. **/
499 process_data(i_stack(i_stack.COUNT),20,i);
500 pop(i);
501 end if;
502
503 if i_stack.COUNT <> 0
504 then
505 if i < i_stack(i_stack.COUNT)
506 then
507
508 /** In-Processing and then pop the Top Entry. **/
509 process_data(i_stack(i_stack.COUNT),20,i);
510 pop(i);
511
512 /** Pop The rest of the Elements **/
513 while ( i <= i_stack(i_stack.COUNT) )
514 loop
515 pop(i);
516 exit when i_stack.COUNT = 0;
517 end loop;
518
519 end if;
520 end if;
521
522 -- Push the value
523 i_stack(i_stack.COUNT+1):=i;
524 /** pre stage processing **/
525 process_data(i_stack(i_stack.COUNT),10,i);
526
527 if(l_statementEnabled) then
528 print_stack;
529 end if;
530
531 if (l_procedureEnabled) then
532 ecx_debug.pop(i_method_name);
533 end if;
534 exception
535 when ecx_utils.program_exit then
536 if (l_procedureEnabled) then
537 ecx_debug.pop(i_method_name);
538 end if;
539 raise ecx_utils.program_exit;
540 when others then
541 if(l_statementEnabled) then
542 ecx_debug.log(l_statement,SQLERRM,i_method_name);
543 end if;
544 if (l_procedureEnabled) then
545 ecx_debug.pop(i_method_name);
546 end if;
547 raise ecx_utils.program_exit;
548 end push;
549
550
551 procedure popall
552 is
553 i_method_name varchar2(2000) := 'ecx_inbound.popall';
554 begin
555 if (l_procedureEnabled) then
556 ecx_debug.push(i_method_name);
557 end if;
558 /** In-Process the last Level on the Stack **/
559 if i_stack.COUNT <> 0
560 then
561 process_data(i_stack(i_stack.COUNT),20,0);
562 end if;
563
564 if(l_statementEnabled) then
565 print_stack;
566 end if;
567
568 while ( i_stack.COUNT > 0)
569 loop
570 pop(0);
571 end loop;
572
573 if(l_statementEnabled) then
574 print_stack;
575 end if;
576
577 if (l_procedureEnabled) then
578 ecx_debug.pop(i_method_name);
579 end if;
580 exception
581 when ecx_utils.program_exit then
582 if (l_procedureEnabled) then
583 ecx_debug.pop(i_method_name);
584 end if;
585 raise ecx_utils.program_exit;
586 when others then
587 if(l_statementEnabled) then
588 ecx_debug.log(l_statement,SQLERRM,i_method_name);
589 end if;
590 if (l_procedureEnabled) then
591 ecx_debug.pop(i_method_name);
592 end if;
593 raise ecx_utils.program_exit;
594 end popall;
595
596 procedure start_level(
597 p_node_pos IN Varchar2) IS
598
599 i_method_name varchar2(2000) := 'ecx_inbound.start_level';
600
601 l_match Boolean := false;
602 i pls_integer;
603
604 BEGIN
605
606 if (l_procedureEnabled) then
607 ecx_debug.push(i_method_name);
608 end if;
609 if(l_statementEnabled) then
610 ecx_debug.log(l_statement,'p_node_pos', p_node_pos,i_method_name);
611 end if;
612
613 if (p_node_pos >= 0)
614 then
615 if (ecx_utils.g_source_levels.count <> 0)
616 then
617 for i in ecx_utils.g_source_levels.first..ecx_utils.g_source_levels.last
618 loop
619 if (ecx_utils.g_source_levels(i).dtd_node_index = p_node_pos)
620 then
621 ecx_utils.g_current_level := ecx_utils.g_source_levels(i).level;
622 push(ecx_utils.g_source_levels(i).level);
623 l_match := True;
624 if(l_statementEnabled) then
625 ecx_debug.log(l_statement,'l_match', l_match,i_method_Name);
626 end if;
627 exit;
628 end if;
629 end loop;
630 end if;
631 end if;
632 ecx_utils.g_previous_level := ecx_utils.g_current_level;
633
634 if (l_procedureEnabled) then
635 ecx_debug.pop(i_method_name);
636 end if;
637
638 EXCEPTION
639 WHEN ecx_utils.program_exit then
640 if (l_procedureEnabled) then
641 ecx_debug.pop(i_method_name);
642 end if;
643 raise;
644
645 WHEN others then
646 if(l_statementEnabled) then
647 ecx_debug.log(l_statement, 'ECX', 'ECX_PROGRAM_ERROR',i_method_name,
648 'PROGRESS_LEVEL',
649 'ECX_INBOUND.START_LEVEL');
650 ecx_debug.log(l_statement, 'ECX', 'ECX_ERROR_MESSAGE',i_method_name, 'ERROR_MESSAGE', SQLERRM);
651 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' ECX_INBOUND.START_LEVEL',
652 i_method_name);
653 end if;
654 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' ECX_INBOUND.START_LEVEL');
655 if (l_procedureEnabled) then
656 ecx_debug.pop(i_method_name);
657 end if;
658 raise ecx_utils.program_exit;
659
660 END start_level;
661
662
663 function get_node_id (
664 p_node IN xmldom.DOMNode,
665 p_node_name IN Varchar2,
666 p_parent_node_id IN pls_integer,
667 p_parent_node_pos IN pls_integer,
668 p_occur IN pls_integer,
669 x_node_pos OUT NOCOPY pls_integer,
670 x_parent_id IN OUT NOCOPY pls_integer) return pls_integer IS
671
672 i_method_name varchar2(2000) := 'ecx_inbound.get_node_id';
673
674 i pls_integer;
675 l_node_id pls_integer := -1;
676 p_cond_node Varchar2(200);
677 p_cond_node_type pls_integer;
678 l_value Varchar2(4000) := null;
679
680 l_node_list xmldom.DOMNodeList;
681 l_text_node xmldom.DOMNode;
682 l_tmp_node xmldom.DOMNode;
683 l_element xmldom.DOMElement;
684 l_node_parent_map_id pls_integer;
685 x_parent_node_map_id pls_integer;
686 i_parent_node_pos pls_integer;
687
688 BEGIN
689 if (l_procedureEnabled) then
690 ecx_debug.push(i_method_name);
691 end if;
692
693
694 if(l_statementEnabled) then
695 ecx_debug.log(l_statement, 'p_node_name', p_node_name,i_method_name);
696 ecx_debug.log(l_statement, 'p_parent_node_id', p_parent_node_id,i_method_name);
697 ecx_debug.log(l_statement, 'p_parent_node_pos', p_parent_node_pos,i_method_name);
698 ecx_debug.log(l_statement, 'p_occur', p_occur,i_method_name);
699 ecx_debug.log(l_statement, 'No of Elements in Source', ecx_utils.g_source.count,i_method_name);
700 ecx_debug.log(l_statement, 'parent_node_map_id', x_parent_node_map_id,i_method_name);
701 end if;
702 x_node_pos := -1;
703 i_parent_node_pos := p_parent_node_pos;
704
705 if (p_parent_node_id >= 0) then
706 /*
707 for i in p_parent_node_pos+1..ecx_utils.g_source.count loop
708 ecx_debug.log(l_statement, 'Node ',ecx_utils.g_source(i).attribute_name) ;
709 ecx_debug.log(l_statement, 'Parent Attr', ecx_utils.g_source(i).parent_attribute_id);
710 end loop;
711 */
712 if(p_parent_node_pos < 0) then
713 i_parent_node_pos := 0;
714 end if;
715 for i in i_parent_node_pos..ecx_utils.g_source.last
716 loop
717 if (ecx_utils.g_source(i).attribute_name = p_node_name) and
718 (ecx_utils.g_source(i).parent_attribute_id = p_parent_node_id)
719 then
720 -- ecx_debug.log(l_statement, 'parent_map_id',
721 -- ecx_utils.g_source(i).parent_node_map_id || ' : ' || i);
722 p_cond_node := ecx_utils.g_source(i).cond_node;
723 p_cond_node_type := ecx_utils.g_source(i).cond_node_type;
724 -- l_node_parent_map_id := ecx_utils.g_source(i).parent_node_map_id;
725
726 if (p_cond_node is not null) then
727 if(l_statementEnabled) then
728 ecx_debug.log(l_statement, 'p_cond_node', p_cond_node,i_method_name);
729 ecx_debug.log(l_statement, 'p_cond_node_type', p_cond_node_type,i_method_name);
730 end if;
731 -- need to get the value for the condition node
732 -- only if we haven't get it.
733 if (l_value is null) then
734 l_element := xmldom.makeElement(p_node);
735 if (p_cond_node_type = 1) then
736 l_node_list := xmldom.getElementsByTagName(l_element, p_cond_node);
737 l_tmp_node := xmldom.item(l_node_list, 0);
738 l_text_node := xmldom.getFirstChild(l_tmp_node);
739 l_value := xmldom.getNodeValue(l_text_node);
740
741 elsif (p_cond_node_type = 2) then
742 l_value := xmldom.getAttribute(l_element, p_cond_node);
743 end if;
744 end if;
745
746 if(l_statementEnabled) then
747 ecx_debug.log(l_statement, 'l_value', l_value,i_method_name);
748 end if;
749 -- find the mapping that match the condition.
750 if (l_value = ecx_utils.g_source(i).cond_value) then
751 /*
752 if ( x_parent_node_map_id is null) or
753 ( x_parent_node_map_id = l_node_parent_map_id ) then
754 */
755 if ( p_parent_node_id = ecx_utils.g_source(i).parent_attribute_id )
756 then
757 --x_parent_node_map_id := ecx_utils.g_source(i).dtd_node_map_id;
758 x_node_pos := i;
759 l_node_id := ecx_utils.g_source(i).attribute_id;
760 exit;
761 end if;
762 end if;
763
764 -- there is no conditional mapping. This is a mapping
765 -- depends on the occurrence.
766 elsif
767 /*
768 (x_parent_node_map_id is null) and
769 */
770 ((ecx_utils.g_source(i).occurrence is null) or
771 (p_occur = ecx_utils.g_source(i).occurrence)) then
772 x_node_pos := i;
773 l_node_id := ecx_utils.g_source(i).attribute_id;
774 exit;
775 elsif (l_node_id = p_parent_node_id) then
776 x_node_pos := i;
777 l_node_id := ecx_utils.g_source(i).attribute_id;
778 exit;
779 end if;
780 end if;
781 end loop;
782
783 if(l_statementEnabled) then
784 ecx_debug.log(l_statement, 'l_node_id', l_node_id,i_method_name);
785 ecx_debug.log(l_statement, 'x_node_pos', x_node_pos,i_method_name);
786 ecx_debug.log(l_statement, 'x_parent_node_map_id', x_parent_node_map_id,i_method_name);
787 end if;
788 end if;
789
790 if(l_statementEnabled) then
791 ecx_debug.log(l_statement, 'l_node_id', l_node_id,i_method_name);
792 ecx_debug.log(l_statement, 'x_node_pos', x_node_pos,i_method_name);
793 ecx_debug.log(l_statement, 'x_parent_node_map_id', x_parent_node_map_id,i_method_name);
794 end if;
795 if (l_procedureEnabled) then
796 ecx_debug.pop(i_method_name);
797 end if;
798 return (l_node_id);
799
800 EXCEPTION
801 WHEN ecx_utils.program_exit then
802 if (l_procedureEnabled) then
803 ecx_debug.pop(i_method_name);
804 end if;
805 raise;
806
807 WHEN others then
808 if(l_statementEnabled) then
809 ecx_debug.log(l_statement,'ECX', 'ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
810 'ECX_INBOUND.GET_NODE_ID');
811 ecx_debug.log(l_statement, 'ECX', 'ECX_ERROR_MESSAGE',i_method_name, 'ERROR_MESSAGE', SQLERRM);
812 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.GET_NODE_ID: ',
813 i_method_name);
814 end if;
815 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.GET_NODE_ID: ');
816 if (l_procedureEnabled) then
817 ecx_debug.pop(i_method_name);
818 end if;
819 raise ecx_utils.program_exit;
820
821 END get_node_id;
822
823
824 procedure process_node (
825 p_int_col_pos IN pls_integer,
826 p_node IN OUT NOCOPY xmldom.DOMNode,
827 p_is_attribute IN Boolean) IS
828
829
830 i_method_name varchar2(2000) := 'ecx_inbound.process_node';
831
832 l_value Varchar2(4000);
833 l_cat_id pls_integer;
834 l_return_status Varchar2(1);
835 l_msg_count pls_integer;
836 l_msg_data Varchar2(2000);
837 l_text_node xmldom.DOMNode;
838
839 BEGIN
840 if (l_procedureEnabled) then
841 ecx_debug.push(i_method_name);
842 end if;
843
844 if (p_is_attribute) then
845 l_text_node := p_node;
846 else
847 l_text_node := xmldom.getFirstChild(p_node);
848 end if;
849
850 if not (xmldom.isnull(l_text_node))
851 then
852 l_value := xmldom.getNodeValue(l_text_node);
853 if(l_statementEnabled) then
854 ecx_debug.log(l_statement, 'p_int_col_pos', p_int_col_pos,i_method_name);
855 ecx_debug.log(l_statement, 'node value', l_value,i_method_name);
856 end if;
857
858 l_cat_id := ecx_utils.g_source(p_int_col_pos).xref_category_id;
859
860 if (l_cat_id is not null) then
861 ecx_code_conversion_pvt.convert_external_value
862 (
863 p_api_version_number => 1.0,
864 p_return_status => l_return_status,
865 p_msg_count => l_msg_count,
866 p_msg_data => l_msg_data,
867 p_value => l_value,
868 p_category_id => l_cat_id,
869 p_snd_tp_id => ecx_utils.g_snd_tp_id,
870 p_rec_tp_id => ecx_utils.g_rec_tp_id ,
871 p_standard_id => ecx_utils.g_standard_id
872 );
873
874 If l_return_status = 'X' OR l_return_status = 'R' Then
875 ecx_utils.g_source(p_int_col_pos).xref_retcode := 1;
876 else
877 ecx_utils.g_source(p_int_col_pos).xref_retcode := 0;
878 end if;
879
880 if(l_statementEnabled) then
881 ecx_debug.log(l_statement, 'xref return code',
882 ecx_utils.g_source(p_int_col_pos).xref_retcode,i_method_name);
883 end if;
884
885 if (l_return_status = ecx_code_conversion_pvt.G_RET_STS_ERROR) or
886 (l_return_status = ecx_code_conversion_pvt.G_RET_STS_UNEXP_ERROR) or
887 (l_return_status = ECX_CODE_CONVERSION_PVT.g_xref_not_found) then
888 if(l_statementEnabled) then
889 ecx_debug.log(l_statement, 'Code Conversion uses the original code.',i_method_name);
890 end if;
891 else
892 if (l_return_status = ECX_CODE_CONVERSION_PVT.g_recv_xref_not_found) then
893 if(l_statementEnabled) then
894 ecx_debug.log(l_statement, 'Code Conversion uses the sender converted value', l_value,i_method_name);
895 end if;
896 end if;
897
898 -- only update the dom if there is code conversion.
899 -- this is only useful for passthrough document and
900 -- we only transmit what we receive plus the code conversion
901 -- if it is a pass through document.
902
903 if(l_statementEnabled) then
904 ecx_debug.log(l_statement, 'node value', l_value,i_method_name);
905 end if;
906 -- update the DOM only if the valus is not null
907 if (l_value is not null) then
908 xmldom.setNodeValue (l_text_node, l_value);
909 end if;
910 end if;
911 end if;
912
913 ecx_utils.g_source(p_int_col_pos).value := l_value;
914
915 if(l_statementEnabled) then
916 ecx_debug.log(l_statement,ecx_utils.g_source(p_int_col_pos).attribute_name ,
917 ecx_utils.g_source(p_int_col_pos).value||' '||
918 ecx_utils.g_source(p_int_col_pos).base_column_name||' '||' '||
919 p_int_col_pos,i_method_name);
920 end if;
921 end if;
922 if (l_procedureEnabled) then
923 ecx_debug.pop(i_method_name);
924 end if;
925
926 EXCEPTION
927 WHEN value_error then
928 ecx_debug.setErrorInfo(2, 30, 'ECX_INVALID_VARCHAR2_LEN');
929 if(l_statementEnabled) then
930 ecx_debug.log(l_statement, ecx_utils.i_errbuf,i_method_name);
931 end if;
932 if (l_procedureEnabled) then
933 ecx_debug.pop(i_method_name);
934 end if;
935 raise ecx_utils.program_exit;
936 WHEN no_data_found then
937 if(l_statementEnabled) then
938 ecx_debug.log(l_statement,'Internal Column Position and Level not mapped for',p_int_col_pos,
939 i_method_name);
940 end if;
941 if (l_procedureEnabled) then
942 ecx_debug.pop(i_method_name);
943 end if;
944 raise ecx_utils.program_exit;
945 WHEN ecx_utils.program_exit then
946 if (l_procedureEnabled) then
947 ecx_debug.pop(i_method_name);
948 end if;
949 raise;
950 WHEN others then
951 if(l_statementEnabled) then
952 ecx_debug.log(l_statement, 'ECX', 'ECX_PROGRAM_ERROR', i_method_name,
953 'PROGRESS_LEVEL',
954 'ECX_INBOUND.PROCESS_NODE');
955 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.PROCESS_NODE: ',
956 i_method_name);
957 end if;
958 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.PROCESS_NODE: ');
959
960 if (l_procedureEnabled) then
961 ecx_debug.pop(i_method_name);
962 end if;
963 raise ecx_utils.program_exit;
964
965 END process_node;
966
967
968 procedure process_attributes (
969 p_node IN OUT NOCOPY xmldom.DOMNode,
970 p_node_id IN pls_integer,
971 p_occur IN pls_integer,
972 p_node_pos IN pls_integer,
973 x_parent_node_map_id IN OUT NOCOPY pls_integer) IS
974
975
976 i_method_name varchar2(2000) := 'ecx_inbound.process_attributes';
977
978 l_attr_node_name Varchar2(80);
979 l_attr_nodemap xmldom.DOMNamedNodeMap;
980 l_num_of_attr pls_integer;
981 l_attr_node_id pls_integer;
982 l_int_col_pos pls_integer;
983 l_attr_node xmldom.DOMNode;
984 l_attr_node_pos pls_integer;
985 i pls_integer := 1;
986
987 BEGIN
988
989 if (l_procedureEnabled) then
990 ecx_debug.push(i_method_name);
991 end if;
992 if(l_statementEnabled) then
993 ecx_debug.log(l_statement, 'p_node_id', p_node_id,i_method_name);
994 ecx_debug.log(l_statement, 'p_occur', p_occur,i_method_name);
995 ecx_debug.log(l_statement, 'p_node_pos', p_node_pos,i_method_name);
996 ecx_debug.log(l_statement, 'x_parent_node_map_id', x_parent_node_map_id,i_method_name);
997 end if;
998 l_attr_nodemap := xmldom.getAttributes(p_node);
999
1000 l_num_of_attr := xmldom.getLength(l_attr_nodemap);
1001 if(l_statementEnabled) then
1002 ecx_debug.log(l_statement,'num_of_attributes', l_num_of_attr,i_method_name);
1003 end if;
1004
1005 while (i <= l_num_of_attr) loop
1006 if(l_statementEnabled) then
1007 ecx_debug.log(l_statement, 'i', i,i_method_name);
1008 end if;
1009 l_int_col_pos := 0;
1010 l_attr_node := xmldom.item(l_attr_nodemap, i-1);
1011 l_attr_node_name := xmldom.getNodeName(l_attr_node);
1012 if(l_statementEnabled) then
1013 ecx_debug.log(l_statement, 'l_attr_node_name', l_attr_node_name,i_method_name);
1014 end if;
1015
1016 l_attr_node_id := get_node_id (l_attr_node, l_attr_node_name,
1017 p_node_id, p_node_pos, p_occur,
1018 l_attr_node_pos, x_parent_node_map_id);
1019 if(l_statementEnabled) then
1020 ecx_debug.log(l_statement, 'l_attr_node_id', l_attr_node_id,i_method_name);
1021 end if;
1022
1023 -- if we find a mapping for the attribute node, then
1024 -- we assign the value
1025 if (l_attr_node_id > 0)
1026 then
1027 process_node (l_attr_node_id, l_attr_node, True);
1028 end if;
1029 i := i+1;
1030 end loop;
1031
1032 if (l_procedureEnabled) then
1033 ecx_debug.pop(i_method_name);
1034 end if;
1035
1036
1037 EXCEPTION
1038 WHEN ecx_utils.program_exit then
1039 if (l_procedureEnabled) then
1040 ecx_debug.pop(i_method_name);
1041 end if;
1042 raise;
1043
1044 WHEN others then
1045 if(l_statementEnabled) then
1046 ecx_debug.log(l_statement,'ECX', 'ECX_PROGRAM_ERROR', i_method_name,'PROGRESS_LEVEL',
1047 'ECX_INBOUND.PROCESS_ATTRIBUTES');
1048 ecx_debug.log(l_statement, 'ECX', 'ECX_ERROR_MESSAGE', i_method_name,'ERROR_MESSAGE', SQLERRM);
1049 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.PROCESS_ATTRIBUTES: ',
1050 i_method_name);
1051 end if;
1052 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.PROCESS_ATTRIBUTES: ');
1053 if (l_procedureEnabled) then
1054 ecx_debug.pop(i_method_name);
1055 end if;
1056 raise ecx_utils.program_exit;
1057
1058 END process_attributes;
1059
1060
1061 procedure get_root_info (
1062 p_doc IN xmldom.DOMDocument,
1063 p_map_id IN pls_integer,
1064 x_root_node_id OUT NOCOPY pls_integer,
1065 x_root_node OUT NOCOPY xmldom.DOMNode) IS
1066
1067 i_method_name varchar2(2000) := 'ecx_inbound.get_root_info';
1068
1069 cursor get_root_elmt (
1070 p_map_id IN pls_integer) IS
1071 select eo.root_element,
1072 0
1073 from ecx_mappings em,
1074 ecx_objects eo
1075 where em.map_id = p_map_id
1076 and em.map_id = eo.map_id
1077 and em.object_id_source = eo.object_id;
1078
1079 l_root_elmt_name Varchar2(80);
1080 l_node_list xmldom.DOMNodeList;
1081 l_root_node xmldom.DOMNode;
1082 no_map_root EXCEPTION;
1083
1084 BEGIN
1085 if (l_procedureEnabled) then
1086 ecx_debug.push(i_method_name);
1087 end if;
1088 -- get the root node.
1089 open get_root_elmt (p_map_id);
1090 fetch get_root_elmt into l_root_elmt_name, x_root_node_id;
1091 if(l_statementEnabled) then
1092 ecx_debug.log(l_statement,'root_element',l_root_elmt_name,i_method_name);
1093 end if;
1094
1095 if get_root_elmt%NOTFOUND then
1096 raise no_map_root;
1097 else
1098 close get_root_elmt;
1099 end if;
1100
1101 l_node_list := xmldom.getElementsByTagName (p_doc, l_root_elmt_name);
1102 x_root_node := xmldom.item (l_node_list, 0);
1103 if (l_procedureEnabled) then
1104 ecx_debug.pop(i_method_name);
1105 end if;
1106
1107
1108 EXCEPTION
1109 WHEN no_map_root then
1110 ecx_debug.setErrorInfo(1, 30, 'ECX_ROOT_INFO_NOT_FOUND');
1111 if(l_statementEnabled) then
1112 ecx_debug.log(l_statement, 'ECX', 'ECX_ROOT_INFO_NOT_FOUND', i_method_name);
1113 end if;
1114 close get_root_elmt;
1115 if (l_procedureEnabled) then
1116 ecx_debug.pop(i_method_name);
1117 end if;
1118 raise ecx_utils.program_exit;
1119
1120 WHEN OTHERS THEN
1121 if(l_statementEnabled) then
1122 ecx_debug.log(l_statement, 'ECX', 'ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
1123 'ECX_INBOUND.GET_ROOT_INFO');
1124 ecx_debug.log(l_statement, 'ECX', 'ECX_ERROR_MESSAGE',i_method_name ,'ERROR_MESSAGE', SQLERRM);
1125 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.GET_ROOT_INFO: ',i_method_name);
1126 end if;
1127 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_INBOUND.GET_ROOT_INFO: ');
1128 if (l_procedureEnabled) then
1129 ecx_debug.pop(i_method_name);
1130 end if;
1131 raise ecx_utils.program_exit;
1132 END get_root_info;
1133
1134
1135 /**
1136 Does the initial setup for structure transformation
1137 **/
1138 procedure structurePrintingSetup
1139 (
1140 i_root_name IN OUT NOCOPY varchar2
1141 )
1142 is
1143
1144 i_method_name varchar2(2000) := 'ecx_inbound.structurePrintingSetup';
1145
1146 i_filename varchar2(200);
1147
1148 begin
1149 if (l_procedureEnabled) then
1150 ecx_debug.push(i_method_name);
1151 end if;
1152
1153 begin
1154 SELECT root_element,
1155 fullpath
1156 INTO i_root_name,
1157 i_filename
1158 FROM ecx_objects eo
1159 WHERE eo.map_id = ecx_utils.g_map_id
1160 AND eo.object_type in ('DTD','XML')
1161 AND eo.object_id = 2;
1162 exception
1163 when others then
1164 ecx_debug.setErrorInfo(2, 30, 'ECX_ROOT_ELEMENT_NOT_FOUND', 'MAP_ID', ecx_utils.g_map_id);
1165 if(l_statementEnabled) then
1166 ecx_debug.log(l_statement,'ECX', 'ECX_ROOT_ELEMENT_NOT_FOUND',i_method_name, 'MAP_ID', ecx_utils.g_map_id);
1167 end if;
1168 if (l_procedureEnabled) then
1169 ecx_debug.pop(i_method_name);
1170 end if;
1171 raise ecx_utils.program_exit;
1172 end;
1173
1174 -- initialize the temporary buffers
1175 ecx_print_local.i_tmpxml.DELETE;
1176 ecx_print_local.l_node_stack.DELETE;
1177
1178 -- PI Node
1179 ecx_print_local.pi_node ('xml', 'version = "1.0" standalone="no" ');
1180
1181 -- comment node
1182 ecx_print_local.comment_node('Oracle eXtensible Markup Language Gateway Server');
1183
1184 -- document node
1185 ecx_print_local.document_node(i_root_name, i_filename, null);
1186
1187 if (l_procedureEnabled) then
1188 ecx_debug.pop(i_method_name);
1189 end if;
1190 end structurePrintingSetup;
1191
1192 /**
1193 Reads the elements from the i_tmpxml stack and writes them
1194 to a CLOB.
1195 **/
1196 procedure getXMLDoc
1197
1198 is
1199
1200 i_method_name varchar2(2000) := 'ecx_inbound.getXMLDoc';
1201 i_writeamount number;
1202 i_temp varchar2(32767);
1203 apnd_status Boolean := FALSE;
1204 i_xmlDOc CLOB;
1205 begin
1206 if (l_procedureEnabled) then
1207 ecx_debug.push(i_method_name);
1208 end if;
1209
1210 -- write the xml from the printing program to a CLOB
1211 dbms_lob.createtemporary(i_xmldoc, TRUE,DBMS_LOB.SESSION);
1212
1213 i_writeamount := 0;
1214 i_temp := '';
1215
1216 for i in 1..ecx_print_local.i_tmpxml.COUNT
1217 loop
1218 -- check for the element length
1219 i_writeamount := length(ecx_print_local.i_tmpxml(i));
1220 -- set append status to true
1221 apnd_status := true;
1222 -- check if temp buffer is full
1223 if (i_writeamount + length(i_temp) > 32000) then
1224 if(l_statementEnabled) then
1225 ecx_debug.log(l_statement,'Buffer Length', to_char(length(i_temp)),i_method_name);
1226 end if;
1227 dbms_lob.writeappend(i_xmldoc,length(i_temp), i_temp);
1228 if(l_statementEnabled) then
1229 ecx_debug.log(l_statement, i_temp,i_method_name);
1230 end if;
1231 apnd_status := false;
1232 i_temp := '';
1233 i_temp := ecx_print_local.i_tmpxml(i);
1234 else
1235 -- add new entry
1236 i_temp := i_temp || ecx_print_local.i_tmpxml(i);
1237 end if;
1238 end loop;
1239
1240 -- check if last append is needed
1241 if (apnd_status) then
1242 dbms_lob.writeappend(i_xmldoc, length(i_temp), i_temp);
1243 if(l_statementEnabled) then
1244 ecx_debug.log(l_statement, i_temp,i_method_name);
1245 end if;
1246 end if;
1247 if(l_statementEnabled) then
1248 ecx_debug.log(l_statement,'inbound clob before parsing',dbms_lob.getLength(i_xmldoc),i_method_name);
1249 ecx_debug.log(l_statement,'Clob Data is ', i_xmldoc,i_method_name);
1250 end if;
1251
1252 -- Parser from the CLOB
1253 xmlparser.parseCLOB(ecx_utils.g_inb_parser, i_xmldoc);
1254 ecx_utils.g_xmldoc := xmlDOM.makeNode(xmlparser.getDocument(ecx_utils.g_inb_parser));
1255 dbms_lob.trim(i_xmldoc, 0);
1256 xmlDOM.writetoCLOB(ecx_utils.g_xmldoc,i_xmldoc);
1257 if(l_statementEnabled) then
1258 ecx_debug.log(l_statement,'inbound clob after parsing',dbms_lob.getLength(i_xmldoc),i_method_name);
1259 ecx_debug.log(l_statement,'Clob Data is ',i_xmldoc,i_method_name);
1260 end if;
1261
1262 if (l_procedureEnabled) then
1263 ecx_debug.pop(i_method_name);
1264 end if;
1265
1266 end getXMLDoc;
1267
1268
1269 /**
1270 ** This procedure is traversing the XML Document tree and
1271 ** put the value into the ecx_utils.g_file_tbl.
1272 ** First, it tries to see the tag name match one of the mapped
1273 ** level start element.
1274 ** If it doesn't match, then go on to its children.
1275 ** If it match, then
1276 ** -- clean up the g_file_tbl from current matched
1277 ** level to all levels below.
1278 ** -- assign value from DOM tree to g_file_tbl.
1279 ** -- call inbound engine when get the next match tag.
1280 ** For the last level of data, this will never get processed by inbound
1281 ** engine since it never gets the next match tag.
1282 ** So, this procedure needs to process the last level at the end.
1283 **/
1284
1285 procedure process_xml_doc (
1286 p_doc IN xmldom.DOMDocument,
1287 p_map_id IN pls_integer,
1288 p_snd_tp_id IN pls_integer,
1289 p_rec_tp_id IN pls_integer,
1290 x_xmlclob OUT NOCOPY clob,
1291 x_parseXML OUT NOCOPY boolean
1292 ) is
1293
1294 i_method_name varchar2(2000) := 'ecx_inbound.process_xml_doc';
1295
1296 l_root_node xmldom.DOMNode;
1297 l_root_element xmldom.DOMElement;
1298 l_node_list xmldom.DOMNodeList;
1299 l_num_of_nodes pls_integer;
1300 node_info_stack node_info_tbl;
1301 l_node xmldom.DOMNode;
1302 l_node_name Varchar2(200);
1303 l_parent_node_map_id pls_integer ;
1304 l_node_id pls_integer := -1;
1305 l_node_pos pls_integer;
1306 l_col_pos pls_integer;
1307 l_children xmldom.DOMNodeList;
1308 l_num_of_child pls_integer;
1309 l_tmp_num_child pls_integer;
1310 l_child xmldom.DOMNode;
1311 l_child_node_type pls_integer;
1312 l_stack_indx pls_integer := 1;
1313 l_next_pos pls_integer;
1314 l_attributes xmldom.DOMNamedNodeMap;
1315 l_num_of_attr pls_integer;
1316 i pls_integer;
1317 i_root_name varchar2(200);
1318
1319 BEGIN
1320 if (l_procedureEnabled) then
1321 ecx_debug.push(i_method_name);
1322 end if;
1323 if(l_statementEnabled) then
1324 ecx_debug.log(l_statement,'p_map_id', p_map_id,i_method_name);
1325 ecx_debug.log(l_statement, 'p_snd_tp_id', p_snd_tp_id,i_method_name);
1326 ecx_debug.log(l_statement, 'p_rec_tp_id', p_rec_tp_id,i_method_name);
1327 end if;
1328 ecx_utils.g_snd_tp_id := p_snd_tp_id;
1329 ecx_utils.g_rec_tp_id := p_rec_tp_id;
1330 ecx_utils.g_previous_level := 0;
1331 /** Initialize the Stack for the Levels **/
1332 i_stack.DELETE;
1333 i_current_depth :=0;
1334
1335 -- Execute the Stage 10 for Level 0
1336
1337 -- In-processing for Document level Source Side
1338 ecx_actions.execute_stage_data(20,0,'S');
1339
1340 -- In-processing for Document level
1341 ecx_actions.execute_stage_data(20,0,'T');
1342
1343 get_root_info (p_doc, p_map_id, node_info_stack(l_stack_indx).parent_node_id,
1344 l_root_node);
1345 l_root_element := xmldom.makeElement(l_root_node);
1346 -- if necessary initialize the printing
1347 if (not (ecx_utils.dom_printing) AND (ecx_utils.structure_printing))
1348 then
1349 structurePrintingSetup(i_root_name);
1350 end if;
1351
1352 if (node_info_stack(l_stack_indx).parent_node_id is null or
1353 node_info_stack(l_stack_indx).parent_node_id = 0) then
1354 l_next_pos := 0;
1355 else
1356 l_next_pos := ecx_utils.g_source_levels(1).dtd_node_index - 2;
1357 end if;
1358
1359 node_info_stack(l_stack_indx).occur := 1;
1360 -- node_info_stack(l_stack_indx).parent_node_map_id := null;
1361 node_info_stack(l_stack_indx).pre_child_name := null;
1362 node_info_stack(l_stack_indx).siblings := 0;
1363
1364 /* Start of changes for Bug 4587719. Processing for the root node sepeartely */
1365 l_node := l_root_node;
1366 l_node_name := xmldom.getNodeName(l_node);
1367
1368 if(l_statementEnabled) then
1369 ecx_debug.log(l_statement,'l_node_name', l_node_name,i_method_name);
1370 ecx_debug.log(l_statement, 'l_stack_indx', l_stack_indx,i_method_name);
1371 ecx_debug.log(l_statement, 'pre_child_name', node_info_stack(l_stack_indx).pre_child_name,i_method_name);
1372 end if;
1373 node_info_stack(l_stack_indx).parent_node_pos := l_next_pos;
1374 node_info_stack(l_stack_indx).pre_child_name := l_node_name;
1375
1376 if(l_statementEnabled) then
1377 ecx_debug.log(l_statement, 'Stack(l_stack_indx)', node_info_stack(l_stack_indx).parent_node_id||
1378 '-'|| node_info_stack(l_stack_indx).parent_node_pos||'-'|| node_info_stack(l_stack_indx).pre_child_name
1379 ||'-'|| node_info_stack(l_stack_indx).siblings||'-'|| node_info_stack(1).occur, i_method_name);
1380 end if;
1381
1382 l_node_id := get_node_id (l_node, l_node_name,
1383 node_info_stack(l_stack_indx).parent_node_id,
1384 node_info_stack(l_stack_indx).parent_node_pos,
1385 node_info_stack(l_stack_indx).occur,
1386 l_node_pos,
1387 l_parent_node_map_id);
1388 if(l_statementEnabled) then
1389 ecx_debug.log(l_statement,'l_node_id', l_node_id,i_method_name);
1390 end if;
1391
1392 start_level(l_node_pos);
1393 l_num_of_child := 0;
1394
1395 if (ecx_utils.dom_printing)
1396 then
1397 -- store the reference to the Node objects that are mapped so that they can
1398 -- be retrieved later when updating the DOM
1399 if (ecx_utils.g_source(l_node_id).map_attribute_id is not null)
1400 then
1401 ecx_utils.g_node_tbl(l_node_id) := l_node;
1402 if(l_statementEnabled) then
1403 ecx_debug.log(l_statement, 'put on xml node stack', l_node_id,i_method_name);
1404 end if;
1405 end if;
1406 end if;
1407
1408 if (ecx_utils.g_source(l_node_pos).has_attributes >0 )
1409 then
1410 process_attributes (l_node, l_node_id,
1411 node_info_stack(l_stack_indx).occur, l_node_pos,
1412 l_parent_node_map_id);
1413 end if;
1414
1415 if(l_statementEnabled) then
1416 ecx_debug.log(l_statement,'Getting Child Nodes for :',xmldom.getNodeName(l_node),i_method_name);
1417 end if;
1418 l_children := xmldom.getChildNodes(l_node);
1419 l_num_of_child := xmldom.getLength (l_children);
1420 l_tmp_num_child := l_num_of_child;
1421 for i in 0..l_tmp_num_child - 1 loop
1422 l_child := xmldom.item (l_children, i);
1423 l_child_node_type := xmldom.getNodeType(l_child);
1424 if (l_child_node_type <> 1 and l_child_node_type <> 2) then
1425 l_num_of_child := l_num_of_child - 1;
1426 end if;
1427 end loop;
1428 if(l_statementEnabled) then
1429 ecx_debug.log(l_statement, 'num of child', l_num_of_child,i_method_name);
1430 end if;
1431 --else
1432 -- l_col_pos := ecx_utils.g_target(l_node_pos).map_attribute_id;
1433 if (l_node_pos is not null) then
1434 process_node (l_node_pos, l_node, False);
1435 end if;
1436 --end if;
1437
1438
1439 if(l_statementEnabled) then
1440 ecx_debug.log(l_statement,'num of siblings: ', node_info_stack(l_stack_indx).siblings,i_method_name);
1441 end if;
1442 if (l_num_of_child = 0) then
1443 l_stack_indx := l_stack_indx -1;
1444 else
1445 l_stack_indx := l_stack_indx + 1;
1446 node_info_stack(l_stack_indx).parent_node_id := l_node_id;
1447 l_next_pos := l_node_pos;
1448 node_info_stack(l_stack_indx).occur := 1;
1449 node_info_stack(l_stack_indx).siblings := l_num_of_child - 1;
1450 -- node_info_stack(l_stack_indx).parent_node_map_id := l_parent_node_map_id;
1451 end if;
1452
1453 /* End of changes for Bug 4587719. Processing for the root node sepeartely */
1454
1455 l_node_list := xmldom.getElementsByTagName (l_root_element, '*');
1456 l_num_of_nodes := xmldom.getLength (l_node_list);
1457
1458 for i in 0..l_num_of_nodes-1 loop
1459 l_node := xmldom.item(l_node_list, i);
1460 l_node_name := xmldom.getNodeName(l_node);
1461
1462 if(l_statementEnabled) then
1463 ecx_debug.log(l_statement,'l_node_name', l_node_name,i_method_name);
1464 ecx_debug.log(l_statement, 'l_stack_indx', l_stack_indx,i_method_name);
1465 ecx_debug.log(l_statement, 'pre_child_name', node_info_stack(l_stack_indx).pre_child_name,i_method_name);
1466 end if;
1467
1468 if (l_node_name = node_info_stack(l_stack_indx).pre_child_name) then
1469 node_info_stack(l_stack_indx).occur := node_info_stack(l_stack_indx).occur + 1;
1470 elsif (l_next_pos is not null) then
1471 node_info_stack(l_stack_indx).parent_node_pos := l_next_pos;
1472 end if;
1473
1474 node_info_stack(l_stack_indx).pre_child_name := l_node_name;
1475
1476 if(l_statementEnabled) then
1477 for i in node_info_stack.first..node_info_stack.last
1478 loop
1479 ecx_debug.log(l_statement, 'Stack('||i||')', node_info_stack(i).parent_node_id||'-'|| node_info_stack(i).parent_node_pos||'-'|| node_info_stack(i).pre_child_name||'-'|| node_info_stack(i).siblings||'-'|| node_info_stack(i).occur, i_method_name);
1480 end loop;
1481 end if;
1482
1483 l_node_id := get_node_id (l_node, l_node_name,
1484 node_info_stack(l_stack_indx).parent_node_id,
1485 node_info_stack(l_stack_indx).parent_node_pos,
1486 node_info_stack(l_stack_indx).occur,
1487 l_node_pos,
1488 l_parent_node_map_id);
1489 if(l_statementEnabled) then
1490 ecx_debug.log(l_statement,'l_node_id', l_node_id,i_method_name);
1491 end if;
1492
1493 start_level(l_node_pos);
1494 l_num_of_child := 0;
1495
1496 if (l_node_id >= 0) then
1497 if (ecx_utils.dom_printing)
1498 then
1499 -- store the reference to the Node objects that are mapped so that they can
1500 -- be retrieved later when updating the DOM
1501 if (ecx_utils.g_source(l_node_id).map_attribute_id is not null)
1502 then
1503 ecx_utils.g_node_tbl(l_node_id) := l_node;
1504 if(l_statementEnabled) then
1505 ecx_debug.log(l_statement, 'put on xml node stack', l_node_id,i_method_name);
1506 end if;
1507 end if;
1508 end if;
1509
1510 if (ecx_utils.g_source(l_node_pos).has_attributes >0 )
1511 then
1512 process_attributes (l_node, l_node_id,
1513 node_info_stack(l_stack_indx).occur, l_node_pos,
1514 l_parent_node_map_id);
1515 end if;
1516
1517 --if (ecx_utils.g_source(l_node_pos).leaf_node = 0) then
1518 if(l_statementEnabled) then
1519 ecx_debug.log(l_statement,'Getting Child Nodes for :',xmldom.getNodeName(l_node),i_method_name);
1520 end if;
1521 l_children := xmldom.getChildNodes(l_node);
1522 l_num_of_child := xmldom.getLength (l_children);
1523 l_tmp_num_child := l_num_of_child;
1524 for i in 0..l_tmp_num_child - 1 loop
1525 l_child := xmldom.item (l_children, i);
1526 l_child_node_type := xmldom.getNodeType(l_child);
1527 if (l_child_node_type <> 1 and l_child_node_type <> 2) then
1528 l_num_of_child := l_num_of_child - 1;
1529 end if;
1530 end loop;
1531 if(l_statementEnabled) then
1532 ecx_debug.log(l_statement, 'num of child', l_num_of_child,i_method_name);
1533 end if;
1534 --else
1535 -- l_col_pos := ecx_utils.g_target(l_node_pos).map_attribute_id;
1536 if (l_node_pos is not null) then
1537 process_node (l_node_pos, l_node, False);
1538 end if;
1539 --end if;
1540 else
1541 l_children := xmldom.getChildNodes(l_node);
1542 l_num_of_child := xmldom.getLength (l_children);
1543 l_tmp_num_child := l_num_of_child;
1544 if(l_statementEnabled) then
1545 ecx_debug.log(l_statement, 'num of child', l_num_of_child,i_method_name);
1546 end if;
1547 /*
1548 if (l_num_of_child = 1) then
1549 l_child := xmldom.item (l_children, 0);
1550 l_child_node_type := xmldom.getNodeType(l_child);
1551 if (l_child_node_type = 3) then
1552 l_num_of_child := 0;
1553 end if;
1554 end if;
1555 */
1556 for i in 0..l_tmp_num_child - 1 loop
1557 l_child := xmldom.item (l_children, i);
1558 l_child_node_type := xmldom.getNodeType(l_child);
1559 if (l_child_node_type <> 1 and l_child_node_type <> 2) then
1560 l_num_of_child := l_num_of_child - 1;
1561 end if;
1562 end loop;
1563 end if;
1564
1565 if(l_statementEnabled) then
1566 ecx_debug.log(l_statement,'num of siblings: ', node_info_stack(l_stack_indx).siblings,i_method_name);
1567 end if;
1568 if (l_num_of_child = 0) then
1569
1570 loop
1571 -- l_parent_node_map_id := node_info_stack(l_stack_indx).parent_node_map_id;
1572 if (node_info_stack(l_stack_indx).siblings > 0) then
1573 node_info_stack(l_stack_indx).siblings :=
1574 node_info_stack(l_stack_indx).siblings -1;
1575 exit;
1576 else
1577 l_stack_indx := l_stack_indx -1;
1578 if (l_stack_indx = 0) then
1579 exit;
1580 end if;
1581 -- l_parent_node_map_id := node_info_stack(l_stack_indx).parent_node_map_id;
1582 end if;
1583 end loop;
1584 else
1585 l_stack_indx := l_stack_indx + 1;
1586 node_info_stack(l_stack_indx).parent_node_id := l_node_id;
1587 l_next_pos := l_node_pos;
1588 node_info_stack(l_stack_indx).occur := 1;
1589 node_info_stack(l_stack_indx).siblings := l_num_of_child - 1;
1590 -- node_info_stack(l_stack_indx).parent_node_map_id := l_parent_node_map_id;
1591 end if;
1592
1593 end loop;
1594
1595 popall;
1596
1597 if (ecx_utils.structure_printing)
1598 then
1599 ecx_print_local.xmlPopall(i_xmlclob);
1600 ecx_util_api.parseXML(ecx_utils.g_inb_parser,
1601 x_xmlclob, x_parseXML, ecx_utils.g_xmldoc);
1602 else
1603 ecx_utils.g_xmldoc := xmlDom.makeNode(p_doc);
1604 end if;
1605 -- At this point g_xmldoc should have the correct dcument
1606
1607 -- Execute the Stage 30 for Level 0
1608 -- Post-Processing for Target
1609 ecx_actions.execute_stage_data(30,0,'T');
1610 -- Post-Processing for Source
1611 ecx_actions.execute_stage_data(30,0,'S');
1612
1613 ecx_utils.g_total_records := ecx_utils.g_total_records + 1;
1614 if(l_statementEnabled) then
1615 ecx_debug.log(l_statement,'Total record processed', ecx_utils.g_total_records,i_method_name);
1616 end if;
1617
1618 if (l_procedureEnabled) then
1619 ecx_debug.pop(i_method_name);
1620 end if;
1621
1622
1623 EXCEPTION
1624 WHEN ecx_utils.program_exit then
1625 if(l_statementEnabled) then
1626 ecx_debug.log(l_statement, 'Clean-up i_stack, l_node_stack and i_tmpxml',i_method_name);
1627 end if;
1628 i_stack.DELETE;
1629 ecx_print_local.i_tmpxml.DELETE;
1630 ecx_print_local.l_node_stack.DELETE;
1631 ecx_utils.g_node_tbl.DELETE;
1632 if (l_procedureEnabled) then
1633 ecx_debug.pop(i_method_name);
1634 end if;
1635 raise;
1636
1637 WHEN OTHERS THEN
1638 if(l_statementEnabled) then
1639 ecx_debug.log(l_statement, 'ECX', 'ECX_PROGRAM_ERROR',i_method_Name,'PROGRESS_LEVEL',
1640 'ECX_INBOUND.PROCESS_XML_DOC');
1641 ecx_debug.log(l_statement, 'ECX', 'ECX_ERROR_MESSAGE', i_method_name,'ERROR_MESSAGE', SQLERRM);
1642 ecx_debug.log(l_statement, 'Clean-up i_stack, l_node_stack and i_tmpxml', i_method_name);
1643 ecx_debug.log(l_statement, 'ECX', ecx_utils.i_errbuf || SQLERRM ||
1644 ' - ECX_INBOUND.PROCESS_XML_DOC: ', i_method_name);
1645 end if;
1646 ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM ||
1647 ' - ECX_INBOUND.PROCESS_XML_DOC: ');
1648
1649 i_stack.DELETE;
1650 ecx_print_local.i_tmpxml.DELETE;
1651 ecx_print_local.l_node_stack.DELETE;
1652 ecx_utils.g_node_tbl.DELETE;
1653 if (l_procedureEnabled) then
1654 ecx_debug.pop(i_method_name);
1655 end if;
1656 raise ecx_utils.program_exit;
1657
1658 END process_xml_doc;
1659
1660 END ecx_inbound;