forked from CloCkWeRX/sdo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDO_DAS_XML_Document.cpp
363 lines (313 loc) · 11.9 KB
/
SDO_DAS_XML_Document.cpp
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
/*
+----------------------------------------------------------------------+
| (c) Copyright IBM Corporation 2005, 2007. |
| All Rights Reserved. |
+----------------------------------------------------------------------+
| |
| Licensed 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. |
+----------------------------------------------------------------------+
| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard |
+----------------------------------------------------------------------+
*/
static char rcs_id[] = "$Id: SDO_DAS_XML_Document.cpp 241789 2007-08-24 15:20:26Z mfp $";
#ifdef PHP_WIN32
/* disable warning about identifier lengths in browser information */
#pragma warning(disable: 4786)
#include <iostream>
#include <math.h>
#include "zend_config.w32.h"
#endif
#include "php_sdo_das_xml_int.h"
#define CLASS_NAME "SDO_DAS_XML_Document"
PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_document_class_entry;
static zend_object_handlers sdo_das_xml_doc_object_handlers;
/* argument definitions of SDO_DAS_XML_Document class, start */
ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLDeclaration_args, 0)
ZEND_ARG_INFO(0, xml_declaration)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLVersion_args, 0)
ZEND_ARG_INFO(0, xml_version)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setEncoding_args, 0)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO();
/* argument definitions of SDO_DAS_XML_Document class, end */
/* {{{ sdo_xmldocument_methods
*
* Every method of SDO_DAS_XML_Document class needs to be defined here
*/
function_entry sdo_das_xml_document_methods[] = {
ZEND_ME(SDO_DAS_XML_Document, getRootDataObject, 0, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, getRootElementURI, 0, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, getRootElementName, 0, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, setXMLDeclaration,
sdo_xmldoc_setXMLDeclaration_args, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, setXMLVersion,
sdo_xmldoc_setXMLVersion_args, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, setEncoding,
sdo_xmldoc_setEncoding_args, ZEND_ACC_PUBLIC)
ZEND_ME(SDO_DAS_XML_Document, __toString, 0,
ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
/* {{{ debug macro functions
*/
SDO_DEBUG_ADDREF(das_xml_document)
SDO_DEBUG_DELREF(das_xml_document)
SDO_DEBUG_DESTROY(das_xml_document)
/* }}} */
/* {{{ sdo_das_xml_document_object_free_storage
*/
void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC)
{
SDO_DEBUG_FREE(object);
xmldocument_object *xmldocument = (xmldocument_object *) object;
zend_hash_destroy(xmldocument->zo.properties);
FREE_HASHTABLE(xmldocument->zo.properties);
if (xmldocument->zo.guards) {
zend_hash_destroy(xmldocument->zo.guards);
FREE_HASHTABLE(xmldocument->zo.guards);
}
if (xmldocument->xmlDocumentPtr) {
xmldocument->xmlDocumentPtr = NULL;
}
efree(xmldocument);
}
/* }}} */
/* {{{ sdo_das_xml_document_object_create
*/
zend_object_value sdo_das_xml_document_object_create(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
zval *tmp;
xmldocument_object *xmldocument;
xmldocument = (xmldocument_object *)emalloc(sizeof(xmldocument_object));
memset(xmldocument, 0, sizeof(xmldocument_object));
xmldocument->zo.ce = ce;
xmldocument->zo.guards = NULL;
ALLOC_HASHTABLE(xmldocument->zo.properties);
zend_hash_init(xmldocument->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(xmldocument->zo.properties, &ce->default_properties,
(copy_ctor_func_t) zval_add_ref, (void *) &tmp,
sizeof(zval *));
retval.handle = zend_objects_store_put(xmldocument, SDO_FUNC_DESTROY(das_xml_document),
sdo_das_xml_document_object_free_storage,
NULL TSRMLS_CC);
retval.handlers = &sdo_das_xml_doc_object_handlers;
SDO_DEBUG_ALLOCATE(retval.handle, xmldocument);
return retval;
}
/* }}} */
/* {{{ sdo_das_xml_document_cast_object
*/
#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1)
static int sdo_das_xml_document_cast_object(zval *readobj, zval *writeobj, int type TSRMLS_DC)
{
int should_free = 0;
#else
static int sdo_das_xml_document_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC)
{
#endif
xmldocument_object *xmldocument;
ostringstream print_buf;
int rc = SUCCESS;
xmldocument = (xmldocument_object *) zend_object_store_get_object(readobj TSRMLS_CC);
try {
/* I don't think Tuscany provides a way to get back to the original
* DataFactory from the XML document, so I'm (expensively and probably
* inaccurately) creating a temporary one.
*/
DataFactoryPtr dataFactoryPtr = DataFactory::getDataFactory();
XMLHelperPtr xmlHelperPtr = HelperProvider::getXMLHelper((DataFactory *)dataFactoryPtr);
print_buf << xmlHelperPtr->save(xmldocument->xmlDocumentPtr);
std::string print_string = print_buf.str();
ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1);
} catch (SDORuntimeException e) {
ZVAL_NULL(writeobj);
sdo_throw_runtimeexception(&e TSRMLS_CC);
rc = FAILURE;
}
return rc;
}
/* }}} */
/* {{{ sdo_das_xml_document_minit
*
* Initializes SDO_DAS_XML_Document class
*/
void sdo_das_xml_document_minit(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_Document", sdo_das_xml_document_methods);
ce.create_object = sdo_das_xml_document_object_create;
sdo_das_xml_document_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
memcpy(&sdo_das_xml_doc_object_handlers, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
sdo_das_xml_doc_object_handlers.add_ref = SDO_FUNC_ADDREF(das_xml_document);
sdo_das_xml_doc_object_handlers.del_ref = SDO_FUNC_DELREF(das_xml_document);
sdo_das_xml_doc_object_handlers.cast_object = sdo_das_xml_document_cast_object;
sdo_das_xml_doc_object_handlers.clone_obj = NULL;
}
/* }}} */
/* {{{ proto SDO_DataObject SDO_DAS_XML_Document::getRootDataObject()
Returns the root SDO_DataObject.
*/
PHP_METHOD(SDO_DAS_XML_Document, getRootDataObject)
{
xmldocument_object *xmldocument;
DataObjectPtr root_do;
char *class_name, *space;
xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
try {
root_do = xmldocument->xmlDocumentPtr->getRootDataObject();
if (!root_do) {
class_name = get_active_class_name (&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error(%i) - root DataObject is NULL",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__);
RETURN_NULL();
}
sdo_do_new(return_value, root_do TSRMLS_CC);
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
}
}
/* }}} SDO_DAS_XML_Document::getRootDataObject */
/* {{{ proto string SDO_DAS_XML_Document::getRootElementURI()
Returns root element URI string.
*/
PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI)
{
xmldocument_object *xmldocument;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
try {
RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementURI(), 1);
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
RETVAL_NULL();
}
}
/* }}} SDO_DAS_XML_Document::getRootElementURI */
/* {{{ proto string SDO_DAS_XML_Document::getRootElementName()
Returns root element name.
*/
PHP_METHOD(SDO_DAS_XML_Document, getRootElementName)
{
xmldocument_object *xmldocument;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
try {
RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementName(), 1);
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
}
}
/* }}} SDO_DAS_XML_Document::getRootElementName */
/* {{{ proto void SDO_DAS_XML_Document::setXMLDeclaration(bool xmlDeclatation)
Sets the xml declaration.
*/
PHP_METHOD(SDO_DAS_XML_Document, setXMLDeclaration)
{
zend_bool xml_declaration;
xmldocument_object *xmldocument;
char *class_name, *space;
if (ZEND_NUM_ARGS() != 1) {
WRONG_PARAM_COUNT;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &xml_declaration) == FAILURE) {
RETURN_FALSE;
}
xmldocument = (xmldocument_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
if (!xmldocument) {
class_name = get_active_class_name (&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DAS_XML_Document not found in store",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__);
RETURN_FALSE;
}
try {
xmldocument->xmlDocumentPtr->setXMLDeclaration(ZEND_TRUTH(xml_declaration));
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} SDO_DAS_XML_Document::setXMLDeclaration */
/* {{{ proto void SDO_DAS_XML_Document::setXMLVersion(string xmlVersion)
Sets the given string as xml version.
*/
PHP_METHOD(SDO_DAS_XML_Document, setXMLVersion)
{
char *xml_version;
int xml_version_len;
xmldocument_object *xmldocument;
if (ZEND_NUM_ARGS() != 1) {
WRONG_PARAM_COUNT;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_version, &xml_version_len) == FAILURE) {
RETURN_FALSE;
}
xmldocument = (xmldocument_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
try {
xmldocument->xmlDocumentPtr->setXMLVersion(xml_version);
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} SDO_DAS_XML_Document::setXMLVersion */
/* {{{ proto void SDO_DAS_XML_Document::setEncoding(string encoding)
Sets the given string as encoding.
*/
PHP_METHOD(SDO_DAS_XML_Document, setEncoding)
{
char *encoding;
int encoding_len;
xmldocument_object *xmldocument;
if (ZEND_NUM_ARGS() != 1) {
WRONG_PARAM_COUNT;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&encoding, &encoding_len) == FAILURE) {
RETURN_FALSE;
}
xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
try {
xmldocument->xmlDocumentPtr->setEncoding(encoding);
} catch (SDORuntimeException e) {
sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} SDO_DAS_XML_Document::setEncoding */
/* {{{ SDO_DAS_XML_Document::__toString
*/
PHP_METHOD(SDO_DAS_XML_Document, __toString)
{
#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1)
sdo_das_xml_document_cast_object(getThis(), return_value, IS_STRING TSRMLS_CC);
#else
sdo_das_xml_document_cast_object(getThis(), return_value, IS_STRING, 0 TSRMLS_CC);
#endif
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/