summaryrefslogtreecommitdiffstats
path: root/axiom/include/axiom_node.h
blob: 310b0b8efc6f9df2d628a638bccd31ea90d0c3d2 (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
/*
 * 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.
 */

#ifndef AXIOM_NODE_H
#define AXIOM_NODE_H

/**
  * @defgroup axiom AXIOM project
  * @{
  * @}
  */

/**
  * @defgroup axiom_om AXIOM
  * @ingroup axiom
  * @{
  * @}
  */

/**
 * @file axiom_node.h
 * @brief defines axiom_node struct
 */
#include <axutil_env.h>
#include <axutil_utils.h>

#ifdef __cplusplus
extern "C"
{
#endif

    typedef struct axiom_node axiom_node_t;
    struct axiom_output;
    struct axiom_document;
    struct axiom_stax_builder;

    /**
     * @defgroup axiom_node  node
     * @ingroup axiom_om
     * @{
     */

    /**
      * @brief AXIOM types
      */
    typedef enum axiom_types_t
    {

        /** Invalid node type */
        AXIOM_INVALID = 0,

        /** AXIOM document type */
        AXIOM_DOCUMENT,

        /** AXIOM element type */
        AXIOM_ELEMENT,

        /** AXIOM doctype type */
        AXIOM_DOCTYPE,

        /** AXIOM comment type */
        AXIOM_COMMENT,

        /** AXIOM attribute type */
        AXIOM_ATTRIBUTE,

        /** AXIOM namespace type */
        AXIOM_NAMESPACE,

        /** AXIOM processing instruction type */
        AXIOM_PROCESSING_INSTRUCTION,

        /** AXIOM text type */
        AXIOM_TEXT,

        /** AXIOM data source, represent a serialized XML fragment with a stream */
        AXIOM_DATA_SOURCE
    } axiom_types_t;

    /**
      * Creates a node struct.
      * @param env Environment. MUST NOT be NULL, .
      * @return a pointer to newly created node struct. NULL on error. 
      */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_create(
        const axutil_env_t * env);

    /**
      * Creates a node struct from a character buffer.
      * @param env Environment. MUST NOT be NULL, .
      * @param buffer string. buffer to make the node
      * @return a pointer to newly created node struct. NULL on error. 
      */
    AXIS2_EXTERN axiom_node_t* AXIS2_CALL
    axiom_node_create_from_buffer(    
        const axutil_env_t * env,
        axis2_char_t *buffer);


    /**
    * Frees an om node and all of its children. Please note that the attached
    * data_element will also be freed along with the node.  If the node is
    * still attached to a parent, it will be detached first, then freed.
    * @param om_node node to be freed.
    * @param env Environment. MUST NOT be NULL, .
    * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
    */
    AXIS2_EXTERN void AXIS2_CALL
    axiom_node_free_tree(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * Adds given node as child to parent. child should not have a parent
    * if child has a parent it will be detached from existing parent
    * @param om_node parent node. cannot be NULL.
    * @param env Environment. MUST NOT be NULL, .
    * @param child child node.
    * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
    */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_node_add_child(
        axiom_node_t * om_node,
        const axutil_env_t * env,
        axiom_node_t * child);

    /**
    * Detaches given node from the parent and reset the links. Will recreate "namespace defined in
    * the parent and used in detached node" within detached node itself
    * @param om_node node to be detached, cannot be NULL.
    * @param env Environment. MUST NOT be NULL, .
    * @return a pointer to detached node,returns NULL on error
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_detach(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
     * Detaches given node from the parent and reset the links. will not adjust the namespace as
     * in the case of axiom_node_detach.
     * @param om_node node to be detached, cannot be NULL.
     * @param env Environment. MUST NOT be NULL, .
     * @return a pointer to detached node,returns NULL on error
     */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_detach_without_namespaces(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * Inserts a sibling node after the given node
    * @param om_node node to whom the sibling to be inserted. , cannot be NULL.
    * @param env Environment. MUST NOT be NULL, .
    * @param node_to_insert the node to be inserted. , cannot be NULL.
    * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
    */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_node_insert_sibling_after(
        axiom_node_t * om_node,
        const axutil_env_t * env,
        axiom_node_t * node_to_insert);

    /**
    * Inserts a sibling node before the given current node
    * @param om_node node to whom the sibling to be inserted. , cannot be NULL.
    * @param env Environment. MUST NOT be NULL, .
    * @param node_to_insert the node to be inserted. , cannot be NULL.
    * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
    */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_node_insert_sibling_before(
        axiom_node_t * om_node,
        const axutil_env_t * env,
        axiom_node_t * node_to_insert);

    /**
    * Serializes the given node. This op makes the node go
    * through its children and  serialize them in order.
    * @param om_node node to be serialized.  cannot be NULL.
    * @param env Environment .MUST NOT be NULL.    
    * @param om_output AXIOM output handler to be used in serializing
    * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE
    */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_node_serialize(
        axiom_node_t * om_node,
        const axutil_env_t * env,
        struct axiom_output *om_output);

    /** get parent of om_node
    *@om_node node 
    *@param env environment
    *@return pointer to parent node of om_node, return NULL if no parent exists or
    *        when an error occured.
    */

    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_parent(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get the first child of om_node
    * @param om_node node
    * @param env environment must not be null.
    * @returns pointer to first child node , NULL is returned on error with 
    *                     error code set in environments error
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_first_child(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**get the first AXIOM_ELEMENT in om_node
    * @param om_node node
    * @param env environment must not be null
    * @returns pointer to first child om element, NULL is returned on error
    * with error code set in environments error.
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_first_element(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get the last child
    * @param om_node node
    * @param env environment, MUST NOT be NULL
    * @return pointer to last child of this node , return NULL on error.
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_last_child(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get the previous sibling 
    * @param om_node om_node struct 
    * @param env environment , must node be null
    * @returns a pointer to previous sibling , NULL if a previous sibling does not exits
    *                (happens when this node is the first child of a node )
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_previous_sibling(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get next sibling
    * @param om_node om_node struct
    * @param env environment, MUST NOT be NULL.
    * @return next sibling of this node.
    */
    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_get_next_sibling(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get the node type of this element
    * Node type can be one of AXIOM_ELEMENT, AXIOM_COMMENT, AXIOM_TEXT
    *      AXIOM_DOCTYPE, AXIOM_PROCESSING_INSTRUCTION
    * @param om_node  node of which node type is required
    * @param env environment
    * @return node type
    */
    AXIS2_EXTERN axiom_types_t AXIS2_CALL
    axiom_node_get_node_type(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * get the struct contained in the node
    * IF the node is on type AXIOM_ELEMENT , this method returns
    * a pointer to  axiom_element_t struct contained
    * @param om_node node
    * @param env environment, MUST NOT be NULL.
    * @returns pointer to struct contained in the node
    *          returns NULL if no struct is contained 
    */
    AXIS2_EXTERN void *AXIS2_CALL
    axiom_node_get_data_element(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
    * Indicates whether parser has parsed this information item completely or not 
    * @param om_node om_node struct
    * @param env environment, MUST NOT be NULL.
    * @returns AXIS2_TRUE if node is completly build, 
    *          AXIS2_FALSE if node is not completed
    */
    AXIS2_EXTERN axis2_bool_t AXIS2_CALL
    axiom_node_is_complete(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
     * returns the associated document,
     * only valid if built using builder and for a node of type 
     * AXIOM_ELEMENT
     * returns null if no document is available
     * @param om_node 
     * @param env environment, MUST NOT be NULL.
     *
     * @return the OM document of the node
     */
    AXIS2_EXTERN struct axiom_document *AXIS2_CALL
                axiom_node_get_document(
                    axiom_node_t * om_node,
                    const axutil_env_t * env);

    /**
     *
     * @param om_node pointer to the OM node struct
     * @param env environment, MUST NOT be NULL
     *
     * @return the string representation of the node
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_node_to_string(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
     *
     * @param om_node pointer to the OM node struct
     * @param env environment, MUST NOT be NULL
     * @param om_output the serialized output will be placed here
     *
     * @return AXIS2_SUCCESS on success else AXIS2_FAILURE
     */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_node_serialize_sub_tree(
        axiom_node_t * om_node,
        const axutil_env_t * env,
        struct axiom_output *om_output);

    /**
     *
     * @param om_node pointer to the OM node struct
     * @param env environment, MUST NOT be NULL
     *
     * @return the tree as a string
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_node_sub_tree_to_string(
        axiom_node_t * om_node,
        const axutil_env_t * env);

    /**
     * Convert the node to string, treating the binary contents, if any, 
     * as non-optimized content.
     * @param om_node pointer to the OM node struct
     * @param env environment, MUST NOT be NULL
     *
     * @return the none optimized string 
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_node_to_string_non_optimized(
        axiom_node_t * om_node,
        const axutil_env_t * env);
    

    /** @} */

#ifdef __cplusplus
}
#endif

#endif                          /* AXIOM_NODE_H */