summaryrefslogtreecommitdiffstats
path: root/src/core/description/svc.c
blob: 9c091577bf96d92ac7d35e4e71d509a2d1422af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <axis2_svc.h>
#include <axis2_addr.h>
#include <axutil_property.h>
#include <axis2_module.h>
#include "../deployment/axis2_desc_builder.h"
#include <axis2_svc_skeleton.h>
#include <axutil_thread.h>
#include <axis2_core_utils.h>

struct axis2_svc
{
    axis2_svc_grp_t *parent;
    axis2_char_t *axis_svc_name;

    /** To keep last update time of the service */
    long last_update;
    axis2_char_t *filename;

    /** To store module descriptions at deploy time parsing */
    axutil_array_list_t *module_list;

    /** Service description  */
    axis2_char_t *svc_desc;

    /** wsdl file path */
    axis2_char_t *wsdl_path;

    /** service folder path */
    axis2_char_t *folder_path;

    /**
     * WSDL related stuff
     */
    axutil_hash_t *ns_map;
    /* Count of the entries in the namespace map */
    int ns_count;
    /* To keep the XML scheama either from WSDL or
     * C2WSDL(in the future)
     */
    axutil_array_list_t *schema_list;

    /**
     * A table that keeps a mapping of unique XSD names (Strings)
     * against the schema objects. This is populated in the first
     * instance the schemas are asked for and then used to serve
     * the subsequent requests
     */
    axutil_hash_t *schema_mapping_table;

    /**
     * This is where operations are kept
     */
    axutil_hash_t *op_alias_map;

    /**
     * This is where action mappings are kept
     */
    axutil_hash_t *op_action_map;

    /**
     * This is where REST mappings are kept
     */
    axutil_hash_t *op_rest_map;

    /**
     * Keeps track whether the schema locations are adjusted
     */
    axis2_bool_t schema_loc_adjusted;

    /**
     * A custom schema name prefix. if set this will be used to
     * modify the schema names
     */
    axis2_char_t *custom_schema_name_prefix;

    /**
     * A custom schema name suffix. will be attached to the
     * schema file name when the files are uniquely named.
     * A good place to add a file extension if needed
     */
    axis2_char_t *custom_schema_name_suffix;
    /* To store the target namespace for the schema */
    axis2_char_t *schema_target_ns;
    axis2_char_t *schema_target_ns_prefix;
    /* To keep the service target name space */
    axis2_char_t *target_ns;
    axis2_char_t *target_ns_prefix;
    /* Used for schema name calculations */
    int sc_calc_count;

    void *impl_class;
    axutil_qname_t *qname;
    axis2_char_t *style;
    axutil_array_list_t *engaged_module_list;

    /** Parameter container to hold service related parameters */
    struct axutil_param_container *param_container;

    /** Flow container that encapsulates the flow related data */
    struct axis2_flow_container *flow_container;

    /** Base description struct */
    axis2_desc_t *base;

    /* Mutex to avoid loading the same service dll twice */
    axutil_thread_mutex_t *mutex;
};

AXIS2_EXTERN axis2_svc_t *AXIS2_CALL
axis2_svc_create(
    const axutil_env_t * env)
{
    axis2_svc_t *svc = NULL;

    svc = (axis2_svc_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_t));
    if(!svc)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory");
        return NULL;
    }

    svc->parent = NULL;
    svc->axis_svc_name = NULL;
    svc->filename = NULL;
    svc->svc_desc = NULL;
    svc->wsdl_path = NULL;
    svc->folder_path = NULL;
    svc->last_update = 0;
    svc->param_container = NULL;
    svc->flow_container = NULL;
    svc->op_alias_map = NULL;
    svc->op_action_map = NULL;
    svc->op_rest_map = NULL;
    svc->module_list = NULL;
    svc->ns_map = NULL;
    svc->ns_count = 0;
    svc->schema_list = NULL;
    svc->schema_mapping_table = NULL;
    svc->schema_loc_adjusted = AXIS2_FALSE;
    svc->custom_schema_name_prefix = NULL;
    svc->custom_schema_name_suffix = NULL;
    svc->schema_target_ns = NULL;
    svc->schema_target_ns_prefix = NULL;
    svc->target_ns = NULL;
    svc->target_ns_prefix = NULL;
    svc->sc_calc_count = 0;
    svc->impl_class = NULL;
    svc->qname = NULL;
    svc->style = NULL;
    svc->base = NULL;

    svc->param_container = axutil_param_container_create(env);
    if(!svc->param_container)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service param container creation failed");
        return NULL;
    }

    svc->flow_container = axis2_flow_container_create(env);
    if(!svc->flow_container)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service flow container creation failed");
        return NULL;
    }

    svc->op_alias_map = axutil_hash_make(env);
    if(!svc->op_alias_map)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation alias map creation failed");
        return NULL;
    }

    svc->op_action_map = axutil_hash_make(env);
    if(!svc->op_action_map)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation action map creation failed");
        return NULL;
    }

    svc->op_rest_map = axutil_hash_make(env);
    if(!svc->op_rest_map)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation rest map creation failed");
        return NULL;
    }

    /** Create module list of default size */
    svc->module_list = axutil_array_list_create(env, 0);
    if(!svc->module_list)
    {
        axis2_svc_free(svc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service module list creation failed");
        return NULL;
    }

    svc->schema_list = axutil_array_list_create(env, AXIS2_ARRAY_LIST_DEFAULT_CAPACITY);
    if(!svc->schema_list)
    {
        axis2_svc_free(svc, env);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service schema list creation failed");
        return NULL;
    }

    svc->engaged_module_list = axutil_array_list_create(env, AXIS2_ARRAY_LIST_DEFAULT_CAPACITY);
    if(!svc->engaged_module_list)
    {
        axis2_svc_free(svc, env);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service engaged modules list creation failed");
        return NULL;
    }

    svc->schema_loc_adjusted = AXIS2_FALSE;
    if(svc->schema_target_ns_prefix)
    {
        AXIS2_FREE(env->allocator, svc->schema_target_ns_prefix);
        svc->schema_target_ns_prefix = NULL;
    }
    svc->schema_target_ns_prefix = axutil_strdup(env, "ns");

    if(svc->target_ns)
    {
        AXIS2_FREE(env->allocator, svc->target_ns);
        svc->target_ns = NULL;
    }
    svc->target_ns = axutil_strdup(env, "http://ws.apache.org/axis2");

    if(svc->target_ns_prefix)
    {
        AXIS2_FREE(env->allocator, svc->target_ns_prefix);
        svc->target_ns_prefix = NULL;
    }
    svc->target_ns_prefix = axutil_strdup(env, "tns");
    svc->sc_calc_count = 0;

    svc->base = axis2_desc_create(env);
    if(!svc->base)
    {
        axis2_svc_free(svc, env);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service base creation failed");
        return NULL;
    }
    svc->mutex = axutil_thread_mutex_create(env->allocator, AXIS2_THREAD_MUTEX_DEFAULT);
    if(!svc->mutex)
    {
        axis2_svc_free(svc, env);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service mutex creation failed");
        return NULL;
    }
    return svc;
}

AXIS2_EXTERN axis2_svc_t *AXIS2_CALL
axis2_svc_create_with_qname(
    const axutil_env_t * env,
    const axutil_qname_t * qname)
{
    axis2_svc_t *svc = NULL;
    axis2_status_t status = AXIS2_FAILURE;

    AXIS2_PARAM_CHECK(env->error, qname, NULL);

    svc = axis2_svc_create(env);
    if(!svc)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service creation failed for name %s",
            axutil_qname_get_localpart(qname, env));
        return NULL;
    }

    status = axis2_svc_set_qname(svc, env, qname);
    if(AXIS2_FAILURE == status)
    {
        axis2_svc_free(svc, env);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting name %s to service failed",
            axutil_qname_get_localpart(qname, env));
        return NULL;
    }

    return svc;
}

AXIS2_EXTERN void AXIS2_CALL
axis2_svc_free(
    axis2_svc_t * svc,
    const axutil_env_t * env)
{
    if(svc->impl_class)
    {
        AXIS2_SVC_SKELETON_FREE((axis2_svc_skeleton_t *)svc->impl_class, env);
    }
    if(svc->param_container)
    {
        axutil_param_container_free(svc->param_container, env);
    }

    if(svc->flow_container)
    {
        axis2_flow_container_free(svc->flow_container, env);
    }

    if(svc->filename)
    {
        AXIS2_FREE(env->allocator, svc->filename);
        svc->filename = NULL;
    }

    if(svc->svc_desc)
    {
        AXIS2_FREE(env->allocator, svc->svc_desc);
        svc->svc_desc = NULL;
    }

    svc->parent = NULL;

    if(svc->module_list)
    {
        int i = 0;
        int size = 0;

        size = axutil_array_list_size(svc->module_list, env);
        for(i = 0; i < size; i++)
        {
            axutil_qname_t *qname = NULL;
            qname = axutil_array_list_get(svc->module_list, env, i);
            if(qname)
            {
                axutil_qname_free(qname, env);
            }
        }
        axutil_array_list_free(svc->module_list, env);
    }

    if(svc->schema_list)
    {
        axutil_array_list_free(svc->schema_list, env);
    }

    if(svc->engaged_module_list)
    {
        axutil_array_list_free(svc->engaged_module_list, env);
    }

    if(svc->axis_svc_name)
    {
        AXIS2_FREE(env->allocator, svc->axis_svc_name);
        svc->axis_svc_name = NULL;
    }

    if(svc->op_alias_map)
    {
        axutil_hash_index_t *hi = NULL;
        void *val = NULL;

        for(hi = axutil_hash_first(svc->op_alias_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            axutil_hash_this(hi, NULL, NULL, &val);

            if(val)
            {
                if(axis2_op_is_from_module((axis2_op_t *)val, env) == AXIS2_FALSE)
                {
                    axis2_op_free((axis2_op_t *)val, env);
                }
                val = NULL;
            }
        }

        axutil_hash_free(svc->op_alias_map, env);
    }

    if(svc->op_action_map)
    {
        axutil_hash_index_t *hi = NULL;
        const void *key = NULL;

        for(hi = axutil_hash_first(svc->op_action_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            axutil_hash_this(hi, &key, NULL, NULL);

            if(key)
            {
                AXIS2_FREE(env->allocator, (axis2_char_t *)key);
                key = NULL;
            }
        }
        axutil_hash_free(svc->op_action_map, env);
    }

    if(svc->op_rest_map)
    {
        axis2_core_utils_free_rest_map(env, svc->op_rest_map);
    }

    if(svc->schema_target_ns_prefix)
    {
        AXIS2_FREE(env->allocator, svc->schema_target_ns_prefix);
        svc->schema_target_ns_prefix = NULL;
    }

    if(svc->target_ns)
    {
        AXIS2_FREE(env->allocator, svc->target_ns);
        svc->target_ns = NULL;
    }

    if(svc->wsdl_path)
    {
        AXIS2_FREE(env->allocator, svc->wsdl_path);
        svc->wsdl_path = NULL;
    }

    if(svc->folder_path)
    {
        AXIS2_FREE(env->allocator, svc->folder_path);
        svc->folder_path = NULL;
    }

    if(svc->target_ns_prefix)
    {
        AXIS2_FREE(env->allocator, svc->target_ns_prefix);
        svc->target_ns_prefix = NULL;
    }

    if(svc->qname)
    {
        axutil_qname_free(svc->qname, env);
    }

    if(svc->style)
    {
        AXIS2_FREE(env->allocator, svc->style);
    }

    if(svc->base)
    {
        axis2_desc_free(svc->base, env);
    }
    if(svc->mutex)
    {
        axutil_thread_mutex_destroy(svc->mutex);
    }
    if(svc)
    {
        AXIS2_FREE(env->allocator, svc);
        svc = NULL;
    }
    return;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_op(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axis2_op_t * op)
{
    axis2_status_t status = AXIS2_FAILURE;
    axis2_msg_recv_t *msg_recv = NULL;
    const axutil_qname_t *qname = NULL;
    axis2_char_t *key = NULL;
    const axis2_char_t *svcname = NULL;
    axutil_array_list_t *mappings_list = NULL;
    int size = 0;
    int j = 0;

    AXIS2_PARAM_CHECK(env->error, op, AXIS2_FAILURE);
    svcname = axis2_svc_get_name(svc, env);
    qname = axis2_op_get_qname(op, env);
    if(qname)
        key = axutil_qname_get_localpart(qname, env);
    mappings_list = axis2_op_get_wsamapping_list(op, env);
    /* Adding action mappings into service */
    if(mappings_list)
        size = axutil_array_list_size(mappings_list, env);
    for(j = 0; j < size; j++)
    {
        axis2_char_t *mapping = NULL;

        mapping = (axis2_char_t *)axutil_array_list_get(mappings_list, env, j);
        status = axis2_svc_add_mapping(svc, env, mapping, op);
        if(AXIS2_SUCCESS != status)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "Adding operation %s to service %s mapping list failed", svcname, key);
            return status;
        }
    }

    status = axis2_op_set_parent(op, env, svc);
    if(AXIS2_SUCCESS != status)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting service %s as operation %s parent failed",
            svcname, key);
        return status;
    }
    msg_recv = axis2_op_get_msg_recv(op, env);
    if(msg_recv == NULL)
    {
        msg_recv = axis2_desc_builder_load_default_msg_recv(env);
        axis2_op_set_msg_recv(op, env, msg_recv);
    }
    if(key)
    {
        /* If service defines the operation, then we should not override with module level 
         * operation. Module operations are global. If any setting to be modified, those operations
         * can be defined in service */
        if(!axutil_hash_get(svc->op_alias_map, key, AXIS2_HASH_KEY_STRING))
        {
            axutil_hash_set(svc->op_alias_map, key, AXIS2_HASH_KEY_STRING, op);
        }
    }
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_op_t *AXIS2_CALL
axis2_svc_get_op_with_qname(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axutil_qname_t * op_qname)
{
    axis2_op_t *op = NULL;
    axis2_char_t *nc_name = NULL;

    axis2_char_t *nc_tmp = NULL;
    /* This is just for the sake of comparison,
     * and must not be used to change the passed value
     */
    axis2_bool_t is_matched = AXIS2_FALSE;

    AXIS2_PARAM_CHECK(env->error, op_qname, NULL);

    nc_name = axutil_qname_get_localpart(op_qname, env);
    nc_tmp = nc_name;

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    op = axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }

    if(*nc_tmp && svc->op_action_map)
    {
        axutil_hash_index_t *hi = NULL;
        const void *key = NULL;

        for(hi = axutil_hash_first(svc->op_action_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            axutil_hash_this(hi, &key, NULL, NULL);

            nc_tmp = nc_name;

            if(key)
            {
                axis2_char_t *search = NULL;
                axis2_bool_t match_start = AXIS2_TRUE;
                axis2_char_t *search_tmp = NULL;

                search = (axis2_char_t *)key;

                if(!axutil_strchr(search, '*'))
                {
                    if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                    }
                    continue;
                }

                if(search[0] == '*')
                {
                    search++;
                    if(!*search)
                    {
                        nc_tmp = (axis2_char_t *)key;
                        is_matched = AXIS2_TRUE;
                        break;
                    }
                    else if(axutil_strchr(search, '*'))
                    {
                        continue;
                    }
                    match_start = AXIS2_FALSE;
                }
                while(search && *search)
                {
                    int length = 0;
                    axis2_char_t *loc_tmp = NULL;

                    if(search_tmp)
                    {
                        AXIS2_FREE(env->allocator, search_tmp);
                        search_tmp = NULL;
                    }
                    loc_tmp = axutil_strchr(search, '*');
                    if(loc_tmp && *loc_tmp)
                    {
                        if(!loc_tmp[1])
                        {
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        length = (int)(loc_tmp - search);
                        /* We are sure that the difference lies within the int range */
                        search_tmp = (axis2_char_t *)(AXIS2_MALLOC(env->allocator,
                            sizeof(axis2_char_t) * (length + 1)));
                        strncpy(search_tmp, search, length);
                        search_tmp[length] = '\0';
                    }
                    else if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                    if(search_tmp && axutil_strstr(nc_tmp, search_tmp))
                    {
                        if(match_start && !(axutil_strncmp(nc_tmp, search, length) == 0))
                        {
                            break;
                        }
                        else if(!match_start)
                        {
                            match_start = AXIS2_TRUE;
                        }
                    }
                    else
                    {
                        break;
                    }
                    search += axutil_strlen(search_tmp) + 1;
                    nc_tmp = axutil_strstr(nc_tmp, search_tmp) + axutil_strlen(search_tmp);
                }
                if(search_tmp)
                {
                    AXIS2_FREE(env->allocator, search_tmp);
                    search_tmp = NULL;
                }
                if(is_matched || !*search)
                {
                    nc_tmp = (axis2_char_t *)key;
                    is_matched = AXIS2_TRUE;
                    break;
                }
            }
        }
    }
    if(!is_matched)
    {
        nc_tmp = nc_name;
    }

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    return (axis2_op_t *)axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
}

AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axis2_svc_get_rest_op_list_with_method_and_location(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * method,
    const axis2_char_t * location)
{
    axutil_array_list_t *op_list = NULL;
    axis2_char_t *key = NULL;
    axis2_char_t *loc_str = NULL;
    axis2_char_t *loc_str_tmp = NULL;
    axis2_char_t *rindex = NULL;
    int plen;

    AXIS2_PARAM_CHECK(env->error, method, NULL);
    AXIS2_PARAM_CHECK(env->error, location, NULL);

    loc_str_tmp = (axis2_char_t *)location; /* Casted to facilitate loop */
    if(loc_str_tmp[1] == '/')
    {
        loc_str_tmp++;
    } /* ignore any '/' at the beginning */
    if(strchr(loc_str_tmp, '?'))
    {
        axis2_char_t *temp = NULL;

        temp = strchr(loc_str_tmp, '?');
        temp[0] = '\0';
    } /* ignore block after '?' */
    do
    {
        axis2_char_t *temp = NULL;
        temp = strchr(loc_str_tmp, '{');
        if(temp)
        {
            loc_str_tmp = temp;
        }
        else
        {
            loc_str_tmp += strlen(loc_str_tmp);
            break;
        }
    }
    while(loc_str_tmp[1] && loc_str_tmp[1] == '{');

    loc_str = (axis2_char_t *)axutil_strmemdup(location, (loc_str_tmp - location), env);

    rindex = axutil_rindex(loc_str, '/');
    if(rindex && *rindex)
    {
        loc_str_tmp = axutil_string_substring_ending_at(loc_str, (int)(rindex - loc_str));
        /* We are sure that the difference lies within the int range */
    }
    else
    {
        loc_str_tmp = loc_str;
    }

    plen = axutil_strlen(method) + axutil_strlen(loc_str_tmp) + 2;
    key = (axis2_char_t *)(AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * plen));
    sprintf(key, "%s:%s", method, loc_str_tmp);
    AXIS2_FREE(env->allocator, loc_str);
    op_list = (axutil_array_list_t *)axutil_hash_get(svc->op_rest_map, key, AXIS2_HASH_KEY_STRING);
    AXIS2_FREE(env->allocator, key);
    return op_list;
}

AXIS2_EXTERN axis2_op_t *AXIS2_CALL
axis2_svc_get_op_with_name(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * nc_name)
{
    AXIS2_PARAM_CHECK(env->error, nc_name, NULL);

    return (axis2_op_t *)axutil_hash_get(svc->op_alias_map, nc_name, AXIS2_HASH_KEY_STRING);
}

AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axis2_svc_get_all_ops(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->op_alias_map;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_parent(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axis2_svc_grp_t * svc_grp)
{
    AXIS2_PARAM_CHECK(env->error, svc_grp, AXIS2_FAILURE);

    svc->parent = svc_grp;
    if(svc_grp)
    {
        axis2_desc_set_parent(svc->base, env, axis2_svc_grp_get_base(svc_grp, env));
    }

    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_svc_grp_t *AXIS2_CALL
axis2_svc_get_parent(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->parent;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_qname(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axutil_qname_t * qname)
{
    AXIS2_PARAM_CHECK(env->error, qname, AXIS2_FAILURE);
    if(svc->qname)
    {
        axutil_qname_free(svc->qname, env);
    }

    if(qname)
    {
        svc->qname = axutil_qname_clone((axutil_qname_t *)qname, env);
    }
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN const axutil_qname_t *AXIS2_CALL
axis2_svc_get_qname(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->qname;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_param(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axutil_param_t * param)
{
    axis2_char_t *paramname = NULL;
    const axis2_char_t *svcname = axis2_svc_get_name(svc, env);
    AXIS2_PARAM_CHECK(env->error, param, AXIS2_FAILURE);
    paramname = axutil_param_get_name(param, env);

    if(axis2_svc_is_param_locked(svc, env, axutil_param_get_name(param, env)))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_PARAMETER_LOCKED_CANNOT_OVERRIDE, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Parameter %s is locked for service %s", paramname,
            svcname);
        return AXIS2_FAILURE;
    }
    return axutil_param_container_add_param(svc->param_container, env, param);
}

AXIS2_EXTERN axutil_param_t *AXIS2_CALL
axis2_svc_get_param(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * name)
{
    axutil_param_t *param = NULL;
    AXIS2_PARAM_CHECK(env->error, name, NULL);

    param = axutil_param_container_get_param(svc->param_container, env, name);
    if(!param && svc->parent)
    {
        param = axis2_svc_grp_get_param(svc->parent, env, name);
    }
    return param;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_remove_param(
	const axis2_svc_t *svc,
	const axutil_env_t *env,
	const axis2_char_t *param_name)
{
	axis2_status_t status = AXIS2_FAILURE;
	status = axutil_param_container_delete_param(svc->param_container, env, param_name);
	return status;
}


AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axis2_svc_get_all_params(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return axutil_param_container_get_params(svc->param_container, env);
}

AXIS2_EXTERN axis2_bool_t AXIS2_CALL
axis2_svc_is_param_locked(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * param_name)
{
    axis2_bool_t locked = AXIS2_FALSE;
    axutil_param_t *param = NULL;
    axis2_svc_grp_t *parent = NULL;
    axis2_bool_t ret = AXIS2_FALSE;

    AXIS2_PARAM_CHECK(env->error, param_name, AXIS2_FALSE);

    /* Checking the locked value of parent */

    parent = axis2_svc_get_parent(svc, env);
    if(parent)
        locked = axis2_svc_grp_is_param_locked(parent, env, param_name);
    if(parent && locked)
    {
        return AXIS2_TRUE;
    }
    param = axis2_svc_get_param(svc, env, param_name);
    if(param)
    {
        ret = axutil_param_is_locked(param, env);
    }
    return ret;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_engage_module(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axis2_module_desc_t * module_desc,
    axis2_conf_t * conf)
{
    axis2_phase_resolver_t *phase_resolver = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    const axis2_char_t *svcname = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_svc_engage_module");

    AXIS2_PARAM_CHECK(env->error, module_desc, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, conf, AXIS2_FAILURE);

    svcname = axis2_svc_get_name(svc, env);
    phase_resolver = axis2_phase_resolver_create_with_config(env, conf);
    if(!phase_resolver)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating phase resolver failed for service %s",
            svcname);

        return AXIS2_FAILURE;
    }

    status = axis2_phase_resolver_engage_module_to_svc(phase_resolver, env, svc, module_desc);
    if(status)
    {
        const axutil_qname_t *qname = NULL;
        status = axutil_array_list_add(svc->engaged_module_list, env, module_desc);
        qname = axis2_module_desc_get_qname(module_desc, env);
        axis2_svc_add_module_qname(svc, env, qname);
    }

    if(phase_resolver)
    {
        axis2_phase_resolver_free(phase_resolver, env);
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_svc_engage_module");

    return status;
}

AXIS2_EXTERN axis2_bool_t AXIS2_CALL
axis2_svc_is_module_engaged(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axutil_qname_t * module_qname)
{
    int i = 0, size = 0;
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_svc_is_module_engaged");
    size = axutil_array_list_size(svc->engaged_module_list, env);
    for(i = 0; i < size; i++)
    {
        const axutil_qname_t *module_qname_l = NULL;
        axis2_module_desc_t *module_desc_l = NULL;

        module_desc_l = (axis2_module_desc_t *)axutil_array_list_get(svc->engaged_module_list, env,
            i);
        module_qname_l = axis2_module_desc_get_qname(module_desc_l, env);

        if(axutil_qname_equals(module_qname, env, module_qname_l))
        {
            return AXIS2_TRUE;
        }
    }
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_svc_is_module_engaged");
    return AXIS2_FALSE;
}

AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axis2_svc_get_engaged_module_list(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->engaged_module_list;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_disengage_module(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axis2_module_desc_t * module_desc,
    axis2_conf_t * conf)
{
    axis2_phase_resolver_t *phase_resolver = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    const axis2_char_t *svcname = NULL;

    AXIS2_PARAM_CHECK(env->error, module_desc, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, conf, AXIS2_FAILURE);
    svcname = axis2_svc_get_name(svc, env);

    phase_resolver = axis2_phase_resolver_create_with_config(env, conf);
    if(!phase_resolver)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating phase resolver failed for service %s",
            svcname);
        return AXIS2_FAILURE;
    }
    status = axis2_phase_resolver_disengage_module_from_svc(phase_resolver, env, svc, module_desc);
	if(status == AXIS2_SUCCESS)
	{
		/** Remove this module from the engaged modules list */
		const axutil_qname_t *mod_qname = NULL;
		int i = 0, size = 0;

		mod_qname = axis2_module_desc_get_qname(module_desc, env);

	    size = axutil_array_list_size(svc->engaged_module_list, env);
		for(i = 0; i < size; i++)
		{
			const axutil_qname_t *module_qname_l = NULL;
			axis2_module_desc_t *module_desc_l = NULL;

			module_desc_l = (axis2_module_desc_t *)axutil_array_list_get(svc->engaged_module_list, env,
				i);
			module_qname_l = axis2_module_desc_get_qname(module_desc_l, env);

			if(axutil_qname_equals(mod_qname, env, module_qname_l))
			{
				axutil_array_list_remove(svc->engaged_module_list, env, i);
				break;
			}
		}
	}

    axis2_phase_resolver_free(phase_resolver, env);

    return status;
}

/**
 * Here we extract all operations defined in module.xml and built execution 
 * chains for them by calling axis2_phase_resolver_build_execution_chains_for_module_op()
 * function. Within that function handlers of the modules defined for that 
 * operation are added to module operation chains appropriately.
 */
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_module_ops(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axis2_module_desc_t * module_desc,
    axis2_conf_t * conf)
{
    axutil_hash_t *map = NULL;
    axutil_hash_index_t *index = NULL;
    axis2_phase_resolver_t *phase_resolver = NULL;
    axis2_op_t *op_desc = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    const axis2_char_t *svcname = NULL;
    axis2_char_t *modname = NULL;
    axis2_char_t *opname = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_svc_add_module_ops");
    AXIS2_PARAM_CHECK(env->error, module_desc, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, conf, AXIS2_FAILURE);
    svcname = axis2_svc_get_name(svc, env);
    modname = axutil_qname_get_localpart(axis2_module_desc_get_qname(module_desc, env), env);
    map = axis2_module_desc_get_all_ops(module_desc, env);
    phase_resolver = axis2_phase_resolver_create_with_config_and_svc(env, conf, svc);
    if(!phase_resolver)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating phase resolver failed for service %s",
            svcname);
        return AXIS2_FAILURE;
    }
    for(index = axutil_hash_first(map, env); index; index = axutil_hash_next(env, index))
    {
        void *v = NULL;
        axutil_hash_this(index, NULL, NULL, &v);
        op_desc = (axis2_op_t *)v;
        opname = axutil_qname_get_localpart(axis2_op_get_qname(op_desc, env), env);
        status = axis2_phase_resolver_build_execution_chains_for_module_op(phase_resolver, env,
            op_desc);

        if(AXIS2_SUCCESS != status)
        {
            if(phase_resolver)
            {
                axis2_phase_resolver_free(phase_resolver, env);
            }
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "Builidng module operation %s failed for module %s", opname, modname);
            return status;
        }

        status = axis2_svc_add_op(svc, env, op_desc);
        if(AXIS2_SUCCESS != status)
        {
            if(phase_resolver)
            {
                axis2_phase_resolver_free(phase_resolver, env);
            }
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Adding operation %s to service %s failed",
                opname, svcname);
            return status;
        }

    }

    if(phase_resolver)
    {
        axis2_phase_resolver_free(phase_resolver, env);
    }
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_svc_add_module_ops");
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_name(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    if(svc->qname)
    {
        return axutil_qname_get_localpart(svc->qname, env);
    }

    return NULL;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_name(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * axis_svc_name)
{
    AXIS2_PARAM_CHECK(env->error, axis_svc_name, AXIS2_FAILURE);

    if(svc->axis_svc_name)
    {
        AXIS2_FREE(env->allocator, svc->axis_svc_name);
        svc->axis_svc_name = NULL;
    }
    svc->axis_svc_name = axutil_strdup(env, axis_svc_name);
    if(!svc->axis_svc_name)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory");
        return AXIS2_FAILURE;
    }
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_last_update(
    axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN long AXIS2_CALL
axis2_svc_get_last_update(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->last_update;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_file_name(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->filename;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_file_name(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * filename)
{
    AXIS2_PARAM_CHECK(env->error, filename, AXIS2_FAILURE);

    if(svc->filename)
    {
        AXIS2_FREE(env->allocator, svc->filename);
        svc->filename = NULL;
    }
    svc->filename = (axis2_char_t *)axutil_strdup(env, filename);
    if(!svc->filename)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory");
        return AXIS2_FAILURE;
    }
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_svc_desc(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->svc_desc;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_svc_desc(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * svc_desc)
{
    AXIS2_PARAM_CHECK(env->error, svc_desc, AXIS2_FAILURE);

    if(svc->svc_desc)
    {
        AXIS2_FREE(env->allocator, svc->svc_desc);
        svc->svc_desc = NULL;
    }
    svc->svc_desc = (axis2_char_t *)axutil_strdup(env, svc_desc);
    if(!svc->svc_desc)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory");
        return AXIS2_FAILURE;
    }
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_mapping(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * mapping_key,
    axis2_op_t * op_desc)
{
    AXIS2_PARAM_CHECK(env->error, mapping_key, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, op_desc, AXIS2_FAILURE);

    axutil_hash_set(svc->op_action_map, axutil_strdup(env, mapping_key), AXIS2_HASH_KEY_STRING,
        op_desc);
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_rest_mapping(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * method,
    const axis2_char_t * location,
    axis2_op_t * op_desc)
{

    axis2_char_t *mapping_url = NULL;
    int key_len = 0;
    axis2_char_t* question_char = NULL;
    axis2_char_t* local_location_str = NULL;
    axis2_status_t status = AXIS2_SUCCESS;

    local_location_str = (axis2_char_t *)location; /* Casted to facilitate loop */

    /* skip the beginning '/' */
    if(*local_location_str == '/')
    {
        local_location_str++;
    }
    question_char = axutil_strchr(local_location_str, '?');
    if(question_char)
    {
        *question_char = '\0';
    }

    key_len = axutil_strlen(method) + axutil_strlen(local_location_str) + 2;

    mapping_url = (axis2_char_t *)(AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * key_len));
    if(!mapping_url)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create the rest mapping url");
        return AXIS2_FAILURE;
    }

    sprintf(mapping_url, "%s:%s", method, local_location_str);

    status = axis2_core_utils_prepare_rest_mapping(env, mapping_url, svc->op_rest_map, op_desc);

    if(mapping_url)
    {
        AXIS2_FREE(env->allocator, mapping_url);
    }

    /* restore the question character */
    if(question_char)
    {
        *question_char = '?';
    }

    return status;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_add_module_qname(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axutil_qname_t * module_qname)
{
    axutil_qname_t *qmodule_qname_l = NULL;

    AXIS2_PARAM_CHECK(env->error, module_qname, AXIS2_FAILURE);

    qmodule_qname_l = axutil_qname_clone((axutil_qname_t *)module_qname, env);
    return axutil_array_list_add(svc->module_list, env, qmodule_qname_l);
}

AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axis2_svc_get_all_module_qnames(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->module_list;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_target_ns(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->target_ns;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_target_ns(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * ns)
{
    AXIS2_PARAM_CHECK(env->error, ns, AXIS2_FAILURE);

    if(svc->target_ns)
    {
        AXIS2_FREE(env->allocator, svc->target_ns);
        svc->target_ns = NULL;
    }
    svc->target_ns = axutil_strdup(env, ns);
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_target_ns_prefix(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->target_ns_prefix;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_target_ns_prefix(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * prefix)
{
    AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE);

    if(svc->target_ns_prefix)
    {
        AXIS2_FREE(env->allocator, svc->target_ns_prefix);
        svc->target_ns_prefix = NULL;
    }
    svc->target_ns_prefix = axutil_strdup(env, prefix);
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axis2_svc_get_ns_map(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->ns_map;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_ns_map(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axutil_hash_t * ns_map)
{
    axutil_hash_index_t *hi = NULL;

    AXIS2_PARAM_CHECK(env->error, ns_map, AXIS2_FAILURE);

    if(svc->ns_map)
    {
        for(hi = axutil_hash_first(svc->ns_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            void *value = NULL;
            void *key = NULL;
            axutil_hash_this(hi, (const void **)&key, NULL, (void **)&value);
            if(key)
            {
                AXIS2_FREE(env->allocator, key);
                key = NULL;
            }
            if(value)
            {
                AXIS2_FREE(env->allocator, value);
                value = NULL;
            }
        }
        axutil_hash_free(svc->ns_map, env);
    }
    svc->ns_map = ns_map;
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axis2_svc_swap_mapping_table(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    axutil_hash_t * orig_table)
{
    axutil_hash_t *new_table = NULL;
    axutil_hash_index_t *hi = NULL;

    AXIS2_PARAM_CHECK(env->error, orig_table, NULL);

    new_table = axutil_hash_make(env);

    for(hi = axutil_hash_first(orig_table, env); env; hi = axutil_hash_next(env, hi))
    {
        void *value = NULL;
        void *key = NULL;

        axutil_hash_this(hi, (const void **)&key, NULL, (void **)&value);
        axutil_hash_set(new_table, value, AXIS2_HASH_KEY_STRING, key);
    }
    return new_table;
}

AXIS2_EXTERN void *AXIS2_CALL
axis2_svc_get_impl_class(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->impl_class;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_impl_class(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    void *impl_class)
{
    svc->impl_class = impl_class;
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axutil_param_container_t *AXIS2_CALL
axis2_svc_get_param_container(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->param_container;
}

AXIS2_EXTERN axis2_flow_container_t *AXIS2_CALL
axis2_svc_get_flow_container(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->flow_container;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_svc_wsdl_path(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->wsdl_path;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_svc_wsdl_path(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * wsdl_path)
{
    AXIS2_PARAM_CHECK(env->error, wsdl_path, AXIS2_FAILURE);
    svc->wsdl_path = (axis2_char_t *)axutil_strdup(env, wsdl_path);
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN const axis2_char_t *AXIS2_CALL
axis2_svc_get_svc_folder_path(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->folder_path;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_set_svc_folder_path(
    axis2_svc_t * svc,
    const axutil_env_t * env,
    const axis2_char_t * folder_path)
{
    AXIS2_PARAM_CHECK(env->error, folder_path, AXIS2_FAILURE);
    svc->folder_path = (axis2_char_t *)axutil_strdup(env, folder_path);
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_desc_t *AXIS2_CALL
axis2_svc_get_base(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->base;
}

AXIS2_EXTERN axutil_thread_mutex_t * AXIS2_CALL
axis2_svc_get_mutex(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->mutex;
}

AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axis2_svc_get_rest_map(
    const axis2_svc_t * svc,
    const axutil_env_t * env)
{
    return svc->op_rest_map;
}