summaryrefslogtreecommitdiffstats
path: root/src/core/description/module_desc.c
blob: a5b27c7d94e6362a6c2496692ea3afafdbc83cdf (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
/*
 * 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_module_desc.h>
#include <axis2_module.h>

struct axis2_module_desc
{
    axis2_module_t *module;
    axutil_qname_t *qname;
    axis2_conf_t *parent;

    /**
     * To store module operations , which are supposed to be added to a service
     * the module is engaged to a service
     */
    axutil_hash_t *ops;

    /** 
     * flow container that encapsulates the flows associated with the 
     * module 
     */
    axis2_flow_container_t *flow_container;

    /** 
     * parameter container that stores all the parameters associated with 
     * the module 
     */
    axutil_param_container_t *params;
};

AXIS2_EXTERN axis2_module_desc_t *AXIS2_CALL
axis2_module_desc_create(
    const axutil_env_t * env)
{
    axis2_module_desc_t *module_desc = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    module_desc = (axis2_module_desc_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_module_desc_t));

    if(!module_desc)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    module_desc->qname = NULL;
    module_desc->module = NULL;
    module_desc->parent = NULL;
    module_desc->params = NULL;
    module_desc->flow_container = NULL;
    module_desc->ops = NULL;

    module_desc->params = axutil_param_container_create(env);
    if(!module_desc->params)
    {
        axis2_module_desc_free(module_desc, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    module_desc->flow_container = axis2_flow_container_create(env);
    if(!module_desc->flow_container)
    {
        axis2_module_desc_free(module_desc, env);
AXIS2_ERROR_SET    (env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE)
    return NULL;
}

module_desc->ops = axutil_hash_make(env);
if (!module_desc->ops)
{
    axis2_module_desc_free(module_desc, env);
    AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
    return NULL;
}

return module_desc;
}

AXIS2_EXTERN axis2_module_desc_t *AXIS2_CALL
axis2_module_desc_create_with_qname(
    const axutil_env_t * env,
    const axutil_qname_t * qname)
{
    axis2_module_desc_t *module_desc = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, qname, NULL);

    module_desc = axis2_module_desc_create(env);
    if(!module_desc)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    module_desc->qname = (axutil_qname_t *)qname;

    return module_desc;
}

AXIS2_EXTERN void AXIS2_CALL
axis2_module_desc_free(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    AXIS2_ENV_CHECK(env, void);

    if(module_desc->module)
    {
        axis2_module_shutdown(module_desc->module, env);
    }

    if(module_desc->params)
    {
        axutil_param_container_free(module_desc->params, env);
    }

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

    module_desc->parent = NULL;

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

    if(module_desc->ops)
    {
        axutil_hash_index_t *hi = NULL;
        void *val = NULL;
        for(hi = axutil_hash_first(module_desc->ops, env); hi; hi = axutil_hash_next(env, hi))
        {
            struct axis2_op *op = NULL;
            axutil_hash_this(hi, NULL, NULL, &val);
            op = (struct axis2_op *)val;
            if(op)
                axis2_op_free(op, env);
            val = NULL;
            op = NULL;

        }
        axutil_hash_free(module_desc->ops, env);
    }

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

    return;
}

AXIS2_EXTERN void AXIS2_CALL
axis2_module_desc_free_void_arg(
    void *module_desc,
    const axutil_env_t * env)
{
    axis2_module_desc_t *module_desc_l = NULL;

    AXIS2_ENV_CHECK(env, void);
    module_desc_l = (axis2_module_desc_t *)module_desc;
    axis2_module_desc_free(module_desc_l, env);
    return;
}

AXIS2_EXTERN axis2_flow_t *AXIS2_CALL
axis2_module_desc_get_in_flow(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return axis2_flow_container_get_in_flow(module_desc->flow_container, env);
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_in_flow(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_flow_t * in_flow)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, in_flow, AXIS2_FAILURE);

    return axis2_flow_container_set_in_flow(module_desc->flow_container, env, in_flow);
}

AXIS2_EXTERN axis2_flow_t *AXIS2_CALL
axis2_module_desc_get_out_flow(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return axis2_flow_container_get_out_flow(module_desc->flow_container, env);
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_out_flow(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_flow_t * out_flow)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, out_flow, AXIS2_FAILURE);

    return axis2_flow_container_set_out_flow(module_desc->flow_container, env, out_flow);
}

AXIS2_EXTERN axis2_flow_t *AXIS2_CALL
axis2_module_desc_get_fault_in_flow(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return axis2_flow_container_get_fault_in_flow(module_desc->flow_container, env);
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_fault_in_flow(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_flow_t * falut_in_flow)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, falut_in_flow, AXIS2_FAILURE);

    return axis2_flow_container_set_fault_in_flow(module_desc->flow_container, env, falut_in_flow);
}

AXIS2_EXTERN axis2_flow_t *AXIS2_CALL
axis2_module_desc_get_fault_out_flow(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return axis2_flow_container_get_fault_out_flow(module_desc->flow_container, env);
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_fault_out_flow(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_flow_t * fault_out_flow)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, fault_out_flow, AXIS2_FAILURE);

    return axis2_flow_container_set_fault_out_flow(module_desc->flow_container, env, fault_out_flow);
}

AXIS2_EXTERN const axutil_qname_t *AXIS2_CALL
axis2_module_desc_get_qname(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->qname;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_qname(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    const axutil_qname_t * qname)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, qname, AXIS2_FAILURE);

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

    module_desc->qname = axutil_qname_clone((axutil_qname_t *)qname, env);

    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_add_op(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_op_t * op)
{
    const axutil_qname_t *op_qname = NULL;
    axis2_char_t *op_name = NULL;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, op, AXIS2_FAILURE);

    if(!(module_desc->ops))
    {
        module_desc->ops = axutil_hash_make(env);
        if(!module_desc->ops)
            return AXIS2_FAILURE;
    }

    op_qname = axis2_op_get_qname(op, env);

    if(!op_qname)
    {
        return AXIS2_FAILURE;
    }
    op_name = axutil_qname_to_string((axutil_qname_t *)op_qname, env);
    axutil_hash_set(module_desc->ops, op_name, AXIS2_HASH_KEY_STRING, op);

    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
axis2_module_desc_get_all_ops(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->ops;
}

AXIS2_EXTERN axis2_conf_t *AXIS2_CALL
axis2_module_desc_get_parent(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->parent;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_parent(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_conf_t * parent)
{
    AXIS2_PARAM_CHECK(env->error, parent, AXIS2_FAILURE);

    module_desc->parent = parent;
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_add_param(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axutil_param_t * param)
{
    axis2_char_t *param_name_l = NULL;
    axis2_status_t ret_status = AXIS2_FAILURE;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);

    param_name_l = axutil_param_get_name(param, env);
    if(!param_name_l)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_PARAM, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    if(AXIS2_TRUE == axis2_module_desc_is_param_locked(module_desc, env, param_name_l))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_PARAMETER_LOCKED_CANNOT_OVERRIDE, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    else
    {
        ret_status = axutil_param_container_add_param(module_desc->params, env, param);
    }
    return ret_status;
}

AXIS2_EXTERN axutil_param_t *AXIS2_CALL
axis2_module_desc_get_param(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    const axis2_char_t * name)
{
    AXIS2_PARAM_CHECK(env->error, name, NULL);

    return axutil_param_container_get_param(module_desc->params, env, name);
}

AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
axis2_module_desc_get_all_params(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return axutil_param_container_get_params(module_desc->params, env);
}

AXIS2_EXTERN axis2_bool_t AXIS2_CALL
axis2_module_desc_is_param_locked(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    const axis2_char_t * param_name)
{
    axis2_bool_t locked = AXIS2_FALSE;
    axis2_bool_t ret_state = AXIS2_FALSE;
    axutil_param_t *param_l = NULL;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, param_name, AXIS2_FAILURE);

    /* checking the locked value of parent */
    if(!module_desc->parent)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_MODULE_DESC, AXIS2_FAILURE);
        return AXIS2_FALSE;
    }
    locked = axis2_conf_is_param_locked(module_desc->parent, env, param_name);

    if(AXIS2_TRUE == locked)
    {
        ret_state = AXIS2_TRUE;
    }
    else
    {
        param_l = axis2_module_desc_get_param(module_desc, env, param_name);
        if(param_l && AXIS2_TRUE == axutil_param_is_locked(param_l, env))
            ret_state = AXIS2_TRUE;
        else
            ret_state = AXIS2_FALSE;

    }
    return ret_state;
}

AXIS2_EXTERN axis2_module_t *AXIS2_CALL
axis2_module_desc_get_module(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->module;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_module_desc_set_module(
    axis2_module_desc_t * module_desc,
    const axutil_env_t * env,
    axis2_module_t * module)
{
    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, module, AXIS2_FAILURE);
    module_desc->module = module;
    return AXIS2_SUCCESS;
}

AXIS2_EXTERN axutil_param_container_t *AXIS2_CALL
axis2_module_desc_get_param_container(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->params;
}

AXIS2_EXTERN axis2_flow_container_t *AXIS2_CALL
axis2_module_desc_get_flow_container(
    const axis2_module_desc_t * module_desc,
    const axutil_env_t * env)
{
    return module_desc->flow_container;
}