cvs: pecl /sdo .cvsignore MakePackage.php SDO_CPPException.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DAS_XML.cpp
SDO_DAS_XML_Document.cpp SDO_DataObject.cpp SDO_Exception.cpp SDO_List.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp
SDO_Model_Type.cpp SDO_Sequence.cpp config.m4 config.w32 das_xml.cpp php_sdo.h php_sdo_das_xml.h php_sdo_das_xml_int.h php_sdo_int.h sdo.cpp
sdo_utils.cpp xmldas_utils.cpp /sdo/DAS Relational.php /sdo/DAS/Relational DataObjectHelper.php InsertAction.php /sdo/DAS/Relational/Scenarios
companydb_db2.sql /sdo/commonj/sdo ChangeSummaryImpl.cpp DataFactoryImpl.cpp DataObject.h DataObjectImpl.cpp DataObjectImpl.h DataObjectList.h
DataObjectListImpl.cpp DataObjectListImpl.h PropertyImpl.cpp SAX2Namespaces.cpp SDOSAX2Parser.cpp SDOSchemaSAX2Parser.cpp SDOXMLStreamWriter.cpp
SDOXMLStreamWriter.h SDOXMLWriter.cpp SDOXMLWriter.h SDOXSDStreamWriter.cpp SDOXSDStreamWriter.h SDOXSDWriter.cpp SDOXSDWr! iter.h SchemaInfo.h
Sequence.h SequenceImpl.cpp SequenceImpl.h SettingList.cpp SettingList.h Type.h XMLHelper.h XMLHelperImpl.cpp XMLHelperImpl.h XSDHelper.h
XSDHelperImpl.cpp XSDHelperImpl.h /sdo/commonj/sdo/xmldas XMLDAS.h XMLDASImpl.cpp XMLDASImpl.h /sdo/tests 001.phpt 002.phpt 003.phpt 004.phpt
005.phpt 006.phpt SDOAPITest.php test.inc /sdo/tests/XMLDAS/Examples .cvsignore Example1.php Example2.php Example3.php Example4.php Example5.php
animalTypes.xsd jungle.xsd /sdo/tests/XMLDAS/PHPUnitTests XMLDASTest.php /sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType abstract.xsd
/sdo/tests/XMLDAS/PHPUnitTests/anyElement animalTypes.xsd jungle.xsd /sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType person.xml person.xsd
/sdo/tests/XMLDAS/PHPUnitTests/missingType company_missing_type.xsd /sdo/tests/XMLDAS/PHPUnitTests/nillable company_with_nillable_SN.xml
company_with_nillable_SN.xsd /sdo/tests/XMLDAS/PHPUnitTests/parseErrors parse_errors.xml parse_errors.xsd
/sdo/tests! /XMLDAS/PHPUnitTests/restrictedComplexType load.php name.xml name.xsd
| From: | Matthew Peters | Date: | Mon, 20 Feb 2006 18:50:27 +0000 |
| Subject: | cvs: pecl /sdo .cvsignore MakePackage.php SDO_CPPException.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DAS_XML.cpp SDO_DAS_XML_Document.cpp SDO_DataObject.cpp SDO_Exception.cpp SDO_List.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Model_Type.cpp SDO_Sequence.cpp config.m4 config.w32 das_xml.cpp php_sdo.h php_sdo_das_xml.h php_sdo_das_xml_int.h php_sdo_int.h sdo.cpp sdo_utils.cpp xmldas_utils.cpp /sdo/DAS Relational.php /sdo/DAS/Relational DataObjectHelper.php InsertAction.php /sdo/DAS/Relational/Scenarios companydb_db2.sql /sdo/commonj/sdo ChangeSummaryImpl.cpp DataFactoryImpl.cpp DataObject.h DataObjectImpl.cpp DataObjectImpl.h DataObjectList.h DataObjectListImpl.cpp DataObjectListImpl.h PropertyImpl.cpp SAX2Namespaces.cpp SDOSAX2Parser.cpp SDOSchemaSAX2Parser.cpp SDOXMLStreamWriter.cpp SDOXMLStreamWriter.h SDOXMLWriter.cpp SDOXMLWriter.h SDOXSDStreamWriter.cpp SDOXSDStreamWriter.h SDOXSDWriter.cpp SDOXSDWr! iter.h SchemaInfo.h Sequence.h SequenceImpl.cpp SequenceImpl.h SettingList.cpp SettingList.h Type.h XMLHelper.h XMLHelperImpl.cpp XMLHelperImpl.h XSDHelper.h XSDHelperImpl.cpp XSDHelperImpl.h /sdo/commonj/sdo/xmldas XMLDAS.h XMLDASImpl.cpp XMLDASImpl.h /sdo/tests 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt 006.phpt SDOAPITest.php test.inc /sdo/tests/XMLDAS/Examples .cvsignore Example1.php Example2.php Example3.php Example4.php Example5.php animalTypes.xsd jungle.xsd /sdo/tests/XMLDAS/PHPUnitTests XMLDASTest.php /sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType abstract.xsd /sdo/tests/XMLDAS/PHPUnitTests/anyElement animalTypes.xsd jungle.xsd /sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType person.xml person.xsd /sdo/tests/XMLDAS/PHPUnitTests/missingType company_missing_type.xsd /sdo/tests/XMLDAS/PHPUnitTests/nillable company_with_nillable_SN.xml company_with_nillable_SN.xsd /sdo/tests/XMLDAS/PHPUnitTests/parseErrors parse_errors.xml parse_errors.xsd /sdo/tests! /XMLDAS/PHPUnitTests/restrictedComplexType load.php name.xml name.xsd |
||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-5227@lists.php.net to get a copy of this message | ||
mfp Mon Feb 20 18:50:27 2006 UTC
Added files:
/pecl/sdo SDO_CPPException.cpp SDO_Exception.cpp
/pecl/sdo/tests/XMLDAS/Examples .cvsignore Example4.php
Example5.php animalTypes.xsd
jungle.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType
abstract.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement animalTypes.xsd
jungle.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType person.xml
person.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType
company_missing_type.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable
company_with_nillable_SN.xml
company_with_nillable_SN.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors parse_errors.xml
parse_errors.xsd
/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType load.php
name.xml
name.xsd
Modified files:
/pecl/sdo .cvsignore MakePackage.php SDO_DAS_ChangeSummary.cpp
SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp
SDO_DAS_XML.cpp SDO_DAS_XML_Document.cpp
SDO_DataObject.cpp SDO_List.cpp SDO_Model_Property.cpp
SDO_Model_ReflectionDataObject.cpp SDO_Model_Type.cpp
SDO_Sequence.cpp config.m4 config.w32 das_xml.cpp
php_sdo.h php_sdo_das_xml.h php_sdo_das_xml_int.h
php_sdo_int.h sdo.cpp sdo_utils.cpp xmldas_utils.cpp
/pecl/sdo/DAS Relational.php
/pecl/sdo/DAS/Relational DataObjectHelper.php InsertAction.php
/pecl/sdo/DAS/Relational/Scenarios companydb_db2.sql
/pecl/sdo/commonj/sdo ChangeSummaryImpl.cpp DataFactoryImpl.cpp
DataObject.h DataObjectImpl.cpp
DataObjectImpl.h DataObjectList.h
DataObjectListImpl.cpp DataObjectListImpl.h
PropertyImpl.cpp SAX2Namespaces.cpp
SDOSAX2Parser.cpp SDOSchemaSAX2Parser.cpp
SDOXMLStreamWriter.cpp SDOXMLStreamWriter.h
SDOXMLWriter.cpp SDOXMLWriter.h
SDOXSDStreamWriter.cpp SDOXSDStreamWriter.h
SDOXSDWriter.cpp SDOXSDWriter.h SchemaInfo.h
Sequence.h SequenceImpl.cpp SequenceImpl.h
SettingList.cpp SettingList.h Type.h
XMLHelper.h XMLHelperImpl.cpp XMLHelperImpl.h
XSDHelper.h XSDHelperImpl.cpp XSDHelperImpl.h
/pecl/sdo/commonj/sdo/xmldas XMLDAS.h XMLDASImpl.cpp XMLDASImpl.h
/pecl/sdo/tests test.inc 001.phpt 002.phpt 003.phpt 004.phpt
005.phpt 006.phpt SDOAPITest.php
/pecl/sdo/tests/XMLDAS/Examples Example1.php Example2.php
Example3.php
/pecl/sdo/tests/XMLDAS/PHPUnitTests XMLDASTest.php
Log:
Bring PHP repository to 0_9_0
http://cvs.php.net/viewcvs.cgi/pecl/sdo/.cvsignore?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/.cvsignore diff -u pecl/sdo/.cvsignore:1.5 pecl/sdo/.cvsignore:1.6 --- pecl/sdo/.cvsignore:1.5 Tue Jan 17 14:22:27 2006 +++ pecl/sdo/.cvsignore Mon Feb 20 18:50:25 2006 @@ -28,6 +28,7 @@ config.log .cdtproject include +commonj *.loT run-tests.php -sdo-*.tgz +.settings http://cvs.php.net/viewcvs.cgi/pecl/sdo/MakePackage.php?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/MakePackage.php diff -u pecl/sdo/MakePackage.php:1.11 pecl/sdo/MakePackage.php:1.12 --- pecl/sdo/MakePackage.php:1.11 Tue Jan 17 14:17:27 2006 +++ pecl/sdo/MakePackage.php Mon Feb 20 18:50:25 2006 @@ -1,5 +1,5 @@ <?php - /* $Id: MakePackage.php,v 1.11 2006/01/17 14:17:27 cem Exp $ */ + /* $Id: MakePackage.php,v 1.12 2006/02/20 18:50:25 mfp Exp $ */ require_once('PEAR/PackageFileManager.php'); $packagexml = new PEAR_PackageFileManager; if (PEAR::isError($packagexml)) { @@ -43,12 +43,35 @@ // . "The SDO_Model_ReflectionDataObject gives the programmer access to " // . "the type and structure information in a data object's model. " // . "This can help with debugging, or be used in dynamic user interface generation.", - 'notes' => "This release adds support for open types. These are types which " - . "can have additional properties added to a runtime instance, for example " - . "to support an XML <any/> element.\n" - . "Also various bug fixes. ", +// 'notes' => "This release adds support for open types. These are types which " +// . "can have additional properties added to a runtime instance, for example " +// . "to support an XML <any/> element.\n" +// . "Also various bug fixes. ", + +'notes' => +"The following changes have been made between 0.7.1 and this release.\n" +. "The changes which are visible at the programming interface are:\n" +. "The interface to the XML Data Access Service has been revised:\n" +. "The names of the methods to load and save documents to improve consistency with other packages.\n" +. "A new method, createDocument(), has been added to enable creation of a document from scratch.\n" +. "The saveDataObjectToFile()/String() methods have been replaced by saveFile()String() methods on the Document object.\n" +. "Some getters and setters on the Document have been fixed or removed.\n" +. "The XML Data Access Service has added support for the following XML Schema:\n" +. "Open types: support for <any> element and <anyAttribute>\n" +. "Type inheritance: both simple and complex types can be derived by restriction or extension\n" +. "Abstract types: the use of abstract types in the schema is supported\n" +. "The XML DAS now supports printing its SDO type and property model using print or echo.\n" +. "The XML DAS can now produce formatted Document (see optional formatting argument on saveFile() and saveString())\n" +. "The getType() method on a DataObject has been replaced with getTypeName() and getTypeNamespaceURI() methods.\n" +. "\n" +. "Other changes in this release:\n" +. "The memory management in the sdo and sdo_das_xml extensions has been overhauled to squeeze out any memory leaks\n" +. "Exception messages from the extension have been improved so that they never refer to the underlying C/C++ code\n" +. "PropertyNotSetException has been improved so that it replicates the way arrays and objects behave as closely as possible\n" +. "The parsing that the XML DAS performs on both XML Schema and instance documents has been improved so that problems are picked up and reported earlier.\n" + , 'simpleoutput' => true, - 'version' => '0.7.1', + 'version' => '0.9.0', 'baseinstalldir' => 'SDO', 'state' => 'beta', 'license' => 'Apache 2.0', http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_ChangeSummary.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/SDO_DAS_ChangeSummary.cpp diff -u pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.5 pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.6 --- pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.5 Wed Oct 5 09:56:01 2005 +++ pecl/sdo/SDO_DAS_ChangeSummary.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_ChangeSummary.cpp,v 1.5 2005/10/05 09:56:01 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_ChangeSummary.cpp,v 1.6 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -92,10 +92,13 @@ void sdo_das_changesummary_new(zval *me, ChangeSummaryPtr change_summary TSRMLS_DC) { sdo_das_changesummary_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_changesummary_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } @@ -129,10 +132,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { my_object->change_summary->beginLogging(); @@ -155,10 +154,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { my_object->change_summary->endLogging(); @@ -181,10 +176,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_BOOL(my_object->change_summary->isLogging()); @@ -201,29 +192,26 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldValues) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop; ChangeSummaryPtr change_summary; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get (z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { SettingList& sl = my_object->change_summary->getOldValues(dop); @@ -252,10 +240,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { const ChangedDataObjectList& cdol = my_object->change_summary->getChangedDataObjects(); @@ -278,30 +262,27 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangeType) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop; ChangeSummaryPtr change_summary; long change_type = CS_NONE; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get (z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { /* this order is important: for example isDeleted and isModified may both return true, @@ -328,31 +309,27 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldContainer) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop, container_dop; ChangeSummaryPtr change_summary; long change_type = 0; - zval *container_zval; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get(z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { container_dop = change_summary->getOldContainer(dop); @@ -360,13 +337,7 @@ if (!container_dop) { RETVAL_NULL(); } else { - container_zval = (zval *)container_dop->getUserData(); - if (container_zval == (zval *)SDO_USER_DATA_EMPTY) { - php_error(E_ERROR, "%s:%i: container is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } else { - RETVAL_ZVAL(container_zval, 1, 0); - } + sdo_do_new(return_value, container_dop TSRMLS_CC); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_DataFactory.cpp?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/SDO_DAS_DataFactory.cpp diff -u pecl/sdo/SDO_DAS_DataFactory.cpp:1.7 pecl/sdo/SDO_DAS_DataFactory.cpp:1.8 --- pecl/sdo/SDO_DAS_DataFactory.cpp:1.7 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/SDO_DAS_DataFactory.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_DataFactory.cpp,v 1.7 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_DataFactory.cpp,v 1.8 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -90,15 +90,30 @@ } /* }}} */ +/* {{{ sdo_das_df_get + * utility function for DAS implementations + */ +DataFactoryPtr sdo_das_df_get(zval *me TSRMLS_DC) +{ + sdo_das_df_object *my_object; + + my_object = (sdo_das_df_object *)zend_object_store_get_object(me TSRMLS_CC); + return my_object->dfp; +} +/* }}} */ + /* {{{ sdo_das_df_new */ void sdo_das_df_new(zval *me, DataFactoryPtr dfp TSRMLS_DC) { sdo_das_df_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_datafactoryimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } @@ -146,30 +161,27 @@ PHP_METHOD(SDO_DAS_DataFactoryImpl, create) { sdo_das_df_object *my_object; - char *namespaceURI; - int *namespaceURI_len; - char *typeName; - int *typeName_len; - zval *z_new_do; + char *type_uri; + int *type_uri_len; + char *type_name; + int *type_name_len; DataObjectPtr dop; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len) == FAILURE) + &type_uri, &type_uri_len, &type_name, &type_name_len) == FAILURE) return; my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); try { - dop = my_object->dfp->create(namespaceURI, typeName); + dop = my_object->dfp->create(type_uri, type_name); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); return; } /* We have a good data object, so set up its PHP incarnation */ - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, dop TSRMLS_CC); - RETVAL_ZVAL(z_new_do, 1, 0); + sdo_do_new(return_value, dop TSRMLS_CC); } /* }}} */ @@ -197,14 +209,16 @@ PHP_METHOD(SDO_DAS_DataFactoryImpl, addType) { sdo_das_df_object *my_object; - char *namespaceURI; - int namespaceURI_len; - char *typeName; - int typeName_len; - + char *type_uri; + int type_uri_len; + char *type_name; + int type_name_len; + /* optional parameters with default values */ - zend_bool sequenced = false; - zend_bool open = false; + zend_bool is_sequenced = false; + zend_bool is_open = false; + zend_bool is_abstract = false; + zend_bool is_derived = false; /* optional array of optional argumants */ zval *args = NULL; @@ -215,52 +229,121 @@ uint key_string_len; ulong key_index; + /* and a further array for the basetype values */ + HashTable *basetype_hash; + zval **z_basetype_uri; + zval **z_basetype_name; + char *basetype_uri; + char *basetype_name; + + char *class_name, *space; + if (ZEND_NUM_ARGS() < 2) WRONG_PARAM_COUNT; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssb|b", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &sequenced, &open) == SUCCESS) { - /* the old (deprecated) signature */ - php_error(E_WARNING, "use of deprecated signature for %s", get_active_function_name(TSRMLS_C)); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &args) == FAILURE) { - return; - } else if (args != NULL) { - args_hash = Z_ARRVAL_P(args); - - for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); - zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; - zend_hash_move_forward_ex(args_hash, &args_pointer)) { - if (zend_hash_get_current_key_ex( - args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { - if (strcmp(key_string, "sequenced") == SUCCESS) { - sequenced = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "open") == SUCCESS) { - open = sdo_get_boolean_value (*value); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a", + &type_uri, &type_uri_len, &type_name, &type_name_len, + &args) == FAILURE) { + return; + } + + if (args != NULL) { + args_hash = Z_ARRVAL_P(args); + + for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); + zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; + zend_hash_move_forward_ex(args_hash, &args_pointer)) { + if (zend_hash_get_current_key_ex( + args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { + + if (strcmp(key_string, "sequenced") == SUCCESS) { + is_sequenced = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "open") == SUCCESS) { + is_open = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "abstract") == SUCCESS) { + is_abstract = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "basetype") == SUCCESS) { + /* If the basetype option is present, its value + * is an array of type uri and type name. + */ + is_derived = true; + if (Z_TYPE_PP(value) != IS_ARRAY) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): %s argument should be an array", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + basetype_hash = Z_ARRVAL_PP(value); + if (zend_hash_num_elements(basetype_hash) != 2) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): %s array should have exactly two elements", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + if (zend_hash_index_find(basetype_hash, 0, (void **)&z_basetype_uri) == SUCCESS && + Z_TYPE_PP(z_basetype_uri) == IS_STRING) { + basetype_uri = Z_STRVAL_PP(z_basetype_uri); + } else { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): invalid value for %s type namespace URI", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + if (zend_hash_index_find(basetype_hash, 1, (void **)&z_basetype_name) == SUCCESS&& + Z_TYPE_PP(z_basetype_name) == IS_STRING) { + basetype_name = Z_STRVAL_PP(z_basetype_name); } else { - php_error(E_WARNING, "unrecognized option %s in parameter array for %s", - key_string, get_active_function_name(TSRMLS_C)); + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): invalid value for %s type name", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; } - } else { - php_error(E_WARNING, "%i : option name must be a string in parameter array for %s", - key_index, get_active_function_name(TSRMLS_C)); - } - } + continue; + } /* end basetype */ + + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): unrecognized option %s in parameter array", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + + } else { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): option name must be a string in parameter array #%i", + class_name, space, get_active_function_name(TSRMLS_C), key_index); + } } } my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); - + try { - my_object->dfp->addType(namespaceURI, typeName, ZEND_TRUTH(sequenced), ZEND_TRUTH(open)); + my_object->dfp->addType(type_uri, type_name, + ZEND_TRUTH(is_sequenced), ZEND_TRUTH(is_open), ZEND_TRUTH(is_abstract)); + + if (is_derived) { + my_object->dfp->setBaseType(type_uri, type_name, basetype_uri, basetype_name); + } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } - + return; } /* }}} */ @@ -270,18 +353,18 @@ */ PHP_METHOD(SDO_DAS_DataFactoryImpl, addPropertyToType) { - char *parent_namespaceURI; - int parent_namespaceURI_len; - char *parent_typeName; - int parent_typeName_len; - - char *propertyName; - int propertyName_len; - - char *namespaceURI; - int namespaceURI_len; - char *typeName; - int typeName_len; + char *parent_type_uri; + int parent_type_uri_len; + char *parent_type_name; + int parent_type_name_len; + + char *property_name; + int property_name_len; + + char *type_uri; + int type_uri_len; + char *type_name; + int type_name_len; /* optional array of optional argumants */ zval *args = NULL; @@ -294,157 +377,168 @@ /* optional parameters with default values */ zend_bool many = false; - zend_bool readOnly = false; + zend_bool read_only = false; zend_bool containment = true; zval *default_value = NULL; sdo_das_df_object *my_object; + char *class_name, *space; if (ZEND_NUM_ARGS() < 5) WRONG_PARAM_COUNT; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sssssb|bb", - &parent_namespaceURI, &parent_namespaceURI_len, &parent_typeName, &parent_typeName_len, - &propertyName, &propertyName_len, - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &many, &readOnly, &containment) == SUCCESS) { - /* the old (deprecated) signature */ - php_error(E_WARNING, "use of deprecated signature for %s", get_active_function_name(TSRMLS_C)); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssss|a", - &parent_namespaceURI, &parent_namespaceURI_len, &parent_typeName, &parent_typeName_len, - &propertyName, &propertyName_len, - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &args) == FAILURE) { - return; - } else if (args != NULL) { - args_hash = Z_ARRVAL_P(args); - - for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); - zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; - zend_hash_move_forward_ex(args_hash, &args_pointer)) { - if (zend_hash_get_current_key_ex( - args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { - if (strcmp(key_string, "many") == SUCCESS) { - many = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "readonly") == SUCCESS) { - readOnly = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "containment") == SUCCESS) { - containment = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "opposite") == SUCCESS) { - php_error(E_WARNING, "option %s not yet implemented for %s", - key_string, get_active_function_name(TSRMLS_C)); - } else - if (strcmp(key_string, "default") == SUCCESS) { - default_value = *value; - } else { - php_error(E_WARNING, "unrecognized option %s in parameter array for %s", - key_string, get_active_function_name(TSRMLS_C)); - } - } else { - php_error(E_WARNING, "%i : option name must be a string in parameter array for %s", - key_index, get_active_function_name(TSRMLS_C)); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssss|a", + &parent_type_uri, &parent_type_uri_len, &parent_type_name, &parent_type_name_len, + &property_name, &property_name_len, + &type_uri, &type_uri_len, &type_name, &type_name_len, + &args) == FAILURE) { + return; + } else if (args != NULL) { + args_hash = Z_ARRVAL_P(args); + + for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); + zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; + zend_hash_move_forward_ex(args_hash, &args_pointer)) { + if (zend_hash_get_current_key_ex( + args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { + if (strcmp(key_string, "many") == SUCCESS) { + many = sdo_get_boolean_value (*value); + continue; + } + if (strcmp(key_string, "readonly") == SUCCESS) { + read_only = sdo_get_boolean_value (*value); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): option %s not yet implemented", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + continue; } - } + if (strcmp(key_string, "containment") == SUCCESS) { + containment = sdo_get_boolean_value (*value); + continue; + } + if (strcmp(key_string, "opposite") == SUCCESS) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): option %s not yet implemented", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + continue; + } + if (strcmp(key_string, "default") == SUCCESS) { + default_value = *value; + continue; + } + + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s::%s: unrecognized option %s in parameter array", + CLASS_NAME, get_active_function_name(TSRMLS_C), key_string); + + } else { + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s::%s: option name must be a string in parameter array #%i", + CLASS_NAME, get_active_function_name(TSRMLS_C), key_index); + } + } - } - + } + my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); try { - my_object->dfp->addPropertyToType(parent_namespaceURI, parent_typeName, propertyName, namespaceURI, typeName, - ZEND_TRUTH(many), ZEND_TRUTH(readOnly), ZEND_TRUTH(containment)); + my_object->dfp->addPropertyToType(parent_type_uri, parent_type_name, property_name, type_uri, type_name, + ZEND_TRUTH(many), ZEND_TRUTH(read_only), ZEND_TRUTH(containment)); if (default_value) { if (many) { zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: multivalued property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: multivalued property %s cannot have a default value", CLASS_NAME, __LINE__, property_name); } else if (Z_TYPE_P(default_value) == IS_NULL) { zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: property %s cannot have a NULL default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: property %s cannot have a NULL default value", CLASS_NAME, __LINE__, property_name); } else { /* copy the value so that the original is not modified */ zval temp_zval = *default_value; zval_copy_ctor(&temp_zval); - const Type& type = my_object->dfp->getType(namespaceURI, typeName); - const Type& parentType = my_object->dfp->getType(parent_namespaceURI, parent_typeName); + const Type& type = my_object->dfp->getType(type_uri, type_name); + const Type& parentType = my_object->dfp->getType(parent_type_uri, parent_type_name); switch (type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); break; case Type::BooleanType: convert_to_boolean(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (bool)ZEND_TRUTH(Z_BVAL(temp_zval))); + my_object->dfp->setDefault(parentType, property_name, (bool)ZEND_TRUTH(Z_BVAL(temp_zval))); break; case Type::ByteType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (char)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (char)Z_LVAL(temp_zval)); break; case Type::BytesType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval), Z_STRLEN(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval), Z_STRLEN(temp_zval)); break; case Type::CharacterType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (char)(Z_STRVAL(temp_zval)[0])); + my_object->dfp->setDefault(parentType, property_name, (char)(Z_STRVAL(temp_zval)[0])); break; case Type::DateType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (SDODate)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (SDODate)Z_LVAL(temp_zval)); break; case Type::DoubleType: convert_to_double(&temp_zval); /*TODO this may need more work. On Windows, simply omitting the cast, or casting to double, * leads to an ambiguous overloaded function message. But some platforms may baulk at long double. */ - my_object->dfp->setDefault(parentType, propertyName, (long double)Z_DVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (long double)Z_DVAL(temp_zval)); break; case Type::FloatType: convert_to_double(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (float)Z_DVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (float)Z_DVAL(temp_zval)); break; case Type::IntegerType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (long)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (long)Z_LVAL(temp_zval)); break; case Type::LongType: if (Z_TYPE(temp_zval) == IS_LONG) { - my_object->dfp->setDefault(parentType, propertyName, (int64_t)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (int64_t)Z_LVAL(temp_zval)); } else { convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); } break; case Type::ShortType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (short)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (short)Z_LVAL(temp_zval)); break; case Type::StringType: case Type::UriType: case Type::TextType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); break; case Type::DataObjectType: zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: DataObject property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: DataObject property %s cannot have a default value", + CLASS_NAME, __LINE__, property_name); break; case Type::ChangeSummaryType: zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: ChangeSummary property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: ChangeSummary property %s cannot have a default value", + CLASS_NAME, __LINE__, property_name); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, - type.getName(), propertyName); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, + type.getName(), property_name); } zval_dtor(&temp_zval); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_Setting.cpp?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/SDO_DAS_Setting.cpp diff -u pecl/sdo/SDO_DAS_Setting.cpp:1.11 pecl/sdo/SDO_DAS_Setting.cpp:1.12 --- pecl/sdo/SDO_DAS_Setting.cpp:1.11 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_DAS_Setting.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_Setting.cpp,v 1.11 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_Setting.cpp,v 1.12 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -92,10 +92,13 @@ void sdo_das_setting_new(zval *me, Setting *setting TSRMLS_DC) { sdo_das_setting_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_setting_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } @@ -114,8 +117,8 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; MAKE_STD_ZVAL(return_value); try { @@ -125,7 +128,9 @@ const Property& property = setting->getProperty(); switch(property.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -147,7 +152,9 @@ case Type::CharacterType: wchar_value = setting->getCharacterValue(); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), property.getName()); } char_value = setting->getByteValue(); RETVAL_STRINGL(&char_value, 1, 1); @@ -181,18 +188,23 @@ /* An old value may legitimately be null */ RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, property.getType().getName(), property.getName()); } } @@ -211,31 +223,27 @@ HashTable *properties; zval *tmp; Setting *setting; + zval z_holder; + const char *property_name; - ALLOC_HASHTABLE(properties); + array_init(&z_holder); my_object = sdo_das_setting_get_instance(object TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - setting = my_object->setting; - const char *propertyName = setting->getProperty().getName(); - - zend_hash_init(properties, 1, NULL, NULL, 0); - - /* TODO if the setting is for a list element, we should - * probably include the list index as part of the key - */ - - tmp = sdo_das_setting_read_value(my_object TSRMLS_CC); - - zend_hash_update(properties, (char *)propertyName, 1 + strlen(propertyName), - &tmp, sizeof(zval *), NULL); - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } + try { + setting = my_object->setting; + property_name = setting->getProperty().getName(); + + /* TODO if the setting is for a list element, we should + * probably include the list index as part of the key + */ + + tmp = sdo_das_setting_read_value(my_object TSRMLS_CC); + + add_assoc_zval (&z_holder, (char *)property_name, tmp); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -255,42 +263,37 @@ } my_object = sdo_das_setting_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { + + setting = my_object->setting; + try { + const Property& property = setting->getProperty(); + + print_buf << "object(" << CLASS_NAME << + ")#" << readobj->value.obj.handle; + + if (property.isMany()) { + print_buf << '[' << setting->getIndex() << ']'; + } + + if (setting->isSet() && property.getType().isDataType()) { + print_buf << "=>"; + if (setting->isNull()) { + print_buf << "NULL"; + } else { + print_buf << '\"' << setting->getCStringValue() << '\"'; + } + } + + print_buf << '}'; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - setting = my_object->setting; - try { - const Property& property = setting->getProperty(); - - print_buf << "object(" << CLASS_NAME << - ")#" << readobj->value.obj.handle; - - if (property.isMany()) { - print_buf << '[' << setting->getIndex() << ']'; - } - - if (setting->isSet() && property.getType().isDataType()) { - print_buf << "=>"; - if (setting->isNull()) { - print_buf << "NULL"; - } else { - print_buf << '\"' << setting->getCStringValue() << '\"'; - } - } - - print_buf << '}'; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } - } + } switch(type) { case IS_STRING: @@ -344,10 +347,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { const Property& property = my_object->setting->getProperty(); @@ -371,10 +370,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_STRING((char *)my_object->setting->getProperty().getName(), 1); @@ -398,10 +393,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } value = sdo_das_setting_read_value(my_object TSRMLS_CC); RETVAL_ZVAL(value, 1, 0); @@ -421,10 +412,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (my_object->setting->getProperty().isMany()) { @@ -451,10 +438,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_BOOL(my_object->setting->isSet()); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_XML.cpp?r1=1.13&r2=1.14&diff_format=u Index: pecl/sdo/SDO_DAS_XML.cpp diff -u pecl/sdo/SDO_DAS_XML.cpp:1.13 pecl/sdo/SDO_DAS_XML.cpp:1.14 --- pecl/sdo/SDO_DAS_XML.cpp:1.13 Thu Jan 26 15:50:57 2006 +++ pecl/sdo/SDO_DAS_XML.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_XML.cpp,v 1.13 2006/01/26 15:50:57 mfp Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_XML.cpp,v 1.14 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -33,14 +33,12 @@ #include "zend_interfaces.h" // needed for several uses of zend_call_method() -/******************* Forward declarations for this module only **********************/ -zend_object_value sdo_das_xml_object_create (zend_class_entry *ce TSRMLS_DC); -void sdo_das_xml_object_free_storage (void *object TSRMLS_DC); - #define PARSER_EXCEPTION_MSG_LEN 1000 +#define MAX_ERRORS 50 +#define CLASS_NAME "SDO_DAS_XML" -zend_class_entry* sdo_das_xml_class_entry; -zend_object_handlers sdo_das_xml_object_handlers; +PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_class_entry; +static zend_object_handlers sdo_das_xml_object_handlers; /* argument definitions of SDO_DAS_XML class, start */ ZEND_BEGIN_ARG_INFO(sdo_das_xml___construct_args, 0) @@ -56,45 +54,33 @@ ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_das_xml_loadFile_args, 0) - ZEND_ARG_INFO(0, fileName) + ZEND_ARG_INFO(0, file_name) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_das_xml_loadString_args, 0) - ZEND_ARG_INFO(0, xmlString) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO(sdo_das_xml_createdo_args, 0) - ZEND_ARG_INFO(0, nameSpaceURI) - ZEND_ARG_INFO(0, typeName) + ZEND_ARG_INFO(0, xml_string) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDocString_args, 0) - ZEND_ARG_INFO(0, docObj) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_saveFile_args, 0, ZEND_RETURN_VALUE, 2) + ZEND_ARG_INFO(0, document) + ZEND_ARG_INFO(0, xml_file) + ZEND_ARG_INFO(0, indent) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDocFile_args, 0) - ZEND_ARG_INFO(0, docObj) - ZEND_ARG_INFO(0, xmlFile) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_saveString_args, 0, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, document) + ZEND_ARG_INFO(0, indent) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDOString_args, 0) - ZEND_ARG_INFO(0, dataobj) - ZEND_ARG_INFO(0, rootURI) - ZEND_ARG_INFO(0, rootName) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_createDocument_args, 0, ZEND_RETURN_VALUE, 0) + ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, element_name) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDOFile_args, 0) - ZEND_ARG_INFO(0, dataobj) - ZEND_ARG_INFO(0, rootURI) - ZEND_ARG_INFO(0, rootName) - ZEND_ARG_INFO(0, xmlFile) +ZEND_BEGIN_ARG_INFO(sdo_das_xml_createDataObject_args, 0) + ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_name) ZEND_END_ARG_INFO(); - -//ZEND_BEGIN_ARG_INFO(sdo_das_xml_getProperty_args, 0) -// ZEND_ARG_INFO(0, nameSpaceURI) -// ZEND_ARG_INFO(0, typeName) -//ZEND_END_ARG_INFO(); - /* argument definitions of SDO_DAS_XML class, end */ /* {{{ SDO_DAS_XML Class methods @@ -106,69 +92,25 @@ ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(SDO_DAS_XML, addTypes, sdo_das_xml_addTypes_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, loadFromFile, sdo_das_xml_loadFile_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, loadFromString, sdo_das_xml_loadString_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDocumentToString, sdo_das_xml_saveDocString_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDocumentToFile, sdo_das_xml_saveDocFile_args, + ZEND_ME(SDO_DAS_XML, loadFile, sdo_das_xml_loadFile_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDataObjectToString, sdo_das_xml_saveDOString_args, + ZEND_ME(SDO_DAS_XML, loadString, sdo_das_xml_loadString_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDataObjectToFile, sdo_das_xml_saveDOFile_args, + ZEND_ME(SDO_DAS_XML, saveFile, sdo_das_xml_saveFile_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, createDataObject, sdo_das_xml_createdo_args, + ZEND_ME(SDO_DAS_XML, saveString, sdo_das_xml_saveString_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, getTypes, 0, + ZEND_ME(SDO_DAS_XML, createDocument, sdo_das_xml_createDocument_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, __toString, 0, + ZEND_ME(SDO_DAS_XML, createDataObject, sdo_das_xml_createDataObject_args, ZEND_ACC_PUBLIC) -// ZEND_ME(SDO_DAS_XML, getProperty, sdo_das_xml_getProperty_args, -// ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DAS_XML, __toString, 0, + ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} }; /* }}} */ -/* {{{ initialize_sdo_das_xml_class - */ -void initialize_sdo_das_xml_class(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML", sdo_das_xml_methods); - ce.create_object = sdo_das_xml_object_create; - sdo_das_xml_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - memcpy(&sdo_das_xml_object_handlers, zend_get_std_object_handlers(), - sizeof(zend_object_handlers)); - sdo_das_xml_object_handlers.clone_obj = NULL; -} -/* }}} */ - - -/* {{{ sdo_das_xml_object_create - */ -zend_object_value sdo_das_xml_object_create(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - zval *tmp; - xmldas_object *obj = (xmldas_object *) emalloc(sizeof(xmldas_object)); - memset(obj, 0, sizeof(xmldas_object)); - - obj->z_obj.ce = ce; - ALLOC_HASHTABLE(obj->z_obj.properties); - zend_hash_init(obj->z_obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(obj->z_obj.properties, &ce->default_properties, - (copy_ctor_func_t) zval_add_ref, (void *) &tmp, - sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, NULL, - sdo_das_xml_object_free_storage, - NULL TSRMLS_CC); - retval.handlers = &sdo_das_xml_object_handlers; - return retval; -} -/* }}} */ - /* {{{ sdo_das_xml_object_free_storage */ void sdo_das_xml_object_free_storage(void *object TSRMLS_DC) @@ -177,144 +119,66 @@ * Frees up the SDO_DAS_XML object also decrements reference to * PHP version of SDO_DAS_DataFactory */ - sdo_das_df_object *das_obj; - xmldas_object *obj = (xmldas_object *) object; - zend_hash_destroy(obj->z_obj.properties); - FREE_HASHTABLE(obj->z_obj.properties); - - if (obj->php_das_df) { - das_obj = (sdo_das_df_object *) - zend_object_store_get_object(obj->php_das_df TSRMLS_CC); + xmldas_object *xmldas = (xmldas_object *)object; + zend_hash_destroy(xmldas->zo.properties); + FREE_HASHTABLE(xmldas->zo.properties); - if(das_obj) { - das_obj->dfp = NULL; - } - zend_objects_store_del_ref(obj->php_das_df TSRMLS_CC); - } - efree(obj); + zval_dtor(&xmldas->z_df); + efree(xmldas); } /* }}} */ -/* {{{ create_dataobject_tree +/* {{{ sdo_das_xml_object_create */ -void create_dataobject_tree(DataObjectPtr data_object TSRMLS_DC) +zend_object_value sdo_das_xml_object_create(zend_class_entry *ce TSRMLS_DC) { - zval *z_obj; - zend_object *php_das_obj = NULL; - MAKE_STD_ZVAL(z_obj); - if (!data_object) { - return; - // tempting to raise an error as this should never happen - not going to do it though - // php_error(E_ERROR, "SDO_DAS_XML::create_dataobject_tree was passed a null argument"); - } - if (data_object->getUserData() != (void*) 0xFFFFFFFF) { - // if the user data is set then we have encountered this object before - // and already created a PHP object corresponding to it. - // This will happen when we follow a reference to an object that - // was already visited following a different reference: for example following the - // employee_of_the_month non-containment reference to an employee who has already been - // visited by following the department->employee containmment reference. - // Since we already have a corresponding object, return without creating another. - return; - } - sdo_do_new(z_obj, data_object TSRMLS_CC); - // not sure whether any need to increase the reference count? - // zend_objects_store_add_ref(z_obj TSRMLS_CC); - const Type& data_object_type = data_object->getType(); - PropertyList pl = data_object->getInstanceProperties(); - for (int i = 0; i < pl.size(); i++) { - const Type& property_type = pl[i].getType(); - if (data_object->isSet(pl[i])) { - if (pl[i].isMany()) { - DataObjectList& dol = data_object->getList(pl[i]); - for (int j = 0; j <dol.size(); j++) { - create_dataobject_tree(dol[j] TSRMLS_CC); - } - } else { - if (!property_type.isDataType()) { - create_dataobject_tree(data_object->getDataObject(pl[i]) - TSRMLS_CC); - } - } - } - } + zend_object_value retval; + zval *tmp; + xmldas_object *xmldas; + + xmldas = (xmldas_object *)emalloc(sizeof(xmldas_object)); + memset(xmldas, 0, sizeof(xmldas_object)); + + xmldas->zo.ce = ce; + ALLOC_HASHTABLE(xmldas->zo.properties); + zend_hash_init(xmldas->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(xmldas->zo.properties, &ce->default_properties, + (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + retval.handle = zend_objects_store_put(xmldas, NULL, + sdo_das_xml_object_free_storage, NULL TSRMLS_CC); + retval.handlers = &sdo_das_xml_object_handlers; + return retval; } /* }}} */ -/* {{{ PHP_METHOD(SDO_DAS_XML, __construct) +/* {{{ sdo_das_xml_minit */ -PHP_METHOD(SDO_DAS_XML, __construct) +void sdo_das_xml_minit(TSRMLS_D) { - php_error(E_ERROR, "SDO_DAS_XML::__construct - you cannot instantiate SDO_DAS_XML by calling the constructor. Use SDO_DAS_XML::create(xsd) static function instead."); + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML", sdo_das_xml_methods); + ce.create_object = sdo_das_xml_object_create; + sdo_das_xml_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + + memcpy(&sdo_das_xml_object_handlers, zend_get_std_object_handlers(), + sizeof(zend_object_handlers)); + sdo_das_xml_object_handlers.clone_obj = NULL; } /* }}} */ -/* {{{ proto SDO_DAS_XML SDO_DAS_XML::addTypes(string xsd_file) +/* {{{ PHP_METHOD(SDO_DAS_XML, __construct) */ -PHP_METHOD(SDO_DAS_XML, addTypes) +PHP_METHOD(SDO_DAS_XML, __construct) { - xmldas_object* xmldas = NULL; - char* file_name; - int len = 0; - zval * retval = NULL; - zend_class_entry *ce = NULL; - zval *this_obj = getThis(); - ostringstream print_buf; - - // TODO lots of code duplicated with create() - - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name,&len) == FAILURE) { - RETURN_FALSE; - } - if (!len) { - RETURN_FALSE; - } - - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if(!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::addTypes - Unable to get XMLDAS object from object store"); - } - try { - xmldas->targetNamespaceURI = xmldas->xsdHelper->defineFile(file_name); - - int error_count = xmldas->xsdHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - ostringstream print_buf; - - print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xsdHelper->getErrorMessage(error_ix); - } - string print_string = print_buf.str(); - sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); - } - } catch (SDOFileNotFoundException e) { - sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); - } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); - } + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ - /* {{{ proto SDO_DAS_XML SDO_DAS_XML::create(string xsd_file) */ PHP_METHOD(SDO_DAS_XML, create) @@ -325,589 +189,553 @@ * Returns : * SDO_DAS_XML object with model information built-in *****************************************************************************/ - xmldas_object* xmldas = NULL; - char* file_name; - int len = 0; - zval * retval = NULL; - zend_class_entry *ce = NULL; - sdo_das_df_object *das_df_obj; - DataFactoryPtr dataFactory; + xmldas_object *xmldas; + char *file_name; + int file_name_len; + DataFactoryPtr dataFactoryPtr; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() > 1) { WRONG_PARAM_COUNT; } + Z_TYPE_P(return_value) = IS_OBJECT; if (object_init_ex(return_value, sdo_das_xml_class_entry) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to create SDO_DAS_XML"); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; - } - + } xmldas = (xmldas_object *) zend_object_store_get_object(return_value TSRMLS_CC); - dataFactory = DataFactory::getDataFactory(); - xmldas->dataFactory = dataFactory; - xmldas->xsdHelper = HelperProvider::getXSDHelper((DataFactory*)dataFactory); - xmldas->xmlHelper = HelperProvider::getXMLHelper((DataFactory*)dataFactory); + /* Create a C++ DataFactory and an SDO_DAS_DataFactory wrapper for it */ + dataFactoryPtr = DataFactory::getDataFactory(); + INIT_ZVAL(xmldas->z_df); + sdo_das_df_new(&xmldas->z_df, dataFactoryPtr TSRMLS_CC); + + xmldas->xsdHelperPtr = HelperProvider::getXSDHelper((DataFactory *)dataFactoryPtr); + xmldas->xmlHelperPtr = HelperProvider::getXMLHelper((DataFactory *)dataFactoryPtr); if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name,&len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { RETURN_FALSE; } - if(!len) { + if(!file_name_len) { RETURN_FALSE; } try { - xmldas->targetNamespaceURI = xmldas->xsdHelper->defineFile(file_name); + xmldas->xsdHelperPtr->defineFile(file_name); - int error_count = xmldas->xsdHelper->getErrorCount(); + int error_count = xmldas->xsdHelperPtr->getErrorCount(); if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - ostringstream print_buf; - - print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xsdHelper->getErrorMessage(error_ix); - } + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::create - Unable to parse the supplied xsd file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xsdHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } catch (SDOFileNotFoundException e) { sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + +} +/* }}} end SDO_DAS_XML::create */ + +/* {{{ proto SDO_DAS_XML SDO_DAS_XML::addTypes(string xsd_file) + */ +PHP_METHOD(SDO_DAS_XML, addTypes) +{ + xmldas_object *xmldas; + char *file_name; + int file_name_len; + bool exception_thrown = false; + + // TODO lots of code duplicated with create() - /******************************************************************** - * Instantiate an SDO_DAS_DataFactoryImpl object now. Fill in with the - * dataFactory that we created above. - ********************************************************************/ - ce = zend_fetch_class("SDO_DAS_DataFactoryImpl", - strlen("SDO_DAS_DataFactoryImpl"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (!ce) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to fetch SDO_DAS_DataFactoryImpl class"); - RETURN_NULL(); + if (ZEND_NUM_ARGS() != 1) { + WRONG_PARAM_COUNT; } - MAKE_STD_ZVAL(retval); - if (object_init_ex(retval, ce) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to create SDO_DAS_DataFactoryImpl"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { + RETURN_FALSE; + } + if (!file_name_len) { + RETURN_FALSE; } - das_df_obj = (sdo_das_df_object *) zend_object_store_get_object(retval TSRMLS_CC); - if(!das_df_obj) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to get SDO_DAS_DataFactory object from object store"); - } - das_df_obj->dfp = dataFactory; - xmldas->php_das_df = retval; - zend_objects_store_add_ref(xmldas->php_das_df TSRMLS_CC); + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + try { + xmldas->xsdHelperPtr->defineFile(file_name); + + int error_count = xmldas->xsdHelperPtr->getErrorCount(); + if (error_count > 0) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xsdHelperPtr->getErrorMessage(error_ix); + } + string print_string = print_buf.str(); + sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); + RETURN_NULL(); + } + } catch (SDOFileNotFoundException e) { + sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); + exception_thrown = true; + } catch (SDOXMLParserException *e) { + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; + } catch (SDORuntimeException e) { + sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); + exception_thrown = true; + } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + } -/* }}} end SDO_DAS_XML::create */ +/* }}} */ -/* {{{ proto SDO_XMLDocument SDO_DAS_XML::loadFromFile(string xml_file) +/* {{{ proto SDO_XMLDocument SDO_DAS_XML::loadFile(string xml_file) */ -PHP_METHOD(SDO_DAS_XML, loadFromFile) +PHP_METHOD(SDO_DAS_XML, loadFile) { /* * Returns XMLDocument Object containing root SDO object built from the * given path to xml instance document. */ - xmldocument_object *doc_obj = NULL; - xmldas_object *xmldas = NULL; - char* file_name; - int len = 0; - zval *this_obj = getThis(); - zend_class_entry *ce = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *file_name; + int file_name_len; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { RETURN_FALSE; } - if (len) { + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (file_name_len) { Z_TYPE_P(return_value) = IS_OBJECT; - ce = zend_fetch_class("SDO_DAS_XML_Document", - strlen("SDO_DAS_XML_Document"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (object_init_ex(return_value, ce) == FAILURE) { - php_error(E_ERROR,"SDO_DAS_XML::loadFile - Unable to create SDO_DAS_XML"); + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); RETURN_NULL(); } - doc_obj = (xmldocument_object *) zend_object_store_get_object(return_value TSRMLS_CC); - if (!doc_obj) { - php_error(E_ERROR, "SDO_DAS_XML::loadFile - Unable to get XMLDocument object from object store"); + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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_NULL(); } - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if(!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::loadFromFile - Unable to get XMLDAS object from object store"); - } + try { - doc_obj->xdoch = xmldas->xmlHelper->loadFile(file_name,xmldas->targetNamespaceURI); - if (doc_obj->xdoch && doc_obj->xdoch->getRootDataObject() && (xmldas->xmlHelper->getErrorCount() == 0)) { - create_dataobject_tree(doc_obj->xdoch->getRootDataObject() TSRMLS_CC); - } else { - ostringstream print_buf; - print_buf << "SDO_DAS_XML::loadFromFile - Unable to obtain a root data object from the supplied XML\n"; - int error_count = xmldas->xmlHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xmlHelper->getErrorMessage(error_ix); - } - } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->loadFile(file_name); + int error_count = xmldas->xmlHelperPtr->getErrorCount(); + if ((error_count > 0) || + (!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::loadFile - Unable to parse the supplied xml file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xmlHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); RETURN_NULL(); } } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch (SDOFileNotFoundException e) { sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } else { RETURN_FALSE; } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + } /* }}} SDO_DAS_XML::loadFile */ -/* {{{ proto SDO_DAS_XML_Document SDO_DAS_XML::loadFromString(string xml_string) +/* {{{ proto SDO_DAS_XML_Document SDO_DAS_XML::loadString(string xml_string) */ -PHP_METHOD(SDO_DAS_XML, loadFromString) +PHP_METHOD(SDO_DAS_XML, loadString) { /* Returns SDO_DAS_XML_Document Object containing root SDO object built from the given xml string. */ - xmldocument_object *doc_obj = NULL; - xmldas_object *xmldas = NULL; - char* xml_string; - int len = 0; - zval *this_obj = getThis(); - zend_class_entry *ce = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *xml_string; + int xml_string_len; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_string, &len) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_string, &xml_string_len) == FAILURE) { RETURN_FALSE; } - if (len) { + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (xml_string_len) { Z_TYPE_P(return_value) = IS_OBJECT; - ce = zend_fetch_class("SDO_DAS_XML_Document", strlen("SDO_DAS_XML_Document"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (object_init_ex(return_value, ce) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to create SDO_DAS_XML"); + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } - doc_obj = (xmldocument_object *) zend_object_store_get_object(return_value TSRMLS_CC); - if (!doc_obj) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to get SDO_DAS_XML_Document object from object store"); - } - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to get SDO_DAS_XML object from object store"); - } + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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__); + } + try { istringstream str((const char *)xml_string); - doc_obj->xdoch = xmldas->xmlHelper->load(str); - if (doc_obj->xdoch && doc_obj->xdoch->getRootDataObject() && (xmldas->xmlHelper->getErrorCount() == 0)) { - create_dataobject_tree(doc_obj->xdoch->getRootDataObject() TSRMLS_CC); - } else { - ostringstream print_buf; - print_buf << "SDO_DAS_XML::loadFromString - Unable to obtain a root data object from the supplied XML\n"; - int error_count = xmldas->xmlHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the XML string (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the XML string:\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xmlHelper->getErrorMessage(error_ix); - } - } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->load(str); + int error_count = xmldas->xmlHelperPtr->getErrorCount(); + if ((error_count > 0) || + (!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::loadString - Unable to parse the supplied xml string\n"; + print_buf << error_count << " parse error(s) occurred when parsing the string"; + if (error_count > MAX_ERRORS) { + print_buf << "(only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n" ; + + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xmlHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); + RETURN_NULL(); } } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char*)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } else { RETURN_FALSE; } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } } /* }}} SDO_DAS_XML::load */ - -/* {{{ proto SDO_DataObject SDO_DAS_XML::createDataObject(string namespace_uri, string type_name) +/* {{{ proto void SDO_DAS_XML::saveFile(SDO_XMLDocument xdoc, string xml_file) */ -PHP_METHOD(SDO_DAS_XML, createDataObject) +PHP_METHOD(SDO_DAS_XML, saveFile) { - /* - * Returns SDO_DataObject for a given namespace_uri and the type name. - */ - xmldas_object *obj = NULL; - zval *this_obj = getThis(); - zval *namespace_uri = NULL; - zval *type_name = NULL; - zval *retval; + zval *z_document; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *xml_file; + int xml_file_len = 0; + long indent = -1; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 2) { + if (ZEND_NUM_ARGS() != 2 && ZEND_NUM_ARGS() != 3) { WRONG_PARAM_COUNT; } + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", - &namespace_uri, &type_name) == FAILURE) { - RETURN_FALSE; - } - - obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, "SDO_DAS_XML::createDataObject - Unable to get SDO_DAS_XML object from object store"); - } - zend_call_method(&obj->php_das_df, Z_OBJCE_P(obj->php_das_df), NULL, - "create", strlen("create"), &retval, 2, namespace_uri, - type_name TSRMLS_CC); - /* - *TODO, Check are we leaking memory here? - */ - if (retval) { - RETVAL_ZVAL(retval, 1, 0); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML::createDataObject */ - - -/* {{{ proto string SDO_DAS_XML::saveDocumentToString(SDO_XMLDocument xdoc) - */ -PHP_METHOD(SDO_DAS_XML, saveDocumentToString) -{ - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldocument_object *xml_doc_ptr; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; - - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&xml_doc_obj) == FAILURE) { - RETURN_FALSE; - } - xml_doc_ptr = (xmldocument_object *) zend_object_store_get_object(xml_doc_obj TSRMLS_CC); - if (!xml_doc_ptr) { - php_error(E_ERROR, "SDO_DAS_XML::saveDocumentToString - Unable to get SDO_DAS_XML_Document object from object store"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", + &z_document, sdo_das_xml_document_class_entry, &xml_file, + &xml_file_len, &indent) == FAILURE) { + RETURN_FALSE; + } + + xmldocument = (xmldocument_object *) zend_object_store_get_object(z_document 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__); } try { - retval = das_obj->xmlHelper->save(xml_doc_ptr->xdoch); + xmldas->xmlHelperPtr->save(xmldocument->xmlDocumentPtr, xml_file, indent); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } - ret_string = (char *)emalloc(strlen(retval) + 1); - memset(ret_string, 0, strlen(retval) + 1); - strcpy(ret_string, retval); - /* - * retval to be freed using "delete" as it was - * allocated using "new" in save method - */ - delete retval; - RETVAL_STRING((char *)ret_string, 0); } /* }}} */ - -/* {{{ proto void SDO_DAS_XML::saveDocumentToFile(SDO_XMLDocument xdoc, string xml_file) +/* {{{ proto string SDO_DAS_XML::saveString(SDO_XMLDocument xdoc) */ -PHP_METHOD(SDO_DAS_XML, saveDocumentToFile) +PHP_METHOD(SDO_DAS_XML, saveString) { - char *xml_file = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldocument_object *xml_doc_ptr; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + zval *z_document; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + long indent = -1; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 2) { + if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", - &xml_doc_obj, &xml_file, - &file_len) == FAILURE) { - RETURN_FALSE; - } - xml_doc_ptr = (xmldocument_object *) zend_object_store_get_object(xml_doc_obj TSRMLS_CC); - if (!xml_doc_ptr) { - php_error(E_ERROR, "SDO_DAS_XML::save - Unable to get SDO_DAS_XML_Document object from object sotre"); + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", + &z_document, sdo_das_xml_document_class_entry, &indent) == FAILURE) { + RETURN_FALSE; + } + + xmldocument = (xmldocument_object *) zend_object_store_get_object(z_document 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__); } try { - das_obj->xmlHelper->save(xml_doc_ptr->xdoch, xml_file); + char *retval = xmldas->xmlHelperPtr->save(xmldocument->xmlDocumentPtr, indent); + RETVAL_STRING(retval, 1); + /* + * retval to be freed using "delete" as it was + * allocated using "new" in save method + */ + delete retval; } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ - -/* {{{ proto string SDO_DAS_XML::saveDataObjectToString(SDO_DataObject do, string root_uri, string root_name) +/* {{{ proto SDO_DAS_XML SDO_DAS_XML::createDocument(empty | typename | uri,typename) */ -PHP_METHOD(SDO_DAS_XML, saveDataObjectToString) +PHP_METHOD(SDO_DAS_XML, createDocument) { - char *root_uri = NULL; - char *root_name = NULL; - zval *data_obj = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *namespace_uri; + char *element_name; + int namespace_uri_len; + int element_name_len; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 3) { + if (ZEND_NUM_ARGS() > 2) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zss", - &data_obj, &root_uri, &uri_len, - &root_name, &name_len) == FAILURE) { - RETURN_FALSE; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - php_do = (sdo_do_object *) zend_object_store_get_object(data_obj TSRMLS_CC); - if (!php_do) { - php_error(E_ERROR, "XML_DAS::save - We are unable to get SDO_DataObject from object store"); + + Z_TYPE_P(return_value) = IS_OBJECT; + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); + RETURN_NULL(); + } + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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_NULL(); } + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + try { - retval = das_obj->xmlHelper->save(php_do->dop, root_uri, root_name); - } catch (SDORuntimeException e) { + if (ZEND_NUM_ARGS() == 2) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &namespace_uri, &namespace_uri_len, &element_name, &element_name_len) == FAILURE) { + RETURN_FALSE; + } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(element_name, namespace_uri); + } else if (ZEND_NUM_ARGS() == 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &element_name, &element_name_len) == FAILURE) { + RETURN_FALSE; + } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(element_name); + } else { + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(); + } + if ((!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + RETURN_NULL(); + } + } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); + RETURN_NULL(); } - ret_string = (char *)emalloc(strlen(retval) + 1); - memset(ret_string, 0, strlen(retval) + 1); - strcpy(ret_string, retval); - /* - * retval to be freed using "delete" as it was - * allocated using "new" in save method - */ - delete retval; - RETVAL_STRING((char *)ret_string, 0); + } -/* }}} */ +/* }}} end SDO_DAS_XML::create */ -/* {{{ proto void SDO_DAS_XML::saveDataObjectToFile(SDO_DataObject do, string root_uri, string root_name string xml_file) +/* {{{ proto SDO_DataObject SDO_DAS_XML::createDataObject(string namespace_uri, string type_name) */ -PHP_METHOD(SDO_DAS_XML, saveDataObjectToFile) +PHP_METHOD(SDO_DAS_XML, createDataObject) { - char *xml_file = NULL; - char *root_uri = NULL; - char *root_name = NULL; - zval *data_obj = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + /* + * Returns SDO_DataObject for a given namespace_uri and the type name. + */ + xmldas_object *xmldas; + zval *z_namespace_uri; + zval *z_type_name; + zval *z_do, *z_df; - if (ZEND_NUM_ARGS() != 4) { + if (ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsss", - &data_obj, &root_uri, &uri_len, &root_name, - &name_len, &xml_file, - &file_len) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", + &z_namespace_uri, &z_type_name) == FAILURE) { RETURN_FALSE; } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - php_do = (sdo_do_object *) zend_object_store_get_object(data_obj TSRMLS_CC); - if (!php_do) { - php_error(E_ERROR, "SDO_DAS_XML::save - We are unable to get SDO_DataObject from object store"); - } - try { - das_obj->xmlHelper->save(php_do->dop, root_uri, root_name, xml_file); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto void SDO_DAS_XML::getTypes() - */ -PHP_METHOD(SDO_DAS_XML, getTypes) -{ - xmldas_object *das_obj = NULL; - zval* this_obj = getThis(); - char* namespace_uri = NULL; - char* type_name = NULL; - int namespace_uri_len = 0; - int type_name_len = 0; + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); -printf("entered get types\n"); + /* Invoke SDO_DAS_DataFactory::create */ + z_df = &xmldas->z_df; + zend_call_method(&z_df, Z_OBJCE(xmldas->z_df), NULL, + "create", strlen("create"), &z_do, 2, z_namespace_uri, + z_type_name TSRMLS_CC); + RETVAL_ZVAL(z_do, 0, 1); - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!das_obj) { - php_error(E_ERROR, "SDO_DAS_XML::getTypes - Unable to get SDO_DAS_XML object from object store"); - } - - TypeList t = das_obj->dataFactory->getTypes(); - int count = t.size(); - printf("%d types defined\n", count); - for (int i = 0; i < count ; i++) { - printf ("%i %s\n", i, t[i].getName()); - } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", -// &namespace_uri,&namespace_uri_len, &type_name, &type_name_len) == FAILURE) { -// RETURN_FALSE; -// } - // at this point we have char* versions of uri and type name - // TODO: get a property of the requested type from Hydra - // pass to SDO_Model_Property::sdo_model_property_new - // return to the user - return; } -/* }}} */ +/* }}} SDO_DAS_XML::createDataObject */ /* {{{ xmldas_cast_object */ -static int xmldas_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) +static void xmldas_cast_object(zval *readobj, zval *writeobj TSRMLS_DC) { - xmldas_object *my_object; - ostringstream print_buf; - zval free_obj; - int rc = SUCCESS; - const char *indent = "\n"; - - if (should_free) { - free_obj = *writeobj; - } - - my_object = (xmldas_object *) zend_object_store_get_object(readobj TSRMLS_CC); - if (!my_object) { - php_error(E_ERROR, "SDO_DAS_XML::cast object - Unable to get SDO_DAS_XML object from object store"); - } else { - try { - print_buf << indent << "object(" << "SDO_DAS_XML" << ")#" << readobj->value.obj.handle << " {"; - TypeList t = my_object->dataFactory->getTypes(); - int count = t.size(); - print_buf << "\n" << count << " types defined:\n"; - for (int i = 0; i < count ; i++) { - if (strlen (t[i].getURI()) == 0) { - print_buf << " " << i << " " << "(no namespace)" << ":" << t[i].getName() << "\n"; - } else { - print_buf << " " << i << " " << t[i].getURI() << ":" << t[i].getName() << "\n"; - } - } - print_buf << "}"; - - 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; + xmldas_object *xmldas; + ostringstream print_buf; + const char *indent = "\n"; + DataFactoryPtr dataFactoryPtr; + + xmldas = (xmldas_object *) zend_object_store_get_object(readobj TSRMLS_CC); + + try { + dataFactoryPtr = sdo_das_df_get(&xmldas->z_df TSRMLS_CC); + TypeList tl = dataFactoryPtr->getTypes(); + print_buf << indent << "object(" << "SDO_XML_DAS" << ")#" << + readobj->value.obj.handle << " {"; + print_buf << indent << tl.size() << " types have been defined. The types and their properties are::"; + + for (int ix = 0; ix < tl.size(); ix++) { + if (tl[ix].getURI() == NULL || strlen(tl[ix].getURI()) == 0) { + print_buf << indent << ix+1 << ". " << "{no namespace)" << ":" << tl[ix].getName(); + } else { + print_buf << indent << ix+1 << ". " << tl[ix].getURI() << ":" << tl[ix].getName(); + } + PropertyList pl = tl[ix].getProperties(); + for (int px = 0; px < pl.size() ; px++) { + print_buf << indent << " - " << pl[px].getName() << " (" ; + if (pl[px].getType().getURI() == NULL || strlen(pl[px].getType().getURI()) == 0) { + print_buf << "{no namespace)" << ":" << pl[px].getType().getName(); + } else { + print_buf << pl[px].getType().getURI() << ":" << pl[px].getType().getName(); + } + print_buf << ")"; + } } + + print_buf << indent << "}"; + + 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); } - - if (should_free) { - zval_dtor(&free_obj); - } - return rc; + } /* }}} */ + + /* {{{ SDO_DAS_XML::__toString */ PHP_METHOD(SDO_DAS_XML, __toString) { - xmldas_cast_object(getThis(), return_value, IS_STRING, 0 TSRMLS_CC); + xmldas_cast_object(getThis(), return_value TSRMLS_CC); } /* }}} */ -/* {{{ proto void SDO_DAS_XML::getProperty() - */ -PHP_METHOD(SDO_DAS_XML, getProperty) -{ - xmldas_object *das_obj = NULL; - zval* this_obj = getThis(); - char* namespace_uri = NULL; - char* type_name = NULL; - int namespace_uri_len = 0; - int type_name_len = 0; - - // TODO - // When the rest of open types is ready, re-enable and complete this method - if (ZEND_NUM_ARGS() != 2) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!das_obj) { - php_error(E_ERROR, "SDO_DAS_XML::getProperty - Unable to get SDO_DAS_XML object from object store"); - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &namespace_uri,&namespace_uri_len, &type_name, &type_name_len) == FAILURE) { - RETURN_FALSE; - } - // at this point we have char* versions of uri and type name - // TODO: get a property of the requested type from Hydra - // pass to SDO_Model_Property::sdo_model_property_new - // return to the user - return; -} -/* }}} */ - /* * Local variables: * tab-width: 4 http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_XML_Document.cpp?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/SDO_DAS_XML_Document.cpp diff -u pecl/sdo/SDO_DAS_XML_Document.cpp:1.9 pecl/sdo/SDO_DAS_XML_Document.cpp:1.10 --- pecl/sdo/SDO_DAS_XML_Document.cpp:1.9 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/SDO_DAS_XML_Document.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_XML_Document.cpp,v 1.9 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_XML_Document.cpp,v 1.10 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -31,33 +31,24 @@ #include "php_sdo_das_xml_int.h" -// Forward declarations for ths module only -zend_object_value sdo_das_xml_document_object_create(zend_class_entry *ce TSRMLS_DC); -void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC); +#define CLASS_NAME "SDO_DAS_XML_Document" -zend_object_handlers sdo_das_xml_doc_object_handlers; +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_setEncoding_args, 0) - ZEND_ARG_INFO(0, encoding) -ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLDeclaration_args, 0) - ZEND_ARG_INFO(0, xmlDeclaration) + ZEND_ARG_INFO(0, xml_declaration) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLVersion_args, 0) - ZEND_ARG_INFO(0, xmlVersion) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setSchemaLocation_args, 0) - ZEND_ARG_INFO(0, schemaLocation) + ZEND_ARG_INFO(0, xml_version) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setNoNamespaceSchemaLocation_args, 0) - ZEND_ARG_INFO(0, noNamespaceSchemaLocation) +ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setEncoding_args, 0) + ZEND_ARG_INFO(0, encoding) ZEND_END_ARG_INFO(); -/* argument definations of SDO_DAS_XML_Document class, end */ +/* argument definitions of SDO_DAS_XML_Document class, end */ /* {{{ sdo_xmldocument_methods * @@ -67,120 +58,98 @@ 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, getEncoding, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setEncoding, - sdo_xmldoc_setEncoding_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getXMLDeclaration, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DAS_XML_Document, setXMLDeclaration, sdo_xmldoc_setXMLDeclaration_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getXMLVersion, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DAS_XML_Document, setXMLVersion, sdo_xmldoc_setXMLVersion_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getSchemaLocation, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setSchemaLocation, - sdo_xmldoc_setSchemaLocation_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation, 0, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation, - sdo_xmldoc_setNoNamespaceSchemaLocation_args, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DAS_XML_Document, setEncoding, + sdo_xmldoc_setEncoding_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ - -/* {{{ initialize_sdo_das_xml_document_class - * - * Initializes SDO_DAS_XML_Document class +/* {{{ sdo_das_xml_document_free_storage */ -void -initialize_sdo_das_xml_document_class(TSRMLS_D) { - zend_class_entry ce; - zend_class_entry* sdo_das_xml_doc_cls_entry; - - 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_doc_cls_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.clone_obj = NULL; +void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC) +{ + + xmldocument_object *xmldocument = (xmldocument_object *) object; + zend_hash_destroy(xmldocument->zo.properties); + FREE_HASHTABLE(xmldocument->zo.properties); + + if (xmldocument->xmlDocumentPtr) { + delete xmldocument->xmlDocumentPtr; + } + 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 *obj = (xmldocument_object *) - emalloc(sizeof(xmldocument_object)); - memset(obj, 0, sizeof(xmldocument_object)); - - obj->z_obj.ce = ce; - ALLOC_HASHTABLE(obj->z_obj.properties); - zend_hash_init(obj->z_obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(obj->z_obj.properties, &ce->default_properties, - (copy_ctor_func_t) zval_add_ref, (void *) &tmp, - sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, NULL, - sdo_das_xml_document_object_free_storage, - NULL TSRMLS_CC); +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; + 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, NULL, + sdo_das_xml_document_object_free_storage, + NULL TSRMLS_CC); retval.handlers = &sdo_das_xml_doc_object_handlers; return retval; } /* }}} */ - -/* {{{ sdo_das_xml_document_free_storage +/* {{{ sdo_das_xml_document_minit + * + * Initializes SDO_DAS_XML_Document class */ -void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC) { - - xmldocument_object *obj = (xmldocument_object *) object; - zend_hash_destroy(obj->z_obj.properties); - FREE_HASHTABLE(obj->z_obj.properties); +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); - if (obj->xdoch) { - delete obj->xdoch; - } - efree(obj); + memcpy(&sdo_das_xml_doc_object_handlers, zend_get_std_object_handlers(), + sizeof(zend_object_handlers)); + sdo_das_xml_doc_object_handlers.clone_obj = NULL; } /* }}} */ - -/* {{{ proto SDO_DataObject SDO_DAS_XML_Document::getRoorDataObject() +/* {{{ proto SDO_DataObject SDO_DAS_XML_Document::getRootDataObject() Returns the root SDO_DataObject. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootDataObject) { - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - zval *retval = NULL; - zend_object *php_das_obj = NULL; - DataObject *root_do = NULL; - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } +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 = obj->xdoch->getRootDataObject(); + root_do = xmldocument->xmlDocumentPtr->getRootDataObject(); if (!root_do) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to find root DataObject"); - RETURN_NULL(); - } - retval = (zval *) root_do->getUserData(); - if (!retval) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to find php version of root DataObject"); + 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); } - RETVAL_ZVAL(retval, 1, 0); } /* }}} SDO_DAS_XML_Document::getRootDataObject */ @@ -188,31 +157,22 @@ /* {{{ proto string SDO_DAS_XML_Document::getRootElementURI() Returns root element URI string. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI) +{ + xmldocument_object *xmldocument; + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootElementURI - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); + try { - retval = obj->xdoch->getRootElementURI(); + RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementURI(), 1); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); RETURN_NULL(); } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } + } /* }}} SDO_DAS_XML_Document::getRootElementURI */ @@ -220,206 +180,48 @@ /* {{{ proto string SDO_DAS_XML_Document::getRootElementName() Returns root element name. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootElementName) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootElementName - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getRootElementName(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getRootElementName */ - - -/* {{{ proto string SDO_DAS_XML_Document::getEncoding() - Returns encoding string. - */ -PHP_METHOD(SDO_DAS_XML_Document, getEncoding) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getEncoding - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getEncoding(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getEncoding */ - - -/* {{{ proto boolean SDO_DAS_XML_Document::getXMLDeclaration() - Returns whethe xml declaration is set or not. - */ -PHP_METHOD(SDO_DAS_XML_Document, getXMLDeclaration) { - bool retval; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getXMLDeclaration - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getXMLDeclaration(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - RETVAL_BOOL(retval); -} -/* }}} SDO_DAS_XML_Document::getXMLDeclaration */ - +PHP_METHOD(SDO_DAS_XML_Document, getRootElementName) +{ + xmldocument_object *xmldocument; -/* {{{ proto string SDO_DAS_XML_Document::getXMLVersion() - Returns xml declaration string. - */ -PHP_METHOD(SDO_DAS_XML_Document, getXMLVersion) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getXMLVersion - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getXMLVersion(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getXMLVersion */ - + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); -/* {{{ proto string SDO_DAS_XML_Document::getSchemaLocation() - Returns schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, getSchemaLocation) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } try { - retval = obj->xdoch->getSchemaLocation(); + RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementName(), 1); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getSchemaLocation */ - -/* {{{ proto string SDO_DAS_XML_Document::getNoNamespaceSchemaLocation() - Returns no namespace schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getNoNamespaceSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getNoNamespaceSchemaLocation(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } } -/* }}} SDO_DAS_XML_Document::getNoNamespaceSchemaLocation */ - +/* }}} 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) { - bool xmlDeclaration; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +PHP_METHOD(SDO_DAS_XML_Document, setXMLDeclaration) +{ + long 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", &xmlDeclaration) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &xml_declaration) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setXMLDeclaration - Unable to get SDO_DAS_XML_Document Object from object store"); + 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 { - obj->xdoch->setXMLDeclaration(xmlDeclaration); + xmldocument->xmlDocumentPtr->setXMLDeclaration(ZEND_TRUTH(xml_declaration)); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } @@ -427,123 +229,52 @@ } /* }}} 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 *xmlVersion = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xmlVersion, &len) == FAILURE) { - RETURN_FALSE; - } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setXMLVersion - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - obj->xdoch->setXMLVersion(xmlVersion); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - return; -} -/* }}} SDO_DAS_XML_Document::setXMLVersion */ - +PHP_METHOD(SDO_DAS_XML_Document, setXMLVersion) +{ + char *xml_version; + int xml_version_len; + xmldocument_object *xmldocument; -/* {{{ proto void SDO_DAS_XML_Document::setSchemaLocation(string schemaLocation) - Sets the given string as schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, setSchemaLocation) { - char *schemaLocation = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaLocation, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_version, &xml_version_len) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - obj->xdoch->setSchemaLocation(schemaLocation); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - return; -} -/* }}} SDO_DAS_XML_Document::setSchemaLocation */ - + xmldocument = (xmldocument_object *) zend_object_store_get_object(getThis() TSRMLS_CC); -/* {{{ proto void SDO_DAS_XML_Document::setNoNamespaceSchemaLocation(string nnschemaLocation) - Sets the given string as no namespace schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation) { - char *nnSchemaLocation = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &nnSchemaLocation, &len) == FAILURE) { - RETURN_FALSE; - } - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setNoNamespaceSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } try { - obj->xdoch->setNoNamespaceSchemaLocation(nnSchemaLocation); + xmldocument->xmlDocumentPtr->setXMLVersion(xml_version); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } + return; } -/* }}} SDO_DAS_XML_Document::setNoNamespaceSchemaLocation */ - +/* }}} 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 = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +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, &len) == FAILURE) { + &encoding, &encoding_len) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setEncoding - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); + try { - obj->xdoch->setEncoding(encoding); + xmldocument->xmlDocumentPtr->setEncoding(encoding); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DataObject.cpp?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/SDO_DataObject.cpp diff -u pecl/sdo/SDO_DataObject.cpp:1.12 pecl/sdo/SDO_DataObject.cpp:1.13 --- pecl/sdo/SDO_DataObject.cpp:1.12 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_DataObject.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DataObject.cpp,v 1.12 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DataObject.cpp,v 1.13 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -36,6 +36,16 @@ #define CLASS_NAME "SDO_DataObject" +/** {{{ sdo_do_object + * The internal structure for an SDO_DataObjectImpl + * This extends the standard zend_object + */ +typedef struct { + zend_object zo; /* The standard zend_object */ + DataObjectPtr dop; /* The C++ DataObject */ +} sdo_do_object; +/* }}} */ + /* {{{ sdo_do_iterator * The iterator data for this class - extends the standard zend_object_iterator */ @@ -63,16 +73,27 @@ */ static void sdo_do_object_free_storage(void *object TSRMLS_DC) { - sdo_do_object *my_object; + sdo_do_object *my_object; + char *space; + char *class_name; my_object = (sdo_do_object *)object; zend_hash_destroy(my_object->zo.properties); FREE_HASHTABLE(my_object->zo.properties); /* just release the reference, and the reference counting will kick in */ - /*TODO assigning NULL triggers an error in the C++ library at shutdown. - *my_object->dop = NULL; - */ + if (my_object->dop) { + try { + my_object->dop->setUserData((void *)SDO_USER_DATA_EMPTY); + + /* causes an Access Violation :-( */ + //my_object->dop = NULL; + } catch (SDORuntimeException e) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): internal error - caught exception freeing DataObject", + class_name, space, get_active_function_name(TSRMLS_C)); + } + } efree(object); } /* }}} */ @@ -99,6 +120,69 @@ } /* }}} */ +/* {{{ sdo_do_get + * utility function to get C++ DataObject from zval + */ +DataObjectPtr sdo_do_get(zval *me TSRMLS_DC) +{ + sdo_do_object *my_object; + + my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); + if (my_object) + return my_object->dop; + else + return NULL; +} +/* }}} */ + +/* {{{ sdo_do_new + * Find the PHP object corresponding to the CPP object, or create one. + * The DataObject has no public constructor, this is in effect its factory method. + */ +void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC) +{ + sdo_do_object *my_object; + char *class_name, *space; + + int object_handle = (int)dop->getUserData(); + + Z_TYPE_P(me) = IS_OBJECT; + /* If the object is already known to php, its user data will contain + * the value of the object handle. + */ + if (object_handle == SDO_USER_DATA_EMPTY) { + if (object_init_ex(me, sdo_dataobjectimpl_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); + return; + } + + my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); + my_object->dop = dop; + /* add a back pointer to the C++ object */ + try { + dop->setUserData ((void *)me->value.obj.handle); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); + } + } else { + me->value.obj.handle = object_handle; + me->value.obj.handlers = &sdo_do_object_handlers; + me->value.obj.handlers->add_ref(me TSRMLS_CC); + + /* Sanity check */ + my_object = (sdo_do_object *)sdo_do_get_instance(me TSRMLS_CC); + if (!my_object) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject #%d not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, object_handle); + return; + } + } +} +/* }}} */ + /* {{{ sdo_do_clone_obj */ static zend_object_value sdo_do_clone_obj(zval *object TSRMLS_DC) @@ -131,12 +215,9 @@ sdo_do_object *my_object = (sdo_do_object *)NULL; DataObjectPtr dop; int return_value = 0; + char *class_name, *space; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } dop = my_object->dop; @@ -162,7 +243,9 @@ } else { switch (propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -196,15 +279,21 @@ /* since the property is set, the data object cannot be 'empty' */ break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%i: unexpected type %s for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getType().getName(), xpath); return_value = 0; } @@ -224,7 +313,9 @@ { zval *return_value; - MAKE_STD_ZVAL(return_value); + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; + try { DataObjectList& list_value = sdo->dop->getList(xpath); if (&list_value == NULL) { @@ -251,51 +342,48 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; - MAKE_STD_ZVAL(return_value); try { if (propertyp->isMany()) { - /* If the property is many-valued and the list is uninitialized, - * all bets are off. The C++ library does not catch this - * consistently, so ... - */ + /* If the property is many-valued and the list is uninitialized, + * all bets are off. The C++ library does not catch this + * consistently, so ... + */ if (! dop->isSet(xpath)) { zend_throw_exception_ex(sdo_indexoutofboundsexception_class_entry, 0 TSRMLS_CC, - "Cannot read list at index \"%s\" because the list is empty", + "Cannot read list at index '%s' because the list is empty", (char *)xpath); - RETVAL_NULL(); return return_value; } } else { - /* - * If the property is single-valued, we should just leave it to the - * C++ library to decide whether the property is set, but currently - * it fails to detect this error, so we shall catch it here instead. - * To be honest, there is no justification in the spec for - * restricting this to DataObject types, but it just doesn't seem - * right in the PHP world to throw an exception when a primitive - * happens to be unset. - */ - if (propertyp->isReference() && !dop->isValid(xpath)) { + /* + * If the property is single-valued, we should just leave it to the + * C++ library to decide whether the property is set, but currently + * it fails to detect this error, so we shall catch it here instead. + */ + if (!dop->isValid(xpath)) { zend_throw_exception_ex(sdo_propertynotsetexception_class_entry, 0 TSRMLS_CC, - "Cannot read property \"%s\" because it is not set", - (char *)xpath); - RETVAL_NULL(); + "Cannot read property '%s' because it is not set", + propertyp->getName()); return return_value; } } - + if (dop->isNull(xpath)) { RETVAL_NULL(); } else { switch(propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes' for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -317,7 +405,9 @@ case Type::CharacterType: wchar_value = dop->getCharacter(xpath); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); } char_value = dop->getByte(xpath); RETVAL_STRINGL(&char_value, 1, 1); @@ -348,33 +438,36 @@ case Type::DataObjectType: doh_value = dop->getDataObject(xpath); if (!doh_value) { - php_error(E_WARNING, "%s:%i: read a NULL DataObject for property '%s'", CLASS_NAME, __LINE__, - propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): read a NULL DataObject for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - if (doh_value_zval == (zval *)SDO_USER_DATA_EMPTY) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, - propertyp->getType().getName(), xpath); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, + propertyp->getType().getName(), propertyp->getName()); } } return return_value; } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); - RETVAL_NULL(); + efree(return_value); + return_value = 0; } return return_value; } @@ -392,14 +485,7 @@ zval *return_value; - my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - MAKE_STD_ZVAL(return_value); - RETVAL_NULL(); - return return_value; - } - + my_object = sdo_do_get_instance(object TSRMLS_CC); dop = my_object->dop; try { @@ -443,10 +529,6 @@ sdo_do_object *my_object; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (sdo_parse_offset_param( @@ -471,15 +553,10 @@ sdo_do_object *my_object, *value_object; DataObjectPtr dop; zval temp_zval; - bool is_open; Type::Types type_enum; + char *class_name, *space; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } - dop = my_object->dop; try { @@ -516,8 +593,9 @@ zval_copy_ctor(&temp_zval); switch(type_enum) { - case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -574,23 +652,38 @@ dop->setCString(xpath, Z_STRVAL(temp_zval)); break; case Type::DataObjectType: - convert_to_object(&temp_zval); - if (!instanceof_function(Z_OBJCE(temp_zval), sdo_dataobjectimpl_class_entry TSRMLS_CC)) { - php_error(E_ERROR, "%s:%i: cannot cast %s to %s", CLASS_NAME, __LINE__, - Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); + if (Z_TYPE_P(z_propertyValue) != IS_OBJECT) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0,0 TSRMLS_CC, + "%s%s%s(): cannot cast %s to %s for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), + zend_zval_type_name(z_propertyValue), CLASS_NAME, xpath); + } else if (!instanceof_function(Z_OBJCE_P(z_propertyValue), sdo_dataobjectimpl_class_entry TSRMLS_CC)) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0,0 TSRMLS_CC, + "%s%s%s(): cannot cast %s to %s for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), + Z_OBJCE_P(z_propertyValue)->name, + sdo_dataobjectimpl_class_entry->name, xpath); } else { - value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + value_object = (sdo_do_object *)zend_object_store_get_object(z_propertyValue TSRMLS_CC); dop->setDataObject(xpath, value_object->dop); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, (property_p ? property_p->getType().getName() : ""), xpath); } zval_dtor(&temp_zval); @@ -608,49 +701,48 @@ static HashTable *sdo_do_get_properties(zval *object TSRMLS_DC) { sdo_do_object *my_object; - HashTable *properties; + HashTable *properties; int entries; - zval *tmp; + zval *tmp; + + zval z_holder; - ALLOC_HASHTABLE(properties); + array_init(&z_holder); my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - PropertyList pl = my_object->dop->getInstanceProperties(); - entries = pl.size(); - zend_hash_init(properties, entries, NULL, NULL, 0); - for (long index = 0; index < entries; index++) { - /* It's safe to use the property directly here, it cannot be an xpath */ - const Property& property = pl[index]; - const char *propertyName = property.getName(); - - /* Usually we check isMany() before isSet(), because we should not return NULL just because - * the List is empty. But for get_properties the return values are readonly, so it's - * safer and clearer to omit empty lists. - */ - if (my_object->dop->isSet(property)) { - if (property.isMany()) { - long count = 0; - tmp = sdo_do_read_list(my_object, propertyName, &property TSRMLS_CC); - sdo_list_count_elements (tmp, &count TSRMLS_CC); - if (count == 0) - continue; - } else { - tmp = sdo_do_read_value(my_object, propertyName, &property TSRMLS_CC); - } + + try { + PropertyList pl = my_object->dop->getInstanceProperties(); + entries = pl.size(); + for (long index = 0; index < entries; index++) { + /* It's safe to use the property directly here, it cannot be an xpath */ + const Property& property = pl[index]; + const char *propertyName = property.getName(); + + /* Usually we check isMany() before isSet(), because we should not return NULL just because + * the List is empty. But for get_properties the return values are readonly, so it's + * safer and clearer to omit empty lists. + */ + if (my_object->dop->isSet(property)) { + if (property.isMany()) { + long count = 0; + tmp = sdo_do_read_list(my_object, propertyName, &property TSRMLS_CC); + sdo_list_count_elements (tmp, &count TSRMLS_CC); + if (count == 0) + continue; } else { - continue; + tmp = sdo_do_read_value(my_object, propertyName, &property TSRMLS_CC); } - zend_hash_update(properties, (char *)propertyName, 1 + strlen(propertyName), - &tmp, sizeof(zval *), NULL); + } else { + continue; } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); + add_assoc_zval(&z_holder, (char *)propertyName, tmp); } + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } + + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -742,55 +834,49 @@ } my_object = sdo_do_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { + + try { + const Type& type = my_object->dop->getType(); + PropertyList pl = my_object->dop->getInstanceProperties(); - try { - const Type& type = my_object->dop->getType(); - PropertyList pl = my_object->dop->getInstanceProperties(); + print_buf << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " (" << pl.size() << ") {"; + + for (unsigned int i = 0; i < pl.size(); i++) { + const Property& prop = pl[i]; + + if (i > 0) { + print_buf << "; "; + } - print_buf << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " (" << pl.size() << ") {"; + print_buf << prop.getName(); - for (unsigned int i = 0; i < pl.size(); i++) { - const Property& prop = pl[i]; + /* We'll try to print the value for single-valued primitives only. + * Multi-valued properties just get a dimension. + */ + if (prop.isMany()) { + print_buf << '[' << my_object->dop->getList(prop).size() << ']'; - if (i > 0) { - print_buf << "; "; + } else if (my_object->dop->isSet(i) && prop.getType().isDataType()) { + print_buf << "=>"; + if (my_object->dop->isNull(i)) { + print_buf << "NULL"; + } else { + print_buf << '\"' << my_object->dop->getCString(i) << '\"'; } - print_buf << prop.getName(); - - /* We'll try to print the value for single-valued primitives only. - * Multi-valued properties just get a dimension. - */ - if (prop.isMany()) { - print_buf << '[' << my_object->dop->getList(prop).size() << ']'; - - } else if (my_object->dop->isSet(i) && prop.getType().isDataType()) { - print_buf << "=>"; - if (my_object->dop->isNull(i)) { - print_buf << "NULL"; - } else { - print_buf << '\"' << my_object->dop->getCString(i) << '\"'; - } - - } } - - print_buf << '}'; - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; } - } + + print_buf << '}'; + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -823,11 +909,6 @@ sdo_do_object *my_object; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - *count = 0; - return FAILURE; - } try { *count = my_object->dop->getInstanceProperties().size(); @@ -839,11 +920,37 @@ } /* }}} */ -static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC); +/* {{{ sdo_do_iterator_rewind + */ +static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC) +{ + sdo_do_iterator *iterator = (sdo_do_iterator *)iter; + zval *z_do_object = (zval *)iterator->zoi.data; + sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(z_do_object TSRMLS_CC); + + try { + PropertyList pl = my_object->dop->getInstanceProperties(); + for (iterator->index = 0; + iterator->index < pl.size() && ! my_object->dop->isValid(iterator->index); + iterator->index++); + iterator->valid = (iterator->index < pl.size()); + } catch (SDORuntimeException e) { + iterator->valid = false; + sdo_throw_runtimeexception(&e TSRMLS_CC); + } +} +/* }}} */ /* {{{ sdo_do_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_do_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_do_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(object TSRMLS_CC); sdo_do_iterator *iterator = (sdo_do_iterator *)emalloc(sizeof(sdo_do_iterator)); @@ -963,27 +1070,6 @@ } /* }}} */ -/* {{{ sdo_do_iterator_rewind - */ -static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC) -{ - sdo_do_iterator *iterator = (sdo_do_iterator *)iter; - zval *z_do_object = (zval *)iterator->zoi.data; - sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(z_do_object TSRMLS_CC); - - try { - PropertyList pl = my_object->dop->getInstanceProperties(); - for (iterator->index = 0; - iterator->index < pl.size() && ! my_object->dop->isValid(iterator->index); - iterator->index++); - iterator->valid = (iterator->index < pl.size()); - } catch (SDORuntimeException e) { - iterator->valid = false; - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - /* {{{ sdo_do_serialize * Both the model and the graph are serialized to a buffer. */ @@ -997,18 +1083,14 @@ xmldas::XMLDAS *xmldasp; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return FAILURE; - } try { xmldasp = sdo_get_XMLDAS(); /* create an XML representation of the model */ serialized_model = xmldasp->generateSchema(my_object->dop); model_length = strlen(serialized_model); - /* serialize the data graph */ - serialized_graph = xmldasp->save(my_object->dop, 0, 0); + /* serialize the data graph to an unformatted string */ + serialized_graph = xmldasp->save(my_object->dop, 0, 0, -1); graph_length = strlen(serialized_graph); /* @@ -1030,41 +1112,6 @@ } /* }}} */ -/* {{{ sdo_do_populate_graph - * walk the data graph creating a php wrapper for each data object. - * Return the zval for the root object. - */ -static zval *sdo_do_populate_graph (DataObjectPtr dop TSRMLS_DC) -{ - zval *z_new_do; - - /* We may have previously encountered this DataObject, perhaps as a non-containment reference. - * If so, don't create a duplicate PHP object. - */ - z_new_do = (zval *)dop->getUserData(); - if (z_new_do == (zval *)SDO_USER_DATA_EMPTY) { - - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, dop TSRMLS_CC); - - PropertyList pl = dop->getInstanceProperties(); - for (int i = 0; i < pl.size(); i++) { - if (dop->isSet(pl[i])) { - if (pl[i].isMany()) { - DataObjectList& dol = dop->getList(pl[i]); - for (int j = 0; j < dol.size(); j++) { - sdo_do_populate_graph(dol[j] TSRMLS_CC); - } - } else if (pl[i].getType().isDataObjectType()) { - sdo_do_populate_graph(dop->getDataObject(pl[i]) TSRMLS_CC); - } - } - } - } - return z_new_do; -} -/* }}} */ - /* {{{ sdo_do_unserialize * Recreate the graph and underlying model from a buffer. */ @@ -1073,7 +1120,6 @@ char *serialized_model; char *serialized_graph; zval *factory_zval; - zval *root_object_zval; xmldas::XMLDAS *xmldasp; /* @@ -1094,10 +1140,10 @@ /* Load the graph */ DataObjectPtr root_dop = xmldasp->load(serialized_graph)->getRootDataObject(); - /* Walk the graph creating its PHP representation */ - root_object_zval = sdo_do_populate_graph(root_dop TSRMLS_CC); - **object = *root_object_zval; - zval_copy_ctor(*object); + /* Create a PHP object fot the root. Other nodes will be created + * lazily as required. + */ + sdo_do_new(*object, root_dop TSRMLS_CC); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1108,30 +1154,6 @@ } /* }}} */ -/* {{{ sdo_do_new - * The DataObject has no public constructor, this is in effect its factory method. - */ -void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC) -{ - sdo_do_object *my_object; - - Z_TYPE_P(me) = IS_OBJECT; - if (object_init_ex(me, sdo_dataobjectimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); - return; - } - - my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); - my_object->dop = dop; - /* add a back pointer to the C++ object */ - try { - dop->setUserData ((void *)me); - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - /* {{{ sdo_do_minit */ void sdo_do_minit(zend_class_entry *tmp_ce TSRMLS_DC) @@ -1175,7 +1197,11 @@ */ PHP_METHOD(SDO_DataObjectImpl, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -1185,21 +1211,15 @@ { sdo_do_object *my_object; DataObjectPtr container_dop; - zval *container_zval; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { container_dop = my_object->dop->getContainer(); if (!container_dop) { RETVAL_NULL(); } else { - container_zval = (zval *)container_dop->getUserData(); - RETVAL_ZVAL(container_zval, 1, 0); + sdo_do_new(return_value, container_dop TSRMLS_CC); } } catch (SDORuntimeException e){ sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1207,73 +1227,48 @@ } /* }}} */ -/* {{{ SDO_DataObjectImpl::getContainmentPropertyName +/* {{{ SDO_DataObjectImpl::clear */ -PHP_METHOD(SDO_DataObjectImpl, getContainmentPropertyName) +PHP_METHOD(SDO_DataObjectImpl, clear) { - sdo_do_object *my_object; - - php_error(E_WARNING, - "SDO_DataObject::getContainmentPropertyName() is deprecated, and will be removed in the next release. Use SDO_Model_ReflectionDataObject::getContainmentProperty()"); + sdo_do_object *my_object; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { - RETVAL_STRING((char *)my_object->dop->getContainmentProperty().getName(), 1); - } catch (SDOPropertyNotFoundException e) { - /* In this case the C++ API means we must catch an exception on the normal path */ - RETVAL_NULL(); - } catch (SDORuntimeException e) { + my_object->dop->clear(); + } catch (SDORuntimeException e){ sdo_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ -/* {{{ SDO_DataObjectImpl::clear +/* {{{ SDO_DataObjectImpl::getTypeName */ -PHP_METHOD(SDO_DataObjectImpl, clear) +PHP_METHOD(SDO_DataObjectImpl, getTypeName) { - sdo_do_object *my_object; - + sdo_do_object *my_object; + my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - my_object->dop->clear(); - } catch (SDORuntimeException e){ - sdo_throw_runtimeexception(&e TSRMLS_CC); - } + + try { + RETVAL_STRING((char *)my_object->dop->getType().getName(), 1); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ -/* {{{ SDO_DataObjectImpl::getType +/* {{{ SDO_DataObjectImpl::getTypeURI */ -PHP_METHOD(SDO_DataObjectImpl, getType) +PHP_METHOD(SDO_DataObjectImpl, getTypeNamespaceURI) { sdo_do_object *my_object; - - php_error(E_WARNING, - "SDO_DataObject::getType() is deprecated, and will be removed in the next release. Use SDO_Model_ReflectionDataObject::getType()"); - + my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { - const Type& type = my_object->dop->getType(); - - /* return the type as a PHP array */ - array_init(return_value); - add_next_index_string(return_value, (char *)type.getURI(), 1); - add_next_index_string(return_value, (char *)type.getName(), 1); + RETVAL_STRING((char *)my_object->dop->getType().getURI(), 1); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } @@ -1288,16 +1283,11 @@ const char *xpath; sdo_do_object *my_object; DataObjectPtr dop, new_dop; - zval *z_new_do; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_property) == FAILURE) return; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } dop = my_object->dop; @@ -1314,9 +1304,7 @@ } /* We have a good data object, so set up its PHP incarnation */ - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, new_dop TSRMLS_CC); - RETVAL_ZVAL(z_new_do, 1, 0); + sdo_do_new(return_value, new_dop TSRMLS_CC); } /* }}} */ @@ -1332,11 +1320,6 @@ } my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } - dop = my_object->dop; try { @@ -1345,7 +1328,7 @@ RETVAL_NULL(); } else { /* Create the PHP wrapper */ - sdo_sequence_new (return_value, seqp, dop TSRMLS_CC); + sdo_sequence_new (return_value, seqp TSRMLS_CC); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1365,10 +1348,6 @@ } my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } dop = my_object->dop; http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_List.cpp?r1=1.13&r2=1.14&diff_format=u Index: pecl/sdo/SDO_List.cpp diff -u pecl/sdo/SDO_List.cpp:1.13 pecl/sdo/SDO_List.cpp:1.14 --- pecl/sdo/SDO_List.cpp:1.13 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_List.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_List.cpp,v 1.13 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_List.cpp,v 1.14 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -56,7 +56,6 @@ const ChangedDataObjectList *cdolp; const SettingList *slp; }; - const Type *typep; /* only used for DataObjectList */ } sdo_list_object; /* }}} */ @@ -124,10 +123,13 @@ static sdo_list_object *sdo_list_new(zval *me, zend_class_entry *ce TSRMLS_DC) { sdo_list_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, ce) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return (sdo_list_object *)NULL; } @@ -145,7 +147,6 @@ my_object = sdo_list_new(me, sdo_dataobjectlist_class_entry TSRMLS_CC); my_object->list_type = TYPE_DataObjectList; - my_object->typep = &type; my_object->dolp = dolp; } /* }}} */ @@ -160,7 +161,6 @@ my_object->list_type = TYPE_ChangedDataObjectList; my_object->cdolp = cdolp; - my_object->typep = NULL; } /* }}} */ @@ -174,7 +174,6 @@ my_object->list_type = TYPE_SettingList; my_object->slp = &sl; - my_object->typep = NULL; } /* }}} */ @@ -187,20 +186,23 @@ wchar_t wchar_value; zval *return_value; DataObjectPtr doh_value; - zval *doh_value_zval; + char *class_name, *space; - const DataObjectList& dol = *my_object->dolp; - const Type *type = my_object->typep; + DataObjectList& dol = *my_object->dolp; - MAKE_STD_ZVAL(return_value); + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; + try { if (index >= dol.size()) { RETVAL_NULL(); } else { - MAKE_STD_ZVAL(return_value); - switch(type->getTypeEnum()) { + const Type& type = dol.getType(); + switch(type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -222,7 +224,9 @@ case Type::CharacterType: wchar_value = dol.getCharacter(index); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost reading many-valued property", + class_name, space, get_active_function_name(TSRMLS_C)); } char_value = dol.getByte(index); RETVAL_STRINGL(&char_value, 1, 1); @@ -256,18 +260,23 @@ if (!doh_value) { RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type->getTypeEnum()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getTypeEnum()); } } @@ -284,10 +293,11 @@ static zval *sdo_changeddataobjectlist_read_value(sdo_list_object *my_object, long index TSRMLS_DC) { const ChangedDataObjectList& dol = *my_object->cdolp; - zval *doh_value_zval; zval *return_value; MAKE_STD_ZVAL(return_value); + return_value->refcount = 0; + /* Elements of a ChangedDataObjectList are all DataObject type */ try { if (index >= dol.size()) { @@ -298,8 +308,7 @@ if (!doh_value) { RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } } } catch (SDORuntimeException e) { @@ -317,6 +326,7 @@ const SettingList& sl = *my_object->slp; MAKE_STD_ZVAL(return_value); + return_value->refcount = 0; /* Elements of a SettingList are all DAS_Setting type */ try { @@ -336,13 +346,12 @@ */ static void sdo_dataobjectlist_write_value(sdo_list_object *my_object, long index, zval *z_value, sdo_write_type write_type TSRMLS_DC) { - sdo_do_object *value_object; zval temp_zval; + char *class_name, *space; DataObjectList& dol = *my_object->dolp; - const Type *type = my_object->typep; - try { + try { if (write_type != TYPE_APPEND && (index < 0 || index >= dol.size())) { zend_throw_exception_ex(sdo_indexoutofboundsexception_class_entry, 0 TSRMLS_CC, @@ -351,7 +360,7 @@ } /* - * Since we may have to coerce the type, we make a local copy of the zval, so that the + * Since we may have to coerce the type, we make a local copy of the zval, so that the * original is unaffected. * * TODO This could be optimized to only copy if we do actually change the type. @@ -361,10 +370,13 @@ /* we must have at least the type enum here in case this is an append and * we don't know what type to append - */ - switch(type->getTypeEnum()) { + */ + const Type& type = dol.getType(); + switch(type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -492,24 +504,30 @@ "Class %s is not an instance of %s", Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); } else { - value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + DataObjectPtr dop = sdo_do_get(&temp_zval TSRMLS_CC); if (write_type == TYPE_APPEND) { - dol.append(value_object->dop); + dol.append(dop); } else if (write_type == TYPE_INSERT) { - dol.insert(index, value_object->dop); + dol.insert(index, dop); } else { - dol.setDataObject(index, value_object->dop); + dol.setDataObject(index, dop); } } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %s", CLASS_NAME, __LINE__, type->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getName()); } zval_dtor(&temp_zval); } catch (SDORuntimeException e) { @@ -522,8 +540,8 @@ */ static int sdo_dataobjectlist_valid(sdo_list_object *my_object, long index, int check_empty TSRMLS_DC) { - int return_value = 0; - const Type *type; + int return_value = 0; + char *class_name, *space; try { return_value = (index >= 0 && index < my_object->dolp->size()); @@ -531,10 +549,12 @@ if (return_value && check_empty) { /* cf SDO_DataObject.read_dimension() */ DataObjectList& dol = *my_object->dolp; - type = my_object->typep; - switch (type->getTypeEnum()) { + const Type& type = dol.getType(); + switch (type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -567,15 +587,21 @@ return_value = (!(dol[index])); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type->getTypeEnum()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getTypeEnum()); return_value = 0; } } @@ -637,20 +663,19 @@ char *propertyName = NULL; long index; int return_value = 0; - sdo_list_object *my_object; + sdo_list_object *my_object; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return 0; } - + index = Z_LVAL_P(offset); - + my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -663,9 +688,11 @@ return_value = sdo_das_settinglist_valid(my_object, index, check_empty TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } - + return return_value; } /* }}} */ @@ -677,20 +704,17 @@ long index; sdo_list_object *my_object; zval *return_value; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return 0; } index = Z_LVAL_P(offset); my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - MAKE_STD_ZVAL(return_value); - RETVAL_NULL(); - return return_value; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -703,7 +727,9 @@ return_value = sdo_das_settinglist_read_value(my_object, index TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } return return_value; @@ -717,18 +743,17 @@ long index; sdo_list_object *my_object; DataObjectList *dol; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return; } index = Z_LVAL_P(offset); - my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } + my_object = sdo_list_get_instance(object TSRMLS_CC); switch(my_object->list_type) { case TYPE_DataObjectList: @@ -753,7 +778,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } /* }}} */ @@ -765,6 +792,7 @@ long index = -1; sdo_list_object *my_object; sdo_write_type write_type; + char *class_name, *space; if (Z_TYPE_P(z_value) == IS_NULL) { /* TODO: fix this when the C++ lib supports a NULL property */ @@ -776,8 +804,10 @@ if (offset == 0 || Z_TYPE_P(offset) == IS_NULL) { write_type = TYPE_APPEND; } else { - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return; } index = Z_LVAL_P(offset); @@ -785,10 +815,6 @@ } my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -803,7 +829,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } @@ -819,13 +847,12 @@ HashTable *properties; int entries; zval *tmp; + zval z_holder; + char *space, *class_name; my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } - ALLOC_HASHTABLE(properties); + + array_init(&z_holder); try { switch (my_object->list_type) { @@ -839,11 +866,11 @@ entries = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); return 0; } - - zend_hash_init(properties, entries, NULL, NULL, 0); for (long index = 0; index < entries; index++) { @@ -858,11 +885,12 @@ tmp = sdo_das_settinglist_read_value(my_object, index TSRMLS_CC); break; } - zend_hash_next_index_insert(properties, &tmp, sizeof (zval *), NULL); + add_next_index_zval(&z_holder, tmp); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -876,18 +904,18 @@ zval free_obj; int rc = SUCCESS; int entries; + char *class_name, *space; if (should_free) { free_obj = *writeobj; } my_object = sdo_list_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_list_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else if (my_object->list_type > TYPE_SettingList) { - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + + if (my_object->list_type > TYPE_SettingList) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); ZVAL_NULL(writeobj); rc = FAILURE; } else { @@ -917,7 +945,7 @@ case TYPE_DataObjectList: { DataObjectList& dol = *my_object->dolp; - if (my_object->typep->isDataType()) { + if (dol.getType().isDataType()) { print_buf << " {"; for (int i = 0; i < entries; i++) { if (i > 0) print_buf << "; "; @@ -988,6 +1016,7 @@ DataObjectList *dol1, *dol2; int entries; zval result; + char *class_name, *space; INIT_PZVAL(&result); @@ -1002,7 +1031,9 @@ case TYPE_DataObjectList: break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object1->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object1->list_type); return FAILURE; } @@ -1035,7 +1066,14 @@ /* {{{ sdo_list_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_list_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_list_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_list_iterator *iterator = (sdo_list_iterator *)emalloc(sizeof(sdo_list_iterator)); object->refcount++; @@ -1062,6 +1100,7 @@ { int valid; long count; + char *class_name, *space; sdo_list_iterator *iterator = (sdo_list_iterator *)iter; zval *z_list_object = (zval *)iterator->zoi.data; @@ -1079,7 +1118,9 @@ count = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } valid = (iterator->index >= 0 && iterator->index < count) ? SUCCESS : FAILURE; } catch (SDORuntimeException e) { @@ -1106,6 +1147,8 @@ */ static void sdo_list_iterator_current_data (zend_object_iterator *iter, zval ***data TSRMLS_DC) { + char *class_name, *space; + sdo_list_iterator *iterator = (sdo_list_iterator *)iter; zval *z_list_object = (zval *)iterator->zoi.data; sdo_list_object *my_object = (sdo_list_object *)sdo_list_get_instance(z_list_object TSRMLS_CC); @@ -1122,7 +1165,9 @@ iterator->value = sdo_das_settinglist_read_value(my_object, iterator->index TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); return; } } catch (SDORuntimeException e) { @@ -1156,12 +1201,10 @@ int sdo_list_count_elements(zval *object, long *count TSRMLS_DC) { sdo_list_object *my_object; + char *class_name, *space; my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } + try { switch (my_object->list_type) { case TYPE_ChangedDataObjectList: @@ -1174,7 +1217,9 @@ *count = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1223,7 +1268,11 @@ */ PHP_METHOD(SDO_List, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -1247,6 +1296,7 @@ long index = -1; sdo_list_object *my_object; sdo_write_type write_type; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &z_value, &z_index) == FAILURE) { return; @@ -1262,10 +1312,6 @@ } my_object = sdo_list_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -1280,7 +1326,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_Property.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/SDO_Model_Property.cpp diff -u pecl/sdo/SDO_Model_Property.cpp:1.3 pecl/sdo/SDO_Model_Property.cpp:1.4 --- pecl/sdo/SDO_Model_Property.cpp:1.3 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_Property.cpp Mon Feb 20 18:50:25 2006 @@ -1,25 +1,25 @@ -/* +/* +----------------------------------------------------------------------+ -| (c) Copyright IBM Corporation 2005. | +| (c) Copyright IBM Corporation 2005. | | 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 | ++----------------------------------------------------------------------+ +| | +| 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: Caroline Maynard | -+----------------------------------------------------------------------+ +| | +| 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: Caroline Maynard | ++----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_Property.cpp,v 1.3 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_Property.cpp,v 1.4 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -48,7 +48,7 @@ /* {{{ sdo_model_property_get_instance */ -static sdo_model_property_object *sdo_model_property_get_instance(zval *me TSRMLS_DC) +static sdo_model_property_object *sdo_model_property_get_instance(zval *me TSRMLS_DC) { return (sdo_model_property_object *)zend_object_store_get_object(me TSRMLS_CC); } @@ -102,19 +102,22 @@ /* {{{ sdo_model_property_new */ void sdo_model_property_new(zval *me, const Property *propertyp TSRMLS_DC) -{ +{ sdo_model_property_object *my_object; + char *class_name, *space; - Z_TYPE_P(me) = IS_OBJECT; + Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_model_propertyimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } my_object = (sdo_model_property_object *)zend_object_store_get_object(me TSRMLS_CC); my_object->propertyp = propertyp; - zend_update_property_string(sdo_model_propertyimpl_class_entry, me, + zend_update_property_string(sdo_model_propertyimpl_class_entry, me, "name", strlen("name"), (char *)propertyp->getName() TSRMLS_CC); } /* }}} */ @@ -124,13 +127,16 @@ void sdo_model_property_get_default(const Property *propertyp, zval *return_value TSRMLS_DC) { uint bytes_len; char *bytes_value; - char char_value; + char char_value; wchar_t wchar_value; + char *class_name, *space; try { switch(propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -156,7 +162,9 @@ case Type::CharacterType: wchar_value = propertyp->getCharacterDefault(); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); } char_value = propertyp->getByteDefault(); RETVAL_STRINGL(&char_value, 1, 1); @@ -195,21 +203,25 @@ RETVAL_STRINGL(bytes_value, bytes_len, 0); /* TODO restore this code instead of the above once getCStringDefault is implemented */ /* RETVAL_STRING((char *)property.getCStringDefault(), 1); */ - break; + break; case Type::DataObjectType: /* A data object type cannot have a default */ RETVAL_NULL(); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected type 'ChangeSummaryType' for property %s", - CLASS_NAME, __LINE__, propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected type 'ChangeSummaryType' for property %s", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected type 'TextType' for property %s", - CLASS_NAME, __LINE__, propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected type 'TextType' for property %s", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; default: - php_error(E_ERROR, "%s:%i: unexpected type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getType().getName(), propertyp->getName()); } } catch (SDORuntimeException e) { @@ -220,14 +232,14 @@ /* {{{ sdo_model_property_string */ -void sdo_model_property_string (ostringstream& print_buf, const Property *propertyp, const char *old_indent TSRMLS_DC) -{ +void sdo_model_property_string (ostringstream& print_buf, const Property *propertyp, const char *old_indent TSRMLS_DC) +{ zval z_default; const Type& type = propertyp->getType(); char *indent = (char *)emalloc(strlen(old_indent) + 4 + 1); sprintf (indent, "%s ", old_indent); - + print_buf << indent; if (propertyp->isReadOnly()) { @@ -237,7 +249,7 @@ if (type.isDataObjectType() && !propertyp->isContainment()) { print_buf << "<reference"; //if (!type.equals(propertyp->getContainingType())) { - // print_buf << " " << propertyp->getContainingType().getURI() << + // print_buf << " " << propertyp->getContainingType().getURI() << // ":" << propertyp->getContainingType().getName(); //} print_buf << "> "; @@ -255,7 +267,7 @@ } /*TODO it would be preferable if sdo4cpp had a hasDefault() method. - * While it does not, we get a default value and only display it if it + * While it does not, we get a default value and only display it if it * seems to be a non-default default */ sdo_model_property_get_default(propertyp, &z_default TSRMLS_CC); @@ -302,35 +314,29 @@ /* }}} */ /* {{{ sdo_model_property_cast_object -*/ -static int sdo_model_property_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) +*/ +static int sdo_model_property_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) { sdo_model_property_object *my_object; ostringstream print_buf; zval free_obj; int rc = SUCCESS; - + if (should_free) { free_obj = *writeobj; } - + my_object = sdo_model_property_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_property_object *)NULL) { + try { + sdo_model_property_string (print_buf, my_object->propertyp, "\n" TSRMLS_CC); + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - try { - sdo_model_property_string (print_buf, my_object->propertyp, "\n" TSRMLS_CC); - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } } - + switch(type) { case IS_STRING: convert_to_string(writeobj); @@ -347,7 +353,7 @@ default: rc = FAILURE; } - + if (should_free) { zval_dtor(&free_obj); } @@ -360,7 +366,7 @@ void sdo_model_property_minit(zend_class_entry *tmp_ce TSRMLS_DC) { tmp_ce->create_object = sdo_model_property_object_create; - + sdo_model_propertyimpl_class_entry = zend_register_internal_class(tmp_ce TSRMLS_CC); zend_declare_property_null (sdo_model_propertyimpl_class_entry, "name", strlen("name"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_class_implements(sdo_model_propertyimpl_class_entry TSRMLS_CC, 1, sdo_model_property_class_entry); @@ -377,17 +383,21 @@ /* {{{ SDO_Model_PropertyImpl::__construct */ PHP_METHOD(SDO_Model_PropertyImpl, __construct) -{ - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); +{ + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ /* {{{ SDO_Model_PropertyImpl::getName */ -PHP_METHOD(SDO_Model_PropertyImpl, getName) +PHP_METHOD(SDO_Model_PropertyImpl, getName) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -403,10 +413,10 @@ /* {{{ SDO_Model_PropertyImpl::getType */ -PHP_METHOD(SDO_Model_PropertyImpl, getType) +PHP_METHOD(SDO_Model_PropertyImpl, getType) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -422,10 +432,10 @@ /* {{{ SDO_Model_PropertyImpl::isMany */ -PHP_METHOD(SDO_Model_PropertyImpl, isMany) +PHP_METHOD(SDO_Model_PropertyImpl, isMany) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -441,10 +451,10 @@ /* {{{ SDO_Model_PropertyImpl::isReadOnly */ -PHP_METHOD(SDO_Model_PropertyImpl, isReadOnly) +PHP_METHOD(SDO_Model_PropertyImpl, isReadOnly) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -460,10 +470,10 @@ /* {{{ SDO_Model_PropertyImpl::isContainment */ -PHP_METHOD(SDO_Model_PropertyImpl, isContainment) +PHP_METHOD(SDO_Model_PropertyImpl, isContainment) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -479,11 +489,11 @@ /* {{{ SDO_Model_PropertyImpl::getOpposite */ -PHP_METHOD(SDO_Model_PropertyImpl, getOpposite) +PHP_METHOD(SDO_Model_PropertyImpl, getOpposite) { sdo_model_property_object *my_object; const Property *opposite_p; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -502,14 +512,14 @@ /* {{{ SDO_Model_PropertyImpl::getContainingType */ -PHP_METHOD(SDO_Model_PropertyImpl, getContainingType) +PHP_METHOD(SDO_Model_PropertyImpl, getContainingType) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - + my_object = sdo_model_property_get_instance(getThis() TSRMLS_CC); try { sdo_model_type_new (return_value, &my_object->propertyp->getContainingType() TSRMLS_CC); @@ -521,14 +531,14 @@ /* {{{ SDO_Model_PropertyImpl::getDefault */ -PHP_METHOD(SDO_Model_PropertyImpl, getDefault) +PHP_METHOD(SDO_Model_PropertyImpl, getDefault) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - + my_object = sdo_model_property_get_instance(getThis() TSRMLS_CC); sdo_model_property_get_default (my_object->propertyp, return_value TSRMLS_CC); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_ReflectionDataObject.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/SDO_Model_ReflectionDataObject.cpp diff -u pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.4 pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.5 --- pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.4 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_ReflectionDataObject.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_ReflectionDataObject.cpp,v 1.4 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_ReflectionDataObject.cpp,v 1.5 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -104,52 +104,47 @@ } my_object = sdo_model_rdo_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_rdo_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { - try { - const Type& type = my_object->dop->getType(); - PropertyList pl = my_object->dop->getInstanceProperties(); - - print_buf << indent << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " {"; - print_buf << indent << " - "; - if (my_object->dop->getContainer()) { - print_buf << - "Instance of {" << my_object->dop->getContainmentProperty().getName() << "}"; - } else { - print_buf << "ROOT OBJECT"; - } - - print_buf << indent << " - Type "; - sdo_model_type_summary_string (print_buf, &type TSRMLS_CC); - - print_buf << indent << " - Instance Properties"; - print_buf << "[" << pl.size() <<"]"; - - if (pl.size() > 0) { - print_buf << " {"; - for (int i = 0; i < pl.size(); i++) { - sdo_model_property_string (print_buf, &pl[i], "\n " TSRMLS_CC); - } - print_buf << indent << " }"; - } else { - print_buf <<";"; + + try { + const Type& type = my_object->dop->getType(); + PropertyList pl = my_object->dop->getInstanceProperties(); + + print_buf << indent << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " {"; + print_buf << indent << " - "; + if (my_object->dop->getContainer()) { + print_buf << + "Instance of {" << my_object->dop->getContainmentProperty().getName() << "}"; + } else { + print_buf << "ROOT OBJECT"; + } + + print_buf << indent << " - Type "; + sdo_model_type_summary_string (print_buf, &type TSRMLS_CC); + + print_buf << indent << " - Instance Properties"; + print_buf << "[" << pl.size() <<"]"; + + if (pl.size() > 0) { + print_buf << " {"; + for (int i = 0; i < pl.size(); i++) { + sdo_model_property_string (print_buf, &pl[i], "\n " TSRMLS_CC); } - - print_buf << indent << "}"; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; + print_buf << indent << " }"; + } else { + print_buf <<";"; } - } + + print_buf << indent << "}"; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -180,10 +175,13 @@ void sdo_model_rdo_minit(zend_class_entry *tmp_ce TSRMLS_DC) { zend_class_entry **reflector_ce_ptr; + char *class_name, *space; tmp_ce->create_object = sdo_model_rdo_object_create; - if (zend_hash_find(CG(class_table), "reflector", sizeof("reflector"), (void **)&reflector_ce_ptr) == FAILURE) { - php_error(E_ERROR, "%s:%i: can't find class entry for Reflector", CLASS_NAME, __LINE__); + if (zend_hash_find(CG(class_table), "reflector", sizeof("reflector"), (void **)&reflector_ce_ptr) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not find Reflector class", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } @@ -205,8 +203,8 @@ { int argc; zval *z_do; - sdo_do_object *target; sdo_model_rdo_object *my_object; + char *class_name, *space; if ((argc = ZEND_NUM_ARGS()) != 1) { WRONG_PARAM_COUNT; @@ -218,13 +216,15 @@ my_object = sdo_model_rdo_get_instance(getThis() TSRMLS_CC); - target = (sdo_do_object *)zend_object_store_get_object(z_do TSRMLS_CC); - if (target == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + DataObjectPtr dop = sdo_do_get(z_do TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name (&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETURN_NULL(); } - my_object->dop = target->dop; + my_object->dop = dop; } /* }}} */ @@ -242,18 +242,23 @@ { zend_class_entry *reflection_ce; zend_function *reflection_export_zf; + char *class_name, *space; /* Just call up to Reflection::export */ reflection_ce = zend_fetch_class ("Reflection", strlen("Reflection"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (!reflection_ce) { - php_error(E_ERROR, "%s:%i: Could not find Reflection class", CLASS_NAME, __LINE__); + if (!reflection_ce) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not find Reflection class", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } reflection_export_zf = zend_std_get_static_method(reflection_ce, "export", strlen("export") TSRMLS_CC); - if (!reflection_export_zf) { - php_error(E_ERROR, "%s:%i: Could not call Reflection::export method", CLASS_NAME, __LINE__); + if (!reflection_export_zf) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not call Reflection::export method", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_Type.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/SDO_Model_Type.cpp diff -u pecl/sdo/SDO_Model_Type.cpp:1.3 pecl/sdo/SDO_Model_Type.cpp:1.4 --- pecl/sdo/SDO_Model_Type.cpp:1.3 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_Type.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_Type.cpp,v 1.3 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_Type.cpp,v 1.4 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -95,10 +95,13 @@ void sdo_model_type_new(zval *me, const Type *typep TSRMLS_DC) { sdo_model_type_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_model_typeimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } @@ -138,6 +141,9 @@ */ void sdo_model_type_summary_string (ostringstream& print_buf, const Type *typep TSRMLS_DC) { + if (typep->isAbstractType()) { + print_buf << "<abstract> "; + } if (typep->isOpenType()) { print_buf << "<open> "; } @@ -199,21 +205,16 @@ } my_object = sdo_model_type_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_type_object *)NULL) { + + try { + sdo_model_type_string (print_buf, my_object->typep, "\n" TSRMLS_CC); + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - try { - sdo_model_type_string (print_buf, my_object->typep, "\n" TSRMLS_CC); - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } - } + } switch(type) { case IS_STRING: @@ -267,7 +268,11 @@ */ PHP_METHOD(SDO_Model_TypeImpl, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -314,8 +319,8 @@ { sdo_model_type_object *my_object; zval *z_do; - sdo_do_object *target; int argc; + char *class_name, *space; if ((argc = ZEND_NUM_ARGS()) != 1) { WRONG_PARAM_COUNT; @@ -326,19 +331,29 @@ } my_object = sdo_model_type_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_model_type_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } - target = (sdo_do_object *)zend_object_store_get_object(z_do TSRMLS_CC); - if (target == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + DataObjectPtr dop = sdo_do_get(z_do TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name (&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } try { - RETVAL_BOOL(target->dop->getType().equals(*my_object->typep)); + const Type& my_type = *my_object->typep; + const Type *target_type = &dop->getType(); + RETVAL_FALSE; + + /* walk up the target object's type hierarchy */ + while (target_type) { + if (my_type.equals(*target_type)) { + RETURN_TRUE; + } else { + target_type = target_type->getBaseType(); + } + } + } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } @@ -472,6 +487,25 @@ } /* }}} */ +/* {{{ SDO_Model_TypeImpl::isAbstractType + */ +PHP_METHOD(SDO_Model_TypeImpl, isAbstractType) +{ + sdo_model_type_object *my_object; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + my_object = sdo_model_type_get_instance(getThis() TSRMLS_CC); + try { + RETVAL_BOOL(my_object->typep->isAbstractType()); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); + } +} +/* }}} */ + /* {{{ SDO_Model_TypeImpl::getBaseType */ PHP_METHOD(SDO_Model_TypeImpl, getBaseType) http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Sequence.cpp?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/SDO_Sequence.cpp diff -u pecl/sdo/SDO_Sequence.cpp:1.11 pecl/sdo/SDO_Sequence.cpp:1.12 --- pecl/sdo/SDO_Sequence.cpp:1.11 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Sequence.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Sequence.cpp,v 1.11 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Sequence.cpp,v 1.12 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -40,7 +40,6 @@ typedef struct { zend_object zo; /* The standard zend_object */ SequencePtr seqp; /* The C++ Sequence */ - DataObjectPtr dop; /* The C++ DataObject */ } sdo_seq_object; /* }}} */ @@ -70,6 +69,7 @@ static int sdo_sequence_valid(sdo_seq_object *my_object, long sequence_index, int check_empty TSRMLS_DC) { int return_value = 0; + char *class_name, *space; try { Sequence& seq = *my_object->seqp; @@ -78,7 +78,9 @@ if (return_value && check_empty) { switch(seq.getTypeEnum(sequence_index)) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -112,11 +114,15 @@ return_value = (!seq.getDataObjectValue(sequence_index)); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%; unexpected DataObject type %i for sequence index %i", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, seq.getTypeEnum(sequence_index), sequence_index); return_value = 0; } @@ -138,8 +144,8 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; MAKE_STD_ZVAL(return_value); @@ -147,7 +153,9 @@ Sequence& seq = *my_object->seqp; switch(seq.getTypeEnum(sequence_index)) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -169,7 +177,9 @@ case Type::CharacterType: wchar_value = seq.getCharacterValue(sequence_index); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), sequence_index); } char_value = seq.getByteValue(sequence_index); RETVAL_STRINGL(&char_value, 1, 1); @@ -201,24 +211,23 @@ case Type::DataObjectType: doh_value = seq.getDataObjectValue(sequence_index); if (!doh_value) { - php_error(E_WARNING, "%s:%i: read a NULL DataObject for sequence index %i", CLASS_NAME, __LINE__, - sequence_index); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): read a NULL DataObject for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), sequence_index); RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - if (doh_value_zval == NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } else { - RETVAL_ZVAL(doh_value_zval, 1, 0); - } + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%; unexpected DataObject type %i for sequence index %i", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, seq.getTypeEnum(sequence_index), sequence_index); } } catch (SDORuntimeException e) { @@ -235,6 +244,7 @@ static void sdo_sequence_write_value(sdo_seq_object *my_object, char *xpath, long sequence_index, Type::Types type_enum, zval *z_value, sdo_write_type write_type TSRMLS_DC) { zval temp_zval; + char *class_name, *space; try { Sequence& seq = *my_object->seqp; @@ -257,7 +267,9 @@ switch (type_enum) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -385,19 +397,21 @@ "Class %s is not an instance of %s", Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); } else { - sdo_do_object *value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + DataObjectPtr dop = sdo_do_get(&temp_zval TSRMLS_CC); if (write_type == TYPE_APPEND) { - seq.addDataObject(xpath, value_object->dop); + seq.addDataObject(xpath, dop); } else if (write_type == TYPE_INSERT) { - seq.addDataObject(sequence_index, xpath, value_object->dop); + seq.addDataObject(sequence_index, xpath, dop); } else { - seq.setDataObjectValue(sequence_index, value_object->dop); + seq.setDataObjectValue(sequence_index, dop); }; } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: convert_to_string(&temp_zval); @@ -410,7 +424,9 @@ } break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type_enum); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type_enum); } zval_dtor(&temp_zval); } catch (SDORuntimeException e) { @@ -432,10 +448,6 @@ sequence_index = Z_LVAL_P(offset); my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } try { return_value = sdo_sequence_valid(my_object, sequence_index, check_empty TSRMLS_CC); @@ -488,10 +500,6 @@ } my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (offset == 0 || Z_TYPE_P(offset) == IS_NULL) { @@ -525,11 +533,7 @@ convert_to_long_ex(&offset); sequence_index = Z_LVAL_P(offset); - my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } + my_object = sdo_sequence_get_instance(object TSRMLS_CC); try { if (sequence_index < 0 || sequence_index >= my_object->seqp->size()) { @@ -553,30 +557,26 @@ static HashTable *sdo_sequence_get_properties(zval *object TSRMLS_DC) { sdo_seq_object *my_object; - HashTable *properties; - int entries; - zval *tmp; + HashTable *properties; + int entries; + zval *tmp; + zval z_holder; my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } - ALLOC_HASHTABLE(properties); + + array_init(&z_holder); try { entries = my_object->seqp->size(); - - zend_hash_init(properties, entries, NULL, NULL, 0); - for (long index = 0; index < entries; index++) { tmp = sdo_sequence_read_value(my_object, index TSRMLS_CC); - zend_hash_next_index_insert(properties, &tmp, sizeof (zval *), NULL); + add_next_index_zval(&z_holder, tmp); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -595,43 +595,37 @@ } my_object = sdo_sequence_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_seq_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { - Sequence& seq = *my_object->seqp; - try { - print_buf << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " (" << seq.size() << ") {"; - - for (unsigned int i = 0; i < seq.size(); i++) { - if (i > 0) print_buf << "; "; - if (seq.isText(i)) { - print_buf << '\"' << seq.getCStringValue(i) << '\"'; - } else { - const Property& property = seq.getProperty(i); - print_buf << property.getName(); - if (property.isMany()) { - print_buf << '[' << seq.getListIndex(i) << ']'; - } - if (property.getType().isDataType()) { - print_buf << "=>\"" << seq.getCStringValue(i) << '\"'; - } + Sequence& seq = *my_object->seqp; + try { + print_buf << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " (" << seq.size() << ") {"; + + for (unsigned int i = 0; i < seq.size(); i++) { + if (i > 0) print_buf << "; "; + if (seq.isText(i)) { + print_buf << '\"' << seq.getCStringValue(i) << '\"'; + } else { + const Property& property = seq.getProperty(i); + print_buf << property.getName(); + if (property.isMany()) { + print_buf << '[' << seq.getListIndex(i) << ']'; } + if (property.getType().isDataType()) { + print_buf << "=>\"" << seq.getCStringValue(i) << '\"'; + } } - - print_buf << '}'; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; } - } + + print_buf << '}'; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -659,7 +653,14 @@ /* {{{ sdo_sequence_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_sequence_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_sequence_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_seq_iterator *iterator = (sdo_seq_iterator *)emalloc(sizeof(sdo_seq_iterator)); object->refcount++; @@ -775,7 +776,6 @@ zend_hash_destroy(my_object->zo.properties); FREE_HASHTABLE(my_object->zo.properties); my_object->seqp = NULL; - my_object->dop = NULL; efree(object); } @@ -805,20 +805,22 @@ /* {{{ sdo_sequence_new */ -void sdo_sequence_new(zval *me, SequencePtr seqp, DataObjectPtr dop TSRMLS_DC) +void sdo_sequence_new(zval *me, SequencePtr seqp TSRMLS_DC) { sdo_seq_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_sequenceimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } my_object = (sdo_seq_object *)zend_object_store_get_object(me TSRMLS_CC); my_object->seqp = seqp; - my_object->dop = dop; } /* }}} */ @@ -878,61 +880,14 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ -/* {{{ SDO_SequenceImpl::getPropertyIndex +/* {{{ SDO_SequenceImpl::move */ -PHP_METHOD(SDO_SequenceImpl, getPropertyIndex) -{ - sdo_seq_object *my_object; - long sequence_index; - - php_error(E_WARNING, - "SDO_Sequence::getPropertyIndex() is deprecated, and will be removed in the next release."); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sequence_index) == FAILURE) - return; - - my_object = sdo_sequence_get_instance(getThis() TSRMLS_CC); - try { - if (my_object->seqp->isText(sequence_index)) { - RETVAL_LONG(-1); - } else { - const Property& property = my_object->seqp->getProperty(sequence_index); - RETVAL_LONG(property.getContainingType().getPropertyIndex(property.getName())); - } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} - -PHP_METHOD(SDO_SequenceImpl, getPropertyName) -{ - sdo_seq_object *my_object; - long sequence_index; - - php_error(E_WARNING, - "SDO_Sequence::getPropertyName() is deprecated, and will be removed in the next release. Use SDO_Sequence::getProperty()->getName()"); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sequence_index) == FAILURE) - return; - - my_object = sdo_sequence_get_instance(getThis() TSRMLS_CC); - try { - if (my_object->seqp->isText(sequence_index)) { - RETVAL_NULL(); - } else { - const Property& property = my_object->seqp->getProperty(sequence_index); - RETVAL_STRING((char *)property.getName(), 1); - } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} - PHP_METHOD(SDO_SequenceImpl, move) { sdo_seq_object *my_object; - long toIndex, fromIndex; + long toIndex, fromIndex; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &toIndex, &fromIndex) == FAILURE) return; @@ -944,18 +899,21 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ +/* {{{ SDO_SequenceImpl::insert + */ PHP_METHOD(SDO_SequenceImpl, insert) { sdo_seq_object *my_object; - zval *z_value; - zval *z_property = NULL; - zval *z_sequence_index = NULL; - long sequence_index; - const Property *property_p; + zval *z_value; + zval *z_property = NULL; + zval *z_sequence_index = NULL; + long sequence_index; + const Property *property_p; sdo_write_type write_type; - Type::Types type_enum; - const char *xpath; + Type::Types type_enum; + const char *xpath; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &z_value, &z_sequence_index, &z_property) == FAILURE) @@ -978,7 +936,8 @@ type_enum = Type::TextType; xpath = NULL; } else { - if (sdo_parse_offset_param (my_object->dop, z_property, &property_p, &xpath, 0, 0 TSRMLS_CC) == FAILURE) + if (sdo_parse_offset_param (my_object->seqp->getDataObject(), + z_property, &property_p, &xpath, 0, 0 TSRMLS_CC) == FAILURE) return; if (property_p == NULL) { @@ -996,7 +955,10 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ +/* {{{ SDO_SequenceImpl::count + */ PHP_METHOD(SDO_SequenceImpl, count) { long count = 0; @@ -1004,6 +966,7 @@ sdo_sequence_count_elements(getThis(), &count TSRMLS_CC); RETVAL_LONG(count); } +/* }}} */ /* * Local variables: http://cvs.php.net/viewcvs.cgi/pecl/sdo/config.m4?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/config.m4 diff -u pecl/sdo/config.m4:1.12 pecl/sdo/config.m4:1.13 --- pecl/sdo/config.m4:1.12 Wed Jan 25 17:07:22 2006 +++ pecl/sdo/config.m4 Mon Feb 20 18:50:25 2006 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.12 2006/01/25 17:07:22 cem Exp $ +dnl $Id: config.m4,v 1.13 2006/02/20 18:50:25 mfp Exp $ PHP_ARG_ENABLE(sdo, sdo , [ --enable-sdo Enable sdo support]) @@ -31,7 +31,7 @@ sdo_lib_srcs="commonj/sdo/ChangedDataObjectListImpl.cpp commonj/sdo/ChangeSummary.cpp commonj/sdo/ChangeSummaryImpl.cpp commonj/sdo/CopyHelper.cpp commonj/sdo/DASProperty.cpp commonj/sdo/DASType.cpp commonj/sdo/DASValue.cpp commonj/sdo/DASValues.cpp commonj/sdo/DataFactory.cpp commonj/sdo/DataFactoryImpl.cpp commonj/sdo/DataGraph.cpp commonj/sdo/DataGraphImpl.cpp commonj/sdo/DataObject.cpp commonj/sdo/DataObjectImpl.cpp commonj/sdo/DataObjectList.cpp commonj/sdo/DataObjectListImpl.cpp commonj/sdo/DefaultLogWriter.cpp commonj/sdo/EqualityHelper.cpp commonj/sdo/HelperProvider.cpp commonj/sdo/Logger.cpp commonj/sdo/LogWriter.cpp commonj/sdo/ParserErrorSetter.cpp commonj/sdo/Property.cpp commonj/sdo/PropertyDefinition.cpp commonj/sdo/PropertyImpl.cpp commonj/sdo/PropertyList.cpp commonj/sdo/PropertySetting.cpp commonj/sdo/RefCountingObject.cpp commonj/sdo/RefCountingPointer.cpp commonj/sdo/SAX2Attribute.cpp commonj/sdo/SAX2Attributes.cpp commonj/sdo/SAX2Namespaces.cpp commonj/s! do/SAX2Parser.cpp commonj/sdo/SchemaInfo.cpp commonj/sdo/SdoCheck.cpp commonj/sdo/SDODate.cpp commonj/sdo/SdoRuntime.cpp commonj/sdo/SDORuntimeException.cpp commonj/sdo/SDOSAX2Parser.cpp commonj/sdo/SDOSchemaSAX2Parser.cpp commonj/sdo/SDOXMLBufferWriter.cpp commonj/sdo/SDOXMLFileWriter.cpp commonj/sdo/SDOXMLStreamWriter.cpp commonj/sdo/SDOXMLString.cpp commonj/sdo/SDOXMLWriter.cpp commonj/sdo/SDOXSDBufferWriter.cpp commonj/sdo/SDOXSDFileWriter.cpp commonj/sdo/SDOXSDStreamWriter.cpp commonj/sdo/SDOXSDWriter.cpp commonj/sdo/Sequence.cpp commonj/sdo/SequenceImpl.cpp commonj/sdo/Setting.cpp commonj/sdo/SettingList.cpp commonj/sdo/Type.cpp commonj/sdo/TypeDefinition.cpp commonj/sdo/TypeDefinitions.cpp commonj/sdo/TypeImpl.cpp commonj/sdo/TypeList.cpp commonj/sdo/XMLDocument.cpp commonj/sdo/XMLDocumentImpl.cpp commonj/sdo/XMLHelper.cpp commonj/sdo/XMLHelperImpl.cpp commonj/sdo/XMLQName.cpp commonj/sdo/XpathHelper.cpp commonj/sdo/XSDHelper.cpp commonj/sdo/XSDHelperImpl.cpp commonj! /sdo/XSDPropertyInfo.cpp commonj/sdo/XSDTypeInfo.cpp commonj/sdo/xmlda s/XMLDASCheck.cpp commonj/sdo/xmldas/XMLDAS.cpp commonj/sdo/xmldas/XMLDASImpl.cpp" -PHP_NEW_EXTENSION(sdo, sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp $sdo_lib_srcs, $ext_shared,,-I@ext_srcdir@) +PHP_NEW_EXTENSION(sdo, sdo.cpp SDO_CPPException.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_Exception.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp $sdo_lib_srcs, $ext_shared,,-I@ext_srcdir@) PHP_ADD_BUILD_DIR($ext_builddir/commonj/sdo) PHP_ADD_BUILD_DIR($ext_builddir/commonj/sdo/xmldas) http://cvs.php.net/viewcvs.cgi/pecl/sdo/config.w32?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/config.w32 diff -u pecl/sdo/config.w32:1.7 pecl/sdo/config.w32:1.8 --- pecl/sdo/config.w32:1.7 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/config.w32 Mon Feb 20 18:50:25 2006 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.7 2005/12/02 17:33:47 mfp Exp $ +// $Id: config.w32,v 1.8 2006/02/20 18:50:25 mfp Exp $ // vim:ft=javascript ARG_ENABLE("sdo", "enable sdo support", "no"); @@ -10,7 +10,7 @@ /* first build the sdo core extension ... */ EXTENSION('sdo', - 'sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp', + 'sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp SDO_Exception.cpp SDO_CPPException.cpp', 'yes', '/GX /D SDO_EXPORTS /D XMLDAS_EXPORTS'); http://cvs.php.net/viewcvs.cgi/pecl/sdo/das_xml.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/das_xml.cpp diff -u pecl/sdo/das_xml.cpp:1.4 pecl/sdo/das_xml.cpp:1.5 --- pecl/sdo/das_xml.cpp:1.4 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/das_xml.cpp Mon Feb 20 18:50:25 2006 @@ -15,12 +15,12 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: das_xml.cpp,v 1.4 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: das_xml.cpp,v 1.5 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -77,10 +77,10 @@ PHP_MINIT_FUNCTION(sdo_das_xml) { - initialize_sdo_das_xml_class(TSRMLS_C); - initialize_sdo_das_xml_document_class(TSRMLS_C); - initialize_sdo_das_xml_parserexception_class(TSRMLS_C); - initialize_sdo_das_xml_fileexception_class(TSRMLS_C); + sdo_das_xml_minit(TSRMLS_C); + sdo_das_xml_document_minit(TSRMLS_C); + sdo_das_xml_parserexception_minit(TSRMLS_C); + sdo_das_xml_fileexception_minit(TSRMLS_C); return SUCCESS; } @@ -92,11 +92,11 @@ PHP_MINFO_FUNCTION(sdo_das_xml) { php_info_print_table_start(); - php_info_print_table_header(2, "sdo_das_xml support", "enabled"); - php_info_print_table_header(2, "sdo_das_xml version", SDO_DAS_XML_VERSION); + php_info_print_table_row(2, "sdo_das_xml support", "enabled"); + php_info_print_table_row(2, "sdo_das_xml version", SDO_DAS_XML_VERSION); php_info_print_table_end(); } -/* }}} */ +/* }}} */ /* * Local variables: http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo.h?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/php_sdo.h diff -u pecl/sdo/php_sdo.h:1.8 pecl/sdo/php_sdo.h:1.9 --- pecl/sdo/php_sdo.h:1.8 Tue Jan 17 11:43:16 2006 +++ pecl/sdo/php_sdo.h Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_sdo.h,v 1.8 2006/01/17 11:43:16 cem Exp $ */ +/* $Id: php_sdo.h,v 1.9 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_H #define PHP_SDO_H @@ -50,8 +50,21 @@ PHP_METHOD(SDO_PropertyAccess, __get); PHP_METHOD(SDO_PropertyAccess, __set); +/* {{{ proto string SDO_DataObject::getTypeName() +Return the name of the type for this SDO_DataObject. +A convenience method corresponding to +SDO_Model_ReflectionDataObject::getType().getName() +*/ +PHP_METHOD(SDO_DataObject, getTypeName); +/* }}} */ -PHP_METHOD(SDO_DataObject, getType); /* deprecated */ +/* {{{ proto string SDO_DataObject::getTypeNamespaceURI() +Return the namespace URI of the type for this SDO_DataObject. +A convenience method corresponding to +SDO_Model_ReflectionDataObject::getType().getNamespaceURI() +*/ +PHP_METHOD(SDO_DataObject, getTypeNamespaceURI); +/* }}} */ /* {{{ proto SDO_Sequence SDO_DataObject::getSequence() Return the SDO_Sequence for this SDO_DataObject. Accessing the SDO_DataObject @@ -91,8 +104,6 @@ PHP_METHOD(SDO_DataObject, getContainer); /* }}} */ -PHP_METHOD(SDO_DataObject, getContainmentPropertyName); /* deprecated */ - /* {{{ proto SDO_Model_Property SDO_Sequence::getProperty(integer sequence_index) Return the property for the specified sequence index. @@ -105,9 +116,6 @@ PHP_METHOD(SDO_Sequence, getProperty); /* }}} */ -PHP_METHOD(SDO_Sequence, getPropertyIndex); /*deprecated */ -PHP_METHOD(SDO_Sequence, getPropertyName); /* deprecated */ - /* {{{ proto void SDO_Sequence::move(integer toIndex, integer fromIndex) Modify the position of the item in the sequence, without altering the value of the property in the SDO_DataObject. @@ -121,7 +129,7 @@ PHP_METHOD(SDO_Sequence, move); /* }}} */ -/* {{{ proto void SDO_Sequnece::insert(mixed value [, integer sequenceIndex, mixed propertyIdentifier]) +/* {{{ proto void SDO_Sequence::insert(mixed value [, integer sequence_index, mixed property_identifier]) Insert a new element at a specified position in the sequence. All subsequent sequence items are moved up. The new value to be inserted. This can be either a primitive or an SDO_DataObject @@ -155,20 +163,20 @@ PHP_METHOD(SDO_List, count); -/* {{{ proto void SDO_DataFactory::create(string namespaceURI, string typeName) -Create an SDO_DataObject of the type specified by typeName with the given namespace URI. +/* {{{ proto void SDO_DataFactory::create(string type_namespace_uri, string type_name) +Create an SDO_DataObject of the type specified by type_name with the given namespace URI. For example, the following creates a new SDO_DataObject of type 'CompanyType' where that type belongs to the namespace 'CompanyNS' $df->create('CompanyNS', 'CompanyType'); -The namespace of the type +The namespace URI of the type The name of the type Returns the newly created SDO_DataObject -Throws SDO_TypeNotFoundException if the namespaceURI and typeName do not correspond to a type known to this factory +Throws SDO_TypeNotFoundException if the namespace URI and type name do not correspond to a type known to this factory */ PHP_METHOD(SDO_DataFactory, create); /* }}} */ @@ -186,7 +194,7 @@ PHP_METHOD(SDO_DAS_DataFactory, getDataFactory); /* }}} */ -/* {{{ proto void SDO_DAS_DataFactory::addType(string namespaceURI, string typeName [, array options]) +/* {{{ proto void SDO_DAS_DataFactory::addType(string type_namespace_uri, string type_name [, array options]) Add a new type to the SDO_DAS_DataFactory, defined by its namespace and type name. @@ -206,21 +214,21 @@ PHP_METHOD(SDO_DAS_DataFactory, addType); /* }}} */ -/* {{{ proto void SDO_DAS_DataFactory::addPropertyToType(string parentNamespaceURI, string parentTypeName, string propertyName, string propertyNamespaceURI, string propertyTypeName [, array options]) +/* {{{ proto void SDO_DAS_DataFactory::addPropertyToType(string parent_type_namespace_uri, string parent_type_name, string property_name, string type_namespace_uri, string type_name [, array options]) Add a property to a type. The type must already be known to the SDO_DAS_DataFactory (i.e. have been added using addType()). The property becomes a property of the type. This is how the graph model for the structure of an SDO_DataObject is built. -The namespaceURI for the parent type +The namespace URI for the parent type -The typeName for the parent type +The type name for the parent type The name of by which the property will be known -The namespaceURI for the type of the property +The namespace URI for the type of the property -The typeName for the type of the property +The type name for the type of the property Optional associative array of optional arguments for the new property. Valid keys are: @@ -231,8 +239,8 @@ "default" to specifiy a default value for the property. "Default" is a mixed type argument, and omitting a default means the property does not have one. "opposite" to specify the property at the other end of a bi-directional relationship. Opposite is an array of three values -required to identify the opposite property. The first two are namespaceURI and type name and identify the type which contains -the opposite property, the thirs value is the property name of the opposite property. +required to identify the opposite property. The first two are namespace URI and type name and identify the type which contains +the opposite property, the third value is the property name of the opposite property. Example: to add a 'name' property to a Person type: $df->addPropertyToType('PersonNS', 'PersonType', @@ -280,7 +288,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangedDataObjects); /* }}} */ -/* {{{ proto integer SDO_DAS_ChangeSummary::getChangeType(SDO_DataObject dataObject) +/* {{{ proto integer SDO_DAS_ChangeSummary::getChangeType(SDO_DataObject data_object) Get the type of change which has been made to the supplied SDO_DataObject. The SDO_DataObject which has been changed @@ -292,7 +300,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangeType); /* }}} */ -/* {{{ proto SDO_List SDO_DAS_ChangeSummary::getOldValues(SDO_DataObject dataObject) +/* {{{ proto SDO_List SDO_DAS_ChangeSummary::getOldValues(SDO_DataObject data_object) Get a list of the old values for a given changed SDO_DataObject. The data object which has been changed. @@ -302,7 +310,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldValues); /* }}} */ -/* {{{ proto SDO_DataObject SDO_DAS_ChangeSummary::getOldContainer(SDO_DataObject dataObject) +/* {{{ proto SDO_DataObject SDO_DAS_ChangeSummary::getOldContainer(SDO_DataObject data_object) Get the old container (SDO_DataObject) for a deleted SDO_DataObject. The SDO_DataObject which has been deleted. @@ -365,7 +373,7 @@ PHP_METHOD(SDO_Model_Type, getNamespaceURI); /* }}} */ -/* {{{ proto boolean SDO_Model_Type::isInstance(SDO_DataObject dataObject) +/* {{{ proto boolean SDO_Model_Type::isInstance(SDO_DataObject data_object) Returns true if the object is an instance of the type. The SDO_DataObject to test. @@ -402,12 +410,20 @@ /* }}} */ /* {{{ proto boolean SDO_Model_Type::isOpenType() -Returns true if this type corresponds to a an SDO_DataObject which allows +Returns true if this type corresponds to an SDO_DataObject which allows open content, that is, aditional properties to be added to an instance. */ PHP_METHOD(SDO_Model_Type, isOpenType); /* }}} */ +/* {{{ proto boolean SDO_Model_Type::isAbstractType() +Returns true if this type is abstract, that is, no SDO_DataObject +of this type can be instantiated, though other types may inherit +from it. +*/ +PHP_METHOD(SDO_Model_Type, isAbstractType); +/* }}} */ + /* {{{ proto SDO_Model_Type SDO_Model_Type::getBaseType() Get the base (parent) type for this type. Returns NULL if this type does not inherit from any other type. @@ -509,13 +525,63 @@ PHP_METHOD(SDO_Model_ReflectionDataObject, getContainmentProperty); /* }}} */ + +/* {{{ proto SDO_Exception::getCause() +Returns the cause of this exception or NULL if the cause is nonexistent or unknown. +*/ +PHP_METHOD(SDO_Exception, getCause); +/* }}} */ + +/* {{{ proto SDO_CPPException::getClass() +Returns the name of the C++ exception class . +*/ +PHP_METHOD(SDO_CPPException, getClass); +/* }}} */ + +/* {{{ proto SDO_CPPException::getFile() +Returns the C++ file where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getFile); +/* }}} */ + +/* {{{ proto SDO_CPPException::getLine() +Returns the C++ line number where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getLine); +/* }}} */ + +/* {{{ proto SDO_CPPException::getFunction() +Returns the name of the C++ function where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getFunction); +/* }}} */ + +/* {{{ proto SDO_CPPException::getMessage() +Returns the detailed error text from the C++ exception. +*/ +PHP_METHOD(SDO_CPPException, getMessage); +/* }}} */ + +/* {{{ proto SDO_CPPException::getSeverity() +Returns the severity level from the C++ exception. +*/ +PHP_METHOD(SDO_CPPException, getSeverity); +/* }}} */ + +/* {{{ proto string SDO_CPPException::__toString() +Return a string representation of the object. +*/ +PHP_METHOD(SDO_CPPException, __toString); +/* }}} */ + /* {{{ Implementation methods */ PHP_METHOD(SDO_DAS_DataFactoryImpl, create); PHP_METHOD(SDO_DAS_DataFactoryImpl, addType); PHP_METHOD(SDO_DAS_DataFactoryImpl, addPropertyToType); PHP_METHOD(SDO_DataObjectImpl, __construct); -PHP_METHOD(SDO_DataObjectImpl, getType); +PHP_METHOD(SDO_DataObjectImpl, getTypeName); +PHP_METHOD(SDO_DataObjectImpl, getTypeNamespaceURI); PHP_METHOD(SDO_DataObjectImpl, getSequence); PHP_METHOD(SDO_DataObjectImpl, createDataObject); PHP_METHOD(SDO_DataObjectImpl, clear); @@ -542,6 +608,7 @@ PHP_METHOD(SDO_Model_TypeImpl, isDataType); PHP_METHOD(SDO_Model_TypeImpl, isSequencedType); PHP_METHOD(SDO_Model_TypeImpl, isOpenType); +PHP_METHOD(SDO_Model_TypeImpl, isAbstractType); PHP_METHOD(SDO_Model_TypeImpl, getBaseType); PHP_METHOD(SDO_Model_PropertyImpl, __construct); http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_das_xml.h?r1=1.6&r2=1.7&diff_format=u Index: pecl/sdo/php_sdo_das_xml.h diff -u pecl/sdo/php_sdo_das_xml.h:1.6 pecl/sdo/php_sdo_das_xml.h:1.7 --- pecl/sdo/php_sdo_das_xml.h:1.6 Thu Jan 26 14:18:44 2006 +++ pecl/sdo/php_sdo_das_xml.h Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_das_xml.h,v 1.6 2006/01/26 14:18:44 mfp Exp $ */ +/* $Id: php_sdo_das_xml.h,v 1.7 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_DAS_XML_H #define PHP_SDO_DAS_XML_H @@ -31,6 +31,18 @@ #define SDO_DAS_XML_VERSION "0.7.1" +#ifdef PHP_WIN32 +# if defined (SDO_DAS_XML_EXPORTS) +# define PHP_SDO_DAS_XML_API __declspec(dllexport) +# elif defined(COMPILE_DL_SDO_DAS_XML) +# define PHP_SDO_DAS_XML_API __declspec(dllimport) +# else +# define PHP_SDO_DAS_XML_API +# endif +#else +#define PHP_SDO_DAS_XML_API +#endif + PHP_MINIT_FUNCTION(sdo_das_xml); PHP_MINFO_FUNCTION(sdo_das_xml); @@ -38,32 +50,21 @@ PHP_METHOD(SDO_DAS_XML, __construct); PHP_METHOD(SDO_DAS_XML, create); PHP_METHOD(SDO_DAS_XML, addTypes); -PHP_METHOD(SDO_DAS_XML, loadFromFile); -PHP_METHOD(SDO_DAS_XML, loadFromString); +PHP_METHOD(SDO_DAS_XML, loadFile); +PHP_METHOD(SDO_DAS_XML, loadString); +PHP_METHOD(SDO_DAS_XML, saveFile); +PHP_METHOD(SDO_DAS_XML, saveString); +PHP_METHOD(SDO_DAS_XML, createDocument); PHP_METHOD(SDO_DAS_XML, createDataObject); -PHP_METHOD(SDO_DAS_XML, saveDocumentToString); -PHP_METHOD(SDO_DAS_XML, saveDocumentToFile); -PHP_METHOD(SDO_DAS_XML, saveDataObjectToString); -PHP_METHOD(SDO_DAS_XML, saveDataObjectToFile); -PHP_METHOD(SDO_DAS_XML, getTypes); PHP_METHOD(SDO_DAS_XML, __toString); -//PHP_METHOD(SDO_DAS_XML, getProperty); - /* SDO_DAS_XML_Document Class methods declarations */ PHP_METHOD(SDO_DAS_XML_Document, getRootDataObject); PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI); PHP_METHOD(SDO_DAS_XML_Document, getRootElementName); -PHP_METHOD(SDO_DAS_XML_Document, getEncoding); -PHP_METHOD(SDO_DAS_XML_Document, setEncoding); -PHP_METHOD(SDO_DAS_XML_Document, getXMLDeclaration); PHP_METHOD(SDO_DAS_XML_Document, setXMLDeclaration); -PHP_METHOD(SDO_DAS_XML_Document, getXMLVersion); PHP_METHOD(SDO_DAS_XML_Document, setXMLVersion); -PHP_METHOD(SDO_DAS_XML_Document, getSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, setSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation); +PHP_METHOD(SDO_DAS_XML_Document, setEncoding); #endif /* PHP_SDO_DAS_XML_H */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_das_xml_int.h?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/php_sdo_das_xml_int.h diff -u pecl/sdo/php_sdo_das_xml_int.h:1.9 pecl/sdo/php_sdo_das_xml_int.h:1.10 --- pecl/sdo/php_sdo_das_xml_int.h:1.9 Thu Jan 26 14:18:44 2006 +++ pecl/sdo/php_sdo_das_xml_int.h Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_das_xml_int.h,v 1.9 2006/01/26 14:18:44 mfp Exp $ */ +/* $Id: php_sdo_das_xml_int.h,v 1.10 2006/02/20 18:50:25 mfp Exp $ */ #ifndef _PHP_SDO_DEFS_H #define _PHP_SDO_DEFS_H @@ -43,39 +43,34 @@ /***************** Dependencies between files within XML_DAS ********/ /* The following four are called from das_xml.cpp's MINIT, and will be found in SDO_DAS_XML., SDO_DAS_XML_Document., and xmldas_utils.cpp */ -void initialize_sdo_das_xml_class(TSRMLS_D); -void initialize_sdo_das_xml_document_class(TSRMLS_D); -void initialize_sdo_das_xml_parserexception_class(TSRMLS_D); -void initialize_sdo_das_xml_fileexception_class(TSRMLS_D); +void sdo_das_xml_minit(TSRMLS_D); +void sdo_das_xml_document_minit(TSRMLS_D); +void sdo_das_xml_parserexception_minit(TSRMLS_D); +void sdo_das_xml_fileexception_minit(TSRMLS_D); /* The following three are defined in xmldas_utils.cpp - they logically belong in a xmldas_utils.h file */ -void sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); -void sdo_das_xml_throw_fileexception(char* filename TSRMLS_DC); -void sdo_das_xml_throw_parserexception(char* filename TSRMLS_DC); +zval *sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +zval *sdo_das_xml_throw_fileexception(char* filename TSRMLS_DC); +zval *sdo_das_xml_throw_parserexception(char* filename TSRMLS_DC); + +extern PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_class_entry; +extern PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_document_class_entry; /******************* Our data types ***********************************/ /* SDO_DAS_XML */ typedef struct { - zend_object z_obj; - XMLHelperPtr xmlHelper; - XSDHelperPtr xsdHelper; - SDOXMLString targetNamespaceURI; - zval *php_das_df; - DataFactoryPtr dataFactory; // Hydra dF + zend_object zo; + XMLHelperPtr xmlHelperPtr; + XSDHelperPtr xsdHelperPtr; + zval z_df; } xmldas_object; /* SDO_DAS_XML_Document */ typedef struct { - zend_object z_obj; - XMLDocumentPtr xdoch; + zend_object zo; + XMLDocumentPtr xmlDocumentPtr; } xmldocument_object; -/* SDO_DAS_DataFactory */ -typedef struct { - zend_object zo; - DataFactoryPtr dfp; -} sdo_das_df_object; - #endif /*_PHP_SDO_DEFS_H*/ /* http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_int.h?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/php_sdo_int.h diff -u pecl/sdo/php_sdo_int.h:1.12 pecl/sdo/php_sdo_int.h:1.13 --- pecl/sdo/php_sdo_int.h:1.12 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/php_sdo_int.h Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_int.h,v 1.12 2006/01/25 17:08:02 cem Exp $ */ +/* $Id: php_sdo_int.h,v 1.13 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_INT_H #define PHP_SDO_INT_H @@ -44,15 +44,6 @@ #define SDO_TOSTRING_MAX 1024 -/** - * The internal structure for an SDO_DataObjectImpl - * This extends the standard zend_object - */ -typedef struct { - zend_object zo; /* The standard zend_object */ - DataObjectPtr dop; /* The C++ DataObject */ -} sdo_do_object; - enum sdo_changesummary_type { CS_NONE = 0, CS_MODIFICATION = 1, @@ -94,12 +85,15 @@ extern PHP_SDO_API zend_class_entry *sdo_invalidconversionexception_class_entry; extern PHP_SDO_API zend_class_entry *sdo_indexoutofboundsexception_class_entry; extern PHP_SDO_API zend_class_entry *sdo_unsupportedoperationexception_class_entry; +extern PHP_SDO_API zend_class_entry *sdo_cppexception_class_entry; extern PHP_SDO_API void sdo_das_df_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_das_df_new(zval *me, DataFactoryPtr dfp TSRMLS_DC); +extern PHP_SDO_API DataFactoryPtr sdo_das_df_get(zval *me TSRMLS_DC); extern PHP_SDO_API void sdo_do_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC); +extern PHP_SDO_API DataObjectPtr sdo_do_get(zval *me TSRMLS_DC); extern PHP_SDO_API void sdo_list_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_dataobjectlist_new(zval *me, const Type& typeh, DataObjectList *listh TSRMLS_DC); @@ -114,7 +108,7 @@ extern PHP_SDO_API void sdo_das_setting_new(zval *me, Setting *setting TSRMLS_DC); extern PHP_SDO_API void sdo_sequence_minit(zend_class_entry *tmp TSRMLS_DC); -extern PHP_SDO_API void sdo_sequence_new(zval *me, SequencePtr seqp, DataObjectPtr dop TSRMLS_DC); +extern PHP_SDO_API void sdo_sequence_new(zval *me, SequencePtr seqp TSRMLS_DC); extern PHP_SDO_API void sdo_model_type_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_model_type_new(zval *me, const Type *typep TSRMLS_DC); @@ -127,18 +121,19 @@ extern PHP_SDO_API void sdo_model_rdo_minit(zend_class_entry *tmp TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_propertytnotfoundexception(SDOPropertyNotFoundException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_typenotfoundexception(SDOTypeNotFoundException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_unsupportedoperationexception(SDOUnsupportedOperationException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_invalidconversionexception(SDOInvalidConversionException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +extern PHP_SDO_API zval *sdo_throw_exception(zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC); +extern PHP_SDO_API zval *sdo_throw_exception_ex(zend_class_entry *ce, long code, zval *z_cause TSRMLS_DC, char *format, ...); +extern PHP_SDO_API void sdo_exception_minit(zend_class_entry *tmp TSRMLS_DC); +extern PHP_SDO_API void sdo_exception_new(zval *me, zend_class_entry *ce, const char *message, long code, zval *cause TSRMLS_DC); +extern PHP_SDO_API function_entry *sdo_exception_get_methods(); +extern PHP_SDO_API zval *sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +extern PHP_SDO_API void sdo_cppexception_minit(zend_class_entry *tmp TSRMLS_DC); +extern PHP_SDO_API void sdo_cppexception_new(zval *me, SDORuntimeException *cpp_exception TSRMLS_DC); extern PHP_SDO_API void sdo_make_long_class_constant(zend_class_entry *ce, char *name, long value); extern PHP_SDO_API xmldas::XMLDAS *sdo_get_XMLDAS(); -extern PHP_SDO_API function_entry *sdo_get_exception_methods(); - extern PHP_SDO_API int sdo_parse_offset_param(DataObjectPtr dop, zval *z_offset, const Property **return_property, const char **return_xpath, int property_required, int quiet TSRMLS_DC); extern PHP_SDO_API Type::Types sdo_map_zval_type (zval *z_value); http://cvs.php.net/viewcvs.cgi/pecl/sdo/sdo.cpp?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/sdo.cpp diff -u pecl/sdo/sdo.cpp:1.8 pecl/sdo/sdo.cpp:1.9 --- pecl/sdo/sdo.cpp:1.8 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/sdo.cpp Mon Feb 20 18:50:25 2006 @@ -20,7 +20,7 @@ */ -static char rcs_id[] = "$Id: sdo.cpp,v 1.8 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: sdo.cpp,v 1.9 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -72,6 +72,7 @@ PHP_SDO_API zend_class_entry *sdo_invalidconversionexception_class_entry; PHP_SDO_API zend_class_entry *sdo_indexoutofboundsexception_class_entry; PHP_SDO_API zend_class_entry *sdo_unsupportedoperationexception_class_entry; +PHP_SDO_API zend_class_entry *sdo_cppexception_class_entry; /* }}} */ /* {{{ single SDO_DataObject parameter */ @@ -102,12 +103,12 @@ ZEND_END_ARG_INFO(); function_entry sdo_dataobject_methods[] = { - ZEND_ABSTRACT_ME(SDO_DataObject, getType, 0) + ZEND_ABSTRACT_ME(SDO_DataObject, getTypeName, 0) + ZEND_ABSTRACT_ME(SDO_DataObject, getTypeNamespaceURI, 0) ZEND_ABSTRACT_ME(SDO_DataObject, getSequence, 0) ZEND_ABSTRACT_ME(SDO_DataObject, createDataObject, arginfo_sdo_dataobject_createdataobject) ZEND_ABSTRACT_ME(SDO_DataObject, clear, 0) ZEND_ABSTRACT_ME(SDO_DataObject, getContainer, 0) - ZEND_ABSTRACT_ME(SDO_DataObject, getContainmentPropertyName, 0) {NULL, NULL, NULL} }; /* }}} */ @@ -130,8 +131,6 @@ function_entry sdo_sequence_methods[] = { ZEND_ABSTRACT_ME(SDO_Sequence, getProperty, arginfo_sdo_sequence_getproperty) - ZEND_ABSTRACT_ME(SDO_Sequence, getPropertyIndex, arginfo_sdo_sequence_getproperty) - ZEND_ABSTRACT_ME(SDO_Sequence, getPropertyName, arginfo_sdo_sequence_getproperty) ZEND_ABSTRACT_ME(SDO_Sequence, move, arginfo_sdo_sequence_move) ZEND_ABSTRACT_ME(SDO_Sequence, insert, arginfo_sdo_sequence_insert) ZEND_ABSTRACT_ME(SDO_Sequence, count, 0) @@ -155,7 +154,7 @@ /* {{{ SDO_DataFactory methods */ static ZEND_BEGIN_ARG_INFO(arginfo_sdo_datafactory_create, 0) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_END_ARG_INFO(); @@ -174,16 +173,16 @@ /* {{{ SDO_DAS_DataFactory methods */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_sdo_das_datafactory_addType, 0, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); static ZEND_BEGIN_ARG_INFO_EX(arginfo_sdo_das_datafactory_addPropertyToType, 0, ZEND_RETURN_VALUE, 5) - ZEND_ARG_INFO(0, parent_namespace_uri) + ZEND_ARG_INFO(0, parent_type_namespace_uri) ZEND_ARG_INFO(0, parent_type_name) ZEND_ARG_INFO(0, property_name) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); @@ -236,12 +235,12 @@ ZEND_ME(SDO_DataObjectImpl, __set, arginfo___set, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, count, 0, ZEND_ACC_PUBLIC) /* inherited from SDO_DataObject ... */ - ZEND_ME(SDO_DataObjectImpl, getType, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DataObjectImpl, getTypeName, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DataObjectImpl, getTypeNamespaceURI, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, getSequence, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, createDataObject, arginfo_sdo_dataobject_createdataobject, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, clear, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, getContainer, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DataObjectImpl, getContainmentPropertyName, 0, ZEND_ACC_PUBLIC) /* inherited from SDO_DAS_DataObject ... */ ZEND_ME(SDO_DataObjectImpl, getChangeSummary, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} @@ -251,8 +250,6 @@ /* {{{ SDO_SequenceImpl methods */ function_entry sdo_sequenceimpl_methods[] = { ZEND_ME(SDO_SequenceImpl, getProperty, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_SequenceImpl, getPropertyIndex, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_SequenceImpl, getPropertyName, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, move, arginfo_sdo_sequence_move, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, insert, arginfo_sdo_sequence_insert, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, count, 0, ZEND_ACC_PUBLIC) @@ -274,6 +271,7 @@ ZEND_ABSTRACT_ME(SDO_Model_Type, isDataType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, isSequencedType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, isOpenType, 0) + ZEND_ABSTRACT_ME(SDO_Model_Type, isAbstractType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, getBaseType, 0) {NULL, NULL, NULL} }; @@ -288,6 +286,7 @@ ZEND_ME(SDO_Model_TypeImpl, isDataType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, isSequencedType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, isOpenType, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_Model_TypeImpl, isAbstractType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, getBaseType, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -338,17 +337,29 @@ }; /* }}} */ -/* {{{ SDO_Exception methods - * These are used for all SDO exceptions, none of them have any methods other than inherited ones - */ +/* {{{ SDO_Exception methods */ function_entry sdo_exception_methods[] = { + ZEND_ME(SDO_Exception, getCause, 0, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; +/* }}} */ + +/* {{{ SDO_CPPException methods */ +function_entry sdo_cppexception_methods[] = { + ZEND_ME(SDO_CPPException, getClass, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getFile, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getLine, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getFunction, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getMessage, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getSeverity, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, __toString, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ -/* {{{ sdo_get_exception_methods +/* {{{ sdo_exception_get_methods */ -PHP_SDO_API function_entry *sdo_get_exception_methods() +PHP_SDO_API function_entry *sdo_exception_get_methods() { return sdo_exception_methods; } @@ -483,14 +494,7 @@ /* class SDO_Exception extends Exception */ INIT_CLASS_ENTRY(ce, "SDO_Exception", sdo_exception_methods); - sdo_exception_class_entry = zend_register_internal_class_ex( - &ce, -#if (PHP_MAJOR_VERSION < 6) - zend_exception_get_default(), -#else - zend_exception_get_default(TSRMLS_C), -#endif - NULL TSRMLS_CC); + sdo_exception_minit(&ce TSRMLS_CC); /* class SDO_PropertyNotFoundException extends SDO_Exception */ INIT_CLASS_ENTRY(ce, "SDO_PropertyNotFoundException", sdo_exception_methods); @@ -522,6 +526,9 @@ sdo_unsupportedoperationexception_class_entry = zend_register_internal_class_ex( &ce, sdo_exception_class_entry, NULL TSRMLS_CC); + /* class SDO_CPPException */ + INIT_CLASS_ENTRY(ce, "SDO_CPPException", sdo_cppexception_methods); + sdo_cppexception_minit(&ce TSRMLS_CC); return SUCCESS; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/sdo_utils.cpp?r1=1.6&r2=1.7&diff_format=u Index: pecl/sdo/sdo_utils.cpp diff -u pecl/sdo/sdo_utils.cpp:1.6 pecl/sdo/sdo_utils.cpp:1.7 --- pecl/sdo/sdo_utils.cpp:1.6 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/sdo_utils.cpp Mon Feb 20 18:50:25 2006 @@ -20,7 +20,7 @@ */ -static char rcs_id[] = "$Id: sdo_utils.cpp,v 1.6 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: sdo_utils.cpp,v 1.7 2006/02/20 18:50:25 mfp Exp $"; /* * Utility functions for internal use by the SDO extension @@ -32,94 +32,11 @@ #endif #include "php.h" -#include "zend_exceptions.h" #include "php_sdo_int.h" static xmldas::XMLDAS *xmldasp = NULL; -/* {{{ sdo_throw_exception - * rethrows a C++ SDO exception with a PHP SDO exception wrapper - */ -static void sdo_throw_exception(zend_class_entry *ce, SDORuntimeException *e, char *extra TSRMLS_DC) -{ - if (extra) - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s: %s\n Filename %s\n At line %ld in function %s\n Message %s\n", - extra, e->getEClassName(), e->getFileName(), e->getLineNumber(), e->getFunctionName(), e->getMessageText()); - else - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n Filename %s\n At line %ld in function %s\n Message %s\n", - e->getEClassName(), e->getFileName(), e->getLineNumber(), e->getFunctionName(), e->getMessageText()); -} -/* }}} */ - -/* {{{ sdo_throw_typenotfoundexception - */ -void sdo_throw_typenotfoundexception(SDOTypeNotFoundException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_typenotfoundexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_propertynotfoundexception - */ -void sdo_throw_propertynotfoundexception(SDOPropertyNotFoundException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_propertynotfoundexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_unsupportedoperationexception - */ -void sdo_throw_unsupportedoperationexception(SDOUnsupportedOperationException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_unsupportedoperationexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_invalidconversionexception - */ -void sdo_throw_invalidconversionexception(SDOInvalidConversionException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_invalidconversionexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_indexoutofboundsexception - */ -void sdo_throw_indexoutfboundsexception(SDOIndexOutOfRangeException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_indexoutofboundsexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_runtimeexception - * maps a C++ SDO exception to a PHP SDO exception and throws it - */ -void sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) -{ - zend_class_entry *exception_class; - const char *exception_type = e->getEClassName(); - - if (strcmp(exception_type, "SDOUnsupportedOperationException") == 0) - exception_class = sdo_unsupportedoperationexception_class_entry; - else if (strcmp(exception_type, "SDOPropertyNotFoundException") == 0 || - strcmp(exception_type, "SDOPathNotFoundException") == 0) - exception_class = sdo_propertynotfoundexception_class_entry; - else if (strcmp(exception_type, "SDOTypeNotFoundException") == 0) - exception_class = sdo_typenotfoundexception_class_entry; - else if (strcmp(exception_type, "SDOIndexOutOfRangeException") == 0) - exception_class = sdo_indexoutofboundsexception_class_entry; - else if (strcmp(exception_type, "SDOInvalidConversionException") == 0) - exception_class = sdo_invalidconversionexception_class_entry; - else if (strcmp(exception_type, "SDOPropertyNotSetException") == 0) - exception_class = sdo_propertynotsetexception_class_entry; - else - exception_class = sdo_exception_class_entry; - - sdo_throw_exception(exception_class, e, NULL TSRMLS_CC); -} -/* }}} */ - /* {{{ sdo_make_long_class_constant * creates a class constant */ @@ -164,26 +81,23 @@ case IS_NULL: if (!quiet) { class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_WARNING, "%s%s%s(): parameter is NULL", + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): parameter is NULL", class_name, space, get_active_function_name(TSRMLS_C)); } return FAILURE; case IS_STRING: xpath = Z_STRVAL_P(z_offset); - + /* If the type is open, then it's OK for the xpath offset to * specify an unknown property. But even an open type may have * defined properties, so we still need to try for one. */ - try { + if (property_required || dop->hasProperty(xpath)) { + /* exception will be thrown if xpath is invalid */ property_p = &dop->getProperty(xpath); - } catch (SDORuntimeException e) { - if (property_required) { - throw e; - return FAILURE; - } else { - property_p = NULL; - } + } else { + property_p = NULL; } break; case IS_LONG: @@ -210,8 +124,9 @@ case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(z_offset), sdo_model_property_class_entry TSRMLS_CC)) { if (!quiet) { - class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_WARNING, "%s%s%s(): expects object parameter to be SDO_Model_Property, %s given", + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): expects object parameter to be SDO_Model_Property, %s given", class_name, space, get_active_function_name(TSRMLS_C), Z_OBJCE_P(z_offset)->name); } @@ -223,7 +138,7 @@ default: if (!quiet) { class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_ERROR, "%s%s%s(): invalid dimension type %i", + php_error(E_ERROR, "%s%s%s(): internal error - invalid dimension type %i", class_name, space, get_active_function_name(TSRMLS_C), Z_TYPE_P(z_offset)); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/xmldas_utils.cpp?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/xmldas_utils.cpp diff -u pecl/sdo/xmldas_utils.cpp:1.8 pecl/sdo/xmldas_utils.cpp:1.9 --- pecl/sdo/xmldas_utils.cpp:1.8 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/xmldas_utils.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: xmldas_utils.cpp,v 1.8 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: xmldas_utils.cpp,v 1.9 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -27,7 +27,7 @@ #include <iostream> #include <math.h> #include "zend_config.w32.h" -#endif +#endif #include "php_sdo_das_xml_int.h" @@ -36,75 +36,47 @@ zend_class_entry *sdo_das_xml_parserexception_ce = NULL; zend_class_entry *sdo_das_xml_fileexception_ce = NULL; -/* {{{ initialize_sdo_das_parserexception_class +/* {{{ sdo_das_parserexception_minit */ -void initialize_sdo_das_xml_parserexception_class(TSRMLS_D) +void sdo_das_xml_parserexception_minit(TSRMLS_D) { - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_ParserException", sdo_get_exception_methods()); + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_ParserException", sdo_exception_get_methods()); sdo_das_xml_parserexception_ce = zend_register_internal_class_ex(&ce, NULL, "sdo_exception" TSRMLS_CC); } /* }}} */ -/* {{{ initialize_sdo_das_parserexception_class +/* {{{ sdo_das_parserexception_minit */ -void initialize_sdo_das_xml_fileexception_class(TSRMLS_D) +void sdo_das_xml_fileexception_minit(TSRMLS_D) { - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_FileException", sdo_get_exception_methods()); + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_FileException", sdo_exception_get_methods()); sdo_das_xml_fileexception_ce = zend_register_internal_class_ex(&ce, NULL, "sdo_exception" TSRMLS_CC); } /* }}} */ -/* {{{ sdo_das_xml_throw_exception - * Throws C++ SDO exception as PHP exception - */ -static void -sdo_das_xml_throw_exception(zend_class_entry *ce, SDORuntimeException *e, char *extra TSRMLS_DC) -{ - if (extra) { - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s: %s\n Filename %s\n At line %ld in function %s\n Message %s\n", - extra, e->getEClassName(), e->getFileName(), - e->getLineNumber(), e->getFunctionName(), - e->getMessageText()); - } else { - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n Filename %s\n At line %ld in function %s\n Message %s\n", - e->getEClassName(), e->getFileName(), - e->getLineNumber(), e->getFunctionName(), - e->getMessageText()); - } -} -/* }}} */ - /* {{{ sdo_das_xml_throw_runtimeexception */ -void -sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) +zval *sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) { - const char *exception_type = e->getEClassName(); - sdo_throw_runtimeexception(e TSRMLS_CC); + return sdo_throw_runtimeexception(e TSRMLS_CC); } /* }}} */ /* {{{ sdo_das_xml_throw_parserexception */ -void -sdo_das_xml_throw_parserexception(char * msg TSRMLS_DC) +zval *sdo_das_xml_throw_parserexception(char *msg TSRMLS_DC) { - zend_class_entry *ce = sdo_das_xml_parserexception_ce; - - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n", msg); + return zend_throw_exception(sdo_das_xml_parserexception_ce, msg, 0 TSRMLS_CC); } /* }}} */ /* {{{ sdo_das_xml_throw_fileexception */ -void sdo_das_xml_throw_fileexception(char *filename TSRMLS_DC) +zval *sdo_das_xml_throw_fileexception(char *filename TSRMLS_DC) { - zend_class_entry *ce = sdo_das_xml_fileexception_ce; - - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "File \"%s\" could not be found.\n", filename); + return zend_throw_exception_ex(sdo_das_xml_fileexception_ce, + 0 TSRMLS_CC, "File \"%s\" could not be found", filename); } /* }}} */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational.php?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/DAS/Relational.php diff -u pecl/sdo/DAS/Relational.php:1.9 pecl/sdo/DAS/Relational.php:1.10 --- pecl/sdo/DAS/Relational.php:1.9 Fri Jan 20 12:34:43 2006 +++ pecl/sdo/DAS/Relational.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: Relational.php,v 1.9 2006/01/20 12:34:43 mfp Exp $ +$Id: Relational.php,v 1.10 2006/02/20 18:50:25 mfp Exp $ */ require_once 'SDO/DAS/Relational/Exception.php'; @@ -145,7 +145,7 @@ $dbh->commit(); return $root; } - + /** * Given an SQL query in the form of a prepared PDO statement and a value list, execute it, * normalise the result set into a data graph and return it. @@ -160,13 +160,9 @@ $dbh->commit(); return $root; } - + public function normaliseResultSet($pdo_stmt, $column_specifier) { - if (gettype(PDO_FETCH_ASSOC) == 'string') { - include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; - } else { - include_once "SDO/DAS/Relational/PDOConstants.underscore.inc.php"; - } + include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; if ($column_specifier == null) { $all_rows = $pdo_stmt->fetchAll(SDO_DAS_Relational_PDO_FETCH_ASSOC); } else { @@ -243,7 +239,7 @@ throw new SDO_DAS_Relational_Exception('The result set from ExecuteQuery contained a column with name ' . $col . ' but there is no table with a column with this name.'); case 1: foreach ($table_names_with_this_column as $table_name => $property_name) // only one entry - $parsed_row[$table_name][$property_name] = $value; + $parsed_row[$table_name][$property_name] = $value; break; default: throw new SDO_DAS_Relational_Exception('The result set from ExecuteQuery contained a column with name ' . $col . ' but there is more than one table with a column with this name. You need to pass a column specifier to resolve the ambiguity.'); @@ -332,11 +328,11 @@ if ($setting->isSet()) { $original_value = $setting->getValue(); echo ", which had original value "; - ob_start(); - var_dump($original_value); - $content = ob_get_contents(); - ob_end_clean(); - echo "$content\n"; + ob_start(); + var_dump($original_value); + $content = ob_get_contents(); + ob_end_clean(); + echo "$content\n"; } else { echo ", which was originally not set\n"; } @@ -383,8 +379,8 @@ private static function isRoot($do) { - $reflection_do = new SDO_Model_ReflectionDataObject($do); - $type = $reflection_do->getType(); + $rdo = new SDO_Model_ReflectionDataObject($do); + $type = $rdo->getType(); return ($type->namespaceURI == SDO_DAS_Relational::DAS_NAMESPACE && $type->name == SDO_DAS_Relational::DAS_ROOT_TYPE); } @@ -392,7 +388,7 @@ { return $df->create(SDO_DAS_Relational::DAS_NAMESPACE, SDO_DAS_Relational::DAS_ROOT_TYPE); } - + public function getObjectModel() { return $this->object_model; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/DataObjectHelper.php?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/DAS/Relational/DataObjectHelper.php diff -u pecl/sdo/DAS/Relational/DataObjectHelper.php:1.5 pecl/sdo/DAS/Relational/DataObjectHelper.php:1.6 --- pecl/sdo/DAS/Relational/DataObjectHelper.php:1.5 Fri Jan 20 12:33:58 2006 +++ pecl/sdo/DAS/Relational/DataObjectHelper.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: DataObjectHelper.php,v 1.5 2006/01/20 12:33:58 mfp Exp $ +$Id: DataObjectHelper.php,v 1.6 2006/02/20 18:50:25 mfp Exp $ */ /** @@ -54,11 +54,11 @@ { $type = self::getApplicationType($data_object); $pk_property_name = $object_model->getPropertyRepresentingPrimaryKeyFromType($type); - if (!isset($data_object[$pk_property_name])) { - return null; - } else { + if (isset($data_object[$pk_property_name])) { $pk = $data_object[$pk_property_name]; return $pk; + } else { + return null; } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/InsertAction.php?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/DAS/Relational/InsertAction.php diff -u pecl/sdo/DAS/Relational/InsertAction.php:1.7 pecl/sdo/DAS/Relational/InsertAction.php:1.8 --- pecl/sdo/DAS/Relational/InsertAction.php:1.7 Wed Oct 19 11:35:42 2005 +++ pecl/sdo/DAS/Relational/InsertAction.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: InsertAction.php,v 1.7 2005/10/19 11:35:42 cem Exp $ +$Id: InsertAction.php,v 1.8 2006/02/20 18:50:25 mfp Exp $ */ /** @@ -159,11 +159,7 @@ private function storeThisObjectsPrimaryKey($dbh) { - if (gettype(PDO_FETCH_ASSOC) == 'string') { - include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; - } else { - include_once "SDO/DAS/Relational/PDOConstants.underscore.inc.php"; - } + include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; $type = SDO_DAS_Relational_DataObjectHelper::getApplicationType($this->do); $pk_property_name = $this->object_model->getPropertyRepresentingPrimaryKeyFromType($type); http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql diff -u pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.3 pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.4 --- pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.3 Tue Jan 17 09:47:58 2006 +++ pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql Mon Feb 20 18:50:25 2006 @@ -1,17 +1,17 @@ -connect to company - -drop table company -drop table department -drop table employee - -create table company ( id integer not null generated by default as identity, \ - name varchar(20), employee_of_the_month integer, \ - primary key(id)) - -create table department ( id integer not null generated by default as identity, \ - name varchar(20), location varchar(10), \ - number integer, co_id integer, primary key(id) ) - -create table employee ( id integer not null generated by default as identity, \ - name varchar(20), SN char(4), \ +connect to company + +drop table company +drop table department +drop table employee + +create table company ( id integer not null generated by default as identity, \ + name varchar(20), employee_of_the_month integer, \ + primary key(id)) + +create table department ( id integer not null generated by default as identity, \ + name varchar(20), location varchar(10), \ + number integer, co_id integer, primary key(id) ) + +create table employee ( id integer not null generated by default as identity, \ + name varchar(20), SN char(4), \ manager smallint, dept_id integer, primary key(id)) \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp diff -u pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.4 pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/ChangeSummaryImpl.h" @@ -191,11 +191,11 @@ for (int j=0 ; j < slist.size();j++) { - if (!strcmp(slist[j].getProperty().getName(), + if (!strcmp(slist.get(j)->getProperty().getName(), prop.getName()) - && slist[j].getIndex() == + && slist.get(j)->getIndex() == index) { // these are settings of the same prop/index, we @@ -271,7 +271,7 @@ if (!ob->isSet(pl[i])) { - sl.append(Setting(false,false, 0,0,pl[i],0)); + sl.append(new Setting(false,false, 0,0,pl[i],0)); continue; } if (pl[i].isMany()) @@ -283,18 +283,18 @@ // needs to be the data object in cases where... if (pl[i].getType().isDataType()) { setPropValue(&value,&len,ob,pl[j]); - sl.append(Setting(true,false,value,len,pl[i],j)); + sl.append(new Setting(true,false,value,len,pl[i],j)); } else { value = (void*)dol[j]; - sl.append(Setting(true,false,value,0,pl[i],j)); + sl.append(new Setting(true,false,value,0,pl[i],j)); } } } else { setPropValue(&value,&len,ob,pl[i]); - sl.append(Setting(true,ob->isNull(pl[i]),value,len,pl[i],0)); + sl.append(new Setting(true,ob->isNull(pl[i]),value,len,pl[i],0)); } } @@ -315,17 +315,18 @@ { for (int i=0;i<sl.size();i++) { - if (!strcmp(slist[j].getProperty().getName(), - sl[i].getProperty().getName()) + if (!strcmp(slist.get(j)->getProperty().getName(), + sl.get(i)->getProperty().getName()) - && slist[j].getIndex() == - sl[i].getIndex()) + && slist.get(j)->getIndex() == + sl.get(i)->getIndex()) { // these are settings of the same prop/index, we // need the old value to get transferred. sl.remove(i); - sl.insert(i,slist[j]); + sl.insert(i,new Setting(*(slist.get(j)))); + } } } @@ -801,7 +802,7 @@ for (int i=0;i<slist.size();i++) { - if (!strcmp(slist[i].getProperty().getName(),prop.getName())) + if (!strcmp(slist.get(i)->getProperty().getName(),prop.getName())) { LOGINFO(INFO,"ChangeSummary: Change of a property which was already changed - ignore"); return; @@ -814,7 +815,7 @@ if (!ob->isSet(prop)) { - slist.append(Setting(false,false,0,0,prop,0)); + slist.append(new Setting(false,false,0,0,prop,0)); return; } @@ -828,7 +829,7 @@ DataObjectList& dol = ob->getList(prop); if (dol.size() == 0) { - slist.append(Setting(false,false,0,0,prop,0)); + slist.append(new Setting(false,false,0,0,prop,0)); return; } for (int i=0;i< dol.size(); i++) @@ -837,18 +838,18 @@ if (prop.getType().isDataType()) { setManyPropValue(&value, &len, (DataObjectImpl*)ob, (DataObjectImpl*)dob, prop); - slist.append(Setting(true,false,value,len,prop,i)); + slist.append(new Setting(true,false,value,len,prop,i)); } else{ value = (void*)dob; - slist.append(Setting(true,false,value,0,prop,i)); + slist.append(new Setting(true,false,value,0,prop,i)); } } } else { setPropValue(&value,&len,ob,prop); - slist.append(Setting(true,ob->isNull(prop),value,len,prop,0)); + slist.append(new Setting(true,ob->isNull(prop),value,len,prop,0)); } return; @@ -1130,8 +1131,8 @@ for (int i=0;i < sl.size(); i++) { if (!strcmp(property.getName(), - sl[i].getProperty().getName())) - return (sl[i]); + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); } } @@ -1142,8 +1143,8 @@ for (int i=0;i < sl.size(); i++) { if (!strcmp(property.getName(), - sl[i].getProperty().getName())) - return (sl[i]); + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); } } @@ -1347,7 +1348,7 @@ unsigned int len = stringConvert(&datavalue, (const char*)value , p); - slist.append(Setting(true,false,datavalue,len,p,index)); + slist.append(new Setting(true,false,datavalue,len,p,index)); // The datavalue will be freed by the deletion of the setting later } @@ -1388,7 +1389,7 @@ // against existing settings - slist.append(Setting(true,false,(void*)indob,0,p,index)); + slist.append(new Setting(true,false,(void*)indob,0,p,index)); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataFactoryImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataFactoryImpl.cpp diff -u pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.4 pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.4 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataFactoryImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ ////////////////////////////////////////////////////////////////////// // DataFactoryImpl.cpp: implementation of the DataFactory class. @@ -358,9 +358,9 @@ if(typeIter == types.end()) { string msg("Type not found: "); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += inTypeName; + if (inTypeName != 0)msg += inTypeName; SDO_THROW_EXCEPTION("addPropertyToType", SDOTypeNotFoundException, msg.c_str()); @@ -381,9 +381,9 @@ if (typeIter2 == types.end()) { string msg("Type not found: "); - msg += propTypeUri; + if (propTypeUri != 0)msg += propTypeUri; msg += " "; - msg += propTypeName; + if (propTypeName != 0)msg += propTypeName; SDO_THROW_EXCEPTION("addPropertyToType", SDOTypeNotFoundException, msg.c_str()); } @@ -902,9 +902,9 @@ if (type == 0) { string msg("Type not found :"); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += inTypeName; + if (inTypeName != 0)msg += inTypeName; SDO_THROW_EXCEPTION("getTypeImpl" , SDOTypeNotFoundException, msg.c_str()); } @@ -1059,7 +1059,7 @@ string msg("Instantiation of unknown type :"); if (uri != 0) msg += uri; msg += " "; - msg += typeName; + if (typeName != 0)msg += typeName; SDO_THROW_EXCEPTION("create" , SDOTypeNotFoundException, msg.c_str()); } @@ -1067,9 +1067,9 @@ if (ti->isAbstractType()) { string msg("Instantiation of abstract type :"); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += typeName; + if (typeName != 0)msg += typeName; SDO_THROW_EXCEPTION("create" , SDOUnsupportedOperationException, msg.c_str()); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObject.h?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObject.h diff -u pecl/sdo/commonj/sdo/DataObject.h:1.4 pecl/sdo/commonj/sdo/DataObject.h:1.5 --- pecl/sdo/commonj/sdo/DataObject.h:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObject.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECT_H_ #define _DATAOBJECT_H_ @@ -109,7 +109,11 @@ virtual SDO_API PropertyList getInstanceProperties() = 0; - + /** + * See if the property currently exists + */ + + virtual SDO_API bool hasProperty(const char* name) = 0; /** * These are just like getType().getProperty(), but may return * values other than the property list for open types. http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.5 pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.6 --- pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.5 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/DataObjectImpl.h" @@ -1228,9 +1228,26 @@ d->setNull(); } else { - const Property& p = d->getProperty(prop); + const PropertyImpl* p = d->getPropertyImpl(prop); + if (p == 0) + { + if(d->getType().isOpenType()) + { + string msg("Cannot set unassigned open property to null:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOUnsupportedOperationException, + msg.c_str()); + } + else + { + string msg("Property Not Found:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOPropertyNotFoundException, + msg.c_str()); + } + } delete prop; - d->setNull(p); + d->setNull((Property&)*p); return; } } @@ -1398,6 +1415,18 @@ return (Property&)*pi; } + /** + * See if the property currently exists + */ + + bool DataObjectImpl::hasProperty(const char* name) + { + PropertyImpl* pi = getPropertyImpl(name); + if (pi == 0) return false; + return true; + } + + PropertyImpl* DataObjectImpl::getPropertyImpl(unsigned int index) { PropertyList props = getType().getProperties(); @@ -2351,8 +2380,11 @@ char *c1 = strchr(c,']'); if (c1 != 0)*c1 = 0; unsigned int i = atoi(++c); - DataObjectList& li = d->getList(p); - li.remove(i); + if (i > 0){ + i--; + DataObjectList& li = d->getList(p); + li.remove(i); + } delete prop; return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.h?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectImpl.h:1.4 pecl/sdo/commonj/sdo/DataObjectImpl.h:1.5 --- pecl/sdo/commonj/sdo/DataObjectImpl.h:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTIMPL_H_ #define _DATAOBJECTIMPL_H_ @@ -389,6 +389,11 @@ virtual DataObjectPtr createDataObject(const Property& property); + /** + * See if the property currently exists + */ + + virtual bool hasProperty(const char* name); virtual void detach(); @@ -552,7 +557,7 @@ virtual bool remove(DataObjectImpl* indol); virtual bool isSet(const Property& prop, unsigned int propertyIndex); - + virtual DataObjectImpl* getDataObjectImpl(const char* path); virtual DataObjectImpl* getDataObjectImpl(unsigned int propertyIndex); virtual DataObjectImpl* getDataObjectImpl(const Property& property); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectList.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectList.h diff -u pecl/sdo/commonj/sdo/DataObjectList.h:1.2 pecl/sdo/commonj/sdo/DataObjectList.h:1.3 --- pecl/sdo/commonj/sdo/DataObjectList.h:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectList.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTLIST_H_ #define _DATAOBJECTLIST_H_ @@ -166,6 +166,25 @@ */ virtual SDO_API DataObjectPtr remove (unsigned int index) = 0; + + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual SDO_API const Type& getType() = 0; + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual SDO_API const Type::Types getTypeEnum() = 0; + }; }; }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectListImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectListImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.4 pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.4 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataObjectListImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/DataObjectListImpl.h" @@ -164,10 +164,39 @@ } + +const Type& DataObjectListImpl::getType() +{ + if (typeUnset) + { + string msg("The list property is open, and the type of the contents has not bee determined yet."); + SDO_THROW_EXCEPTION("Get Type", SDOTypeNotFoundException, + msg.c_str()); + } + return theFactory->getType(typeURI, typeName); +} + + +const Type::Types DataObjectListImpl::getTypeEnum() +{ + if (typeUnset) + { + return Type::UndefinedOpenPropertyType; + + } + return theFactory->getType(typeURI, typeName).getTypeEnum(); +} + + void DataObjectListImpl::insert (unsigned int index, DataObjectPtr d) { if (typeUnset)setType(d->getType().getURI(),d->getType().getName()); + checkFactory(d); + + checkType(theFactory->getType(typeURI,typeName), + d->getType()); + if (container != 0) { container->logChange(pindex); @@ -240,40 +269,67 @@ } + void DataObjectListImpl::checkFactory(DataObjectPtr dob) + { + + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dob; + + if (d->getDataFactory() == theFactory) return; + + string msg("Insertion from incompatible factory "); + const Type& t = d->getType(); + msg += t.getURI(); + msg += "#"; + msg += t.getName(); + msg += " into list "; + msg += typeURI; + msg += "#"; + msg += typeName; + SDO_THROW_EXCEPTION("checkFactory", SDOInvalidConversionException, + msg.c_str()); + } + + void DataObjectListImpl::checkType(const Type& listType, const Type& objectType) { if (listType.equals(objectType)) return; const TypeImpl* ti = ((DataFactoryImpl*)theFactory)->findTypeImpl (objectType.getURI(),objectType.getName()); - - do + if (ti != 0) { - ti = (const TypeImpl*)ti->getBaseType(); - if (ti == 0) break; - if (listType.equals(*ti)) return; - } while (ti != 0); - - // allow types of any substitutes - if (container != 0) - { - PropertyImpl* pi = - container->getPropertyImpl(pindex); - if (pi != 0) + do { - unsigned int subcount = pi->getSubstitutionCount(); - for (int i=0;i<subcount;i++) + ti = (const TypeImpl*)ti->getBaseType(); + if (ti == 0) break; + if (listType.equals(*ti)) return; + } while (ti != 0); + + // allow types of any substitutes + if (container != 0) + { + PropertyImpl* pi = + container->getPropertyImpl(pindex); + if (pi != 0) { - const Type* tsub = pi->getSubstitutionType(i); - if (tsub != 0 && tsub->equals(objectType)) return; + unsigned int subcount = pi->getSubstitutionCount(); + for (int i=0;i<subcount;i++) + { + const Type* tsub = pi->getSubstitutionType(i); + if (tsub != 0 && tsub->equals(objectType)) return; + } } } } // no match.. string msg("Insertion of object of incompatible type "); + msg += objectType.getURI(); + msg += "#"; msg += objectType.getName(); - msg += " into property of type "; + msg += " into list of type "; + msg += listType.getURI(); + msg += "#"; msg += listType.getName(); SDO_THROW_EXCEPTION("TypeCheck", SDOInvalidConversionException, msg.c_str()); @@ -332,6 +388,7 @@ } } + checkFactory(d); checkType(theFactory->getType(typeURI,typeName), d->getType()); @@ -939,6 +996,15 @@ void DataObjectListImpl::setDataObject(unsigned int index, DataObjectPtr dob) { + + if (dob != 0) + { + checkFactory(dob); + + checkType(theFactory->getType(typeURI,typeName), + dob->getType()); + } + validateIndex(index); if (container != 0) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectListImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectListImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.3 pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.4 --- pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectListImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTLISTIMPL_H_ #define _DATAOBJECTLISTIMPL_H_ @@ -140,9 +140,27 @@ virtual DataObjectPtr remove (unsigned int index); + virtual void checkFactory(DataObjectPtr dob); virtual void checkType(const Type& listType, const Type& objectType); virtual void setType(const char* uri, const char* name); + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual const Type& getType(); + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual const Type::Types getTypeEnum(); private: http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/PropertyImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/PropertyImpl.cpp diff -u pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.4 pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/PropertyImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include <iostream> using namespace std; @@ -147,8 +147,8 @@ PropertyImpl::~PropertyImpl() { - if (name != 0) delete name; - if (defvalue != 0) delete defvalue; + if (name != 0) delete (char*)name; + if (defvalue != 0) delete (char*)defvalue; if (stringdef != 0) delete stringdef; for (int i = 0; i < aliases.size();i++) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SAX2Namespaces.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SAX2Namespaces.cpp diff -u pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.3 pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.4 --- pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SAX2Namespaces.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SAX2Namespaces.h" @@ -73,7 +73,7 @@ { // add will not overwrite if it already exists namespaceMap[nsIter->first] = nsIter->second; - } + } return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.3 pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOSAX2Parser.h" @@ -775,22 +775,31 @@ // NOTE: always creating DO doesn't cater for DataType as top element - newDO = dataFactory->create(typeURI, typeName); - - // set the property setting if the root is an extended primitive const Type& tp = dataFactory->getType(typeURI,typeName); - // get the type definition, and see if its an extended primitive. - - XSDTypeInfo* typeInfo = (XSDTypeInfo*) - ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); - if (typeInfo) + if (tp.isDataType()) + { + newDO = dataFactory->create(tns, "RootType"); + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + } + else { - const TypeDefinition& typeDefinition = typeInfo->getTypeDefinition(); - if (typeDefinition.isExtendedPrimitive) + + newDO = dataFactory->create(typeURI, typeName); + + // get the type definition, and see if its an extended primitive. + + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo) { - // The name of this element is the name of a property on the current DO - currentPropertySetting = PropertySetting(newDO, localname, - bToBeNull); + const TypeDefinition& typeDefinition = typeInfo->getTypeDefinition(); + if (typeDefinition.isExtendedPrimitive) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + } } } @@ -833,7 +842,17 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; - } + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit5"); return; } @@ -904,6 +923,16 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit6"); return; } @@ -922,6 +951,16 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit7"); return; } @@ -942,6 +981,17 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) + { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit8"); return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.5 pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.6 --- pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.5 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOSchemaSAX2Parser.h" #include "commonj/sdo/XSDPropertyInfo.h" @@ -70,6 +70,8 @@ { bInSchema = true; // Handle namespace definitions + + schemaInfo.getSchemaNamespaces().merge(namespaces); // Handle attributes @@ -80,7 +82,8 @@ schemaInfo.setTargetNamespaceURI(attributes[i].getValue()); } } - + + currentType.uri = schemaInfo.getTargetNamespaceURI(); currentType.name = "RootType"; currentType.localname="RootType"; @@ -138,6 +141,14 @@ startGroup(localname, prefix, URI, namespaces, attributes); } // end Group handling + else if (localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + if (setter) + { + setter->setError("Schema contains group or attributeGroup which are not yet implemented"); + } + } /////////////////////////////////////////////////////////////////////// // Handle simpleType // These become new types @@ -785,7 +796,7 @@ } // ============================================================================ - // setType + // setType // ============================================================================ void SDOSchemaSAX2Parser::setType( PropertyDefinition& property, @@ -943,6 +954,14 @@ if (qname.getURI().equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) { uri = Type::SDOTypeNamespaceURI; + if (qname.getLocalName().equalsIgnoreCase("ID")) + { + name = "String"; + } + if (qname.getLocalName().equalsIgnoreCase("NCName")) + { + name = "String"; + } if (qname.getLocalName().equalsIgnoreCase("string")) { name = "String"; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.2 pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.3 --- pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXMLStreamWriter.h" #include <sstream> @@ -37,9 +37,9 @@ { } - int SDOXMLStreamWriter::write(XMLDocumentPtr doc) + int SDOXMLStreamWriter::write(XMLDocumentPtr doc, int indent) { - int rc = SDOXMLBufferWriter::write(doc); + int rc = SDOXMLBufferWriter::write(doc, indent); // Now stream the buffer outXmlStream << getBuffer(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.2 pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.3 --- pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXMLSTREAMWRITER_H_ #define _SDOXMLSTREAMWRITER_H_ @@ -42,7 +42,7 @@ SDOXMLStreamWriter(std::ostream& outXML, DataFactoryPtr dataFactory = NULL); virtual ~SDOXMLStreamWriter(); - int write(XMLDocumentPtr doc); + int write(XMLDocumentPtr doc, int indent = -1); private: std::ostream& outXmlStream; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.4 pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.5 --- pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXMLWriter.h" #include "commonj/sdo/SDOXMLString.h" @@ -64,7 +64,7 @@ } } - int SDOXMLWriter::write(XMLDocumentPtr doc) + int SDOXMLWriter::write(XMLDocumentPtr doc, int indent) { if (!doc) { @@ -85,8 +85,22 @@ //namespaceStack.push(namespaces); namespaceMap.empty(); - //xmlTextWriterSetIndent(writer, 1); - //xmlTextWriterSetIndentString(writer, SDOXMLString(" ")); + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;i<indent;i++)chars[i] = ' '; + chars[indent] = 0; + xmlTextWriterSetIndentString(writer, SDOXMLString(chars)); + delete chars; + } + else + { + xmlTextWriterSetIndentString(writer, SDOXMLString("")); + } + } if (doc->getXMLDeclaration()) { @@ -148,41 +162,41 @@ { try { - if (sl[j].getProperty().isMany()) + if (sl.get(j)->getProperty().isMany()) { // manys are elements continue; } - if (sl[j].getProperty().getType().isDataType()) + if (sl.get(j)->getProperty().getType().isDataType()) { // data types are OK rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } else { - DataObjectPtr dob = sl[j].getDataObjectValue(); + DataObjectPtr dob = sl.get(j)->getDataObjectValue(); if (dob) { if (cs->isDeleted(dob)) { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString(cs->getOldXpath(dob))); } else { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString(dob->objectToXPath())); } } else { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString("")); } } @@ -218,33 +232,33 @@ { // single values will have been covered by the attributes. - if (!sl[j].getProperty().isMany()) continue; + if (!sl.get(j)->getProperty().isMany()) continue; - if (sl[j].getProperty().getType().isDataType()) + if (sl.get(j)->getProperty().getType().isDataType()) { rc = xmlTextWriterWriteElement( writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } // if datatype else { - DataObjectPtr dob2 = sl[j].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(j)->getDataObjectValue(); if (!dob2) { continue; } if (cs->isDeleted(dob2)) { - handleChangeSummaryDeletedObject(sl[j].getProperty().getName(), cs,dob2); + handleChangeSummaryDeletedObject(sl.get(j)->getProperty().getName(), cs,dob2); } else { rc = xmlTextWriterStartElement( writer, - SDOXMLString(sl[j].getProperty().getName())); + SDOXMLString(sl.get(j)->getProperty().getName())); rc = xmlTextWriterWriteAttribute( writer, SDOXMLString("sdo:ref"), @@ -296,26 +310,26 @@ for (int j=0;j< sl.size(); j++) { - //if (!sl[j].isSet()) + //if (!sl.get(j)->isSet()) //{ // // unset properties dont need recording - ah but they do! // // continue; //} - if ( sl[j].getProperty().isMany()) + if ( sl.get(j)->getProperty().isMany()) { // manys are elements continue; } - if (!sl[j].getProperty().getType().isDataType()) + if (!sl.get(j)->getProperty().getType().isDataType()) { // data objects are element in a deleted data object. continue; } rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } // for attributes @@ -329,14 +343,14 @@ for (k=sl.size()-1;k>=0; k--) { - if ( !sl[k].getProperty().getType().isDataType() && - sl[k].getProperty().isMany()) + if ( !sl.get(k)->getProperty().getType().isDataType() && + sl.get(k)->getProperty().isMany()) { // its a dataobject type - DataObjectPtr dob2 = sl[k].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); if (!dob2) continue; if (!cs->isDeleted(dob2)) continue; - handleChangeSummaryDeletedObject(sl[k]. + handleChangeSummaryDeletedObject(sl.get(k)-> getProperty().getName(),cs,dob2); } } // for attributes @@ -344,27 +358,27 @@ for (k=0;k< sl.size(); k++) { - if ( !sl[k].getProperty().getType().isDataType()) + if ( !sl.get(k)->getProperty().getType().isDataType()) { - if (sl[k].getProperty().isMany()) continue; + if (sl.get(k)->getProperty().isMany()) continue; // its a single valued dataobject type - DataObjectPtr dob2 = sl[k].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); if (!dob2) continue; if (!cs->isDeleted(dob2)) continue; - handleChangeSummaryDeletedObject(sl[k]. + handleChangeSummaryDeletedObject(sl.get(k)-> getProperty().getName(),cs,dob2); } else { - if ( !sl[k].getProperty().isMany()) continue; + if ( !sl.get(k)->getProperty().isMany()) continue; // could only be many valued data type rc = xmlTextWriterWriteElement(writer, - SDOXMLString(sl[k].getProperty().getName()), - SDOXMLString(sl[k].getCStringValue())); + SDOXMLString(sl.get(k)->getProperty().getName()), + SDOXMLString(sl.get(k)->getCStringValue())); } } // for attributes } @@ -661,7 +675,13 @@ if (isRoot) { tnsURI=elementURI; - rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + if (elementURI.equals("")) { + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, NULL); + } + else + { + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + } if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); } @@ -672,7 +692,7 @@ SDOXMLString theName=elementName; - if (!elementURI.isNull() && !elementURI.equals(tnsURI)) + if (!elementURI.isNull() && !elementURI.equals(tnsURI) && !elementURI.equals("")) { std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); if (it != namespaceMap.end()) @@ -757,6 +777,7 @@ for (it = namespaceMap.begin();it != namespaceMap.end(); ++it) { + if ((*it).first.equals("")) continue; SDOXMLString space = SDOXMLString("xmlns:") + (*it).second; rc = xmlTextWriterWriteAttribute(writer, space, (*it).first); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.2 pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.3 --- pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXMLWRITER_H_ #define _SDOXMLWRITER_H_ @@ -50,7 +50,7 @@ virtual ~SDOXMLWriter(); - int write(XMLDocumentPtr doc); + int write(XMLDocumentPtr doc, int indent=-1); protected: void setWriter(xmlTextWriterPtr textWriter); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.3 pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXSDStreamWriter.h" #include <sstream> @@ -38,9 +38,9 @@ } int SDOXSDStreamWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops) + const propertyMap& openprops, int indent) { - int rc = SDOXSDBufferWriter::write(types, targetNamespaceURI, openprops); + int rc = SDOXSDBufferWriter::write(types, targetNamespaceURI, openprops, indent); // Now stream the buffer outXmlStream << getBuffer(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h diff -u pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.3 pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.4 --- pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXSDSTREAMWRITER_H_ #define _SDOXSDSTREAMWRITER_H_ @@ -43,7 +43,7 @@ virtual ~SDOXSDStreamWriter(); int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops); + const propertyMap& openprops, int indent = -1); private: std::ostream& outXmlStream; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDWriter.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.3 pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXSDWriter.h" #include "iostream" @@ -159,7 +159,7 @@ //////////////////////////////////////// int SDOXSDWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops) + const propertyMap& openprops, int indent) { int i; if (writer == NULL) @@ -170,7 +170,23 @@ int rc = 0; - + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;i<indent;i++)chars[i] = ' '; + chars[indent] = 0; + xmlTextWriterSetIndentString(writer, SDOXMLString(chars)); + delete chars; + } + else + { + xmlTextWriterSetIndentString(writer, SDOXMLString("")); + } + } + // -------------------------------------------------------------- // Write the <schema> definition including namespace information // -------------------------------------------------------------- http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDWriter.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDWriter.h diff -u pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.3 pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.4 --- pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXSDWRITER_H_ #define _SDOXSDWRITER_H_ @@ -48,7 +48,7 @@ virtual ~SDOXSDWriter(); int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops); + const propertyMap& openprops, int indent = -1); protected: void setWriter(xmlTextWriterPtr textWriter); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SchemaInfo.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SchemaInfo.h diff -u pecl/sdo/commonj/sdo/SchemaInfo.h:1.2 pecl/sdo/commonj/sdo/SchemaInfo.h:1.3 --- pecl/sdo/commonj/sdo/SchemaInfo.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SchemaInfo.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SCHEMAINFO_H_ #define _SCHEMAINFO_H_ @@ -49,7 +49,7 @@ private: SAX2Namespaces schemaNamespaces; - SDOXMLString targetNamespaceURI; + SDOXMLString targetNamespaceURI; }; } // End - namespace sdo http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/Sequence.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/Sequence.h diff -u pecl/sdo/commonj/sdo/Sequence.h:1.2 pecl/sdo/commonj/sdo/Sequence.h:1.3 --- pecl/sdo/commonj/sdo/Sequence.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/Sequence.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SEQUENCE_H_ #define _SEQUENCE_H_ @@ -67,6 +67,12 @@ SDO_API virtual const Property& getProperty(unsigned int index) = 0; /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject() = 0; + + /** * * The element of that property if it was many valued. Zero if the * property was single valued. http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SequenceImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SequenceImpl.cpp diff -u pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.3 pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SequenceImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/Property.h" @@ -55,7 +55,7 @@ SequenceImpl::SequenceImpl(DataObject* indo) { - the_do = indo; + the_do = (DataObjectImpl*)indo; } SequenceImpl::SequenceImpl(SequenceImpl* inseq) @@ -69,6 +69,16 @@ return the_list.size(); } + + /** + * Return the data object associated with this sequence + */ + + const DataObjectPtr SequenceImpl::getDataObject() + { + return the_do; + } + const Property& SequenceImpl::getProperty(unsigned int index) { SEQUENCE_ITEM_LIST::iterator i; @@ -432,11 +442,74 @@ } +#define doadder(primtype,primval)\ + bool SequenceImpl::add##primtype(const char* propertyName, primval v)\ + {\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName, v->getType());\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v)\ + {\ + return add##primtype(the_do->getProperty(propertyIndex), v);\ + }\ + bool SequenceImpl::add##primtype(const Property& p, primval v)\ + {\ + if (p.isMany())\ + {\ + DataObjectList& dol = the_do->getList(p);\ + dol.append((primval)v);\ + /* the_list.push_back(seq_item(&p,dol.size()-1));*/\ + return true;\ + }\ + SEQUENCE_ITEM_LIST::iterator i;\ + for (i=the_list.begin();i != the_list.end();++i) {\ + const Property* pp = (*i).getProp();\ + if (pp == 0) continue;\ + if (!strcmp(pp->getName(),p.getName()))\ + {\ + SDO_THROW_EXCEPTION("add", SDOUnsupportedOperationException,\ + "Sequence::add of property which already exists in sequence");\ + }\ + }\ + the_do->set##primtype(p,v);\ + the_list.push_back(seq_item(&p,0));\ + return true;\ + } + #define adder(primtype,primval)\ bool SequenceImpl::add##primtype(const char* propertyName, primval v)\ {\ - return add##primtype(the_do->getProperty(propertyName),v);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v);\ }\ bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v)\ {\ @@ -476,13 +549,28 @@ adder(Float, float); adder(Double, long double); adder(Date, const SDODate); -adder(DataObject, RefCountingPointer<DataObject>); +doadder(DataObject, RefCountingPointer<DataObject>); #define charAdder(primtype,primval)\ bool SequenceImpl::add##primtype(const char* propertyName, primval v, unsigned int len)\ {\ - return add##primtype(the_do->getProperty(propertyName),v, len);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v, len);\ }\ bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v, unsigned int len)\ {\ @@ -517,11 +605,87 @@ charAdder ( Bytes , const char* ); - #define inserter(primtype,primval)\ bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v)\ {\ - return add##primtype(index,the_do->getProperty(propertyName),v);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v)\ + {\ + return add##primtype(index,the_do->getProperty(propertyIndex), v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int index, const Property& p, primval v)\ + {\ + SEQUENCE_ITEM_LIST::iterator i;\ + SEQUENCE_ITEM_LIST::iterator i2 = the_list.end();\ + int j;\ + if (index >= the_list.size()) {\ + return add##primtype(p,v);\ + }\ + if (p.isMany())\ + {\ + DataObjectList& dol = the_do->getList(p);\ + dol.append((primval)v);\ + j = 0;\ + for (i=the_list.begin();(j < index) && (i != the_list.end());++i) {\ + j++;\ + }\ + /*the_list.insert(i,seq_item(&p,dol.size()-1));*/\ + return true;\ + }\ + j = 0;\ + for (i=the_list.begin();i != the_list.end();++i) {\ + const Property* pp = (*i).getProp();\ + if (pp == 0) continue;\ + if (!strcmp(pp->getName(),p.getName()))\ + {\ + SDO_THROW_EXCEPTION("Insert", SDOUnsupportedOperationException,\ + "Sequence::insert of property which already exists in sequence");\ + }\ + if (j == index) {\ + i2 = i;\ + }\ + j++;\ + }\ + the_do->set##primtype(p,v);\ + the_list.insert(i2,seq_item(&p,0));\ + return true;\ + } + +#define doinserter(primtype,primval)\ + bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v)\ + {\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName, v->getType());\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v);\ }\ bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v)\ {\ @@ -575,14 +739,29 @@ inserter(Float, float); inserter(Double, long double); inserter(Date, const SDODate); -inserter(DataObject, RefCountingPointer<DataObject>); +doinserter(DataObject, RefCountingPointer<DataObject>); #define charInserter(primtype,primval)\ bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v, unsigned int len)\ {\ - return add##primtype(index,the_do->getProperty(propertyName),v, len);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v, len);\ }\ bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v, unsigned int len)\ {\ http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SequenceImpl.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SequenceImpl.h diff -u pecl/sdo/commonj/sdo/SequenceImpl.h:1.2 pecl/sdo/commonj/sdo/SequenceImpl.h:1.3 --- pecl/sdo/commonj/sdo/SequenceImpl.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SequenceImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SEQUENCEIMPL_H_ #define _SEQUENCEIMPL_H_ @@ -34,7 +34,7 @@ namespace sdo{ class Property; /* forward declaration */ -class DataObject; +class DataObjectImpl; /** SequenceImpl implements the abstract class Sequence. * @@ -57,6 +57,12 @@ /////////////////////////////////////////////////////////////////////////// virtual const Property& getProperty(unsigned int index); + /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject(); + /////////////////////////////////////////////////////////////////////////// // Returns the property for the given entry index. /////////////////////////////////////////////////////////////////////////// @@ -294,7 +300,7 @@ SequenceImpl(); - DataObject* the_do; + DataObjectImpl* the_do; class seq_item { public: http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SettingList.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SettingList.cpp diff -u pecl/sdo/commonj/sdo/SettingList.cpp:1.2 pecl/sdo/commonj/sdo/SettingList.cpp:1.3 --- pecl/sdo/commonj/sdo/SettingList.cpp:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SettingList.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDORuntimeException.h" @@ -27,9 +27,9 @@ namespace sdo { -SettingList::SettingList(SETTING_VECTOR p) : slist (p) -{ -} +//SettingList::SettingList(SETTING_VECTOR p) : slist (p) +//{ +//} /*SettingList::SettingList(const SettingList &pin) { @@ -44,13 +44,26 @@ SettingList::~SettingList() { + while (slist.size() > 0) + { + Setting* s = slist[0]; + slist.erase(slist.begin()); + delete s; + } + } Setting& SettingList::operator[] (int pos) const { validateIndex(pos); - return (Setting&)slist[pos]; + return (*slist[pos]); +} + +Setting* SettingList::get(int pos) +{ + validateIndex(pos); + return (slist[pos]); } int SettingList::size () const @@ -58,17 +71,17 @@ return slist.size(); } -SETTING_VECTOR SettingList::getVec() const -{ - return slist; -} +//SETTING_VECTOR SettingList::getVec() const +//{ +// return slist; +//} -void SettingList::insert (unsigned int index, const Setting& d) +void SettingList::insert (unsigned int index, Setting* d) { slist.insert(slist.begin()+index, d); } -void SettingList::append (const Setting& d) +void SettingList::append ( Setting* d) { slist.insert(slist.end(),d); } @@ -76,7 +89,9 @@ void SettingList::remove(unsigned int index) { validateIndex(index); + const Setting* s = slist[index]; slist.erase(slist.begin()+index); + delete s; return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SettingList.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SettingList.h diff -u pecl/sdo/commonj/sdo/SettingList.h:1.2 pecl/sdo/commonj/sdo/SettingList.h:1.3 --- pecl/sdo/commonj/sdo/SettingList.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SettingList.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef SETTINGLIST_H #define SETTINGLIST_H @@ -28,7 +28,7 @@ namespace commonj{ namespace sdo{ -typedef std::vector<Setting> SETTING_VECTOR; +typedef std::vector< Setting*> SETTING_VECTOR; /** SettingList is a list of settings returned by a change summary */ @@ -37,7 +37,7 @@ { public: - SettingList(SETTING_VECTOR sl); + //SettingList(SETTING_VECTOR sl); SettingList(); virtual ~SettingList(); @@ -47,7 +47,7 @@ * This gives access to elements of the list */ - virtual Setting& operator[] (int pos) const; + SDO_API virtual Setting& operator[] (int pos) const; /** size() returns the number of settings * @@ -55,16 +55,16 @@ * These may be creations, deletions or changes. */ - virtual int size () const; + SDO_API virtual int size () const; - virtual void insert (unsigned int index, const Setting& d); - virtual void append (const Setting& d); + virtual void insert (unsigned int index, Setting* d); + virtual void append ( Setting* d); virtual void remove (unsigned int index); + virtual Setting* get (int pos); private: SETTING_VECTOR slist; - SETTING_VECTOR getVec() const; void validateIndex(int index) const; }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/Type.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/Type.h diff -u pecl/sdo/commonj/sdo/Type.h:1.3 pecl/sdo/commonj/sdo/Type.h:1.4 --- pecl/sdo/commonj/sdo/Type.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/Type.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDO_TYPE_H_ #define _SDO_TYPE_H_ @@ -73,6 +73,7 @@ DataObjectType, ChangeSummaryType, TextType, + UndefinedOpenPropertyType, num_types }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelper.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelper.h diff -u pecl/sdo/commonj/sdo/XMLHelper.h:1.3 pecl/sdo/commonj/sdo/XMLHelper.h:1.4 --- pecl/sdo/commonj/sdo/XMLHelper.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelper.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _XMLHELPER_H_ #define _XMLHELPER_H_ @@ -45,7 +45,11 @@ * Returns a pointer to the root data object */ - SDO_API virtual XMLDocumentPtr loadFile( + SDO_API virtual XMLDocumentPtr createDocument( + const char* elementname = 0, + const char* rootElementURI=0) = 0; + + SDO_API virtual XMLDocumentPtr loadFile( const char* xmlFile, const char* targetNamespaceURI=0) = 0; SDO_API virtual XMLDocumentPtr load( @@ -60,12 +64,14 @@ * save - Serializes the datagraph to the XML file */ - SDO_API virtual void save(XMLDocumentPtr doc, const char* xmlFile) = 0; + SDO_API virtual void save(XMLDocumentPtr doc, const char* xmlFile, + int indent = -1) = 0; SDO_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) = 0; + const char* xmlFile, + int indent = -1) = 0; /** save saves the graph to XML @@ -73,23 +79,26 @@ * save - Serializes the datagraph to the XML stream */ - SDO_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml) = 0; + SDO_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1) = 0; SDO_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) = 0; + std::ostream& outXml, + int indent = -1) = 0; /** save saves the graph to XML * * save - Serializes the datagraph to a string */ - SDO_API virtual char* save(XMLDocumentPtr doc) = 0; + SDO_API virtual char* save(XMLDocumentPtr doc, int indent = -1) = 0; SDO_API virtual char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) = 0; + const char* rootElementName, + int indent = -1) = 0; /** createDocument creates an XMLDocument * http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelperImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelperImpl.cpp diff -u pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.3 pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelperImpl.cpp Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! #include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! @@ -93,6 +93,76 @@ return new XMLDocumentImpl(dataObject, rootElementURI, rootElementName); } + + XMLDocumentPtr XMLHelperImpl::createDocument(const char* elementname, + const char* rootElementURI) + { + DataFactory* dp = (DataFactory*)getDataFactory(); + if (dp != 0) + { + const TypeImpl* rType = NULL; + if (rootElementURI != 0) + { + rType = ((DataFactoryImpl*)dp)->findTypeImpl + (rootElementURI, "RootType"); + } + else + { + const TypeList& tl = dp->getTypes(); + for (int i=0;i<tl.size();i++) + { + if (!strcmp("RootType",tl[i].getName())) + { + rType = ((DataFactoryImpl*)dp)->findTypeImpl + (tl[i].getURI(), "RootType"); + break; + } + } + } + if (rType) + { + if (elementname && strlen(elementname) != 0) + { + PropertyImpl* pl = rType->getPropertyImpl(elementname); + if (pl != 0) + { + const Type& tp = pl->getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), /*tp.getName()*/ elementname); + } + else + { + string msg("createDocument - cannot find element "); + msg += elementname; + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + } + else + { + const Property& pl = rType->getProperty((unsigned int)0); + const Type& tp = pl.getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), /*tp.getName()*/ pl.getName()); + } + } + else + { + string msg("createDocument - unable to find root type in namespace "); + if (rootElementURI != 0) + msg += rootElementURI; + else + msg += " NULL"; + + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + } + return 0; + } + XMLDocumentPtr XMLHelperImpl::createDocument( DataObjectPtr dataObject, const char* rootElementURI, @@ -137,42 +207,47 @@ return load(str, targetNamespaceURI); } - void XMLHelperImpl::save(XMLDocumentPtr doc, const char* xmlFile) + void XMLHelperImpl::save(XMLDocumentPtr doc, const char* xmlFile, int indent) { SDOXMLFileWriter writer(xmlFile, dataFactory); - writer.write(doc); + writer.write(doc, indent); } void XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) + const char* xmlFile, + int indent) { - save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile); + save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile, + indent); } // Serializes the datagraph to a stream - void XMLHelperImpl::save(XMLDocumentPtr doc, std::ostream& outXml) + void XMLHelperImpl::save(XMLDocumentPtr doc, std::ostream& outXml, + int indent) { SDOXMLStreamWriter writer(outXml, dataFactory); - writer.write(doc); + writer.write(doc, indent); } void XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) + std::ostream& outXml, + int indent ) { - save(createDocument(dataObject,rootElementURI, rootElementName), outXml); + save(createDocument(dataObject,rootElementURI, rootElementName), outXml, indent); } // Serializes the datagraph to a string - char* XMLHelperImpl::save(XMLDocumentPtr doc) + char* XMLHelperImpl::save(XMLDocumentPtr doc, + int indent) { SDOXMLBufferWriter writer(dataFactory); - writer.write(doc); + writer.write(doc, indent); SDOXMLString ret = writer.getBuffer(); char* retString = new char[strlen(ret) +1]; strcpy(retString, ret); @@ -181,9 +256,11 @@ char* XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) + const char* rootElementName, + int indent) { - return save(createDocument(dataObject,rootElementURI, rootElementName)); + return save(createDocument(dataObject,rootElementURI, rootElementName), + indent); } int XMLHelperImpl::getErrorCount() const http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelperImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelperImpl.h diff -u pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.3 pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.4 --- pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelperImpl.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XMLHELPERIMPL_H_ #define _XMLHELPERIMPL_H_ @@ -63,7 +63,11 @@ * Returns a pointer to the root data object */ - virtual XMLDocumentPtr loadFile( + virtual XMLDocumentPtr createDocument( + const char* elementname= 0, + const char* rootElementURI=0); + + virtual XMLDocumentPtr loadFile( const char* xmlFile, const char* targetNamespaceURI = 0); virtual XMLDocumentPtr load( @@ -83,34 +87,37 @@ * save - Serializes the datagraph to the XML file */ - void save(XMLDocumentPtr doc, const char* xmlFile); + void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile); + const char* xmlFile, int indent = -1); /** save saves the graph to XML * * save - Serializes the datagraph to a stream */ - void save(XMLDocumentPtr doc, std::ostream& outXml); + void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml); + std::ostream& outXml, + int indent = -1); /** save saves the graph to XML * * save - Serializes the datagraph to a string */ - char* save(XMLDocumentPtr doc); + char* save(XMLDocumentPtr doc,int indent = -1); char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName); + const char* rootElementName, + int indent = -1); private: int parse(const char* source); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelper.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelper.h diff -u pecl/sdo/commonj/sdo/XSDHelper.h:1.3 pecl/sdo/commonj/sdo/XSDHelper.h:1.4 --- pecl/sdo/commonj/sdo/XSDHelper.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelper.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XSDHELPER_H_ #define _XSDHELPER_H_ @@ -65,15 +65,18 @@ SDO_API virtual char* generate( const TypeList& types, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; SDO_API virtual void generate( const TypeList& types, std::ostream& outXsd, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; SDO_API virtual void generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; /***********************************/ /* Destructor */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelperImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelperImpl.cpp diff -u pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.3 pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelperImpl.cpp Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! #include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! @@ -521,36 +521,39 @@ void XSDHelperImpl::generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDFileWriter writer(fileName); DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); } void XSDHelperImpl::generate( const TypeList& types, std::ostream& outXml, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDStreamWriter writer(outXml); DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); } char* XSDHelperImpl::generate( const TypeList& types, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDBufferWriter writer; DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); SDOXMLString ret = writer.getBuffer(); char* retString = new char[strlen(ret) +1]; strcpy(retString, ret); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelperImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelperImpl.h diff -u pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.3 pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.4 --- pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelperImpl.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XSDHELPERIMPL_H_ #define _XSDHELPERIMPL_H_ @@ -94,17 +94,20 @@ virtual char* generate( const TypeList& types, - const char* targetNamespaceURI = "" + const char* targetNamespaceURI = "", + int indent = -1 ); void generate( const TypeList& types, std::ostream& outXsd, - const char* targetNamespaceURI = "" + const char* targetNamespaceURI = "", + int indent = -1 ); virtual void generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI = ""); + const char* targetNamespaceURI = "", + int indent = -1); virtual DataFactoryPtr getDataFactory(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDAS.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDAS.h diff -u pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDAS.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: XMLDAS.h,v 1.2 2006/01/17 09:41:34 cem Exp $ */ +/* $Id: XMLDAS.h,v 1.3 2006/02/20 18:50:26 mfp Exp $ */ #ifndef _XMLDAS_H_ #define _XMLDAS_H_ @@ -92,35 +92,35 @@ /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to the XML file /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual void save(DataGraphPtr doc, const char* xmlFile) = 0; - XMLDAS_API virtual void save(XMLDocumentPtr doc, const char* xmlFile) = 0; + XMLDAS_API virtual void save(DataGraphPtr doc, const char* xmlFile, int indent = -1) = 0; + XMLDAS_API virtual void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1) = 0; XMLDAS_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) = 0; + const char* xmlFile, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to a stream /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual void save(DataGraphPtr doc, std::ostream& outXml) = 0; - XMLDAS_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml) = 0; + XMLDAS_API virtual void save(DataGraphPtr doc, std::ostream& outXml, int indent = -1) = 0; + XMLDAS_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml, int indent = -1) = 0; XMLDAS_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) = 0; + std::ostream& outXml, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to a string /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual char* save(DataGraphPtr doc) = 0; - XMLDAS_API virtual char* save(XMLDocumentPtr doc) = 0; + XMLDAS_API virtual char* save(DataGraphPtr doc, int indent = -1) = 0; + XMLDAS_API virtual char* save(XMLDocumentPtr doc, int indent = -1) = 0; XMLDAS_API virtual char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) = 0; + const char* rootElementName, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // createDocument http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp diff -u pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp Mon Feb 20 18:50:26 2006 @@ -205,78 +205,78 @@ return load(str); } - void XMLDASImpl::save(DataGraphPtr doc, const char* xmlFile) + void XMLDASImpl::save(DataGraphPtr doc, const char* xmlFile, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - xmlHelper->save(xd, 0,0, xmlFile); + xmlHelper->save(xd, 0,0, xmlFile, indent); // end the tag } - void XMLDASImpl::save(XMLDocumentPtr doc, const char* xmlFile) + void XMLDASImpl::save(XMLDocumentPtr doc, const char* xmlFile, int indent) { - xmlHelper->save(doc, xmlFile); + xmlHelper->save(doc, xmlFile, indent); } void XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) + const char* xmlFile, int indent) { - xmlHelper->save(dataObject,rootElementURI, rootElementName, xmlFile); + xmlHelper->save(dataObject,rootElementURI, rootElementName, xmlFile, indent); } // Serializes the datagraph to a stream - void XMLDASImpl::save(DataGraphPtr doc, ostream& outXml) + void XMLDASImpl::save(DataGraphPtr doc, ostream& outXml, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - xmlHelper->save(xd, 0,0,outXml); + xmlHelper->save(xd, 0,0,outXml, indent); // end the tag } - void XMLDASImpl::save(XMLDocumentPtr doc, ostream& outXml) + void XMLDASImpl::save(XMLDocumentPtr doc, ostream& outXml, int indent) { - xmlHelper->save(doc, outXml); + xmlHelper->save(doc, outXml, indent); } void XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) + std::ostream& outXml, int indent) { - xmlHelper->save(dataObject, rootElementURI, rootElementName, outXml); + xmlHelper->save(dataObject, rootElementURI, rootElementName, outXml, indent); } // Serializes the datagraph to a string - char* XMLDASImpl::save(DataGraphPtr doc) + char* XMLDASImpl::save(DataGraphPtr doc, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - return xmlHelper->save(xd,0,0); + return xmlHelper->save(xd,0,0, indent); // end the tag } - char* XMLDASImpl::save(XMLDocumentPtr doc) + char* XMLDASImpl::save(XMLDocumentPtr doc, int indent) { - return xmlHelper->save(doc); + return xmlHelper->save(doc, indent); } char* XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) + const char* rootElementName, int indent) { - return xmlHelper->save(dataObject, rootElementURI, rootElementName); + return xmlHelper->save(dataObject, rootElementURI, rootElementName, indent); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h diff -u pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h Mon Feb 20 18:50:26 2006 @@ -86,30 +86,30 @@ // save // Serializes the datagraph to the XML file - void save(DataGraphPtr doc, const char* xmlFile); - void save(XMLDocumentPtr doc, const char* xmlFile); + void save(DataGraphPtr doc, const char* xmlFile, int indent = -1); + void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile); + const char* xmlFile, int indent = -1); // Serializes the datagraph to a stream - void save(DataGraphPtr doc, std::ostream& outXml); - void save(XMLDocumentPtr doc, std::ostream& outXml); + void save(DataGraphPtr doc, std::ostream& outXml, int indent = -1); + void save(XMLDocumentPtr doc, std::ostream& outXml, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml); + std::ostream& outXml, int indent = -1); // Serializes the datagraph to a string - char* save(DataGraphPtr doc); - char* save(XMLDocumentPtr doc); + char* save(DataGraphPtr doc, int indent = -1); + char* save(XMLDocumentPtr doc, int indent = -1); char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName); + const char* rootElementName, int indent = -1); // getDataFactory http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/test.inc?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/test.inc diff -u /dev/null pecl/sdo/tests/test.inc:1.4 --- /dev/null Mon Feb 20 18:50:27 2006 +++ pecl/sdo/tests/test.inc Mon Feb 20 18:50:26 2006 @@ -0,0 +1,54 @@ +<?php +/* create a DataFactory */ +$dmsDf = SDO_DAS_DataFactory :: getDataFactory(); + +define('ROOT_NS', 'phpt'); +define('COMPANY_NS', 'companyNS'); +define('ROOT_TYPE', 'RootType'); +define('COMPANY_TYPE', 'CompanyType'); +define('DEPARTMENT_TYPE', 'DepartmentType'); +define('EMPLOYEE_TYPE', 'EmployeeType'); + +// Create the types +$dmsDf->addType(ROOT_NS, ROOT_TYPE); +$dmsDf->addType(COMPANY_NS, COMPANY_TYPE); +$dmsDf->addType(COMPANY_NS, DEPARTMENT_TYPE); +$dmsDf->addType(COMPANY_NS, EMPLOYEE_TYPE); + +// add properties to the root type +$dmsDf->addPropertyToType(ROOT_NS, ROOT_TYPE, 'company', COMPANY_NS, COMPANY_TYPE); + +// add properties to the company type +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'departments', COMPANY_NS, DEPARTMENT_TYPE, array('many'=>true)); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'employeeOfTheMonth', COMPANY_NS, EMPLOYEE_TYPE, array('containment'=>false)); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'CEO', COMPANY_NS, EMPLOYEE_TYPE); + +// add properties to the department type +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'location', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'number', SDO_TYPE_NAMESPACE_URI, 'Integer'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'employees', COMPANY_NS, EMPLOYEE_TYPE, array('many'=>true)); + +// add properties to employee type +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'SN', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'manager', SDO_TYPE_NAMESPACE_URI, 'Boolean'); + +// Test creation of a data object +$company = $dmsDf->create(COMPANY_NS, COMPANY_TYPE); +$company->name = 'MegaCorp'; + +// Test creation of a child data object +$department = $company->createDataObject('departments'); +$department->name = 'Shoe'; + +// Test creation of a child data object +$employee = $department->createDataObject('employees'); +$employee->name = "Sarah Jones"; +$company->employeeOfTheMonth = $employee; + +// Test use of non-containment reference +$ceo = $company->createDataObject('CEO'); +$ceo->name = "Fred Smith"; +?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/001.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/001.phpt diff -u pecl/sdo/tests/001.phpt:1.1 pecl/sdo/tests/001.phpt:1.2 --- pecl/sdo/tests/001.phpt:1.1 Mon Jul 18 16:16:43 2005 +++ pecl/sdo/tests/001.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- Check for sdo presence +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/002.phpt?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/tests/002.phpt diff -u pecl/sdo/tests/002.phpt:1.2 pecl/sdo/tests/002.phpt:1.3 --- pecl/sdo/tests/002.phpt:1.2 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/002.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO getType test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- @@ -12,4 +14,4 @@ ?> --EXPECT-- -companyNS:CompanyType \ No newline at end of file +companyNS:CompanyType http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/003.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/003.phpt diff -u pecl/sdo/tests/003.phpt:1.1 pecl/sdo/tests/003.phpt:1.2 --- pecl/sdo/tests/003.phpt:1.1 Mon Jul 18 16:16:43 2005 +++ pecl/sdo/tests/003.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO var_dump test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- @@ -39,4 +41,4 @@ ["name"]=> string(10) "Fred Smith" } -} \ No newline at end of file +} http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/004.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/004.phpt diff -u pecl/sdo/tests/004.phpt:1.1 pecl/sdo/tests/004.phpt:1.2 --- pecl/sdo/tests/004.phpt:1.1 Mon Aug 8 15:08:54 2005 +++ pecl/sdo/tests/004.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- Check for sdo_das_xml presence +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo_das_xml")) print "skip"; ?> --FILE-- http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/005.phpt?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/005.phpt diff -u pecl/sdo/tests/005.phpt:1.3 pecl/sdo/tests/005.phpt:1.4 --- pecl/sdo/tests/005.phpt:1.3 Wed Oct 5 09:56:14 2005 +++ pecl/sdo/tests/005.phpt Mon Feb 20 18:50:26 2006 @@ -1,12 +1,14 @@ --TEST-- SDO_DAS_XML load test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- <?php $dirname = dirname($_SERVER['SCRIPT_FILENAME']); $xmldas = SDO_DAS_XML::create("${dirname}/company.xsd"); - $xdoc = $xmldas->loadFromFile("${dirname}/company.xml"); + $xdoc = $xmldas->loadFile("${dirname}/company.xml"); $do = $xdoc->getRootDataObject(); print_r($do); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/006.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/006.phpt diff -u pecl/sdo/tests/006.phpt:1.1 pecl/sdo/tests/006.phpt:1.2 --- pecl/sdo/tests/006.phpt:1.1 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/tests/006.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO reflection test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo") || phpversion('sdo') < '0.7.1') print "skip"; ?> @@ -34,4 +36,4 @@ commonj.sdo:Boolean $manager; } } -} \ No newline at end of file +} http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/SDOAPITest.php?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/tests/SDOAPITest.php diff -u pecl/sdo/tests/SDOAPITest.php:1.7 pecl/sdo/tests/SDOAPITest.php:1.8 --- pecl/sdo/tests/SDOAPITest.php:1.7 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/tests/SDOAPITest.php Mon Feb 20 18:50:26 2006 @@ -168,6 +168,10 @@ public function testDataObject() { $this->company = $this->dmsDf->create(COMPANY_NS, COMPANY_TYPE); + // check the type + $this->assertEquals(COMPANY_TYPE, $this->company->getTypeName(), 'getTypeName() failed.'); + $this->assertEquals(COMPANY_NS, $this->company->getTypeNamespaceURI(), 'getTypeNamespaceURI() failed.'); + // Test array operator and setting a property $this->company[0] = 'Acme'; $this->assertEquals('Acme', $this->company[0], 'Property set/get through [] failed.'); @@ -565,7 +569,6 @@ $this->assertEquals(SDO_DAS_ChangeSummary::NONE, $ct, 'Change type set but no changes have been made.'); // make some changes - $oldSN = $simon->SN; $simon->SN = '061130'; $david = $department->createDataObject('employees'); @@ -1156,21 +1159,15 @@ $all_props = $do_type->getProperties(); $this->assertEquals(count($all_props), count($this->company), 'Different number of properties in reflected data object'); - - $iters = 0; - foreach ($all_props as $do_property) { - $do = $this->company[$do_property->name]; - $iters ++; - } - $this->assertEquals(count($all_props), $iters, - 'SDO_Model_ReflectionDataObject iteration test failed - incorrect number of interations.'); - $this->assertTrue($iters > 0, - 'SDO_Model_ReflectionDataObject iteration test failed - zero iterations performed.'); /* Create a dataobject using a SDO_Model_Property */ $department_property = $do_type->getProperty('departments'); $department2 = $this->company->createDataObject($department_property); $department2->name = 'IT'; + $this->assertEquals($department_property->getType()->getName(), $department2->getTypeName(), + 'type name is different from reflected type name'); + $this->assertEquals($department_property->getType()->getNamespaceURI(), $department2->getTypeNamespaceURI(), + 'type namespace URI is different from reflected type namespace URI'); $this->assertEquals($department2->getContainer(), $this->company, 'getContainer() test failed for object created using reflected property'); } @@ -1261,24 +1258,24 @@ /* first add an existing property */ $seq->insert('Sequence name=>'); $seq->insert('OpenSeqName', NULL, 'name'); - $this->assertEquals($open->name, 'OpenSeqName', 'sequence and property access not equal;'); + $this->assertEquals('OpenSeqName', $open->name, 'sequence and property access not equal;'); // FAILED: can't yet set open type through sequence interface // /* now add an unknown property to the open type */ // $seq->insert(' stringA=>'); // $seq->insert('StringValue', NULL, 'stringA'); -// $this->assertEquals($open->stringA, 'StringValue', 'sequence and property access for open type not equal;'); +// $this->assertEquals('StringValue', $open->stringA, 'sequence and property access for open type not equal;'); // // $seq->insert(' numberA=>'); // $seq->insert(42, NULL, 'numberA'); -// $this->assertEquals($open->numberA, 42, 'sequence and property access for open type not equal;'); +// $this->assertEquals(42, $open->numberA, 'sequence and property access for open type not equal;'); // // /* add an unknown data object property */ $employee = $this->dmsDf->create(COMPANY_NS, EMPLOYEE_TYPE); // $seq->insert($employee, NULL, 'object'); // $index = $seq->count() - 1; $employee->name = 'Alien'; -// $this->assertEquals($seq[$index]->name, 'Alien', 'sequence and property access for open type not equal;'); +// $this->assertEquals('Alien', $seq[$index]->name, 'sequence and property access for open type not equal;'); /* bypass the above problem by pre-initializing the open types through the DataObject interface. * Then we can test setting them through the sequence @@ -1289,15 +1286,60 @@ $seq->insert(' numberB=>'); $seq->insert(42, NULL, 'numberB'); - $this->assertEquals($open->numberB, 42, 'sequence and property access for open type not equal;'); + $this->assertEquals(42, $open->numberB, 'sequence and property access for open type not equal;'); $seq->insert(' stringB=>'); $seq->insert('StringValue', NULL, 'stringB'); - $this->assertEquals($open->stringB, 'StringValue', 'sequence and property access for open type not equal;'); + $this->assertEquals('StringValue', $open->stringB, 'sequence and property access for open type not equal;'); $seq->insert(' object=>'); $seq->insert($employee, NULL, 'object'); - $this->assertEquals($open->object->name, 'Alien', 'sequence and property access for open type not equal;'); + $this->assertEquals('Alien', $open->object->name, 'sequence and property access for open type not equal;'); + } + + public function testDerivedType() { + $this->dmsDf->addType(COMPANY_NS, 'DerivedStringType', array('basetype'=>array(SDO_TYPE_NAMESPACE_URI, 'String'))); + $this->dmsDf->addType(COMPANY_NS, 'BaseObjectType', array('abstract'=>true)); + $this->dmsDf->addType(COMPANY_NS, 'DerivedObjectType', array('basetype'=>array(COMPANY_NS, 'BaseObjectType'))); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedString', COMPANY_NS, 'DerivedStringType'); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedObject', COMPANY_NS, 'DerivedObjectType'); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'abstractObject', COMPANY_NS, 'BaseObjectType'); + + $company = $this->dmsDf->create(COMPANY_NS, COMPANY_TYPE); + $company->name = "ACME Corp"; + $company->derivedString = 'Special string'; + + $do = $this->dmsDf->create(COMPANY_NS, 'DerivedObjectType'); + try { + $this->dmsDf->create(COMPANY_NS, 'BaseObjectType'); + $this->assertTrue(false, 'Succeeded in instantiating an abstract type.'); + } catch (SDO_UnsupportedOperationException $e) { + } catch (SDO_Exception $e) { + $this->assertTrue(false, 'Incorrect exception thrown from creating an object of an abstract type:'.$e->getMessage()); + } + + /* It's OK to assign an object of a derived type to a property of an abstract type */ + $company->abstractObject = $do; + + $rcompany = new SDO_Model_ReflectionDataObject($company); + $special_type = $rcompany->getType()->getProperty('derivedString')->getType(); + $base_type = $special_type->getBaseType(); + $this->assertEquals(SDO_TYPE_NAMESPACE_URI, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type'); + $this->assertEquals('String', $base_type->getName(), 'incorrect name for base type'); + $this->assertTrue($base_type->isDataType(), 'incorrect data type for base type'); + + $rdo = new SDO_Model_ReflectionDataObject($do); + $derived_type = $rdo->getType(); + $this->assertFalse($derived_type->isAbstractType(), 'non-abstract type passes isAbstractType()'); + $this->assertTrue($derived_type->isInstance($do), 'object of derived type fails DerivedType::isInstance()'); + + $base_type = $derived_type->getBaseType(); + $this->assertEquals(COMPANY_NS, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type'); + $this->assertEquals('BaseObjectType', $base_type->getName(), 'incorrect name for base type'); + $this->assertFalse($base_type->isDataType(), 'incorrect data type for base type'); + $this->assertTrue($base_type->isAbstractType(), 'abstract type fails isAbstractType()'); + $this->assertTrue($base_type->isInstance($do), 'object of derived type fails BaseType::isInstance()'); + } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example1.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example1.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example1.php Mon Feb 20 18:50:26 2006 @@ -1,12 +1,15 @@ <?php +/** + * Load, update, and save an XML document + */ try { $xmldas = SDO_DAS_XML::create("letter.xsd"); - $xdoc = $xmldas->loadFromFile("letter.xml"); - $do = $xdoc->getRootDataObject(); - $do->date = "September 03, 2004"; - $do->firstName = "Anantoju"; - $do->lastName = "Madhu"; - $xmldas->saveDocumentToFile($xdoc, "letter-out.xml"); + $document = $xmldas->loadFile("letter.xml"); + $root_data_object = $document->getRootDataObject(); + $root_data_object->date = "September 03, 2004"; + $root_data_object->firstName = "Anantoju"; + $root_data_object->lastName = "Madhu"; + $xmldas->saveFile($document, "letter-out.xml"); echo "New file has been written:\n"; print file_get_contents("letter-out.xml"); } catch (SDO_Exception $e) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example2.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example2.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example2.php Mon Feb 20 18:50:26 2006 @@ -1,32 +1,28 @@ <?php +/** + * Create an XML document from scratch + */ try { $xmldas = SDO_DAS_XML::create("letter.xsd"); try { - $do = $xmldas->createDataObject("http://letterSchema", "FormLetter"); - $seq = $do->getSequence(); + $doc = $xmldas->createDocument(); + $rdo = $doc->getRootDataObject(); + $seq = $rdo->getSequence(); $seq->insert("April 09, 2005", NULL, 'date'); $seq->insert("Acme Inc. ", NULL, NULL); $seq->insert("United Kingdom. "); $seq->insert("Dear", NULL, NULL); $seq->insert("Tarun", NULL, "firstName"); $seq->insert("Nayaraaa", NULL, "lastName"); - $do->lastName = "Nayar"; + $rdo->lastName = "Nayar"; $seq->insert("Please note that your order number "); $seq->insert(12345); $seq->insert(" has been dispatched today. Thanks for your business with us."); - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - // this has previously been shown with the Type as the third argument . - // This generates XML with a root element name of FormLetter. - // This works and will reload but is probably not what is wanted. - // This should instead be the root element name 'letter' - print($xmldas->saveDataObjectToString($do, $type->getNamespaceURI(), 'letter')); + print($xmldas->saveString($doc)); } catch (SDO_Exception $e) { print($e); } -} catch (SDO_TypeNotFoundException $e) { - print("Type is not defined in the xsd file"); -} catch (SDO_DAS_XML_ParserException $e) { - print("Problem while parsing"); +} catch (SDO_Exception $e) { + print("Problem creating an XML document: " . $e->getMessage()); } ?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example3.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example3.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example3.php Mon Feb 20 18:50:26 2006 @@ -1,14 +1,10 @@ <?php -try { +/** + * Illustrate the calls that control the XML declaration + */ $xmldas = SDO_DAS_XML::create("letter.xsd"); - $xdoc = $xmldas->loadFromFile("letter.xml"); - print("Encoding is set to : " . $xdoc->getEncoding() . "\n"); - print("XML Version : " . $xdoc->getXMLVersion() . "\n"); - $xdoc->setXMLVersion("1.1"); - print($xmldas->saveDocumentToString($xdoc)); -} catch (SDO_TypeNotFoundException $e) { - print("Type is not defined in the xsd file"); -} catch (SDO_DAS_XML_ParserException $e) { - print("Problem while parsing"); -} + $document = $xmldas->loadFile("letter.xml"); + $document->setXMLVersion("1.1"); + $document->setEncoding("ISO-8859-1"); + print($xmldas->saveString($document)); ?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php diff -u pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.3 pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.4 --- pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.3 Tue Jan 24 14:10:39 2006 +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php Mon Feb 20 18:50:26 2006 @@ -94,7 +94,7 @@ $this->assertFalse($XMLDASTest_error_handler_called, 'Error handler should not have been called for create(). Message was ' . $XMLDASTest_error_handler_msg); } - public function testaddTypes() { + public function testaddTypesAndOpenTypes() { global $XMLDASTest_error_handler_called; global $XMLDASTest_error_handler_severity; global $XMLDASTest_error_handler_msg; @@ -104,23 +104,25 @@ $exception_thrown = false; try { $xmldas = SDO_DAS_XML::create(); - $xmldas->addTypes("menagerie.xsd"); // this is an open type i.e. the xsd specifies it can contain "any" type - $xmldas->addTypes('animalTypes.xsd'); - $xdoc = $xmldas->loadFromFile("menagerie.xml"); - $do = $xdoc->getRootDataObject(); - // check the types were loaded OK - $giraffe = $xmldas->createDataObject('','giraffeType'); - $giraffe->name = "Victor"; - $giraffe->height = 21; - $hippo = $xmldas->createDataObject('','hippoType'); - $hippo->name = "Henry"; - $hippo->weight = 1000; - $snake = $xmldas->createDataObject('','snakeType'); - $snake->name = "Kaa"; - $snake->length = 25; - $do->giraffe = $giraffe; - $do->hippo = $hippo; - $do->snake = $snake; + $xmldas->addTypes('anyElement/jungle.xsd'); // this is an open type i.e. the xsd specifies it can contain "any" type + $xmldas->addTypes('anyElement/animalTypes.xsd'); + $baloo = $xmldas->createDataObject('','bearType'); + $baloo->name = "Baloo"; + $baloo->weight = 800; + + $bagheera = $xmldas->createDataObject('','pantherType'); + $bagheera->name = "Bagheera"; + $bagheera->colour = 'inky black'; + + $kaa = $xmldas->createDataObject('','snakeType'); + $kaa->name = "Kaa"; + $kaa->length = 25; + + $document = $xmldas->createDocument(); + $do = $document->getRootDataObject(); + $do->bear = $baloo; + $do->panther = $bagheera; + $do->snake = $kaa; } catch (Exception $e) { $this->assertTrue(false, "Exception was thrown from addTypes test when it should not have been: ".$e->getMessage()); } @@ -175,7 +177,7 @@ $XMLDASTest_error_handler_called = false; $exception_thrown = false; try { - $xdoc = $xmldas->loadFromFile("what_a_load_of_rubbish.xml"); + $xdoc = $xmldas->loadFile("what_a_load_of_rubbish.xml"); } catch (SDO_DAS_XML_FileException $e) { $exception_thrown = true; } catch (Exception $e) { @@ -194,7 +196,7 @@ ***********************************/ $exception_thrown = false; try { - $xmldas = SDO_DAS_XML::create("parse_errors.xsd"); + $xmldas = SDO_DAS_XML::create('parseErrors/parse_errors.xsd'); } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; } catch (Exception $e) { @@ -203,11 +205,11 @@ $this->assertTrue($exception_thrown, 'SDO_DAS_XML_ParserException should have been thrown'); } - public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFromFile() { + public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFile() { $xmldas = SDO_DAS_XML::create("company.xsd"); $exception_thrown = false; try { - $xdoc = $xmldas->loadFromFile("parse_errors.xml"); + $xdoc = $xmldas->loadFile('parseErrors/parse_errors.xml'); $do = $xdoc->getRootDataObject(); // don't expect to get here } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; @@ -217,11 +219,11 @@ $this->assertTrue($exception_thrown, 'SDO_DAS_XML_ParserException should have been thrown'); } - public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFromString() { + public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadString() { $xmldas = SDO_DAS_XML::create("company.xsd"); $exception_thrown = false; try { - $xdoc = $xmldas->loadFromString("<ugly<"); + $xdoc = $xmldas->loadString("<ugly<"); $do = $xdoc->getRootDataObject(); // don't expect to get here } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; @@ -243,7 +245,7 @@ // the xsd has a company type that refers to an employe type but doesn't define the employee type $exception_thrown = false; try { - $xmldas = SDO_DAS_XML::create("company_missing_type.xsd"); + $xmldas = SDO_DAS_XML::create('missingType/company_missing_type.xsd'); $this->assertTrue(false, "SDO_DAS_XML::create failed to throw SDO_TypeNotFoundException. "); } catch (SDO_TypeNotFoundException $e) { $exception_thrown = true; @@ -253,12 +255,12 @@ $this->assertTrue($exception_thrown,'SDO_TypeNotFoundException should have been thrown but was not'); } - public function testLoadFromFile_NormalPath_WorksWhenFileIsPresent() { + public function testLoadFile_NormalPath_WorksWhenFileIsPresent() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testLoadFromFile - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testLoadFile - Exception Caught" . $e->getMessage()); } } @@ -272,10 +274,10 @@ </departments> </company> */ - public function testLoadFromFile_LoadedGraphCorrespondsToTheXml() { + public function testLoadFile_LoadedGraphCorrespondsToTheXml() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); $this->assertEquals("MegaCorp", $do->name, 'Company name is not valid.'); $this->assertEquals(1, count($do->departments), 'Wrong number of departments.'); @@ -291,16 +293,16 @@ } } - public function testLoadFromFile_LoadedGraphCorrespondsToTheXmlWithNilSn() { + public function testLoadFile_LoadedGraphCorrespondsToTheXmlWithNilSn() { try { - $xmldas = SDO_DAS_XML::create("company_with_nillable_SN.xsd"); - $xdoc = $xmldas->loadFromFile("company_with_nillable_SN.xml"); + $xmldas = SDO_DAS_XML::create('nillable/company_with_nillable_SN.xsd'); + $xdoc = $xmldas->loadFile('nillable/company_with_nillable_SN.xml'); $do = $xdoc->getRootDataObject(); $department = $do->departments[0]; $jane = $department->employees[0]; $this->assertTrue($jane->SN === null && isset($jane->SN), 'Serial number is not null.'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testLoadFile_Loaded.... - Exception Caught" . $e->getMessage()); } } @@ -316,10 +318,10 @@ } } - public function testSaveDocumentToString_SaveAndReloadWorksCorrectly() { + public function testSaveString_SaveAndReloadWorksCorrectly() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); //Change some values @@ -328,25 +330,25 @@ $do->departments[0]->location = "Bangalore"; //Save the changes to xml string - $str = $xmldas->saveDocumentToString($xdoc); + $str = $xmldas->saveString($xdoc); $this->assertTrue(strrpos($str,'Bangalore') > 0, 'Department location not found in saved xml.'); //Test whether it is save correctly or not? - $xdoc1 = $xmldas->loadFromString($str); + $xdoc1 = $xmldas->loadString($str); $do1 = $xdoc1->getRootDataObject(); $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); $this->assertSame($do->departments[0]->employees[0], $do->employeeOfTheMonth, 'Two ways to reach e.o.t.m do not agree.'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDocumentToString - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testSaveString - Exception Caught" . $e->getMessage()); } } - public function testSaveDocumentToFile_SaveAndReloadWorksCorrectly() { + public function testSaveFile_SaveAndReloadWorksCorrectly() { try { $temp_file = tempnam($_ENV['TMP'], 'SDO'); $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); //Change some values @@ -355,274 +357,162 @@ $do->departments[0]->location = "Bangalore"; //Save the changes to xml file - $str = $xmldas->saveDocumentToFile($xdoc, $temp_file); + $str = $xmldas->saveFile($xdoc, $temp_file); //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromFile($temp_file); + $xdoc1 = $xmldas->loadFile($temp_file); $do1 = $xdoc1->getRootDataObject(); unlink($temp_file); $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDocumentToFile - Exception Caught" . $e->getMessage()); - } - } - - public function testSaveDataObjectToString_SaveAndReloadWorksCorrectly() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $do = $xdoc->getRootDataObject(); - - //Change some values - $emp_list = $do->departments[0]->employees; - $do->employeeOfTheMonth = $emp_list[0]; - $do->departments[0]->location = "Bangalore"; - - //Save the changes to xml string - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToString($do, $type->getNamespaceURI(), 'company'); - $this->assertTrue(strrpos($str,'Bangalore') > 0, 'Department location not found in saved xml.'); - - //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromString($str); - $do1 = $xdoc1->getRootDataObject(); - $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); - $this->assertSame($do->departments[0]->employees[0], $do->employeeOfTheMonth, 'Two ways to reach e.o.t.m do not agree.'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDataObjectToString - Exception Caught" . $e->getMessage()); - } - } - - public function testSaveDataObjectToFile_SaveAndReloadWorksCorrectly() { - try { - $temp_file = tempnam($_ENV['TMP'], 'SDO'); - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $do = $xdoc->getRootDataObject(); - - //Change some values - $emp_list = $do->departments[0]->employees; - $do->employeeOfTheMonth = $emp_list[0]; - $do->departments[0]->location = "Bangalore"; - - //Save the changes to xml file - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToFile($do, $type->getNamespaceURI(), 'company', $temp_file); - - //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromFile($temp_file); - $do1 = $xdoc1->getRootDataObject(); - unlink($temp_file); - $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'testSaveDataObjectToFile - Non-containment reference is not valid.'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'testSaveDataObjectToFile - Can not access part of tree from root data object'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDataObjectToFile - Exception Caught" . $e->getMessage()); - } - } - - public function testCreateDataObjectAndSaveToStringWorksCorrectly() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - - //Create Company object - $cmpny = $xmldas->createDataObject("companyNS", "CompanyType"); - $cmpny->name = "Acme Inc."; - - //Using company object, create department object - $dept = $cmpny->createDataObject("departments"); - $dept->name = "Finance"; - $dept->location = "UK"; - - //Create department object without company object - $dept1 = $xmldas->createDataObject("companyNS", "DepartmentType"); - $dept1->location = "Bangalore"; - $dept1->name = "Sales"; - - //Replace the original department object in the company object - $cmpny->departments[0] = $dept1; - - //Test whether changes are saved properly - $model_reflection_object = new SDO_Model_ReflectionDataObject($cmpny); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToString($cmpny, $type->getNamespaceURI(), 'company'); - $xdoc = $xmldas->loadFromString($str); - $do = $xdoc->getRootDataObject(); - $this->assertEquals("Sales", $do->departments[0]->name, 'testCreateDataObject - Can not access part of tree from root data object'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'testCreateDataObject - Can not access part of tree from root data object'); - - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testCreateDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testSaveFile - Exception Caught" . $e->getMessage()); } } public function testXMLDocument_getRootObject() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $this->assertEquals("MegaCorp", $xdoc->getRootDataObject()->name, 'testgetRootDataObject - was not the company'); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ public function testXMLDocument_getRootElementURI() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("CompanyNS", $xdoc->getRootElementURI, 'testgetRootElementURI - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $this->assertEquals("companyNS", $xdoc->getRootElementURI(), 'testgetRootElementURI - wrong answer '); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ public function testXMLDocument_getRootElementName() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("company", $xdoc->getRootElementName, 'testgetRootElementName - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $this->assertEquals("company", $xdoc->getRootElementName(), 'testgetRootElementName - wrong answer '); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ - public function testXMLDocument_getEncoding() { + public function testSetOnDocumentWorksCorrectly() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("UTF-8", $xdoc->getEncoding, 'testgetEncoding - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $xdoc->setXMLVersion("1.1"); + $xdoc->setEncoding("ISO-8859-1"); + $str = $xmldas->saveString($xdoc); + $this->assertTrue(strpos($str, '1.1') > 0, 'XML Version was apparently not set correctly'); + $this->assertTrue(strpos($str, 'ISO-8859-1') > 0, 'Encoding was apparently not set correctly'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testsetEncoding - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ - public function testGetXmlDeclaration() { + public function testCreateDocumentNoArgs() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company_noxmldecl.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals(false, $xdoc->getXMLDeclaration(), 'testgetXMLDeclaration - should return false'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); - } - } + $xdoc = $xmldas->createDocument(); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); - public function testGetXmlVersion() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $this->assertEquals('1.0', $xdoc->getXMLVersion(), 'testgetXMLVersion - should be 1.0'); + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - public function testGetSchemaLocation() { + public function testCreateDocumentOneArg() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $this->assertEquals(null, $xdoc->getSchemaLocation(), 'testgetSchemaLocation - wrong answer'); + $xdoc = $xmldas->createDocument('company'); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); + + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - - public function testSetAndGetEncodingOnDocumentWorksCorrectly() { + public function testCreateDocumentTwoArgs() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $xdoc->setEncoding("UTF-16"); - $this->assertEquals("UTF-16", $xdoc->getEncoding(), 'testsetEncoding - failed after set to UTF-16;'); - - $xdoc->setEncoding("ISO-8859-1"); - $this->assertEquals("ISO-8859-1", $xdoc->getEncoding(), 'testsetEncoding - failed after set to ISO-8859-1;'); + $xdoc = $xmldas->createDocument('companyNS','company'); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testsetEncoding - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - public function testDerivationByExtension() { + public function testExtendedComplexType() { try { - $xmldas = SDO_DAS_XML::create("derivation/extension.xsd"); - $do = $xmldas->createDataObject("", "testExtensionType"); - $author = $do->createDataObject('author'); - $character = $do->createDataObject('character'); - $author->name = "Jane Austen"; - $author->born = "1775"; - $author->dead = "1817"; - $character->name="Elizabeth Bennett"; - $character->qualification="lively playful disposition"; - $this->assertTrue($author->dead == '1817', "testDerivationByExtension - extended element not set correctly"); - $this->assertTrue($character->qualification == 'lively playful disposition', "testDerivationByExtension - extended element not set correctly"); + $xmldas = SDO_DAS_XML::create("extendedComplexType/person.xsd"); + $xdoc = $xmldas->loadFile("extendedComplexType/person.xml"); + $do = $xdoc->getRootDataObject(); + $this->assertTrue($do->first == 'William', 'first name should have been William'); + $this->assertTrue($do->gender == 'male', 'gender should have been male'); + $this->assertTrue($xdoc->getRootElementURI() == 'TNS', 'namespace for the document should be TNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'person', 'root element name should be person but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testDerivationByExtension - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testExtendedComplexType - Unexpected Exception Caught" . $e->getMessage()); } } - - public function testDerivationByRestriction() { + public function testRestrictedComplexType() { try { - $xmldas = SDO_DAS_XML::create("derivation/restriction.xsd"); - $do = $xmldas->createDataObject("", "testRestrictionType"); - $author = $do->createDataObject('author'); - $character = $do->createDataObject('character'); - $author->name = "Jane Austen"; - $author->born = "1775"; - $author->dead = "1817"; - $character->name="Elizabeth Bennett"; - $character->qualification="lively playful disposition"; - $this->assertTrue($author->dead == '1817', "testDerivationByRestriction - extended element not set correctly"); - $this->assertTrue($character->qualification == 'lively playful disposition', "testDerivationByRestriction - extended element not set correctly"); + $xmldas = SDO_DAS_XML::create('restrictedComplexType/name.xsd'); + $xdoc = $xmldas->loadFile('restrictedComplexType/name.xml'); + $do = $xdoc->getRootDataObject(); + $this->assertTrue($do->last == 'Smith', 'last name should have been Smith'); + $this->assertTrue($do->title == 'Mr.', 'title should have been Mr.'); + $this->assertTrue($xdoc->getRootElementURI() == 'TNS', 'namespace for the document should be TNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'formalname', 'root element name should be formalname but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testDerivationByRestriction - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testRestrictedComplexType - Unexpected Exception Caught" . $e->getMessage()); } } + public function testAbstractTypeCannotBeInstantiated() { + global $XMLDASTest_error_handler_called; + global $XMLDASTest_error_handler_severity; + global $XMLDASTest_error_handler_msg; - public function testAbstractType() { + $xmldas = SDO_DAS_XML::create('abstractComplexType/abstract.xsd'); + set_error_handler('XMLDASTest_user_error_handler'); + $XMLDASTest_error_handler_called = false; + $exception_thrown = false; + $created_first_object_ok = false; try { - $xmldas = SDO_DAS_XML::create("derivation/abstract.xsd"); - // hopefully will not be able to create an object of abstract type - $do = $xmldas->createDataObject("", "testAbstractType"); - - } catch (SDO_Exception $e) { + $person = $xmldas->createDataObject('TNS','fullpersoninfo'); // OK + $created_first_object_ok = true; + $person = $xmldas->createDataObject('TNS','personinfo'); // should fail + } catch (Exception $e) { + $this->assertTrue(strpos($e->getMessage(), 'abstract type') > 0, 'Wrong exception text: ' . $e->getMessage()); $exception_thrown = true; - $msg = $e->getMessage(); } - $this->assertTrue($exception_thrown, "testAbstractType - SDO_Exception should have been thrown"); - $this->assertTrue(strpos($msg,'Instantiation of abstract type') != 0, "testAbstractType - wrong message" . $e->getMessage()); - + $this->assertTrue($created_first_object_ok == true, 'Failed to create object of concrete type OK'); + $this->assertTrue($exception_thrown,'testAbstractTypeCannotBeInstantiated - exception should have been thrown'); } - } - -/* Graveyard -tests no longer in set and get encoding -// FAILS - seems likely that some restriction in libxml2 - -$str = $xmldas->saveDocumentToString($xdoc); -$xdoc1 = $xmldas->loadFromString($str); -$this->assertEquals("ISO-8859-1", $xdoc1->getEncoding(), 'testsetEncoding - failed after write to string;'); - -// FAILED -$xdoc->setEncoding("UTF-16"); -$temp_file = tempnam($_ENV['TMP'], 'SDO'); -$xmldas->saveDocumentToFile($xdoc, $temp_file); -$xdoc2 = $xmldas->loadFromFile($temp_file); -unlink($temp_file); -$this->assertEquals("UTF-16", $xdoc2->getEncoding(), 'testsetEncoding - failed after write to file;'); -*/ - ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_CPPException.cpp?view=markup&rev=1.1 Index: pecl/sdo/SDO_CPPException.cpp +++ pecl/sdo/SDO_CPPException.cpp /* +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2005. | | 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: Caroline Maynard | +----------------------------------------------------------------------+ */ static char rcs_id[] = "$Id: SDO_CPPException.cpp,v 1.1 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> #include <math.h> #include "zend_config.w32.h" #endif #include "php.h" #include "zend_exceptions.h" #include "php_sdo_int.h" #include "commonj/sdo/SDORuntimeException.h" #define CLASS_NAME "SDO_CPPException" static zend_object_handlers sdo_cppexception_object_handlers; /* {{{ sdo_throw_runtimeexception * maps a C++ SDO exception to a PHP SDO exception and throws it */ zval *sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) { zval *z_cause; zval *z_sdo_exception; zend_class_entry *exception_class; const char *message = e->getMessageText(); const char *exception_type = e->getEClassName(); MAKE_STD_ZVAL(z_cause); sdo_cppexception_new (z_cause, e TSRMLS_CC); if (strcmp(exception_type, "SDOUnsupportedOperationException") == 0) exception_class = sdo_unsupportedoperationexception_class_entry; else if (strcmp(exception_type, "SDOPropertyNotFoundException") == 0 || strcmp(exception_type, "SDOPathNotFoundException") == 0) exception_class = sdo_propertynotfoundexception_class_entry; else if (strcmp(exception_type, "SDOTypeNotFoundException") == 0) exception_class = sdo_typenotfoundexception_class_entry; else if (strcmp(exception_type, "SDOIndexOutOfRangeException") == 0) exception_class = sdo_indexoutofboundsexception_class_entry; else if (strcmp(exception_type, "SDOInvalidConversionException") == 0) exception_class = sdo_invalidconversionexception_class_entry; else if (strcmp(exception_type, "SDOPropertyNotSetException") == 0) exception_class = sdo_propertynotsetexception_class_entry; else exception_class = sdo_exception_class_entry; z_sdo_exception = sdo_throw_exception (exception_class, message, 0, 0 TSRMLS_CC); z_sdo_exception = sdo_throw_exception (exception_class, message, 0, z_cause TSRMLS_CC); zval_ptr_dtor(&z_cause); return z_sdo_exception; } /* }}} */ /* {{{ sdo_cppexception_object_create */ static zend_object_value sdo_cppexception_create_object(zend_class_entry *ce TSRMLS_DC) { zend_object *object; zval *tmp; /* this must be passed to hash_copy, but doesn't seem to be used */ zval z_object; z_object.value.obj = zend_objects_new(&object, ce TSRMLS_CC); z_object.value.obj.handlers = &sdo_cppexception_object_handlers; ALLOC_HASHTABLE(object->properties); zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); return z_object.value.obj; } /* }}} */ /* {{{ sdo_cppexception_get_property */ static void sdo_cppexception_get_property(zval *me, char *name, long name_len, zval *return_value TSRMLS_DC) { zval *value; value = zend_read_property(sdo_cppexception_class_entry, me, name, name_len, 0 TSRMLS_CC); *return_value = *value; zval_copy_ctor(return_value); INIT_PZVAL(return_value); } /* }}} */ /* {{{ sdo_cppexception_cast_object */ static int sdo_cppexception_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) { ostringstream print_buf; zval free_obj; int rc = SUCCESS; if (should_free) { free_obj = *writeobj; } sdo_cppexception_get_property(readobj, "string", sizeof("string") - 1, writeobj TSRMLS_CC); switch(type) { case IS_STRING: convert_to_string(writeobj); break; case IS_BOOL: convert_to_boolean(writeobj); break; case IS_LONG: convert_to_long(writeobj); break; case IS_DOUBLE: convert_to_double(writeobj); break; default: rc = FAILURE; } if (should_free) { zval_dtor(&free_obj); } return rc; } /* }}} */ /* {{{ sdo_cppexception_minit * This clas is not a PHP Exception, merely a wrapper for the data * from a C++ SDORuntimeException. It has similar properties to a * PHP Exception, but there's no debug trace. */ void sdo_cppexception_minit(zend_class_entry *ce TSRMLS_DC) { sdo_cppexception_class_entry = zend_register_internal_class(ce TSRMLS_CC); sdo_cppexception_class_entry->create_object = sdo_cppexception_create_object; memcpy(&sdo_cppexception_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); /*TODO There's a signature change for cast_object in PHP6. */ #if (PHP_MAJOR_VERSION < 6) sdo_cppexception_object_handlers.cast_object = sdo_cppexception_cast_object; #endif zend_declare_property_string(sdo_cppexception_class_entry, "class", sizeof("class") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "file", sizeof("file") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_long(sdo_cppexception_class_entry, "line", sizeof("line") - 1, 0, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "function", sizeof("function") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_long(sdo_cppexception_class_entry, "severity", sizeof("severity") - 1, E_ERROR, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE TSRMLS_CC); } /* }}} */ /* {{{ sdo_cppexception_new * Instantiate an SDO_CPPException from an SDORuntimeException */ void sdo_cppexception_new(zval *me, SDORuntimeException *cpp_exception TSRMLS_DC) { const char *eclass = cpp_exception->getEClassName(); const char *function = cpp_exception->getFunctionName(); const char *message = cpp_exception->getMessageText(); const char *file = cpp_exception->getFileName(); long line = cpp_exception->getLineNumber(); char *class_name, *space; long severity; ostringstream print_buf; string print_string; switch(cpp_exception->getSeverity()) { case SDORuntimeException::Normal: severity = E_NOTICE; break; case SDORuntimeException::Warning: severity = E_WARNING; break; case SDORuntimeException::Error: case SDORuntimeException::Severe: default: severity = E_ERROR; break; } if (object_init_ex(me, sdo_cppexception_class_entry) == FAILURE) { class_name = get_active_class_name(&space TSRMLS_CC); php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } if (eclass) { zend_update_property_string(sdo_cppexception_class_entry, me, "class", sizeof("class")-1, (char *)eclass TSRMLS_CC); } if (file) { zend_update_property_string(sdo_cppexception_class_entry, me, "file", sizeof("file")-1, (char *)file TSRMLS_CC); } zend_update_property_long(sdo_cppexception_class_entry, me, "line", sizeof("line")-1, line TSRMLS_CC); if (function) { zend_update_property_string(sdo_cppexception_class_entry, me, "function", sizeof("function")-1, (char *)function TSRMLS_CC); } if (message) { zend_update_property_string(sdo_cppexception_class_entry, me, "message", sizeof("message")-1, (char *)message TSRMLS_CC); } zend_update_property_long(sdo_cppexception_class_entry, me, "severity", sizeof("severity")-1, severity TSRMLS_CC); print_buf << *cpp_exception; print_string = print_buf.str(); zend_update_property_stringl (sdo_cppexception_class_entry, me, "string", sizeof("string") - 1, (char *)print_string.c_str(), print_string.length() TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getClass */ PHP_METHOD(SDO_CPPException, getClass) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "class", sizeof("class") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getFile */ PHP_METHOD(SDO_CPPException, getFile) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "file", sizeof("file") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getLine */ PHP_METHOD(SDO_CPPException, getLine) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "line", sizeof("line") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getFunction */ PHP_METHOD(SDO_CPPException, getFunction) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "function", sizeof("function") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getMessage */ PHP_METHOD(SDO_CPPException, getMessage) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "message", sizeof("message") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getSeverity */ PHP_METHOD(SDO_CPPException, getSeverity) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "severity", sizeof("severity") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::__toString */ PHP_METHOD(SDO_CPPException, __toString) { sdo_cppexception_cast_object(getThis(), return_value, IS_STRING, 0 TSRMLS_CC); } /* }}} */ /* * 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 */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Exception.cpp?view=markup&rev=1.1 Index: pecl/sdo/SDO_Exception.cpp +++ pecl/sdo/SDO_Exception.cpp /* +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2005. | | 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: Caroline Maynard | +----------------------------------------------------------------------+ */ static char rcs_id[] = "$Id: SDO_Exception.cpp,v 1.1 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> #include <math.h> #include "zend_config.w32.h" #endif #include "php.h" #include "zend.h" #include "zend_exceptions.h" #include "zend_builtin_functions.h" #include "php_sdo_int.h" #define CLASS_NAME "SDO_Exception" #define MAX_MSG 4096 static zend_class_entry *exception_class_entry; static zend_object_handlers sdo_exception_object_handlers; /* {{{ sdo_exception_object_create */ static zend_object_value sdo_exception_create_object(zend_class_entry *ce TSRMLS_DC) { zend_object *object; zval *tmp; /* this must be passed to hash_copy, but doesn't seem to be used */ zval z_object; zval *z_trace; z_object.value.obj = zend_objects_new(&object, ce TSRMLS_CC); z_object.value.obj.handlers = &sdo_exception_object_handlers; ALLOC_HASHTABLE(object->properties); zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); zend_update_property_string(exception_class_entry, &z_object, "file", sizeof("file") - 1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(exception_class_entry, &z_object, "line", sizeof("line") - 1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); ALLOC_ZVAL(z_trace); z_trace->is_ref = 0; z_trace->refcount = 0; zend_fetch_debug_backtrace(z_trace, 0, 0 TSRMLS_CC); zend_update_property(exception_class_entry, &z_object, "trace", sizeof("trace") - 1, z_trace TSRMLS_CC); return z_object.value.obj; } /* }}} */ /* {{{ sdo_exception_minit */ void sdo_exception_minit(zend_class_entry *ce TSRMLS_DC) { #if (PHP_MAJOR_VERSION < 6) exception_class_entry = zend_exception_get_default(); #else exception_class_entry = zend_exception_get_default(TSRMLS_C); #endif sdo_exception_class_entry = zend_register_internal_class_ex( ce, exception_class_entry, NULL TSRMLS_CC); sdo_exception_class_entry->create_object = sdo_exception_create_object; /* * The SDO_Exception adds a cause property to the base Exception class. * This may be set to any value, normally the original SDO_CPPException. */ zend_declare_property_null(sdo_exception_class_entry, "cause", sizeof("cause") - 1, ZEND_ACC_PUBLIC TSRMLS_CC); memcpy(&sdo_exception_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); sdo_exception_object_handlers.clone_obj = NULL; } /* }}} */ /* {{{ sdo_exception_new * Create a new SDO_Exception of the class specified */ void sdo_exception_new(zval *z_ex, zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC) { char *class_name, *space; Z_TYPE_P(z_ex) = IS_OBJECT; if (object_init_ex(z_ex, ce) == FAILURE) { class_name = get_active_class_name(&space TSRMLS_CC); php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } if (message) { zend_update_property_string(exception_class_entry, z_ex, "message", sizeof("message") - 1, (char *)message TSRMLS_CC); } zend_update_property_long(exception_class_entry, z_ex, "code", sizeof("code") - 1, code TSRMLS_CC); if (z_cause) { zend_update_property(sdo_exception_class_entry, z_ex, "cause", sizeof("cause") - 1, z_cause TSRMLS_CC); } } /* }}} */ /* {{{ sdo_throw_exception * Throw an SDO_Exception */ zval *sdo_throw_exception (zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC) { zval *z_ex; MAKE_STD_ZVAL(z_ex); sdo_exception_new(z_ex, ce, message, code, z_cause TSRMLS_CC); zend_throw_exception_object (z_ex TSRMLS_CC); return z_ex; } /* }}} */ /* {{{ sdo_throw_exception_ex * Throw an SDO_Exception */ zval *sdo_throw_exception_ex(zend_class_entry *ce, long code, zval *z_cause TSRMLS_DC, char *format, ...) { va_list arg; char *message; zval *z_ex; int len; /* TODO: for some reason I don't understand, I get a link error for * zend_vspprintf. So use a temporary buffer and truncate the message * if necessary. */ message = (char *)emalloc(MAX_MSG); va_start(arg, format); len = snprintf(message, MAX_MSG, format, arg); va_end(arg); z_ex = sdo_throw_exception(ce, message, code, z_cause TSRMLS_CC); efree(message); return z_ex; } /* }}} */ /* {{{ sdo_exception_set_cause */ void sdo_exception_set_cause(zval *me, zval *z_cause TSRMLS_DC) { zend_update_property(sdo_exception_class_entry, me, "cause", sizeof("cause") - 1, z_cause TSRMLS_CC); } /* }}} */ /* {{{ sdo_exception_get_cause */ zval *sdo_exception_get_cause(zval *me TSRMLS_DC) { return zend_read_property(sdo_exception_class_entry, me, "cause", sizeof("cause") - 1, 0 TSRMLS_CC); } /* }}} */ /* {{{ SDO_Exception::getCause */ PHP_METHOD(SDO_Exception, getCause) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } zval *z_cause = sdo_exception_get_cause(getThis() TSRMLS_CC); RETURN_ZVAL(z_cause, 1, 0); } /* }}} */ /* * 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 */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/.cvsignore?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/.cvsignore +++ pecl/sdo/tests/XMLDAS/Examples/.cvsignore letter-out.xml http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example4.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/Example4.php +++ pecl/sdo/tests/XMLDAS/Examples/Example4.php <?php /** * Illustrate open types and the use of the addTypes() method */ $xmldas = SDO_DAS_XML::create(); $xmldas->addTypes("jungle.xsd"); // this is an open type i.e. the xsd specifies it can contain "any" type $xmldas->addTypes('animalTypes.xsd'); $baloo = $xmldas->createDataObject('','bearType'); $baloo->name = "Baloo"; $baloo->weight = 800; $bagheera = $xmldas->createDataObject('','pantherType'); $bagheera->name = "Bagheera"; $bagheera->colour = 'inky black'; $kaa = $xmldas->createDataObject('','snakeType'); $kaa->name = "Kaa"; $kaa->length = 25; $document = $xmldas->createDocument(); $do = $document->getRootDataObject(); $do->bear = $baloo; $do->panther = $bagheera; $do->snake = $kaa; print($xmldas->saveString($document,2)); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example5.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/Example5.php +++ pecl/sdo/tests/XMLDAS/Examples/Example5.php <?php /** * Finding out what you can about the document and document element * This can be quite hard to understand because there are four calls * Two calls are made against the document * Two calls are made against the root data object and its model * Because of the SDO-XML mapping rules and how the SDO model is derived * from the XML model, only three possible values can come back from these four calls. * Always, $document->getRootElementURI() == (type of root data object)->namespaceURI * Essentiually, it all comes form the first few lines of the xsd: * <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" * xmlns:letter="http://letterSchema" * targetNamespace="http://letterSchema"> * <xsd:element name="letters" type="letter:FormLetter"/> */ $xmldas = SDO_DAS_XML::create("letter.xsd"); $document = $xmldas->loadFile("letter.xml"); $root_do = $document->getRootDataObject(); /** * Incidentally, the root data object type name and * namespaceURI can also be obtained from the type via * a reflection data object built on the root data object */ //$model_rdo = new SDO_Model_ReflectionDataObject($root_do); //$type = $model_rdo->getType(); //echo "The type name of the root data object is " . $type->name . "\n"; //echo "The namespace URI of the root data object is " . $type->namespaceURI . "\n"; /** * The "root element name" is the element name of the document element * in this case 'letters' * This matches the 'name' attribute of the document element in the xsd and matches * the element name from the xml */ echo "The document element name is " . $document->getRootElementName() . "\n"; assert($document->getRootElementName() == 'letters'); // a property of the document /** * The "root element URI" is the namespace part of the element name of the document element * in this case 'http://letterSchema' since 'letters' is in that namespace * This is taken from the xsd and matches the namespace picked up from the xml */ echo "The document element is in the namespace " . $document->getRootElementURI() . "\n"; assert($document->getRootElementURI() == 'http://letterSchema'); // a property of the document /** * The type name is taken from the SDO model * The XML-SDO mapping rules make this either: * The name of the complexType if there is one (in this case there is) * The document element name if there no complexType * This is taken from the xsd */ echo "The type name of the root data object is " . $root_do->getTypeName() . "\n"; assert($root_do->getTypeName() == 'FormLetter'); /** * The type's namespaceURI is taken from the SDO model * The XML-SDO mapping rules ensure that this will always be the same as * the namepace URI of the document element */ echo "The namespaceURI of the root data object is " . $root_do->getTypeNamespaceURI() . "\n"; assert($root_do->getTypeNamespaceURI() == 'http://letterSchema'); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd +++ pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd <schema xmlns= "http://www.w3.org/2001/XMLSchema"> <complexType name="snakeType"> <sequence> <element name= "name" type="string"/> <element name= "length" type="positiveInteger" /> </sequence> </complexType> <complexType name="bearType"> <sequence> <element name= "name" type="string"/> <element name= "weight" type="positiveInteger" /> </sequence> </complexType> <complexType name="pantherType"> <sequence> <element name= "name" type="string"/> <element name= "colour" type="string" /> </sequence> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/jungle.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/jungle.xsd +++ pecl/sdo/tests/XMLDAS/Examples/jungle.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="jungle"> <complexType> <sequence> <any minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> </element> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <element name="employee" type="fullpersoninfo"/> <complexType name="personinfo" abstract="true"> <sequence> <element name="firstname" type="string"/> <element name="lastname" type="string"/> </sequence> </complexType> <complexType name="fullpersoninfo"> <complexContent> <extension base="personinfo"> <sequence> <element name="address" type="string"/> <element name="city" type="string"/> <element name="country" type="string"/> </sequence> </extension> </complexContent> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <complexType name="snakeType"> <sequence> <element name= "name" type="string"/> <element name= "length" type="positiveInteger" /> </sequence> </complexType> <complexType name="bearType"> <sequence> <element name= "name" type="string"/> <element name= "weight" type="positiveInteger" /> </sequence> </complexType> <complexType name="pantherType"> <sequence> <element name= "name" type="string"/> <element name= "colour" type="string" /> </sequence> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="jungle"> <complexType> <sequence> <any minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> </element> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml <?xml version="1.0"?> <person xmlns="TNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance" title="Mr." gender="male"> <first>William</first> <middle>Henry</middle> <last>Harrison</last> <age>223</age> <birthdate>1773-02-09</birthdate> </person> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <complexType name="NameType"> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complexType> <complexType name="PersonType"> <complexContent> <extension base="tns:NameType"> <sequence> <element name="age" type="positiveInteger"/> <element name="birthdate" type="dateTime"/> </sequence> <attribute name="gender" type="string"/> </extension> </complexContent> </complexType> <element name="person" type="tns:PersonType"/> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="xsd:string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="EmployeeType"> <attribute name="name" type="xsd:string"/> <attribute name="SN" type="xsd:ID"/> <attribute name="manager" type="xsd:boolean"/> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml <?xml version="1.0" encoding="UTF-8" ?> <!-- This XML has an employee with an SN of nil, which should appear in the SDO as NULL --> <company xmlns="companyNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="MegaCorp" employeeOfTheMonth="#/departments.0/employees.1"> <departments name="Advanced Technologies" location="NY" number="123"> <employees> <name>Jane Doe</name> <SN xsi:nil="true"></SN> </employees> </departments> </company> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd <!-- This XSD recasts the properties of employee to elements in order to allow the SN property to be nillable --> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="DepartmentType"> <sequence> <element name="employees" type="company:EmployeeType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="location" type="string"/> <attribute name="number" type="int"/> </complexType> <complexType name="EmployeeType"> <element name="name" type="string"/> <element name="SN" type="ID" nillable="true"/> <element name="manager" type="boolean"/> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml <?xml version="1.0" encoding="UTF-8" ?> <company xmlns="companyNS" name="MegaCorp" employeeOfTheMonth="#/departments.0/employees.1"> <departments name="Advanced Technologies" location="NY" number="123"> <employees name="John Jones" SN="E0001"/> <employees name="Jane Doe" SN="E0003"/> <employees name="Al Smith" SN="E0004" manager="true"/> </departmentsX> </Xcompany> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="DepartmentType"> <sequence> <element name="employees" type="company:EmployeeType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="location" type="string"/> <attribute name="number" type="int"/> </complexType> <complexType name="EmployeeType"> <attribute name="name" type="string"/> <attribute name="SN" type="ID"/> <attribute name="manager" type="boolean"/> </complexType> </XXXXXschema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php <?php $xmldas = SDO_DAS_XML::create("name.xsd"); print $xmldas; $xdoc = $xmldas->loadFile("name.xml"); $do = $xdoc->getRootDataObject(); var_dump($do); $str = $xmldas->saveString($xdoc,2); print $str; $rdo = new SDO_Model_ReflectionDataObject($do); $do_type = $rdo->getType(); $all_props = $do_type->getProperties(); foreach ($all_props as $do_property) { echo "property " . $do_property->getName() . "\n"; } var_dump($do); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml <?xml version="1.0"?> <formalname xmlns="TNS" title="Mr."> <last>Smith</last> </formalname> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <complexType name="FormalNameType"> <complexContent> <restriction base="tns:NameType"> <sequence> <element ref="tns:last"/> </sequence> </restriction> </complexContent> </complexType> <complexType name="NameType"> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complexType> <element name="formalname" type="tns:FormalNameType"/> <element name="last" type="string"/> </schema>
http://cvs.php.net/viewcvs.cgi/pecl/sdo/.cvsignore?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/.cvsignore diff -u pecl/sdo/.cvsignore:1.5 pecl/sdo/.cvsignore:1.6 --- pecl/sdo/.cvsignore:1.5 Tue Jan 17 14:22:27 2006 +++ pecl/sdo/.cvsignore Mon Feb 20 18:50:25 2006 @@ -28,6 +28,7 @@ config.log .cdtproject include +commonj *.loT run-tests.php -sdo-*.tgz +.settings http://cvs.php.net/viewcvs.cgi/pecl/sdo/MakePackage.php?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/MakePackage.php diff -u pecl/sdo/MakePackage.php:1.11 pecl/sdo/MakePackage.php:1.12 --- pecl/sdo/MakePackage.php:1.11 Tue Jan 17 14:17:27 2006 +++ pecl/sdo/MakePackage.php Mon Feb 20 18:50:25 2006 @@ -1,5 +1,5 @@ <?php - /* $Id: MakePackage.php,v 1.11 2006/01/17 14:17:27 cem Exp $ */ + /* $Id: MakePackage.php,v 1.12 2006/02/20 18:50:25 mfp Exp $ */ require_once('PEAR/PackageFileManager.php'); $packagexml = new PEAR_PackageFileManager; if (PEAR::isError($packagexml)) { @@ -43,12 +43,35 @@ // . "The SDO_Model_ReflectionDataObject gives the programmer access to " // . "the type and structure information in a data object's model. " // . "This can help with debugging, or be used in dynamic user interface generation.", - 'notes' => "This release adds support for open types. These are types which " - . "can have additional properties added to a runtime instance, for example " - . "to support an XML <any/> element.\n" - . "Also various bug fixes. ", +// 'notes' => "This release adds support for open types. These are types which " +// . "can have additional properties added to a runtime instance, for example " +// . "to support an XML <any/> element.\n" +// . "Also various bug fixes. ", + +'notes' => +"The following changes have been made between 0.7.1 and this release.\n" +. "The changes which are visible at the programming interface are:\n" +. "The interface to the XML Data Access Service has been revised:\n" +. "The names of the methods to load and save documents to improve consistency with other packages.\n" +. "A new method, createDocument(), has been added to enable creation of a document from scratch.\n" +. "The saveDataObjectToFile()/String() methods have been replaced by saveFile()String() methods on the Document object.\n" +. "Some getters and setters on the Document have been fixed or removed.\n" +. "The XML Data Access Service has added support for the following XML Schema:\n" +. "Open types: support for <any> element and <anyAttribute>\n" +. "Type inheritance: both simple and complex types can be derived by restriction or extension\n" +. "Abstract types: the use of abstract types in the schema is supported\n" +. "The XML DAS now supports printing its SDO type and property model using print or echo.\n" +. "The XML DAS can now produce formatted Document (see optional formatting argument on saveFile() and saveString())\n" +. "The getType() method on a DataObject has been replaced with getTypeName() and getTypeNamespaceURI() methods.\n" +. "\n" +. "Other changes in this release:\n" +. "The memory management in the sdo and sdo_das_xml extensions has been overhauled to squeeze out any memory leaks\n" +. "Exception messages from the extension have been improved so that they never refer to the underlying C/C++ code\n" +. "PropertyNotSetException has been improved so that it replicates the way arrays and objects behave as closely as possible\n" +. "The parsing that the XML DAS performs on both XML Schema and instance documents has been improved so that problems are picked up and reported earlier.\n" + , 'simpleoutput' => true, - 'version' => '0.7.1', + 'version' => '0.9.0', 'baseinstalldir' => 'SDO', 'state' => 'beta', 'license' => 'Apache 2.0', http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_ChangeSummary.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/SDO_DAS_ChangeSummary.cpp diff -u pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.5 pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.6 --- pecl/sdo/SDO_DAS_ChangeSummary.cpp:1.5 Wed Oct 5 09:56:01 2005 +++ pecl/sdo/SDO_DAS_ChangeSummary.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_ChangeSummary.cpp,v 1.5 2005/10/05 09:56:01 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_ChangeSummary.cpp,v 1.6 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -92,10 +92,13 @@ void sdo_das_changesummary_new(zval *me, ChangeSummaryPtr change_summary TSRMLS_DC) { sdo_das_changesummary_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_changesummary_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } @@ -129,10 +132,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { my_object->change_summary->beginLogging(); @@ -155,10 +154,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { my_object->change_summary->endLogging(); @@ -181,10 +176,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_BOOL(my_object->change_summary->isLogging()); @@ -201,29 +192,26 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldValues) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop; ChangeSummaryPtr change_summary; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get (z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { SettingList& sl = my_object->change_summary->getOldValues(dop); @@ -252,10 +240,6 @@ } my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { const ChangedDataObjectList& cdol = my_object->change_summary->getChangedDataObjects(); @@ -278,30 +262,27 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangeType) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop; ChangeSummaryPtr change_summary; long change_type = CS_NONE; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get (z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { /* this order is important: for example isDeleted and isModified may both return true, @@ -328,31 +309,27 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldContainer) { sdo_das_changesummary_object *my_object; - sdo_do_object *my_dataobject; zval *z_dataobject; DataObjectPtr dop, container_dop; ChangeSummaryPtr change_summary; long change_type = 0; - zval *container_zval; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_dataobject, sdo_dataobjectimpl_class_entry) == FAILURE) return; my_object = sdo_das_changesummary_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_changesummary_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } change_summary = my_object->change_summary; /* get the supplied data object */ - my_dataobject = (sdo_do_object *)zend_object_store_get_object(z_dataobject TSRMLS_CC); - if (my_dataobject == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + dop = sdo_do_get(z_dataobject TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETVAL_NULL(); } - dop = my_dataobject->dop; try { container_dop = change_summary->getOldContainer(dop); @@ -360,13 +337,7 @@ if (!container_dop) { RETVAL_NULL(); } else { - container_zval = (zval *)container_dop->getUserData(); - if (container_zval == (zval *)SDO_USER_DATA_EMPTY) { - php_error(E_ERROR, "%s:%i: container is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } else { - RETVAL_ZVAL(container_zval, 1, 0); - } + sdo_do_new(return_value, container_dop TSRMLS_CC); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_DataFactory.cpp?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/SDO_DAS_DataFactory.cpp diff -u pecl/sdo/SDO_DAS_DataFactory.cpp:1.7 pecl/sdo/SDO_DAS_DataFactory.cpp:1.8 --- pecl/sdo/SDO_DAS_DataFactory.cpp:1.7 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/SDO_DAS_DataFactory.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_DataFactory.cpp,v 1.7 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_DataFactory.cpp,v 1.8 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -90,15 +90,30 @@ } /* }}} */ +/* {{{ sdo_das_df_get + * utility function for DAS implementations + */ +DataFactoryPtr sdo_das_df_get(zval *me TSRMLS_DC) +{ + sdo_das_df_object *my_object; + + my_object = (sdo_das_df_object *)zend_object_store_get_object(me TSRMLS_CC); + return my_object->dfp; +} +/* }}} */ + /* {{{ sdo_das_df_new */ void sdo_das_df_new(zval *me, DataFactoryPtr dfp TSRMLS_DC) { sdo_das_df_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_datafactoryimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } @@ -146,30 +161,27 @@ PHP_METHOD(SDO_DAS_DataFactoryImpl, create) { sdo_das_df_object *my_object; - char *namespaceURI; - int *namespaceURI_len; - char *typeName; - int *typeName_len; - zval *z_new_do; + char *type_uri; + int *type_uri_len; + char *type_name; + int *type_name_len; DataObjectPtr dop; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len) == FAILURE) + &type_uri, &type_uri_len, &type_name, &type_name_len) == FAILURE) return; my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); try { - dop = my_object->dfp->create(namespaceURI, typeName); + dop = my_object->dfp->create(type_uri, type_name); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); return; } /* We have a good data object, so set up its PHP incarnation */ - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, dop TSRMLS_CC); - RETVAL_ZVAL(z_new_do, 1, 0); + sdo_do_new(return_value, dop TSRMLS_CC); } /* }}} */ @@ -197,14 +209,16 @@ PHP_METHOD(SDO_DAS_DataFactoryImpl, addType) { sdo_das_df_object *my_object; - char *namespaceURI; - int namespaceURI_len; - char *typeName; - int typeName_len; - + char *type_uri; + int type_uri_len; + char *type_name; + int type_name_len; + /* optional parameters with default values */ - zend_bool sequenced = false; - zend_bool open = false; + zend_bool is_sequenced = false; + zend_bool is_open = false; + zend_bool is_abstract = false; + zend_bool is_derived = false; /* optional array of optional argumants */ zval *args = NULL; @@ -215,52 +229,121 @@ uint key_string_len; ulong key_index; + /* and a further array for the basetype values */ + HashTable *basetype_hash; + zval **z_basetype_uri; + zval **z_basetype_name; + char *basetype_uri; + char *basetype_name; + + char *class_name, *space; + if (ZEND_NUM_ARGS() < 2) WRONG_PARAM_COUNT; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssb|b", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &sequenced, &open) == SUCCESS) { - /* the old (deprecated) signature */ - php_error(E_WARNING, "use of deprecated signature for %s", get_active_function_name(TSRMLS_C)); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a", - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &args) == FAILURE) { - return; - } else if (args != NULL) { - args_hash = Z_ARRVAL_P(args); - - for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); - zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; - zend_hash_move_forward_ex(args_hash, &args_pointer)) { - if (zend_hash_get_current_key_ex( - args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { - if (strcmp(key_string, "sequenced") == SUCCESS) { - sequenced = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "open") == SUCCESS) { - open = sdo_get_boolean_value (*value); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a", + &type_uri, &type_uri_len, &type_name, &type_name_len, + &args) == FAILURE) { + return; + } + + if (args != NULL) { + args_hash = Z_ARRVAL_P(args); + + for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); + zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; + zend_hash_move_forward_ex(args_hash, &args_pointer)) { + if (zend_hash_get_current_key_ex( + args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { + + if (strcmp(key_string, "sequenced") == SUCCESS) { + is_sequenced = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "open") == SUCCESS) { + is_open = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "abstract") == SUCCESS) { + is_abstract = sdo_get_boolean_value (*value); + continue; + } + + if (strcmp(key_string, "basetype") == SUCCESS) { + /* If the basetype option is present, its value + * is an array of type uri and type name. + */ + is_derived = true; + if (Z_TYPE_PP(value) != IS_ARRAY) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): %s argument should be an array", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + basetype_hash = Z_ARRVAL_PP(value); + if (zend_hash_num_elements(basetype_hash) != 2) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): %s array should have exactly two elements", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + if (zend_hash_index_find(basetype_hash, 0, (void **)&z_basetype_uri) == SUCCESS && + Z_TYPE_PP(z_basetype_uri) == IS_STRING) { + basetype_uri = Z_STRVAL_PP(z_basetype_uri); + } else { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): invalid value for %s type namespace URI", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; + } + + if (zend_hash_index_find(basetype_hash, 1, (void **)&z_basetype_name) == SUCCESS&& + Z_TYPE_PP(z_basetype_name) == IS_STRING) { + basetype_name = Z_STRVAL_PP(z_basetype_name); } else { - php_error(E_WARNING, "unrecognized option %s in parameter array for %s", - key_string, get_active_function_name(TSRMLS_C)); + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): invalid value for %s type name", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + return; } - } else { - php_error(E_WARNING, "%i : option name must be a string in parameter array for %s", - key_index, get_active_function_name(TSRMLS_C)); - } - } + continue; + } /* end basetype */ + + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): unrecognized option %s in parameter array", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + + } else { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): option name must be a string in parameter array #%i", + class_name, space, get_active_function_name(TSRMLS_C), key_index); + } } } my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); - + try { - my_object->dfp->addType(namespaceURI, typeName, ZEND_TRUTH(sequenced), ZEND_TRUTH(open)); + my_object->dfp->addType(type_uri, type_name, + ZEND_TRUTH(is_sequenced), ZEND_TRUTH(is_open), ZEND_TRUTH(is_abstract)); + + if (is_derived) { + my_object->dfp->setBaseType(type_uri, type_name, basetype_uri, basetype_name); + } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } - + return; } /* }}} */ @@ -270,18 +353,18 @@ */ PHP_METHOD(SDO_DAS_DataFactoryImpl, addPropertyToType) { - char *parent_namespaceURI; - int parent_namespaceURI_len; - char *parent_typeName; - int parent_typeName_len; - - char *propertyName; - int propertyName_len; - - char *namespaceURI; - int namespaceURI_len; - char *typeName; - int typeName_len; + char *parent_type_uri; + int parent_type_uri_len; + char *parent_type_name; + int parent_type_name_len; + + char *property_name; + int property_name_len; + + char *type_uri; + int type_uri_len; + char *type_name; + int type_name_len; /* optional array of optional argumants */ zval *args = NULL; @@ -294,157 +377,168 @@ /* optional parameters with default values */ zend_bool many = false; - zend_bool readOnly = false; + zend_bool read_only = false; zend_bool containment = true; zval *default_value = NULL; sdo_das_df_object *my_object; + char *class_name, *space; if (ZEND_NUM_ARGS() < 5) WRONG_PARAM_COUNT; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sssssb|bb", - &parent_namespaceURI, &parent_namespaceURI_len, &parent_typeName, &parent_typeName_len, - &propertyName, &propertyName_len, - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &many, &readOnly, &containment) == SUCCESS) { - /* the old (deprecated) signature */ - php_error(E_WARNING, "use of deprecated signature for %s", get_active_function_name(TSRMLS_C)); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssss|a", - &parent_namespaceURI, &parent_namespaceURI_len, &parent_typeName, &parent_typeName_len, - &propertyName, &propertyName_len, - &namespaceURI, &namespaceURI_len, &typeName, &typeName_len, - &args) == FAILURE) { - return; - } else if (args != NULL) { - args_hash = Z_ARRVAL_P(args); - - for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); - zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; - zend_hash_move_forward_ex(args_hash, &args_pointer)) { - if (zend_hash_get_current_key_ex( - args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { - if (strcmp(key_string, "many") == SUCCESS) { - many = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "readonly") == SUCCESS) { - readOnly = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "containment") == SUCCESS) { - containment = sdo_get_boolean_value (*value); - } else - if (strcmp(key_string, "opposite") == SUCCESS) { - php_error(E_WARNING, "option %s not yet implemented for %s", - key_string, get_active_function_name(TSRMLS_C)); - } else - if (strcmp(key_string, "default") == SUCCESS) { - default_value = *value; - } else { - php_error(E_WARNING, "unrecognized option %s in parameter array for %s", - key_string, get_active_function_name(TSRMLS_C)); - } - } else { - php_error(E_WARNING, "%i : option name must be a string in parameter array for %s", - key_index, get_active_function_name(TSRMLS_C)); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssss|a", + &parent_type_uri, &parent_type_uri_len, &parent_type_name, &parent_type_name_len, + &property_name, &property_name_len, + &type_uri, &type_uri_len, &type_name, &type_name_len, + &args) == FAILURE) { + return; + } else if (args != NULL) { + args_hash = Z_ARRVAL_P(args); + + for (zend_hash_internal_pointer_reset_ex(args_hash, &args_pointer); + zend_hash_get_current_data_ex(args_hash, (void **)&value, &args_pointer) == SUCCESS; + zend_hash_move_forward_ex(args_hash, &args_pointer)) { + if (zend_hash_get_current_key_ex( + args_hash, &key_string, &key_string_len, &key_index, 0, &args_pointer) == HASH_KEY_IS_STRING) { + if (strcmp(key_string, "many") == SUCCESS) { + many = sdo_get_boolean_value (*value); + continue; + } + if (strcmp(key_string, "readonly") == SUCCESS) { + read_only = sdo_get_boolean_value (*value); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): option %s not yet implemented", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + continue; } - } + if (strcmp(key_string, "containment") == SUCCESS) { + containment = sdo_get_boolean_value (*value); + continue; + } + if (strcmp(key_string, "opposite") == SUCCESS) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): option %s not yet implemented", + class_name, space, get_active_function_name(TSRMLS_C), key_string); + continue; + } + if (strcmp(key_string, "default") == SUCCESS) { + default_value = *value; + continue; + } + + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s::%s: unrecognized option %s in parameter array", + CLASS_NAME, get_active_function_name(TSRMLS_C), key_string); + + } else { + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s::%s: option name must be a string in parameter array #%i", + CLASS_NAME, get_active_function_name(TSRMLS_C), key_index); + } + } - } - + } + my_object = sdo_das_df_get_instance(getThis() TSRMLS_CC); try { - my_object->dfp->addPropertyToType(parent_namespaceURI, parent_typeName, propertyName, namespaceURI, typeName, - ZEND_TRUTH(many), ZEND_TRUTH(readOnly), ZEND_TRUTH(containment)); + my_object->dfp->addPropertyToType(parent_type_uri, parent_type_name, property_name, type_uri, type_name, + ZEND_TRUTH(many), ZEND_TRUTH(read_only), ZEND_TRUTH(containment)); if (default_value) { if (many) { zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: multivalued property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: multivalued property %s cannot have a default value", CLASS_NAME, __LINE__, property_name); } else if (Z_TYPE_P(default_value) == IS_NULL) { zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: property %s cannot have a NULL default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: property %s cannot have a NULL default value", CLASS_NAME, __LINE__, property_name); } else { /* copy the value so that the original is not modified */ zval temp_zval = *default_value; zval_copy_ctor(&temp_zval); - const Type& type = my_object->dfp->getType(namespaceURI, typeName); - const Type& parentType = my_object->dfp->getType(parent_namespaceURI, parent_typeName); + const Type& type = my_object->dfp->getType(type_uri, type_name); + const Type& parentType = my_object->dfp->getType(parent_type_uri, parent_type_name); switch (type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); break; case Type::BooleanType: convert_to_boolean(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (bool)ZEND_TRUTH(Z_BVAL(temp_zval))); + my_object->dfp->setDefault(parentType, property_name, (bool)ZEND_TRUTH(Z_BVAL(temp_zval))); break; case Type::ByteType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (char)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (char)Z_LVAL(temp_zval)); break; case Type::BytesType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval), Z_STRLEN(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval), Z_STRLEN(temp_zval)); break; case Type::CharacterType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (char)(Z_STRVAL(temp_zval)[0])); + my_object->dfp->setDefault(parentType, property_name, (char)(Z_STRVAL(temp_zval)[0])); break; case Type::DateType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (SDODate)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (SDODate)Z_LVAL(temp_zval)); break; case Type::DoubleType: convert_to_double(&temp_zval); /*TODO this may need more work. On Windows, simply omitting the cast, or casting to double, * leads to an ambiguous overloaded function message. But some platforms may baulk at long double. */ - my_object->dfp->setDefault(parentType, propertyName, (long double)Z_DVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (long double)Z_DVAL(temp_zval)); break; case Type::FloatType: convert_to_double(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (float)Z_DVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (float)Z_DVAL(temp_zval)); break; case Type::IntegerType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (long)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (long)Z_LVAL(temp_zval)); break; case Type::LongType: if (Z_TYPE(temp_zval) == IS_LONG) { - my_object->dfp->setDefault(parentType, propertyName, (int64_t)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (int64_t)Z_LVAL(temp_zval)); } else { convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); } break; case Type::ShortType: convert_to_long(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, (short)Z_LVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, (short)Z_LVAL(temp_zval)); break; case Type::StringType: case Type::UriType: case Type::TextType: convert_to_string(&temp_zval); - my_object->dfp->setDefault(parentType, propertyName, Z_STRVAL(temp_zval)); + my_object->dfp->setDefault(parentType, property_name, Z_STRVAL(temp_zval)); break; case Type::DataObjectType: zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: DataObject property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: DataObject property %s cannot have a default value", + CLASS_NAME, __LINE__, property_name); break; case Type::ChangeSummaryType: zend_throw_exception_ex(sdo_unsupportedoperationexception_class_entry, 0 TSRMLS_CC, - "%s:%i: ChangeSummary property %s cannot have a default value", CLASS_NAME, __LINE__, propertyName); + "%s:%i: ChangeSummary property %s cannot have a default value", + CLASS_NAME, __LINE__, property_name); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, - type.getName(), propertyName); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, + type.getName(), property_name); } zval_dtor(&temp_zval); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_Setting.cpp?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/SDO_DAS_Setting.cpp diff -u pecl/sdo/SDO_DAS_Setting.cpp:1.11 pecl/sdo/SDO_DAS_Setting.cpp:1.12 --- pecl/sdo/SDO_DAS_Setting.cpp:1.11 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_DAS_Setting.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_Setting.cpp,v 1.11 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_Setting.cpp,v 1.12 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -92,10 +92,13 @@ void sdo_das_setting_new(zval *me, Setting *setting TSRMLS_DC) { sdo_das_setting_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_das_setting_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } @@ -114,8 +117,8 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; MAKE_STD_ZVAL(return_value); try { @@ -125,7 +128,9 @@ const Property& property = setting->getProperty(); switch(property.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -147,7 +152,9 @@ case Type::CharacterType: wchar_value = setting->getCharacterValue(); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), property.getName()); } char_value = setting->getByteValue(); RETVAL_STRINGL(&char_value, 1, 1); @@ -181,18 +188,23 @@ /* An old value may legitimately be null */ RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, property.getType().getName(), property.getName()); } } @@ -211,31 +223,27 @@ HashTable *properties; zval *tmp; Setting *setting; + zval z_holder; + const char *property_name; - ALLOC_HASHTABLE(properties); + array_init(&z_holder); my_object = sdo_das_setting_get_instance(object TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - setting = my_object->setting; - const char *propertyName = setting->getProperty().getName(); - - zend_hash_init(properties, 1, NULL, NULL, 0); - - /* TODO if the setting is for a list element, we should - * probably include the list index as part of the key - */ - - tmp = sdo_das_setting_read_value(my_object TSRMLS_CC); - - zend_hash_update(properties, (char *)propertyName, 1 + strlen(propertyName), - &tmp, sizeof(zval *), NULL); - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } + try { + setting = my_object->setting; + property_name = setting->getProperty().getName(); + + /* TODO if the setting is for a list element, we should + * probably include the list index as part of the key + */ + + tmp = sdo_das_setting_read_value(my_object TSRMLS_CC); + + add_assoc_zval (&z_holder, (char *)property_name, tmp); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -255,42 +263,37 @@ } my_object = sdo_das_setting_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { + + setting = my_object->setting; + try { + const Property& property = setting->getProperty(); + + print_buf << "object(" << CLASS_NAME << + ")#" << readobj->value.obj.handle; + + if (property.isMany()) { + print_buf << '[' << setting->getIndex() << ']'; + } + + if (setting->isSet() && property.getType().isDataType()) { + print_buf << "=>"; + if (setting->isNull()) { + print_buf << "NULL"; + } else { + print_buf << '\"' << setting->getCStringValue() << '\"'; + } + } + + print_buf << '}'; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - setting = my_object->setting; - try { - const Property& property = setting->getProperty(); - - print_buf << "object(" << CLASS_NAME << - ")#" << readobj->value.obj.handle; - - if (property.isMany()) { - print_buf << '[' << setting->getIndex() << ']'; - } - - if (setting->isSet() && property.getType().isDataType()) { - print_buf << "=>"; - if (setting->isNull()) { - print_buf << "NULL"; - } else { - print_buf << '\"' << setting->getCStringValue() << '\"'; - } - } - - print_buf << '}'; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } - } + } switch(type) { case IS_STRING: @@ -344,10 +347,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { const Property& property = my_object->setting->getProperty(); @@ -371,10 +370,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_STRING((char *)my_object->setting->getProperty().getName(), 1); @@ -398,10 +393,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } value = sdo_das_setting_read_value(my_object TSRMLS_CC); RETVAL_ZVAL(value, 1, 0); @@ -421,10 +412,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (my_object->setting->getProperty().isMany()) { @@ -451,10 +438,6 @@ } my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_das_setting_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { RETVAL_BOOL(my_object->setting->isSet()); http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_XML.cpp?r1=1.13&r2=1.14&diff_format=u Index: pecl/sdo/SDO_DAS_XML.cpp diff -u pecl/sdo/SDO_DAS_XML.cpp:1.13 pecl/sdo/SDO_DAS_XML.cpp:1.14 --- pecl/sdo/SDO_DAS_XML.cpp:1.13 Thu Jan 26 15:50:57 2006 +++ pecl/sdo/SDO_DAS_XML.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_XML.cpp,v 1.13 2006/01/26 15:50:57 mfp Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_XML.cpp,v 1.14 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -33,14 +33,12 @@ #include "zend_interfaces.h" // needed for several uses of zend_call_method() -/******************* Forward declarations for this module only **********************/ -zend_object_value sdo_das_xml_object_create (zend_class_entry *ce TSRMLS_DC); -void sdo_das_xml_object_free_storage (void *object TSRMLS_DC); - #define PARSER_EXCEPTION_MSG_LEN 1000 +#define MAX_ERRORS 50 +#define CLASS_NAME "SDO_DAS_XML" -zend_class_entry* sdo_das_xml_class_entry; -zend_object_handlers sdo_das_xml_object_handlers; +PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_class_entry; +static zend_object_handlers sdo_das_xml_object_handlers; /* argument definitions of SDO_DAS_XML class, start */ ZEND_BEGIN_ARG_INFO(sdo_das_xml___construct_args, 0) @@ -56,45 +54,33 @@ ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_das_xml_loadFile_args, 0) - ZEND_ARG_INFO(0, fileName) + ZEND_ARG_INFO(0, file_name) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_das_xml_loadString_args, 0) - ZEND_ARG_INFO(0, xmlString) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO(sdo_das_xml_createdo_args, 0) - ZEND_ARG_INFO(0, nameSpaceURI) - ZEND_ARG_INFO(0, typeName) + ZEND_ARG_INFO(0, xml_string) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDocString_args, 0) - ZEND_ARG_INFO(0, docObj) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_saveFile_args, 0, ZEND_RETURN_VALUE, 2) + ZEND_ARG_INFO(0, document) + ZEND_ARG_INFO(0, xml_file) + ZEND_ARG_INFO(0, indent) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDocFile_args, 0) - ZEND_ARG_INFO(0, docObj) - ZEND_ARG_INFO(0, xmlFile) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_saveString_args, 0, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, document) + ZEND_ARG_INFO(0, indent) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDOString_args, 0) - ZEND_ARG_INFO(0, dataobj) - ZEND_ARG_INFO(0, rootURI) - ZEND_ARG_INFO(0, rootName) +ZEND_BEGIN_ARG_INFO_EX(sdo_das_xml_createDocument_args, 0, ZEND_RETURN_VALUE, 0) + ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, element_name) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_das_xml_saveDOFile_args, 0) - ZEND_ARG_INFO(0, dataobj) - ZEND_ARG_INFO(0, rootURI) - ZEND_ARG_INFO(0, rootName) - ZEND_ARG_INFO(0, xmlFile) +ZEND_BEGIN_ARG_INFO(sdo_das_xml_createDataObject_args, 0) + ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_name) ZEND_END_ARG_INFO(); - -//ZEND_BEGIN_ARG_INFO(sdo_das_xml_getProperty_args, 0) -// ZEND_ARG_INFO(0, nameSpaceURI) -// ZEND_ARG_INFO(0, typeName) -//ZEND_END_ARG_INFO(); - /* argument definitions of SDO_DAS_XML class, end */ /* {{{ SDO_DAS_XML Class methods @@ -106,69 +92,25 @@ ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(SDO_DAS_XML, addTypes, sdo_das_xml_addTypes_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, loadFromFile, sdo_das_xml_loadFile_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, loadFromString, sdo_das_xml_loadString_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDocumentToString, sdo_das_xml_saveDocString_args, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDocumentToFile, sdo_das_xml_saveDocFile_args, + ZEND_ME(SDO_DAS_XML, loadFile, sdo_das_xml_loadFile_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDataObjectToString, sdo_das_xml_saveDOString_args, + ZEND_ME(SDO_DAS_XML, loadString, sdo_das_xml_loadString_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, saveDataObjectToFile, sdo_das_xml_saveDOFile_args, + ZEND_ME(SDO_DAS_XML, saveFile, sdo_das_xml_saveFile_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, createDataObject, sdo_das_xml_createdo_args, + ZEND_ME(SDO_DAS_XML, saveString, sdo_das_xml_saveString_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, getTypes, 0, + ZEND_ME(SDO_DAS_XML, createDocument, sdo_das_xml_createDocument_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML, __toString, 0, + ZEND_ME(SDO_DAS_XML, createDataObject, sdo_das_xml_createDataObject_args, ZEND_ACC_PUBLIC) -// ZEND_ME(SDO_DAS_XML, getProperty, sdo_das_xml_getProperty_args, -// ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DAS_XML, __toString, 0, + ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} }; /* }}} */ -/* {{{ initialize_sdo_das_xml_class - */ -void initialize_sdo_das_xml_class(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML", sdo_das_xml_methods); - ce.create_object = sdo_das_xml_object_create; - sdo_das_xml_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - memcpy(&sdo_das_xml_object_handlers, zend_get_std_object_handlers(), - sizeof(zend_object_handlers)); - sdo_das_xml_object_handlers.clone_obj = NULL; -} -/* }}} */ - - -/* {{{ sdo_das_xml_object_create - */ -zend_object_value sdo_das_xml_object_create(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - zval *tmp; - xmldas_object *obj = (xmldas_object *) emalloc(sizeof(xmldas_object)); - memset(obj, 0, sizeof(xmldas_object)); - - obj->z_obj.ce = ce; - ALLOC_HASHTABLE(obj->z_obj.properties); - zend_hash_init(obj->z_obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(obj->z_obj.properties, &ce->default_properties, - (copy_ctor_func_t) zval_add_ref, (void *) &tmp, - sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, NULL, - sdo_das_xml_object_free_storage, - NULL TSRMLS_CC); - retval.handlers = &sdo_das_xml_object_handlers; - return retval; -} -/* }}} */ - /* {{{ sdo_das_xml_object_free_storage */ void sdo_das_xml_object_free_storage(void *object TSRMLS_DC) @@ -177,144 +119,66 @@ * Frees up the SDO_DAS_XML object also decrements reference to * PHP version of SDO_DAS_DataFactory */ - sdo_das_df_object *das_obj; - xmldas_object *obj = (xmldas_object *) object; - zend_hash_destroy(obj->z_obj.properties); - FREE_HASHTABLE(obj->z_obj.properties); - - if (obj->php_das_df) { - das_obj = (sdo_das_df_object *) - zend_object_store_get_object(obj->php_das_df TSRMLS_CC); + xmldas_object *xmldas = (xmldas_object *)object; + zend_hash_destroy(xmldas->zo.properties); + FREE_HASHTABLE(xmldas->zo.properties); - if(das_obj) { - das_obj->dfp = NULL; - } - zend_objects_store_del_ref(obj->php_das_df TSRMLS_CC); - } - efree(obj); + zval_dtor(&xmldas->z_df); + efree(xmldas); } /* }}} */ -/* {{{ create_dataobject_tree +/* {{{ sdo_das_xml_object_create */ -void create_dataobject_tree(DataObjectPtr data_object TSRMLS_DC) +zend_object_value sdo_das_xml_object_create(zend_class_entry *ce TSRMLS_DC) { - zval *z_obj; - zend_object *php_das_obj = NULL; - MAKE_STD_ZVAL(z_obj); - if (!data_object) { - return; - // tempting to raise an error as this should never happen - not going to do it though - // php_error(E_ERROR, "SDO_DAS_XML::create_dataobject_tree was passed a null argument"); - } - if (data_object->getUserData() != (void*) 0xFFFFFFFF) { - // if the user data is set then we have encountered this object before - // and already created a PHP object corresponding to it. - // This will happen when we follow a reference to an object that - // was already visited following a different reference: for example following the - // employee_of_the_month non-containment reference to an employee who has already been - // visited by following the department->employee containmment reference. - // Since we already have a corresponding object, return without creating another. - return; - } - sdo_do_new(z_obj, data_object TSRMLS_CC); - // not sure whether any need to increase the reference count? - // zend_objects_store_add_ref(z_obj TSRMLS_CC); - const Type& data_object_type = data_object->getType(); - PropertyList pl = data_object->getInstanceProperties(); - for (int i = 0; i < pl.size(); i++) { - const Type& property_type = pl[i].getType(); - if (data_object->isSet(pl[i])) { - if (pl[i].isMany()) { - DataObjectList& dol = data_object->getList(pl[i]); - for (int j = 0; j <dol.size(); j++) { - create_dataobject_tree(dol[j] TSRMLS_CC); - } - } else { - if (!property_type.isDataType()) { - create_dataobject_tree(data_object->getDataObject(pl[i]) - TSRMLS_CC); - } - } - } - } + zend_object_value retval; + zval *tmp; + xmldas_object *xmldas; + + xmldas = (xmldas_object *)emalloc(sizeof(xmldas_object)); + memset(xmldas, 0, sizeof(xmldas_object)); + + xmldas->zo.ce = ce; + ALLOC_HASHTABLE(xmldas->zo.properties); + zend_hash_init(xmldas->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(xmldas->zo.properties, &ce->default_properties, + (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + retval.handle = zend_objects_store_put(xmldas, NULL, + sdo_das_xml_object_free_storage, NULL TSRMLS_CC); + retval.handlers = &sdo_das_xml_object_handlers; + return retval; } /* }}} */ -/* {{{ PHP_METHOD(SDO_DAS_XML, __construct) +/* {{{ sdo_das_xml_minit */ -PHP_METHOD(SDO_DAS_XML, __construct) +void sdo_das_xml_minit(TSRMLS_D) { - php_error(E_ERROR, "SDO_DAS_XML::__construct - you cannot instantiate SDO_DAS_XML by calling the constructor. Use SDO_DAS_XML::create(xsd) static function instead."); + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML", sdo_das_xml_methods); + ce.create_object = sdo_das_xml_object_create; + sdo_das_xml_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + + memcpy(&sdo_das_xml_object_handlers, zend_get_std_object_handlers(), + sizeof(zend_object_handlers)); + sdo_das_xml_object_handlers.clone_obj = NULL; } /* }}} */ -/* {{{ proto SDO_DAS_XML SDO_DAS_XML::addTypes(string xsd_file) +/* {{{ PHP_METHOD(SDO_DAS_XML, __construct) */ -PHP_METHOD(SDO_DAS_XML, addTypes) +PHP_METHOD(SDO_DAS_XML, __construct) { - xmldas_object* xmldas = NULL; - char* file_name; - int len = 0; - zval * retval = NULL; - zend_class_entry *ce = NULL; - zval *this_obj = getThis(); - ostringstream print_buf; - - // TODO lots of code duplicated with create() - - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name,&len) == FAILURE) { - RETURN_FALSE; - } - if (!len) { - RETURN_FALSE; - } - - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if(!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::addTypes - Unable to get XMLDAS object from object store"); - } - try { - xmldas->targetNamespaceURI = xmldas->xsdHelper->defineFile(file_name); - - int error_count = xmldas->xsdHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - ostringstream print_buf; - - print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xsdHelper->getErrorMessage(error_ix); - } - string print_string = print_buf.str(); - sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); - } - } catch (SDOFileNotFoundException e) { - sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); - } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); - } + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ - /* {{{ proto SDO_DAS_XML SDO_DAS_XML::create(string xsd_file) */ PHP_METHOD(SDO_DAS_XML, create) @@ -325,589 +189,553 @@ * Returns : * SDO_DAS_XML object with model information built-in *****************************************************************************/ - xmldas_object* xmldas = NULL; - char* file_name; - int len = 0; - zval * retval = NULL; - zend_class_entry *ce = NULL; - sdo_das_df_object *das_df_obj; - DataFactoryPtr dataFactory; + xmldas_object *xmldas; + char *file_name; + int file_name_len; + DataFactoryPtr dataFactoryPtr; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() > 1) { WRONG_PARAM_COUNT; } + Z_TYPE_P(return_value) = IS_OBJECT; if (object_init_ex(return_value, sdo_das_xml_class_entry) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to create SDO_DAS_XML"); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; - } - + } xmldas = (xmldas_object *) zend_object_store_get_object(return_value TSRMLS_CC); - dataFactory = DataFactory::getDataFactory(); - xmldas->dataFactory = dataFactory; - xmldas->xsdHelper = HelperProvider::getXSDHelper((DataFactory*)dataFactory); - xmldas->xmlHelper = HelperProvider::getXMLHelper((DataFactory*)dataFactory); + /* Create a C++ DataFactory and an SDO_DAS_DataFactory wrapper for it */ + dataFactoryPtr = DataFactory::getDataFactory(); + INIT_ZVAL(xmldas->z_df); + sdo_das_df_new(&xmldas->z_df, dataFactoryPtr TSRMLS_CC); + + xmldas->xsdHelperPtr = HelperProvider::getXSDHelper((DataFactory *)dataFactoryPtr); + xmldas->xmlHelperPtr = HelperProvider::getXMLHelper((DataFactory *)dataFactoryPtr); if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name,&len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { RETURN_FALSE; } - if(!len) { + if(!file_name_len) { RETURN_FALSE; } try { - xmldas->targetNamespaceURI = xmldas->xsdHelper->defineFile(file_name); + xmldas->xsdHelperPtr->defineFile(file_name); - int error_count = xmldas->xsdHelper->getErrorCount(); + int error_count = xmldas->xsdHelperPtr->getErrorCount(); if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - ostringstream print_buf; - - print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xsdHelper->getErrorMessage(error_ix); - } + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::create - Unable to parse the supplied xsd file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xsdHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } catch (SDOFileNotFoundException e) { sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + +} +/* }}} end SDO_DAS_XML::create */ + +/* {{{ proto SDO_DAS_XML SDO_DAS_XML::addTypes(string xsd_file) + */ +PHP_METHOD(SDO_DAS_XML, addTypes) +{ + xmldas_object *xmldas; + char *file_name; + int file_name_len; + bool exception_thrown = false; + + // TODO lots of code duplicated with create() - /******************************************************************** - * Instantiate an SDO_DAS_DataFactoryImpl object now. Fill in with the - * dataFactory that we created above. - ********************************************************************/ - ce = zend_fetch_class("SDO_DAS_DataFactoryImpl", - strlen("SDO_DAS_DataFactoryImpl"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (!ce) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to fetch SDO_DAS_DataFactoryImpl class"); - RETURN_NULL(); + if (ZEND_NUM_ARGS() != 1) { + WRONG_PARAM_COUNT; } - MAKE_STD_ZVAL(retval); - if (object_init_ex(retval, ce) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to create SDO_DAS_DataFactoryImpl"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { + RETURN_FALSE; + } + if (!file_name_len) { + RETURN_FALSE; } - das_df_obj = (sdo_das_df_object *) zend_object_store_get_object(retval TSRMLS_CC); - if(!das_df_obj) { - php_error(E_ERROR, "SDO_DAS_XML::create - Unable to get SDO_DAS_DataFactory object from object store"); - } - das_df_obj->dfp = dataFactory; - xmldas->php_das_df = retval; - zend_objects_store_add_ref(xmldas->php_das_df TSRMLS_CC); + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + try { + xmldas->xsdHelperPtr->defineFile(file_name); + + int error_count = xmldas->xsdHelperPtr->getErrorCount(); + if (error_count > 0) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::addTypes - Unable to parse the supplied xsd file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xsdHelperPtr->getErrorMessage(error_ix); + } + string print_string = print_buf.str(); + sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); + RETURN_NULL(); + } + } catch (SDOFileNotFoundException e) { + sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); + exception_thrown = true; + } catch (SDOXMLParserException *e) { + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; + } catch (SDORuntimeException e) { + sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); + exception_thrown = true; + } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + } -/* }}} end SDO_DAS_XML::create */ +/* }}} */ -/* {{{ proto SDO_XMLDocument SDO_DAS_XML::loadFromFile(string xml_file) +/* {{{ proto SDO_XMLDocument SDO_DAS_XML::loadFile(string xml_file) */ -PHP_METHOD(SDO_DAS_XML, loadFromFile) +PHP_METHOD(SDO_DAS_XML, loadFile) { /* * Returns XMLDocument Object containing root SDO object built from the * given path to xml instance document. */ - xmldocument_object *doc_obj = NULL; - xmldas_object *xmldas = NULL; - char* file_name; - int len = 0; - zval *this_obj = getThis(); - zend_class_entry *ce = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *file_name; + int file_name_len; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) { RETURN_FALSE; } - if (len) { + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (file_name_len) { Z_TYPE_P(return_value) = IS_OBJECT; - ce = zend_fetch_class("SDO_DAS_XML_Document", - strlen("SDO_DAS_XML_Document"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (object_init_ex(return_value, ce) == FAILURE) { - php_error(E_ERROR,"SDO_DAS_XML::loadFile - Unable to create SDO_DAS_XML"); + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); RETURN_NULL(); } - doc_obj = (xmldocument_object *) zend_object_store_get_object(return_value TSRMLS_CC); - if (!doc_obj) { - php_error(E_ERROR, "SDO_DAS_XML::loadFile - Unable to get XMLDocument object from object store"); + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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_NULL(); } - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if(!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::loadFromFile - Unable to get XMLDAS object from object store"); - } + try { - doc_obj->xdoch = xmldas->xmlHelper->loadFile(file_name,xmldas->targetNamespaceURI); - if (doc_obj->xdoch && doc_obj->xdoch->getRootDataObject() && (xmldas->xmlHelper->getErrorCount() == 0)) { - create_dataobject_tree(doc_obj->xdoch->getRootDataObject() TSRMLS_CC); - } else { - ostringstream print_buf; - print_buf << "SDO_DAS_XML::loadFromFile - Unable to obtain a root data object from the supplied XML\n"; - int error_count = xmldas->xmlHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\" (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the file \"" << file_name << "\":\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xmlHelper->getErrorMessage(error_ix); - } - } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->loadFile(file_name); + int error_count = xmldas->xmlHelperPtr->getErrorCount(); + if ((error_count > 0) || + (!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::loadFile - Unable to parse the supplied xml file\n"; + print_buf << error_count << " parse error(s) occurred when parsing the file '" << file_name << "'"; + if (error_count > MAX_ERRORS) { + print_buf << " (only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n"; + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xmlHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); RETURN_NULL(); } } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char *)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch (SDOFileNotFoundException e) { sdo_das_xml_throw_fileexception(file_name TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } else { RETURN_FALSE; } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } + } /* }}} SDO_DAS_XML::loadFile */ -/* {{{ proto SDO_DAS_XML_Document SDO_DAS_XML::loadFromString(string xml_string) +/* {{{ proto SDO_DAS_XML_Document SDO_DAS_XML::loadString(string xml_string) */ -PHP_METHOD(SDO_DAS_XML, loadFromString) +PHP_METHOD(SDO_DAS_XML, loadString) { /* Returns SDO_DAS_XML_Document Object containing root SDO object built from the given xml string. */ - xmldocument_object *doc_obj = NULL; - xmldas_object *xmldas = NULL; - char* xml_string; - int len = 0; - zval *this_obj = getThis(); - zend_class_entry *ce = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *xml_string; + int xml_string_len; + char *class_name, *space; + bool exception_thrown = false; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_string, &len) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_string, &xml_string_len) == FAILURE) { RETURN_FALSE; } - if (len) { + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (xml_string_len) { Z_TYPE_P(return_value) = IS_OBJECT; - ce = zend_fetch_class("SDO_DAS_XML_Document", strlen("SDO_DAS_XML_Document"), - ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (object_init_ex(return_value, ce) == FAILURE) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to create SDO_DAS_XML"); + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } - doc_obj = (xmldocument_object *) zend_object_store_get_object(return_value TSRMLS_CC); - if (!doc_obj) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to get SDO_DAS_XML_Document object from object store"); - } - xmldas = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!xmldas) { - php_error(E_ERROR, "SDO_DAS_XML::load - Unable to get SDO_DAS_XML object from object store"); - } + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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__); + } + try { istringstream str((const char *)xml_string); - doc_obj->xdoch = xmldas->xmlHelper->load(str); - if (doc_obj->xdoch && doc_obj->xdoch->getRootDataObject() && (xmldas->xmlHelper->getErrorCount() == 0)) { - create_dataobject_tree(doc_obj->xdoch->getRootDataObject() TSRMLS_CC); - } else { - ostringstream print_buf; - print_buf << "SDO_DAS_XML::loadFromString - Unable to obtain a root data object from the supplied XML\n"; - int error_count = xmldas->xmlHelper->getErrorCount(); - if (error_count > 0) { - int max_errors = 50; - int error_ix = 0; - - if (error_count > max_errors) { - print_buf << error_count << " parse error(s) occured when parsing the XML string (only the first " << max_errors << " shown):\n"; - } else { - print_buf << error_count << " parse error(s) occured when parsing the XML string:\n"; - } - for (error_ix = 0; error_ix < min(error_count,max_errors); error_ix++) { - print_buf << error_ix << ") " << xmldas->xmlHelper->getErrorMessage(error_ix); - } - } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->load(str); + int error_count = xmldas->xmlHelperPtr->getErrorCount(); + if ((error_count > 0) || + (!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + ostringstream print_buf; + + print_buf << "SDO_DAS_XML::loadString - Unable to parse the supplied xml string\n"; + print_buf << error_count << " parse error(s) occurred when parsing the string"; + if (error_count > MAX_ERRORS) { + print_buf << "(only the first " << MAX_ERRORS << " shown)"; + } + print_buf << ":\n" ; + + for (int error_ix = 0; error_ix < min(error_count, MAX_ERRORS); error_ix++) { + print_buf << error_ix + 1 << ". " << xmldas->xmlHelperPtr->getErrorMessage(error_ix); + } string print_string = print_buf.str(); sdo_das_xml_throw_parserexception((char *)print_string.c_str() TSRMLS_CC); - RETURN_NULL(); + RETURN_NULL(); } } catch (SDOXMLParserException *e) { - const char* msg = e->getMessageText(); - sdo_das_xml_throw_parserexception((char*)msg TSRMLS_CC); - RETURN_NULL(); + sdo_das_xml_throw_parserexception((char*)e->getMessageText() TSRMLS_CC); + exception_thrown = true; } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - RETURN_NULL(); + exception_thrown = true; } } else { RETURN_FALSE; } + if (exception_thrown) { + /** + * we set a flag and then do the return from here, because returning out of the catch block + * (i.e. doing RETURN_NULL() inside the catch block) would cause a crash in PHP or MSCVRT soon + * after. Matthew saw this but not Caroline, and only with optimised build, so perhaps something + * specific to particular level of compiler. + */ + RETURN_NULL(); + } } /* }}} SDO_DAS_XML::load */ - -/* {{{ proto SDO_DataObject SDO_DAS_XML::createDataObject(string namespace_uri, string type_name) +/* {{{ proto void SDO_DAS_XML::saveFile(SDO_XMLDocument xdoc, string xml_file) */ -PHP_METHOD(SDO_DAS_XML, createDataObject) +PHP_METHOD(SDO_DAS_XML, saveFile) { - /* - * Returns SDO_DataObject for a given namespace_uri and the type name. - */ - xmldas_object *obj = NULL; - zval *this_obj = getThis(); - zval *namespace_uri = NULL; - zval *type_name = NULL; - zval *retval; + zval *z_document; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *xml_file; + int xml_file_len = 0; + long indent = -1; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 2) { + if (ZEND_NUM_ARGS() != 2 && ZEND_NUM_ARGS() != 3) { WRONG_PARAM_COUNT; } + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", - &namespace_uri, &type_name) == FAILURE) { - RETURN_FALSE; - } - - obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, "SDO_DAS_XML::createDataObject - Unable to get SDO_DAS_XML object from object store"); - } - zend_call_method(&obj->php_das_df, Z_OBJCE_P(obj->php_das_df), NULL, - "create", strlen("create"), &retval, 2, namespace_uri, - type_name TSRMLS_CC); - /* - *TODO, Check are we leaking memory here? - */ - if (retval) { - RETVAL_ZVAL(retval, 1, 0); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML::createDataObject */ - - -/* {{{ proto string SDO_DAS_XML::saveDocumentToString(SDO_XMLDocument xdoc) - */ -PHP_METHOD(SDO_DAS_XML, saveDocumentToString) -{ - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldocument_object *xml_doc_ptr; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; - - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&xml_doc_obj) == FAILURE) { - RETURN_FALSE; - } - xml_doc_ptr = (xmldocument_object *) zend_object_store_get_object(xml_doc_obj TSRMLS_CC); - if (!xml_doc_ptr) { - php_error(E_ERROR, "SDO_DAS_XML::saveDocumentToString - Unable to get SDO_DAS_XML_Document object from object store"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", + &z_document, sdo_das_xml_document_class_entry, &xml_file, + &xml_file_len, &indent) == FAILURE) { + RETURN_FALSE; + } + + xmldocument = (xmldocument_object *) zend_object_store_get_object(z_document 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__); } try { - retval = das_obj->xmlHelper->save(xml_doc_ptr->xdoch); + xmldas->xmlHelperPtr->save(xmldocument->xmlDocumentPtr, xml_file, indent); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } - ret_string = (char *)emalloc(strlen(retval) + 1); - memset(ret_string, 0, strlen(retval) + 1); - strcpy(ret_string, retval); - /* - * retval to be freed using "delete" as it was - * allocated using "new" in save method - */ - delete retval; - RETVAL_STRING((char *)ret_string, 0); } /* }}} */ - -/* {{{ proto void SDO_DAS_XML::saveDocumentToFile(SDO_XMLDocument xdoc, string xml_file) +/* {{{ proto string SDO_DAS_XML::saveString(SDO_XMLDocument xdoc) */ -PHP_METHOD(SDO_DAS_XML, saveDocumentToFile) +PHP_METHOD(SDO_DAS_XML, saveString) { - char *xml_file = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldocument_object *xml_doc_ptr; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + zval *z_document; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + long indent = -1; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 2) { + if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", - &xml_doc_obj, &xml_file, - &file_len) == FAILURE) { - RETURN_FALSE; - } - xml_doc_ptr = (xmldocument_object *) zend_object_store_get_object(xml_doc_obj TSRMLS_CC); - if (!xml_doc_ptr) { - php_error(E_ERROR, "SDO_DAS_XML::save - Unable to get SDO_DAS_XML_Document object from object sotre"); + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", + &z_document, sdo_das_xml_document_class_entry, &indent) == FAILURE) { + RETURN_FALSE; + } + + xmldocument = (xmldocument_object *) zend_object_store_get_object(z_document 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__); } try { - das_obj->xmlHelper->save(xml_doc_ptr->xdoch, xml_file); + char *retval = xmldas->xmlHelperPtr->save(xmldocument->xmlDocumentPtr, indent); + RETVAL_STRING(retval, 1); + /* + * retval to be freed using "delete" as it was + * allocated using "new" in save method + */ + delete retval; } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ - -/* {{{ proto string SDO_DAS_XML::saveDataObjectToString(SDO_DataObject do, string root_uri, string root_name) +/* {{{ proto SDO_DAS_XML SDO_DAS_XML::createDocument(empty | typename | uri,typename) */ -PHP_METHOD(SDO_DAS_XML, saveDataObjectToString) +PHP_METHOD(SDO_DAS_XML, createDocument) { - char *root_uri = NULL; - char *root_name = NULL; - zval *data_obj = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + xmldocument_object *xmldocument; + xmldas_object *xmldas; + char *namespace_uri; + char *element_name; + int namespace_uri_len; + int element_name_len; + char *class_name, *space; - if (ZEND_NUM_ARGS() != 3) { + if (ZEND_NUM_ARGS() > 2) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zss", - &data_obj, &root_uri, &uri_len, - &root_name, &name_len) == FAILURE) { - RETURN_FALSE; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - php_do = (sdo_do_object *) zend_object_store_get_object(data_obj TSRMLS_CC); - if (!php_do) { - php_error(E_ERROR, "XML_DAS::save - We are unable to get SDO_DataObject from object store"); + + Z_TYPE_P(return_value) = IS_OBJECT; + if (object_init_ex(return_value, sdo_das_xml_document_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); + RETURN_NULL(); + } + xmldocument = (xmldocument_object *) zend_object_store_get_object(return_value 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_NULL(); } + + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); + try { - retval = das_obj->xmlHelper->save(php_do->dop, root_uri, root_name); - } catch (SDORuntimeException e) { + if (ZEND_NUM_ARGS() == 2) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &namespace_uri, &namespace_uri_len, &element_name, &element_name_len) == FAILURE) { + RETURN_FALSE; + } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(element_name, namespace_uri); + } else if (ZEND_NUM_ARGS() == 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &element_name, &element_name_len) == FAILURE) { + RETURN_FALSE; + } + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(element_name); + } else { + xmldocument->xmlDocumentPtr = xmldas->xmlHelperPtr->createDocument(); + } + if ((!xmldocument->xmlDocumentPtr) || + (!xmldocument->xmlDocumentPtr->getRootDataObject())) { + RETURN_NULL(); + } + } catch(SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); + RETURN_NULL(); } - ret_string = (char *)emalloc(strlen(retval) + 1); - memset(ret_string, 0, strlen(retval) + 1); - strcpy(ret_string, retval); - /* - * retval to be freed using "delete" as it was - * allocated using "new" in save method - */ - delete retval; - RETVAL_STRING((char *)ret_string, 0); + } -/* }}} */ +/* }}} end SDO_DAS_XML::create */ -/* {{{ proto void SDO_DAS_XML::saveDataObjectToFile(SDO_DataObject do, string root_uri, string root_name string xml_file) +/* {{{ proto SDO_DataObject SDO_DAS_XML::createDataObject(string namespace_uri, string type_name) */ -PHP_METHOD(SDO_DAS_XML, saveDataObjectToFile) +PHP_METHOD(SDO_DAS_XML, createDataObject) { - char *xml_file = NULL; - char *root_uri = NULL; - char *root_name = NULL; - zval *data_obj = NULL; - zval *xml_doc_obj = NULL; - zval *this_obj = getThis(); - sdo_do_object *php_do = NULL; - xmldas_object *das_obj = NULL; - int uri_len = 0, name_len = 0, file_len = 0; - char *retval = NULL; - char *ret_string = NULL; + /* + * Returns SDO_DataObject for a given namespace_uri and the type name. + */ + xmldas_object *xmldas; + zval *z_namespace_uri; + zval *z_type_name; + zval *z_do, *z_df; - if (ZEND_NUM_ARGS() != 4) { + if (ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsss", - &data_obj, &root_uri, &uri_len, &root_name, - &name_len, &xml_file, - &file_len) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", + &z_namespace_uri, &z_type_name) == FAILURE) { RETURN_FALSE; } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - php_do = (sdo_do_object *) zend_object_store_get_object(data_obj TSRMLS_CC); - if (!php_do) { - php_error(E_ERROR, "SDO_DAS_XML::save - We are unable to get SDO_DataObject from object store"); - } - try { - das_obj->xmlHelper->save(php_do->dop, root_uri, root_name, xml_file); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto void SDO_DAS_XML::getTypes() - */ -PHP_METHOD(SDO_DAS_XML, getTypes) -{ - xmldas_object *das_obj = NULL; - zval* this_obj = getThis(); - char* namespace_uri = NULL; - char* type_name = NULL; - int namespace_uri_len = 0; - int type_name_len = 0; + xmldas = (xmldas_object *) zend_object_store_get_object(getThis() TSRMLS_CC); -printf("entered get types\n"); + /* Invoke SDO_DAS_DataFactory::create */ + z_df = &xmldas->z_df; + zend_call_method(&z_df, Z_OBJCE(xmldas->z_df), NULL, + "create", strlen("create"), &z_do, 2, z_namespace_uri, + z_type_name TSRMLS_CC); + RETVAL_ZVAL(z_do, 0, 1); - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!das_obj) { - php_error(E_ERROR, "SDO_DAS_XML::getTypes - Unable to get SDO_DAS_XML object from object store"); - } - - TypeList t = das_obj->dataFactory->getTypes(); - int count = t.size(); - printf("%d types defined\n", count); - for (int i = 0; i < count ; i++) { - printf ("%i %s\n", i, t[i].getName()); - } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", -// &namespace_uri,&namespace_uri_len, &type_name, &type_name_len) == FAILURE) { -// RETURN_FALSE; -// } - // at this point we have char* versions of uri and type name - // TODO: get a property of the requested type from Hydra - // pass to SDO_Model_Property::sdo_model_property_new - // return to the user - return; } -/* }}} */ +/* }}} SDO_DAS_XML::createDataObject */ /* {{{ xmldas_cast_object */ -static int xmldas_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) +static void xmldas_cast_object(zval *readobj, zval *writeobj TSRMLS_DC) { - xmldas_object *my_object; - ostringstream print_buf; - zval free_obj; - int rc = SUCCESS; - const char *indent = "\n"; - - if (should_free) { - free_obj = *writeobj; - } - - my_object = (xmldas_object *) zend_object_store_get_object(readobj TSRMLS_CC); - if (!my_object) { - php_error(E_ERROR, "SDO_DAS_XML::cast object - Unable to get SDO_DAS_XML object from object store"); - } else { - try { - print_buf << indent << "object(" << "SDO_DAS_XML" << ")#" << readobj->value.obj.handle << " {"; - TypeList t = my_object->dataFactory->getTypes(); - int count = t.size(); - print_buf << "\n" << count << " types defined:\n"; - for (int i = 0; i < count ; i++) { - if (strlen (t[i].getURI()) == 0) { - print_buf << " " << i << " " << "(no namespace)" << ":" << t[i].getName() << "\n"; - } else { - print_buf << " " << i << " " << t[i].getURI() << ":" << t[i].getName() << "\n"; - } - } - print_buf << "}"; - - 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; + xmldas_object *xmldas; + ostringstream print_buf; + const char *indent = "\n"; + DataFactoryPtr dataFactoryPtr; + + xmldas = (xmldas_object *) zend_object_store_get_object(readobj TSRMLS_CC); + + try { + dataFactoryPtr = sdo_das_df_get(&xmldas->z_df TSRMLS_CC); + TypeList tl = dataFactoryPtr->getTypes(); + print_buf << indent << "object(" << "SDO_XML_DAS" << ")#" << + readobj->value.obj.handle << " {"; + print_buf << indent << tl.size() << " types have been defined. The types and their properties are::"; + + for (int ix = 0; ix < tl.size(); ix++) { + if (tl[ix].getURI() == NULL || strlen(tl[ix].getURI()) == 0) { + print_buf << indent << ix+1 << ". " << "{no namespace)" << ":" << tl[ix].getName(); + } else { + print_buf << indent << ix+1 << ". " << tl[ix].getURI() << ":" << tl[ix].getName(); + } + PropertyList pl = tl[ix].getProperties(); + for (int px = 0; px < pl.size() ; px++) { + print_buf << indent << " - " << pl[px].getName() << " (" ; + if (pl[px].getType().getURI() == NULL || strlen(pl[px].getType().getURI()) == 0) { + print_buf << "{no namespace)" << ":" << pl[px].getType().getName(); + } else { + print_buf << pl[px].getType().getURI() << ":" << pl[px].getType().getName(); + } + print_buf << ")"; + } } + + print_buf << indent << "}"; + + 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); } - - if (should_free) { - zval_dtor(&free_obj); - } - return rc; + } /* }}} */ + + /* {{{ SDO_DAS_XML::__toString */ PHP_METHOD(SDO_DAS_XML, __toString) { - xmldas_cast_object(getThis(), return_value, IS_STRING, 0 TSRMLS_CC); + xmldas_cast_object(getThis(), return_value TSRMLS_CC); } /* }}} */ -/* {{{ proto void SDO_DAS_XML::getProperty() - */ -PHP_METHOD(SDO_DAS_XML, getProperty) -{ - xmldas_object *das_obj = NULL; - zval* this_obj = getThis(); - char* namespace_uri = NULL; - char* type_name = NULL; - int namespace_uri_len = 0; - int type_name_len = 0; - - // TODO - // When the rest of open types is ready, re-enable and complete this method - if (ZEND_NUM_ARGS() != 2) { - WRONG_PARAM_COUNT; - } - das_obj = (xmldas_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!das_obj) { - php_error(E_ERROR, "SDO_DAS_XML::getProperty - Unable to get SDO_DAS_XML object from object store"); - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", - &namespace_uri,&namespace_uri_len, &type_name, &type_name_len) == FAILURE) { - RETURN_FALSE; - } - // at this point we have char* versions of uri and type name - // TODO: get a property of the requested type from Hydra - // pass to SDO_Model_Property::sdo_model_property_new - // return to the user - return; -} -/* }}} */ - /* * Local variables: * tab-width: 4 http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DAS_XML_Document.cpp?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/SDO_DAS_XML_Document.cpp diff -u pecl/sdo/SDO_DAS_XML_Document.cpp:1.9 pecl/sdo/SDO_DAS_XML_Document.cpp:1.10 --- pecl/sdo/SDO_DAS_XML_Document.cpp:1.9 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/SDO_DAS_XML_Document.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DAS_XML_Document.cpp,v 1.9 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: SDO_DAS_XML_Document.cpp,v 1.10 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -31,33 +31,24 @@ #include "php_sdo_das_xml_int.h" -// Forward declarations for ths module only -zend_object_value sdo_das_xml_document_object_create(zend_class_entry *ce TSRMLS_DC); -void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC); +#define CLASS_NAME "SDO_DAS_XML_Document" -zend_object_handlers sdo_das_xml_doc_object_handlers; +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_setEncoding_args, 0) - ZEND_ARG_INFO(0, encoding) -ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLDeclaration_args, 0) - ZEND_ARG_INFO(0, xmlDeclaration) + ZEND_ARG_INFO(0, xml_declaration) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setXMLVersion_args, 0) - ZEND_ARG_INFO(0, xmlVersion) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setSchemaLocation_args, 0) - ZEND_ARG_INFO(0, schemaLocation) + ZEND_ARG_INFO(0, xml_version) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setNoNamespaceSchemaLocation_args, 0) - ZEND_ARG_INFO(0, noNamespaceSchemaLocation) +ZEND_BEGIN_ARG_INFO(sdo_xmldoc_setEncoding_args, 0) + ZEND_ARG_INFO(0, encoding) ZEND_END_ARG_INFO(); -/* argument definations of SDO_DAS_XML_Document class, end */ +/* argument definitions of SDO_DAS_XML_Document class, end */ /* {{{ sdo_xmldocument_methods * @@ -67,120 +58,98 @@ 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, getEncoding, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setEncoding, - sdo_xmldoc_setEncoding_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getXMLDeclaration, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DAS_XML_Document, setXMLDeclaration, sdo_xmldoc_setXMLDeclaration_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getXMLVersion, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DAS_XML_Document, setXMLVersion, sdo_xmldoc_setXMLVersion_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getSchemaLocation, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setSchemaLocation, - sdo_xmldoc_setSchemaLocation_args, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation, 0, - ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation, - sdo_xmldoc_setNoNamespaceSchemaLocation_args, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DAS_XML_Document, setEncoding, + sdo_xmldoc_setEncoding_args, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ - -/* {{{ initialize_sdo_das_xml_document_class - * - * Initializes SDO_DAS_XML_Document class +/* {{{ sdo_das_xml_document_free_storage */ -void -initialize_sdo_das_xml_document_class(TSRMLS_D) { - zend_class_entry ce; - zend_class_entry* sdo_das_xml_doc_cls_entry; - - 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_doc_cls_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.clone_obj = NULL; +void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC) +{ + + xmldocument_object *xmldocument = (xmldocument_object *) object; + zend_hash_destroy(xmldocument->zo.properties); + FREE_HASHTABLE(xmldocument->zo.properties); + + if (xmldocument->xmlDocumentPtr) { + delete xmldocument->xmlDocumentPtr; + } + 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 *obj = (xmldocument_object *) - emalloc(sizeof(xmldocument_object)); - memset(obj, 0, sizeof(xmldocument_object)); - - obj->z_obj.ce = ce; - ALLOC_HASHTABLE(obj->z_obj.properties); - zend_hash_init(obj->z_obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(obj->z_obj.properties, &ce->default_properties, - (copy_ctor_func_t) zval_add_ref, (void *) &tmp, - sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, NULL, - sdo_das_xml_document_object_free_storage, - NULL TSRMLS_CC); +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; + 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, NULL, + sdo_das_xml_document_object_free_storage, + NULL TSRMLS_CC); retval.handlers = &sdo_das_xml_doc_object_handlers; return retval; } /* }}} */ - -/* {{{ sdo_das_xml_document_free_storage +/* {{{ sdo_das_xml_document_minit + * + * Initializes SDO_DAS_XML_Document class */ -void sdo_das_xml_document_object_free_storage(void *object TSRMLS_DC) { - - xmldocument_object *obj = (xmldocument_object *) object; - zend_hash_destroy(obj->z_obj.properties); - FREE_HASHTABLE(obj->z_obj.properties); +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); - if (obj->xdoch) { - delete obj->xdoch; - } - efree(obj); + memcpy(&sdo_das_xml_doc_object_handlers, zend_get_std_object_handlers(), + sizeof(zend_object_handlers)); + sdo_das_xml_doc_object_handlers.clone_obj = NULL; } /* }}} */ - -/* {{{ proto SDO_DataObject SDO_DAS_XML_Document::getRoorDataObject() +/* {{{ proto SDO_DataObject SDO_DAS_XML_Document::getRootDataObject() Returns the root SDO_DataObject. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootDataObject) { - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - zval *retval = NULL; - zend_object *php_das_obj = NULL; - DataObject *root_do = NULL; - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } +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 = obj->xdoch->getRootDataObject(); + root_do = xmldocument->xmlDocumentPtr->getRootDataObject(); if (!root_do) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to find root DataObject"); - RETURN_NULL(); - } - retval = (zval *) root_do->getUserData(); - if (!retval) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootDataObject - Unable to find php version of root DataObject"); + 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); } - RETVAL_ZVAL(retval, 1, 0); } /* }}} SDO_DAS_XML_Document::getRootDataObject */ @@ -188,31 +157,22 @@ /* {{{ proto string SDO_DAS_XML_Document::getRootElementURI() Returns root element URI string. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI) +{ + xmldocument_object *xmldocument; + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootElementURI - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); + try { - retval = obj->xdoch->getRootElementURI(); + RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementURI(), 1); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); RETURN_NULL(); } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } + } /* }}} SDO_DAS_XML_Document::getRootElementURI */ @@ -220,206 +180,48 @@ /* {{{ proto string SDO_DAS_XML_Document::getRootElementName() Returns root element name. */ -PHP_METHOD(SDO_DAS_XML_Document, getRootElementName) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getRootElementName - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getRootElementName(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getRootElementName */ - - -/* {{{ proto string SDO_DAS_XML_Document::getEncoding() - Returns encoding string. - */ -PHP_METHOD(SDO_DAS_XML_Document, getEncoding) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getEncoding - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getEncoding(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getEncoding */ - - -/* {{{ proto boolean SDO_DAS_XML_Document::getXMLDeclaration() - Returns whethe xml declaration is set or not. - */ -PHP_METHOD(SDO_DAS_XML_Document, getXMLDeclaration) { - bool retval; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getXMLDeclaration - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getXMLDeclaration(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - RETVAL_BOOL(retval); -} -/* }}} SDO_DAS_XML_Document::getXMLDeclaration */ - +PHP_METHOD(SDO_DAS_XML_Document, getRootElementName) +{ + xmldocument_object *xmldocument; -/* {{{ proto string SDO_DAS_XML_Document::getXMLVersion() - Returns xml declaration string. - */ -PHP_METHOD(SDO_DAS_XML_Document, getXMLVersion) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getXMLVersion - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getXMLVersion(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getXMLVersion */ - + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); -/* {{{ proto string SDO_DAS_XML_Document::getSchemaLocation() - Returns schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, getSchemaLocation) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } try { - retval = obj->xdoch->getSchemaLocation(); + RETVAL_STRING((char *)xmldocument->xmlDocumentPtr->getRootElementName(), 1); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } -} -/* }}} SDO_DAS_XML_Document::getSchemaLocation */ - -/* {{{ proto string SDO_DAS_XML_Document::getNoNamespaceSchemaLocation() - Returns no namespace schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation) { - const char *retval = NULL; - int len = 0; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - obj = (xmldocument_object *)zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::getNoNamespaceSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - retval = obj->xdoch->getNoNamespaceSchemaLocation(); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - if (retval) { - RETVAL_STRING((char *)retval, 1); - } else { - RETVAL_NULL(); - } } -/* }}} SDO_DAS_XML_Document::getNoNamespaceSchemaLocation */ - +/* }}} 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) { - bool xmlDeclaration; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +PHP_METHOD(SDO_DAS_XML_Document, setXMLDeclaration) +{ + long 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", &xmlDeclaration) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &xml_declaration) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setXMLDeclaration - Unable to get SDO_DAS_XML_Document Object from object store"); + 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 { - obj->xdoch->setXMLDeclaration(xmlDeclaration); + xmldocument->xmlDocumentPtr->setXMLDeclaration(ZEND_TRUTH(xml_declaration)); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } @@ -427,123 +229,52 @@ } /* }}} 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 *xmlVersion = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xmlVersion, &len) == FAILURE) { - RETURN_FALSE; - } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setXMLVersion - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - obj->xdoch->setXMLVersion(xmlVersion); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - return; -} -/* }}} SDO_DAS_XML_Document::setXMLVersion */ - +PHP_METHOD(SDO_DAS_XML_Document, setXMLVersion) +{ + char *xml_version; + int xml_version_len; + xmldocument_object *xmldocument; -/* {{{ proto void SDO_DAS_XML_Document::setSchemaLocation(string schemaLocation) - Sets the given string as schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, setSchemaLocation) { - char *schemaLocation = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaLocation, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xml_version, &xml_version_len) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - try { - obj->xdoch->setSchemaLocation(schemaLocation); - } catch (SDORuntimeException e) { - sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); - } - return; -} -/* }}} SDO_DAS_XML_Document::setSchemaLocation */ - + xmldocument = (xmldocument_object *) zend_object_store_get_object(getThis() TSRMLS_CC); -/* {{{ proto void SDO_DAS_XML_Document::setNoNamespaceSchemaLocation(string nnschemaLocation) - Sets the given string as no namespace schema location. - */ -PHP_METHOD(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation) { - char *nnSchemaLocation = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &nnSchemaLocation, &len) == FAILURE) { - RETURN_FALSE; - } - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setNoNamespaceSchemaLocation - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } try { - obj->xdoch->setNoNamespaceSchemaLocation(nnSchemaLocation); + xmldocument->xmlDocumentPtr->setXMLVersion(xml_version); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } + return; } -/* }}} SDO_DAS_XML_Document::setNoNamespaceSchemaLocation */ - +/* }}} 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 = NULL; - int len; - zval *this_obj = getThis(); - xmldocument_object *obj = NULL; +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, &len) == FAILURE) { + &encoding, &encoding_len) == FAILURE) { RETURN_FALSE; } - obj = (xmldocument_object *) - zend_object_store_get_object(this_obj TSRMLS_CC); - if (!obj) { - php_error(E_ERROR, - "SDO_DAS_XML_Document::setEncoding - Unable to get SDO_DAS_XML_Document Object from object store"); - RETURN_NULL(); - } - + xmldocument = (xmldocument_object *)zend_object_store_get_object(getThis() TSRMLS_CC); + try { - obj->xdoch->setEncoding(encoding); + xmldocument->xmlDocumentPtr->setEncoding(encoding); } catch (SDORuntimeException e) { sdo_das_xml_throw_runtimeexception(&e TSRMLS_CC); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_DataObject.cpp?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/SDO_DataObject.cpp diff -u pecl/sdo/SDO_DataObject.cpp:1.12 pecl/sdo/SDO_DataObject.cpp:1.13 --- pecl/sdo/SDO_DataObject.cpp:1.12 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_DataObject.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_DataObject.cpp,v 1.12 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_DataObject.cpp,v 1.13 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -36,6 +36,16 @@ #define CLASS_NAME "SDO_DataObject" +/** {{{ sdo_do_object + * The internal structure for an SDO_DataObjectImpl + * This extends the standard zend_object + */ +typedef struct { + zend_object zo; /* The standard zend_object */ + DataObjectPtr dop; /* The C++ DataObject */ +} sdo_do_object; +/* }}} */ + /* {{{ sdo_do_iterator * The iterator data for this class - extends the standard zend_object_iterator */ @@ -63,16 +73,27 @@ */ static void sdo_do_object_free_storage(void *object TSRMLS_DC) { - sdo_do_object *my_object; + sdo_do_object *my_object; + char *space; + char *class_name; my_object = (sdo_do_object *)object; zend_hash_destroy(my_object->zo.properties); FREE_HASHTABLE(my_object->zo.properties); /* just release the reference, and the reference counting will kick in */ - /*TODO assigning NULL triggers an error in the C++ library at shutdown. - *my_object->dop = NULL; - */ + if (my_object->dop) { + try { + my_object->dop->setUserData((void *)SDO_USER_DATA_EMPTY); + + /* causes an Access Violation :-( */ + //my_object->dop = NULL; + } catch (SDORuntimeException e) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): internal error - caught exception freeing DataObject", + class_name, space, get_active_function_name(TSRMLS_C)); + } + } efree(object); } /* }}} */ @@ -99,6 +120,69 @@ } /* }}} */ +/* {{{ sdo_do_get + * utility function to get C++ DataObject from zval + */ +DataObjectPtr sdo_do_get(zval *me TSRMLS_DC) +{ + sdo_do_object *my_object; + + my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); + if (my_object) + return my_object->dop; + else + return NULL; +} +/* }}} */ + +/* {{{ sdo_do_new + * Find the PHP object corresponding to the CPP object, or create one. + * The DataObject has no public constructor, this is in effect its factory method. + */ +void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC) +{ + sdo_do_object *my_object; + char *class_name, *space; + + int object_handle = (int)dop->getUserData(); + + Z_TYPE_P(me) = IS_OBJECT; + /* If the object is already known to php, its user data will contain + * the value of the object handle. + */ + if (object_handle == SDO_USER_DATA_EMPTY) { + if (object_init_ex(me, sdo_dataobjectimpl_class_entry) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); + return; + } + + my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); + my_object->dop = dop; + /* add a back pointer to the C++ object */ + try { + dop->setUserData ((void *)me->value.obj.handle); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); + } + } else { + me->value.obj.handle = object_handle; + me->value.obj.handlers = &sdo_do_object_handlers; + me->value.obj.handlers->add_ref(me TSRMLS_CC); + + /* Sanity check */ + my_object = (sdo_do_object *)sdo_do_get_instance(me TSRMLS_CC); + if (!my_object) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject #%d not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, object_handle); + return; + } + } +} +/* }}} */ + /* {{{ sdo_do_clone_obj */ static zend_object_value sdo_do_clone_obj(zval *object TSRMLS_DC) @@ -131,12 +215,9 @@ sdo_do_object *my_object = (sdo_do_object *)NULL; DataObjectPtr dop; int return_value = 0; + char *class_name, *space; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } dop = my_object->dop; @@ -162,7 +243,9 @@ } else { switch (propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -196,15 +279,21 @@ /* since the property is set, the data object cannot be 'empty' */ break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%i: unexpected type %s for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getType().getName(), xpath); return_value = 0; } @@ -224,7 +313,9 @@ { zval *return_value; - MAKE_STD_ZVAL(return_value); + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; + try { DataObjectList& list_value = sdo->dop->getList(xpath); if (&list_value == NULL) { @@ -251,51 +342,48 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; - MAKE_STD_ZVAL(return_value); try { if (propertyp->isMany()) { - /* If the property is many-valued and the list is uninitialized, - * all bets are off. The C++ library does not catch this - * consistently, so ... - */ + /* If the property is many-valued and the list is uninitialized, + * all bets are off. The C++ library does not catch this + * consistently, so ... + */ if (! dop->isSet(xpath)) { zend_throw_exception_ex(sdo_indexoutofboundsexception_class_entry, 0 TSRMLS_CC, - "Cannot read list at index \"%s\" because the list is empty", + "Cannot read list at index '%s' because the list is empty", (char *)xpath); - RETVAL_NULL(); return return_value; } } else { - /* - * If the property is single-valued, we should just leave it to the - * C++ library to decide whether the property is set, but currently - * it fails to detect this error, so we shall catch it here instead. - * To be honest, there is no justification in the spec for - * restricting this to DataObject types, but it just doesn't seem - * right in the PHP world to throw an exception when a primitive - * happens to be unset. - */ - if (propertyp->isReference() && !dop->isValid(xpath)) { + /* + * If the property is single-valued, we should just leave it to the + * C++ library to decide whether the property is set, but currently + * it fails to detect this error, so we shall catch it here instead. + */ + if (!dop->isValid(xpath)) { zend_throw_exception_ex(sdo_propertynotsetexception_class_entry, 0 TSRMLS_CC, - "Cannot read property \"%s\" because it is not set", - (char *)xpath); - RETVAL_NULL(); + "Cannot read property '%s' because it is not set", + propertyp->getName()); return return_value; } } - + if (dop->isNull(xpath)) { RETVAL_NULL(); } else { switch(propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes' for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -317,7 +405,9 @@ case Type::CharacterType: wchar_value = dop->getCharacter(xpath); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); } char_value = dop->getByte(xpath); RETVAL_STRINGL(&char_value, 1, 1); @@ -348,33 +438,36 @@ case Type::DataObjectType: doh_value = dop->getDataObject(xpath); if (!doh_value) { - php_error(E_WARNING, "%s:%i: read a NULL DataObject for property '%s'", CLASS_NAME, __LINE__, - propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): read a NULL DataObject for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - if (doh_value_zval == (zval *)SDO_USER_DATA_EMPTY) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, - propertyp->getType().getName(), xpath); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, + propertyp->getType().getName(), propertyp->getName()); } } return return_value; } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); - RETVAL_NULL(); + efree(return_value); + return_value = 0; } return return_value; } @@ -392,14 +485,7 @@ zval *return_value; - my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - MAKE_STD_ZVAL(return_value); - RETVAL_NULL(); - return return_value; - } - + my_object = sdo_do_get_instance(object TSRMLS_CC); dop = my_object->dop; try { @@ -443,10 +529,6 @@ sdo_do_object *my_object; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (sdo_parse_offset_param( @@ -471,15 +553,10 @@ sdo_do_object *my_object, *value_object; DataObjectPtr dop; zval temp_zval; - bool is_open; Type::Types type_enum; + char *class_name, *space; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } - dop = my_object->dop; try { @@ -516,8 +593,9 @@ zval_copy_ctor(&temp_zval); switch(type_enum) { - case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -574,23 +652,38 @@ dop->setCString(xpath, Z_STRVAL(temp_zval)); break; case Type::DataObjectType: - convert_to_object(&temp_zval); - if (!instanceof_function(Z_OBJCE(temp_zval), sdo_dataobjectimpl_class_entry TSRMLS_CC)) { - php_error(E_ERROR, "%s:%i: cannot cast %s to %s", CLASS_NAME, __LINE__, - Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); + if (Z_TYPE_P(z_propertyValue) != IS_OBJECT) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0,0 TSRMLS_CC, + "%s%s%s(): cannot cast %s to %s for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), + zend_zval_type_name(z_propertyValue), CLASS_NAME, xpath); + } else if (!instanceof_function(Z_OBJCE_P(z_propertyValue), sdo_dataobjectimpl_class_entry TSRMLS_CC)) { + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0,0 TSRMLS_CC, + "%s%s%s(): cannot cast %s to %s for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), + Z_OBJCE_P(z_propertyValue)->name, + sdo_dataobjectimpl_class_entry->name, xpath); } else { - value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + value_object = (sdo_do_object *)zend_object_store_get_object(z_propertyValue TSRMLS_CC); dop->setDataObject(xpath, value_object->dop); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, (property_p ? property_p->getType().getName() : ""), xpath); } zval_dtor(&temp_zval); @@ -608,49 +701,48 @@ static HashTable *sdo_do_get_properties(zval *object TSRMLS_DC) { sdo_do_object *my_object; - HashTable *properties; + HashTable *properties; int entries; - zval *tmp; + zval *tmp; + + zval z_holder; - ALLOC_HASHTABLE(properties); + array_init(&z_holder); my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - PropertyList pl = my_object->dop->getInstanceProperties(); - entries = pl.size(); - zend_hash_init(properties, entries, NULL, NULL, 0); - for (long index = 0; index < entries; index++) { - /* It's safe to use the property directly here, it cannot be an xpath */ - const Property& property = pl[index]; - const char *propertyName = property.getName(); - - /* Usually we check isMany() before isSet(), because we should not return NULL just because - * the List is empty. But for get_properties the return values are readonly, so it's - * safer and clearer to omit empty lists. - */ - if (my_object->dop->isSet(property)) { - if (property.isMany()) { - long count = 0; - tmp = sdo_do_read_list(my_object, propertyName, &property TSRMLS_CC); - sdo_list_count_elements (tmp, &count TSRMLS_CC); - if (count == 0) - continue; - } else { - tmp = sdo_do_read_value(my_object, propertyName, &property TSRMLS_CC); - } + + try { + PropertyList pl = my_object->dop->getInstanceProperties(); + entries = pl.size(); + for (long index = 0; index < entries; index++) { + /* It's safe to use the property directly here, it cannot be an xpath */ + const Property& property = pl[index]; + const char *propertyName = property.getName(); + + /* Usually we check isMany() before isSet(), because we should not return NULL just because + * the List is empty. But for get_properties the return values are readonly, so it's + * safer and clearer to omit empty lists. + */ + if (my_object->dop->isSet(property)) { + if (property.isMany()) { + long count = 0; + tmp = sdo_do_read_list(my_object, propertyName, &property TSRMLS_CC); + sdo_list_count_elements (tmp, &count TSRMLS_CC); + if (count == 0) + continue; } else { - continue; + tmp = sdo_do_read_value(my_object, propertyName, &property TSRMLS_CC); } - zend_hash_update(properties, (char *)propertyName, 1 + strlen(propertyName), - &tmp, sizeof(zval *), NULL); + } else { + continue; } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); + add_assoc_zval(&z_holder, (char *)propertyName, tmp); } + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } + + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -742,55 +834,49 @@ } my_object = sdo_do_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { + + try { + const Type& type = my_object->dop->getType(); + PropertyList pl = my_object->dop->getInstanceProperties(); - try { - const Type& type = my_object->dop->getType(); - PropertyList pl = my_object->dop->getInstanceProperties(); + print_buf << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " (" << pl.size() << ") {"; + + for (unsigned int i = 0; i < pl.size(); i++) { + const Property& prop = pl[i]; + + if (i > 0) { + print_buf << "; "; + } - print_buf << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " (" << pl.size() << ") {"; + print_buf << prop.getName(); - for (unsigned int i = 0; i < pl.size(); i++) { - const Property& prop = pl[i]; + /* We'll try to print the value for single-valued primitives only. + * Multi-valued properties just get a dimension. + */ + if (prop.isMany()) { + print_buf << '[' << my_object->dop->getList(prop).size() << ']'; - if (i > 0) { - print_buf << "; "; + } else if (my_object->dop->isSet(i) && prop.getType().isDataType()) { + print_buf << "=>"; + if (my_object->dop->isNull(i)) { + print_buf << "NULL"; + } else { + print_buf << '\"' << my_object->dop->getCString(i) << '\"'; } - print_buf << prop.getName(); - - /* We'll try to print the value for single-valued primitives only. - * Multi-valued properties just get a dimension. - */ - if (prop.isMany()) { - print_buf << '[' << my_object->dop->getList(prop).size() << ']'; - - } else if (my_object->dop->isSet(i) && prop.getType().isDataType()) { - print_buf << "=>"; - if (my_object->dop->isNull(i)) { - print_buf << "NULL"; - } else { - print_buf << '\"' << my_object->dop->getCString(i) << '\"'; - } - - } } - - print_buf << '}'; - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; } - } + + print_buf << '}'; + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -823,11 +909,6 @@ sdo_do_object *my_object; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - *count = 0; - return FAILURE; - } try { *count = my_object->dop->getInstanceProperties().size(); @@ -839,11 +920,37 @@ } /* }}} */ -static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC); +/* {{{ sdo_do_iterator_rewind + */ +static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC) +{ + sdo_do_iterator *iterator = (sdo_do_iterator *)iter; + zval *z_do_object = (zval *)iterator->zoi.data; + sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(z_do_object TSRMLS_CC); + + try { + PropertyList pl = my_object->dop->getInstanceProperties(); + for (iterator->index = 0; + iterator->index < pl.size() && ! my_object->dop->isValid(iterator->index); + iterator->index++); + iterator->valid = (iterator->index < pl.size()); + } catch (SDORuntimeException e) { + iterator->valid = false; + sdo_throw_runtimeexception(&e TSRMLS_CC); + } +} +/* }}} */ /* {{{ sdo_do_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_do_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_do_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(object TSRMLS_CC); sdo_do_iterator *iterator = (sdo_do_iterator *)emalloc(sizeof(sdo_do_iterator)); @@ -963,27 +1070,6 @@ } /* }}} */ -/* {{{ sdo_do_iterator_rewind - */ -static void sdo_do_iterator_rewind (zend_object_iterator *iter TSRMLS_DC) -{ - sdo_do_iterator *iterator = (sdo_do_iterator *)iter; - zval *z_do_object = (zval *)iterator->zoi.data; - sdo_do_object *my_object = (sdo_do_object *)sdo_do_get_instance(z_do_object TSRMLS_CC); - - try { - PropertyList pl = my_object->dop->getInstanceProperties(); - for (iterator->index = 0; - iterator->index < pl.size() && ! my_object->dop->isValid(iterator->index); - iterator->index++); - iterator->valid = (iterator->index < pl.size()); - } catch (SDORuntimeException e) { - iterator->valid = false; - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - /* {{{ sdo_do_serialize * Both the model and the graph are serialized to a buffer. */ @@ -997,18 +1083,14 @@ xmldas::XMLDAS *xmldasp; my_object = sdo_do_get_instance(object TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return FAILURE; - } try { xmldasp = sdo_get_XMLDAS(); /* create an XML representation of the model */ serialized_model = xmldasp->generateSchema(my_object->dop); model_length = strlen(serialized_model); - /* serialize the data graph */ - serialized_graph = xmldasp->save(my_object->dop, 0, 0); + /* serialize the data graph to an unformatted string */ + serialized_graph = xmldasp->save(my_object->dop, 0, 0, -1); graph_length = strlen(serialized_graph); /* @@ -1030,41 +1112,6 @@ } /* }}} */ -/* {{{ sdo_do_populate_graph - * walk the data graph creating a php wrapper for each data object. - * Return the zval for the root object. - */ -static zval *sdo_do_populate_graph (DataObjectPtr dop TSRMLS_DC) -{ - zval *z_new_do; - - /* We may have previously encountered this DataObject, perhaps as a non-containment reference. - * If so, don't create a duplicate PHP object. - */ - z_new_do = (zval *)dop->getUserData(); - if (z_new_do == (zval *)SDO_USER_DATA_EMPTY) { - - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, dop TSRMLS_CC); - - PropertyList pl = dop->getInstanceProperties(); - for (int i = 0; i < pl.size(); i++) { - if (dop->isSet(pl[i])) { - if (pl[i].isMany()) { - DataObjectList& dol = dop->getList(pl[i]); - for (int j = 0; j < dol.size(); j++) { - sdo_do_populate_graph(dol[j] TSRMLS_CC); - } - } else if (pl[i].getType().isDataObjectType()) { - sdo_do_populate_graph(dop->getDataObject(pl[i]) TSRMLS_CC); - } - } - } - } - return z_new_do; -} -/* }}} */ - /* {{{ sdo_do_unserialize * Recreate the graph and underlying model from a buffer. */ @@ -1073,7 +1120,6 @@ char *serialized_model; char *serialized_graph; zval *factory_zval; - zval *root_object_zval; xmldas::XMLDAS *xmldasp; /* @@ -1094,10 +1140,10 @@ /* Load the graph */ DataObjectPtr root_dop = xmldasp->load(serialized_graph)->getRootDataObject(); - /* Walk the graph creating its PHP representation */ - root_object_zval = sdo_do_populate_graph(root_dop TSRMLS_CC); - **object = *root_object_zval; - zval_copy_ctor(*object); + /* Create a PHP object fot the root. Other nodes will be created + * lazily as required. + */ + sdo_do_new(*object, root_dop TSRMLS_CC); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1108,30 +1154,6 @@ } /* }}} */ -/* {{{ sdo_do_new - * The DataObject has no public constructor, this is in effect its factory method. - */ -void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC) -{ - sdo_do_object *my_object; - - Z_TYPE_P(me) = IS_OBJECT; - if (object_init_ex(me, sdo_dataobjectimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); - return; - } - - my_object = (sdo_do_object *)zend_object_store_get_object(me TSRMLS_CC); - my_object->dop = dop; - /* add a back pointer to the C++ object */ - try { - dop->setUserData ((void *)me); - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} -/* }}} */ - /* {{{ sdo_do_minit */ void sdo_do_minit(zend_class_entry *tmp_ce TSRMLS_DC) @@ -1175,7 +1197,11 @@ */ PHP_METHOD(SDO_DataObjectImpl, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -1185,21 +1211,15 @@ { sdo_do_object *my_object; DataObjectPtr container_dop; - zval *container_zval; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { container_dop = my_object->dop->getContainer(); if (!container_dop) { RETVAL_NULL(); } else { - container_zval = (zval *)container_dop->getUserData(); - RETVAL_ZVAL(container_zval, 1, 0); + sdo_do_new(return_value, container_dop TSRMLS_CC); } } catch (SDORuntimeException e){ sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1207,73 +1227,48 @@ } /* }}} */ -/* {{{ SDO_DataObjectImpl::getContainmentPropertyName +/* {{{ SDO_DataObjectImpl::clear */ -PHP_METHOD(SDO_DataObjectImpl, getContainmentPropertyName) +PHP_METHOD(SDO_DataObjectImpl, clear) { - sdo_do_object *my_object; - - php_error(E_WARNING, - "SDO_DataObject::getContainmentPropertyName() is deprecated, and will be removed in the next release. Use SDO_Model_ReflectionDataObject::getContainmentProperty()"); + sdo_do_object *my_object; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { - RETVAL_STRING((char *)my_object->dop->getContainmentProperty().getName(), 1); - } catch (SDOPropertyNotFoundException e) { - /* In this case the C++ API means we must catch an exception on the normal path */ - RETVAL_NULL(); - } catch (SDORuntimeException e) { + my_object->dop->clear(); + } catch (SDORuntimeException e){ sdo_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ -/* {{{ SDO_DataObjectImpl::clear +/* {{{ SDO_DataObjectImpl::getTypeName */ -PHP_METHOD(SDO_DataObjectImpl, clear) +PHP_METHOD(SDO_DataObjectImpl, getTypeName) { - sdo_do_object *my_object; - + sdo_do_object *my_object; + my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - } else { - try { - my_object->dop->clear(); - } catch (SDORuntimeException e){ - sdo_throw_runtimeexception(&e TSRMLS_CC); - } + + try { + RETVAL_STRING((char *)my_object->dop->getType().getName(), 1); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); } } /* }}} */ -/* {{{ SDO_DataObjectImpl::getType +/* {{{ SDO_DataObjectImpl::getTypeURI */ -PHP_METHOD(SDO_DataObjectImpl, getType) +PHP_METHOD(SDO_DataObjectImpl, getTypeNamespaceURI) { sdo_do_object *my_object; - - php_error(E_WARNING, - "SDO_DataObject::getType() is deprecated, and will be removed in the next release. Use SDO_Model_ReflectionDataObject::getType()"); - + my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } try { - const Type& type = my_object->dop->getType(); - - /* return the type as a PHP array */ - array_init(return_value); - add_next_index_string(return_value, (char *)type.getURI(), 1); - add_next_index_string(return_value, (char *)type.getName(), 1); + RETVAL_STRING((char *)my_object->dop->getType().getURI(), 1); } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } @@ -1288,16 +1283,11 @@ const char *xpath; sdo_do_object *my_object; DataObjectPtr dop, new_dop; - zval *z_new_do; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_property) == FAILURE) return; my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } dop = my_object->dop; @@ -1314,9 +1304,7 @@ } /* We have a good data object, so set up its PHP incarnation */ - MAKE_STD_ZVAL(z_new_do); - sdo_do_new(z_new_do, new_dop TSRMLS_CC); - RETVAL_ZVAL(z_new_do, 1, 0); + sdo_do_new(return_value, new_dop TSRMLS_CC); } /* }}} */ @@ -1332,11 +1320,6 @@ } my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } - dop = my_object->dop; try { @@ -1345,7 +1328,7 @@ RETVAL_NULL(); } else { /* Create the PHP wrapper */ - sdo_sequence_new (return_value, seqp, dop TSRMLS_CC); + sdo_sequence_new (return_value, seqp TSRMLS_CC); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1365,10 +1348,6 @@ } my_object = sdo_do_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETURN_NULL(); - } dop = my_object->dop; http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_List.cpp?r1=1.13&r2=1.14&diff_format=u Index: pecl/sdo/SDO_List.cpp diff -u pecl/sdo/SDO_List.cpp:1.13 pecl/sdo/SDO_List.cpp:1.14 --- pecl/sdo/SDO_List.cpp:1.13 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_List.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_List.cpp,v 1.13 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_List.cpp,v 1.14 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -56,7 +56,6 @@ const ChangedDataObjectList *cdolp; const SettingList *slp; }; - const Type *typep; /* only used for DataObjectList */ } sdo_list_object; /* }}} */ @@ -124,10 +123,13 @@ static sdo_list_object *sdo_list_new(zval *me, zend_class_entry *ce TSRMLS_DC) { sdo_list_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, ce) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return (sdo_list_object *)NULL; } @@ -145,7 +147,6 @@ my_object = sdo_list_new(me, sdo_dataobjectlist_class_entry TSRMLS_CC); my_object->list_type = TYPE_DataObjectList; - my_object->typep = &type; my_object->dolp = dolp; } /* }}} */ @@ -160,7 +161,6 @@ my_object->list_type = TYPE_ChangedDataObjectList; my_object->cdolp = cdolp; - my_object->typep = NULL; } /* }}} */ @@ -174,7 +174,6 @@ my_object->list_type = TYPE_SettingList; my_object->slp = &sl; - my_object->typep = NULL; } /* }}} */ @@ -187,20 +186,23 @@ wchar_t wchar_value; zval *return_value; DataObjectPtr doh_value; - zval *doh_value_zval; + char *class_name, *space; - const DataObjectList& dol = *my_object->dolp; - const Type *type = my_object->typep; + DataObjectList& dol = *my_object->dolp; - MAKE_STD_ZVAL(return_value); + ALLOC_INIT_ZVAL(return_value); + return_value->refcount = 0; + try { if (index >= dol.size()) { RETVAL_NULL(); } else { - MAKE_STD_ZVAL(return_value); - switch(type->getTypeEnum()) { + const Type& type = dol.getType(); + switch(type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -222,7 +224,9 @@ case Type::CharacterType: wchar_value = dol.getCharacter(index); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost reading many-valued property", + class_name, space, get_active_function_name(TSRMLS_C)); } char_value = dol.getByte(index); RETVAL_STRINGL(&char_value, 1, 1); @@ -256,18 +260,23 @@ if (!doh_value) { RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type->getTypeEnum()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getTypeEnum()); } } @@ -284,10 +293,11 @@ static zval *sdo_changeddataobjectlist_read_value(sdo_list_object *my_object, long index TSRMLS_DC) { const ChangedDataObjectList& dol = *my_object->cdolp; - zval *doh_value_zval; zval *return_value; MAKE_STD_ZVAL(return_value); + return_value->refcount = 0; + /* Elements of a ChangedDataObjectList are all DataObject type */ try { if (index >= dol.size()) { @@ -298,8 +308,7 @@ if (!doh_value) { RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - RETVAL_ZVAL(doh_value_zval, 1, 0); + sdo_do_new(return_value, doh_value TSRMLS_CC); } } } catch (SDORuntimeException e) { @@ -317,6 +326,7 @@ const SettingList& sl = *my_object->slp; MAKE_STD_ZVAL(return_value); + return_value->refcount = 0; /* Elements of a SettingList are all DAS_Setting type */ try { @@ -336,13 +346,12 @@ */ static void sdo_dataobjectlist_write_value(sdo_list_object *my_object, long index, zval *z_value, sdo_write_type write_type TSRMLS_DC) { - sdo_do_object *value_object; zval temp_zval; + char *class_name, *space; DataObjectList& dol = *my_object->dolp; - const Type *type = my_object->typep; - try { + try { if (write_type != TYPE_APPEND && (index < 0 || index >= dol.size())) { zend_throw_exception_ex(sdo_indexoutofboundsexception_class_entry, 0 TSRMLS_CC, @@ -351,7 +360,7 @@ } /* - * Since we may have to coerce the type, we make a local copy of the zval, so that the + * Since we may have to coerce the type, we make a local copy of the zval, so that the * original is unaffected. * * TODO This could be optimized to only copy if we do actually change the type. @@ -361,10 +370,13 @@ /* we must have at least the type enum here in case this is an append and * we don't know what type to append - */ - switch(type->getTypeEnum()) { + */ + const Type& type = dol.getType(); + switch(type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -492,24 +504,30 @@ "Class %s is not an instance of %s", Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); } else { - value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + DataObjectPtr dop = sdo_do_get(&temp_zval TSRMLS_CC); if (write_type == TYPE_APPEND) { - dol.append(value_object->dop); + dol.append(dop); } else if (write_type == TYPE_INSERT) { - dol.insert(index, value_object->dop); + dol.insert(index, dop); } else { - dol.setDataObject(index, value_object->dop); + dol.setDataObject(index, dop); } } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %s", CLASS_NAME, __LINE__, type->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getName()); } zval_dtor(&temp_zval); } catch (SDORuntimeException e) { @@ -522,8 +540,8 @@ */ static int sdo_dataobjectlist_valid(sdo_list_object *my_object, long index, int check_empty TSRMLS_DC) { - int return_value = 0; - const Type *type; + int return_value = 0; + char *class_name, *space; try { return_value = (index >= 0 && index < my_object->dolp->size()); @@ -531,10 +549,12 @@ if (return_value && check_empty) { /* cf SDO_DataObject.read_dimension() */ DataObjectList& dol = *my_object->dolp; - type = my_object->typep; - switch (type->getTypeEnum()) { + const Type& type = dol.getType(); + switch (type.getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -567,15 +587,21 @@ return_value = (!(dol[index])); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'TextType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type->getTypeEnum()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type.getTypeEnum()); return_value = 0; } } @@ -637,20 +663,19 @@ char *propertyName = NULL; long index; int return_value = 0; - sdo_list_object *my_object; + sdo_list_object *my_object; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return 0; } - + index = Z_LVAL_P(offset); - + my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -663,9 +688,11 @@ return_value = sdo_das_settinglist_valid(my_object, index, check_empty TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } - + return return_value; } /* }}} */ @@ -677,20 +704,17 @@ long index; sdo_list_object *my_object; zval *return_value; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return 0; } index = Z_LVAL_P(offset); my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - MAKE_STD_ZVAL(return_value); - RETVAL_NULL(); - return return_value; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -703,7 +727,9 @@ return_value = sdo_das_settinglist_read_value(my_object, index TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } return return_value; @@ -717,18 +743,17 @@ long index; sdo_list_object *my_object; DataObjectList *dol; + char *class_name, *space; - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return; } index = Z_LVAL_P(offset); - my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } + my_object = sdo_list_get_instance(object TSRMLS_CC); switch(my_object->list_type) { case TYPE_DataObjectList: @@ -753,7 +778,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } /* }}} */ @@ -765,6 +792,7 @@ long index = -1; sdo_list_object *my_object; sdo_write_type write_type; + char *class_name, *space; if (Z_TYPE_P(z_value) == IS_NULL) { /* TODO: fix this when the C++ lib supports a NULL property */ @@ -776,8 +804,10 @@ if (offset == 0 || Z_TYPE_P(offset) == IS_NULL) { write_type = TYPE_APPEND; } else { - if (Z_TYPE_P(offset) != IS_LONG) { - php_error(E_ERROR, "%s:%i: invalid dimension type %i", CLASS_NAME, __LINE__, Z_TYPE_P(offset)); + if (Z_TYPE_P(offset) != IS_LONG) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, Z_TYPE_P(offset)); return; } index = Z_LVAL_P(offset); @@ -785,10 +815,6 @@ } my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -803,7 +829,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } @@ -819,13 +847,12 @@ HashTable *properties; int entries; zval *tmp; + zval z_holder; + char *space, *class_name; my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } - ALLOC_HASHTABLE(properties); + + array_init(&z_holder); try { switch (my_object->list_type) { @@ -839,11 +866,11 @@ entries = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); return 0; } - - zend_hash_init(properties, entries, NULL, NULL, 0); for (long index = 0; index < entries; index++) { @@ -858,11 +885,12 @@ tmp = sdo_das_settinglist_read_value(my_object, index TSRMLS_CC); break; } - zend_hash_next_index_insert(properties, &tmp, sizeof (zval *), NULL); + add_next_index_zval(&z_holder, tmp); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -876,18 +904,18 @@ zval free_obj; int rc = SUCCESS; int entries; + char *class_name, *space; if (should_free) { free_obj = *writeobj; } my_object = sdo_list_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_list_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else if (my_object->list_type > TYPE_SettingList) { - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + + if (my_object->list_type > TYPE_SettingList) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); ZVAL_NULL(writeobj); rc = FAILURE; } else { @@ -917,7 +945,7 @@ case TYPE_DataObjectList: { DataObjectList& dol = *my_object->dolp; - if (my_object->typep->isDataType()) { + if (dol.getType().isDataType()) { print_buf << " {"; for (int i = 0; i < entries; i++) { if (i > 0) print_buf << "; "; @@ -988,6 +1016,7 @@ DataObjectList *dol1, *dol2; int entries; zval result; + char *class_name, *space; INIT_PZVAL(&result); @@ -1002,7 +1031,9 @@ case TYPE_DataObjectList: break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object1->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object1->list_type); return FAILURE; } @@ -1035,7 +1066,14 @@ /* {{{ sdo_list_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_list_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_list_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_list_iterator *iterator = (sdo_list_iterator *)emalloc(sizeof(sdo_list_iterator)); object->refcount++; @@ -1062,6 +1100,7 @@ { int valid; long count; + char *class_name, *space; sdo_list_iterator *iterator = (sdo_list_iterator *)iter; zval *z_list_object = (zval *)iterator->zoi.data; @@ -1079,7 +1118,9 @@ count = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } valid = (iterator->index >= 0 && iterator->index < count) ? SUCCESS : FAILURE; } catch (SDORuntimeException e) { @@ -1106,6 +1147,8 @@ */ static void sdo_list_iterator_current_data (zend_object_iterator *iter, zval ***data TSRMLS_DC) { + char *class_name, *space; + sdo_list_iterator *iterator = (sdo_list_iterator *)iter; zval *z_list_object = (zval *)iterator->zoi.data; sdo_list_object *my_object = (sdo_list_object *)sdo_list_get_instance(z_list_object TSRMLS_CC); @@ -1122,7 +1165,9 @@ iterator->value = sdo_das_settinglist_read_value(my_object, iterator->index TSRMLS_CC); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); return; } } catch (SDORuntimeException e) { @@ -1156,12 +1201,10 @@ int sdo_list_count_elements(zval *object, long *count TSRMLS_DC) { sdo_list_object *my_object; + char *class_name, *space; my_object = sdo_list_get_instance(object TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } + try { switch (my_object->list_type) { case TYPE_ChangedDataObjectList: @@ -1174,7 +1217,9 @@ *count = my_object->slp->size(); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); @@ -1223,7 +1268,11 @@ */ PHP_METHOD(SDO_List, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -1247,6 +1296,7 @@ long index = -1; sdo_list_object *my_object; sdo_write_type write_type; + char *class_name, *space; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &z_value, &z_index) == FAILURE) { return; @@ -1262,10 +1312,6 @@ } my_object = sdo_list_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_list_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } switch (my_object->list_type) { case TYPE_DataObjectList: @@ -1280,7 +1326,9 @@ "A SettingList is read-only"); break; default: - php_error(E_ERROR, "%s:%i: unexpected list type %i", CLASS_NAME, __LINE__, my_object->list_type); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - invalid dimension type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, my_object->list_type); } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_Property.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/SDO_Model_Property.cpp diff -u pecl/sdo/SDO_Model_Property.cpp:1.3 pecl/sdo/SDO_Model_Property.cpp:1.4 --- pecl/sdo/SDO_Model_Property.cpp:1.3 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_Property.cpp Mon Feb 20 18:50:25 2006 @@ -1,25 +1,25 @@ -/* +/* +----------------------------------------------------------------------+ -| (c) Copyright IBM Corporation 2005. | +| (c) Copyright IBM Corporation 2005. | | 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 | ++----------------------------------------------------------------------+ +| | +| 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: Caroline Maynard | -+----------------------------------------------------------------------+ +| | +| 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: Caroline Maynard | ++----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_Property.cpp,v 1.3 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_Property.cpp,v 1.4 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -48,7 +48,7 @@ /* {{{ sdo_model_property_get_instance */ -static sdo_model_property_object *sdo_model_property_get_instance(zval *me TSRMLS_DC) +static sdo_model_property_object *sdo_model_property_get_instance(zval *me TSRMLS_DC) { return (sdo_model_property_object *)zend_object_store_get_object(me TSRMLS_CC); } @@ -102,19 +102,22 @@ /* {{{ sdo_model_property_new */ void sdo_model_property_new(zval *me, const Property *propertyp TSRMLS_DC) -{ +{ sdo_model_property_object *my_object; + char *class_name, *space; - Z_TYPE_P(me) = IS_OBJECT; + Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_model_propertyimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } my_object = (sdo_model_property_object *)zend_object_store_get_object(me TSRMLS_CC); my_object->propertyp = propertyp; - zend_update_property_string(sdo_model_propertyimpl_class_entry, me, + zend_update_property_string(sdo_model_propertyimpl_class_entry, me, "name", strlen("name"), (char *)propertyp->getName() TSRMLS_CC); } /* }}} */ @@ -124,13 +127,16 @@ void sdo_model_property_get_default(const Property *propertyp, zval *return_value TSRMLS_DC) { uint bytes_len; char *bytes_value; - char char_value; + char char_value; wchar_t wchar_value; + char *class_name, *space; try { switch(propertyp->getTypeEnum()) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -156,7 +162,9 @@ case Type::CharacterType: wchar_value = propertyp->getCharacterDefault(); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'", + class_name, space, get_active_function_name(TSRMLS_C), propertyp->getName()); } char_value = propertyp->getByteDefault(); RETVAL_STRINGL(&char_value, 1, 1); @@ -195,21 +203,25 @@ RETVAL_STRINGL(bytes_value, bytes_len, 0); /* TODO restore this code instead of the above once getCStringDefault is implemented */ /* RETVAL_STRING((char *)property.getCStringDefault(), 1); */ - break; + break; case Type::DataObjectType: /* A data object type cannot have a default */ RETVAL_NULL(); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected type 'ChangeSummaryType' for property %s", - CLASS_NAME, __LINE__, propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected type 'ChangeSummaryType' for property %s", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; case Type::TextType: - php_error(E_ERROR, "%s:%i: unexpected type 'TextType' for property %s", - CLASS_NAME, __LINE__, propertyp->getName()); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected type 'TextType' for property %s", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getName()); break; default: - php_error(E_ERROR, "%s:%i: unexpected type '%s' for property '%s'", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, propertyp->getType().getName(), propertyp->getName()); } } catch (SDORuntimeException e) { @@ -220,14 +232,14 @@ /* {{{ sdo_model_property_string */ -void sdo_model_property_string (ostringstream& print_buf, const Property *propertyp, const char *old_indent TSRMLS_DC) -{ +void sdo_model_property_string (ostringstream& print_buf, const Property *propertyp, const char *old_indent TSRMLS_DC) +{ zval z_default; const Type& type = propertyp->getType(); char *indent = (char *)emalloc(strlen(old_indent) + 4 + 1); sprintf (indent, "%s ", old_indent); - + print_buf << indent; if (propertyp->isReadOnly()) { @@ -237,7 +249,7 @@ if (type.isDataObjectType() && !propertyp->isContainment()) { print_buf << "<reference"; //if (!type.equals(propertyp->getContainingType())) { - // print_buf << " " << propertyp->getContainingType().getURI() << + // print_buf << " " << propertyp->getContainingType().getURI() << // ":" << propertyp->getContainingType().getName(); //} print_buf << "> "; @@ -255,7 +267,7 @@ } /*TODO it would be preferable if sdo4cpp had a hasDefault() method. - * While it does not, we get a default value and only display it if it + * While it does not, we get a default value and only display it if it * seems to be a non-default default */ sdo_model_property_get_default(propertyp, &z_default TSRMLS_CC); @@ -302,35 +314,29 @@ /* }}} */ /* {{{ sdo_model_property_cast_object -*/ -static int sdo_model_property_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) +*/ +static int sdo_model_property_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) { sdo_model_property_object *my_object; ostringstream print_buf; zval free_obj; int rc = SUCCESS; - + if (should_free) { free_obj = *writeobj; } - + my_object = sdo_model_property_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_property_object *)NULL) { + try { + sdo_model_property_string (print_buf, my_object->propertyp, "\n" TSRMLS_CC); + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - try { - sdo_model_property_string (print_buf, my_object->propertyp, "\n" TSRMLS_CC); - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } } - + switch(type) { case IS_STRING: convert_to_string(writeobj); @@ -347,7 +353,7 @@ default: rc = FAILURE; } - + if (should_free) { zval_dtor(&free_obj); } @@ -360,7 +366,7 @@ void sdo_model_property_minit(zend_class_entry *tmp_ce TSRMLS_DC) { tmp_ce->create_object = sdo_model_property_object_create; - + sdo_model_propertyimpl_class_entry = zend_register_internal_class(tmp_ce TSRMLS_CC); zend_declare_property_null (sdo_model_propertyimpl_class_entry, "name", strlen("name"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_class_implements(sdo_model_propertyimpl_class_entry TSRMLS_CC, 1, sdo_model_property_class_entry); @@ -377,17 +383,21 @@ /* {{{ SDO_Model_PropertyImpl::__construct */ PHP_METHOD(SDO_Model_PropertyImpl, __construct) -{ - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); +{ + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ /* {{{ SDO_Model_PropertyImpl::getName */ -PHP_METHOD(SDO_Model_PropertyImpl, getName) +PHP_METHOD(SDO_Model_PropertyImpl, getName) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -403,10 +413,10 @@ /* {{{ SDO_Model_PropertyImpl::getType */ -PHP_METHOD(SDO_Model_PropertyImpl, getType) +PHP_METHOD(SDO_Model_PropertyImpl, getType) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -422,10 +432,10 @@ /* {{{ SDO_Model_PropertyImpl::isMany */ -PHP_METHOD(SDO_Model_PropertyImpl, isMany) +PHP_METHOD(SDO_Model_PropertyImpl, isMany) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -441,10 +451,10 @@ /* {{{ SDO_Model_PropertyImpl::isReadOnly */ -PHP_METHOD(SDO_Model_PropertyImpl, isReadOnly) +PHP_METHOD(SDO_Model_PropertyImpl, isReadOnly) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -460,10 +470,10 @@ /* {{{ SDO_Model_PropertyImpl::isContainment */ -PHP_METHOD(SDO_Model_PropertyImpl, isContainment) +PHP_METHOD(SDO_Model_PropertyImpl, isContainment) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -479,11 +489,11 @@ /* {{{ SDO_Model_PropertyImpl::getOpposite */ -PHP_METHOD(SDO_Model_PropertyImpl, getOpposite) +PHP_METHOD(SDO_Model_PropertyImpl, getOpposite) { sdo_model_property_object *my_object; const Property *opposite_p; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } @@ -502,14 +512,14 @@ /* {{{ SDO_Model_PropertyImpl::getContainingType */ -PHP_METHOD(SDO_Model_PropertyImpl, getContainingType) +PHP_METHOD(SDO_Model_PropertyImpl, getContainingType) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - + my_object = sdo_model_property_get_instance(getThis() TSRMLS_CC); try { sdo_model_type_new (return_value, &my_object->propertyp->getContainingType() TSRMLS_CC); @@ -521,14 +531,14 @@ /* {{{ SDO_Model_PropertyImpl::getDefault */ -PHP_METHOD(SDO_Model_PropertyImpl, getDefault) +PHP_METHOD(SDO_Model_PropertyImpl, getDefault) { sdo_model_property_object *my_object; - + if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } - + my_object = sdo_model_property_get_instance(getThis() TSRMLS_CC); sdo_model_property_get_default (my_object->propertyp, return_value TSRMLS_CC); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_ReflectionDataObject.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/SDO_Model_ReflectionDataObject.cpp diff -u pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.4 pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.5 --- pecl/sdo/SDO_Model_ReflectionDataObject.cpp:1.4 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_ReflectionDataObject.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_ReflectionDataObject.cpp,v 1.4 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_ReflectionDataObject.cpp,v 1.5 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -104,52 +104,47 @@ } my_object = sdo_model_rdo_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_rdo_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { - try { - const Type& type = my_object->dop->getType(); - PropertyList pl = my_object->dop->getInstanceProperties(); - - print_buf << indent << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " {"; - print_buf << indent << " - "; - if (my_object->dop->getContainer()) { - print_buf << - "Instance of {" << my_object->dop->getContainmentProperty().getName() << "}"; - } else { - print_buf << "ROOT OBJECT"; - } - - print_buf << indent << " - Type "; - sdo_model_type_summary_string (print_buf, &type TSRMLS_CC); - - print_buf << indent << " - Instance Properties"; - print_buf << "[" << pl.size() <<"]"; - - if (pl.size() > 0) { - print_buf << " {"; - for (int i = 0; i < pl.size(); i++) { - sdo_model_property_string (print_buf, &pl[i], "\n " TSRMLS_CC); - } - print_buf << indent << " }"; - } else { - print_buf <<";"; + + try { + const Type& type = my_object->dop->getType(); + PropertyList pl = my_object->dop->getInstanceProperties(); + + print_buf << indent << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " {"; + print_buf << indent << " - "; + if (my_object->dop->getContainer()) { + print_buf << + "Instance of {" << my_object->dop->getContainmentProperty().getName() << "}"; + } else { + print_buf << "ROOT OBJECT"; + } + + print_buf << indent << " - Type "; + sdo_model_type_summary_string (print_buf, &type TSRMLS_CC); + + print_buf << indent << " - Instance Properties"; + print_buf << "[" << pl.size() <<"]"; + + if (pl.size() > 0) { + print_buf << " {"; + for (int i = 0; i < pl.size(); i++) { + sdo_model_property_string (print_buf, &pl[i], "\n " TSRMLS_CC); } - - print_buf << indent << "}"; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; + print_buf << indent << " }"; + } else { + print_buf <<";"; } - } + + print_buf << indent << "}"; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -180,10 +175,13 @@ void sdo_model_rdo_minit(zend_class_entry *tmp_ce TSRMLS_DC) { zend_class_entry **reflector_ce_ptr; + char *class_name, *space; tmp_ce->create_object = sdo_model_rdo_object_create; - if (zend_hash_find(CG(class_table), "reflector", sizeof("reflector"), (void **)&reflector_ce_ptr) == FAILURE) { - php_error(E_ERROR, "%s:%i: can't find class entry for Reflector", CLASS_NAME, __LINE__); + if (zend_hash_find(CG(class_table), "reflector", sizeof("reflector"), (void **)&reflector_ce_ptr) == FAILURE) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not find Reflector class", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } @@ -205,8 +203,8 @@ { int argc; zval *z_do; - sdo_do_object *target; sdo_model_rdo_object *my_object; + char *class_name, *space; if ((argc = ZEND_NUM_ARGS()) != 1) { WRONG_PARAM_COUNT; @@ -218,13 +216,15 @@ my_object = sdo_model_rdo_get_instance(getThis() TSRMLS_CC); - target = (sdo_do_object *)zend_object_store_get_object(z_do TSRMLS_CC); - if (target == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + DataObjectPtr dop = sdo_do_get(z_do TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name (&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); RETURN_NULL(); } - my_object->dop = target->dop; + my_object->dop = dop; } /* }}} */ @@ -242,18 +242,23 @@ { zend_class_entry *reflection_ce; zend_function *reflection_export_zf; + char *class_name, *space; /* Just call up to Reflection::export */ reflection_ce = zend_fetch_class ("Reflection", strlen("Reflection"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (!reflection_ce) { - php_error(E_ERROR, "%s:%i: Could not find Reflection class", CLASS_NAME, __LINE__); + if (!reflection_ce) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not find Reflection class", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } reflection_export_zf = zend_std_get_static_method(reflection_ce, "export", strlen("export") TSRMLS_CC); - if (!reflection_export_zf) { - php_error(E_ERROR, "%s:%i: Could not call Reflection::export method", CLASS_NAME, __LINE__); + if (!reflection_export_zf) { + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - could not call Reflection::export method", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Model_Type.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/SDO_Model_Type.cpp diff -u pecl/sdo/SDO_Model_Type.cpp:1.3 pecl/sdo/SDO_Model_Type.cpp:1.4 --- pecl/sdo/SDO_Model_Type.cpp:1.3 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Model_Type.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Model_Type.cpp,v 1.3 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Model_Type.cpp,v 1.4 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -95,10 +95,13 @@ void sdo_model_type_new(zval *me, const Type *typep TSRMLS_DC) { sdo_model_type_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_model_typeimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } @@ -138,6 +141,9 @@ */ void sdo_model_type_summary_string (ostringstream& print_buf, const Type *typep TSRMLS_DC) { + if (typep->isAbstractType()) { + print_buf << "<abstract> "; + } if (typep->isOpenType()) { print_buf << "<open> "; } @@ -199,21 +205,16 @@ } my_object = sdo_model_type_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_model_type_object *)NULL) { + + try { + sdo_model_type_string (print_buf, my_object->typep, "\n" TSRMLS_CC); + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1); + } catch (SDORuntimeException e) { ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + sdo_throw_runtimeexception(&e TSRMLS_CC); rc = FAILURE; - } else { - try { - sdo_model_type_string (print_buf, my_object->typep, "\n" TSRMLS_CC); - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; - } - } + } switch(type) { case IS_STRING: @@ -267,7 +268,11 @@ */ PHP_METHOD(SDO_Model_TypeImpl, __construct) { - php_error(E_ERROR, "%s:%i: private constructor was called", CLASS_NAME, __LINE__); + char *class_name, *space; + class_name = get_active_class_name(&space TSRMLS_CC); + + php_error(E_ERROR, "%s%s%s(): internal error - private constructor was called", + class_name, space, get_active_function_name(TSRMLS_C)); } /* }}} */ @@ -314,8 +319,8 @@ { sdo_model_type_object *my_object; zval *z_do; - sdo_do_object *target; int argc; + char *class_name, *space; if ((argc = ZEND_NUM_ARGS()) != 1) { WRONG_PARAM_COUNT; @@ -326,19 +331,29 @@ } my_object = sdo_model_type_get_instance(getThis() TSRMLS_CC); - if (my_object == (sdo_model_type_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } - target = (sdo_do_object *)zend_object_store_get_object(z_do TSRMLS_CC); - if (target == (sdo_do_object *)NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); + DataObjectPtr dop = sdo_do_get(z_do TSRMLS_CC); + if (!dop) { + class_name = get_active_class_name (&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - SDO_DataObject not found in store", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return; } try { - RETVAL_BOOL(target->dop->getType().equals(*my_object->typep)); + const Type& my_type = *my_object->typep; + const Type *target_type = &dop->getType(); + RETVAL_FALSE; + + /* walk up the target object's type hierarchy */ + while (target_type) { + if (my_type.equals(*target_type)) { + RETURN_TRUE; + } else { + target_type = target_type->getBaseType(); + } + } + } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } @@ -472,6 +487,25 @@ } /* }}} */ +/* {{{ SDO_Model_TypeImpl::isAbstractType + */ +PHP_METHOD(SDO_Model_TypeImpl, isAbstractType) +{ + sdo_model_type_object *my_object; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + my_object = sdo_model_type_get_instance(getThis() TSRMLS_CC); + try { + RETVAL_BOOL(my_object->typep->isAbstractType()); + } catch (SDORuntimeException e) { + sdo_throw_runtimeexception(&e TSRMLS_CC); + } +} +/* }}} */ + /* {{{ SDO_Model_TypeImpl::getBaseType */ PHP_METHOD(SDO_Model_TypeImpl, getBaseType) http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Sequence.cpp?r1=1.11&r2=1.12&diff_format=u Index: pecl/sdo/SDO_Sequence.cpp diff -u pecl/sdo/SDO_Sequence.cpp:1.11 pecl/sdo/SDO_Sequence.cpp:1.12 --- pecl/sdo/SDO_Sequence.cpp:1.11 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/SDO_Sequence.cpp Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: SDO_Sequence.cpp,v 1.11 2006/01/25 17:08:02 cem Exp $"; +static char rcs_id[] = "$Id: SDO_Sequence.cpp,v 1.12 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -40,7 +40,6 @@ typedef struct { zend_object zo; /* The standard zend_object */ SequencePtr seqp; /* The C++ Sequence */ - DataObjectPtr dop; /* The C++ DataObject */ } sdo_seq_object; /* }}} */ @@ -70,6 +69,7 @@ static int sdo_sequence_valid(sdo_seq_object *my_object, long sequence_index, int check_empty TSRMLS_DC) { int return_value = 0; + char *class_name, *space; try { Sequence& seq = *my_object->seqp; @@ -78,7 +78,9 @@ if (return_value && check_empty) { switch(seq.getTypeEnum(sequence_index)) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; case Type::BigDecimalType: @@ -112,11 +114,15 @@ return_value = (!seq.getDataObjectValue(sequence_index)); break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); return_value = 0; break; default: - php_error(E_ERROR, "%s:%; unexpected DataObject type %i for sequence index %i", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, seq.getTypeEnum(sequence_index), sequence_index); return_value = 0; } @@ -138,8 +144,8 @@ char char_value; wchar_t wchar_value; DataObjectPtr doh_value; - zval *doh_value_zval; zval *return_value; + char *class_name, *space; MAKE_STD_ZVAL(return_value); @@ -147,7 +153,9 @@ Sequence& seq = *my_object->seqp; switch(seq.getTypeEnum(sequence_index)) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -169,7 +177,9 @@ case Type::CharacterType: wchar_value = seq.getCharacterValue(sequence_index); if (wchar_value > INT_MAX) { - php_error(E_WARNING, "%s:%i: wide character data lost", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): wide character data lost for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), sequence_index); } char_value = seq.getByteValue(sequence_index); RETVAL_STRINGL(&char_value, 1, 1); @@ -201,24 +211,23 @@ case Type::DataObjectType: doh_value = seq.getDataObjectValue(sequence_index); if (!doh_value) { - php_error(E_WARNING, "%s:%i: read a NULL DataObject for sequence index %i", CLASS_NAME, __LINE__, - sequence_index); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_WARNING, "%s%s%s(): read a NULL DataObject for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), sequence_index); RETVAL_NULL(); } else { - doh_value_zval = (zval *)doh_value->getUserData(); - if (doh_value_zval == NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - RETVAL_NULL(); - } else { - RETVAL_ZVAL(doh_value_zval, 1, 0); - } + sdo_do_new(return_value, doh_value TSRMLS_CC); } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; default: - php_error(E_ERROR, "%s:%; unexpected DataObject type %i for sequence index %i", CLASS_NAME, __LINE__, + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i for sequence index %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, seq.getTypeEnum(sequence_index), sequence_index); } } catch (SDORuntimeException e) { @@ -235,6 +244,7 @@ static void sdo_sequence_write_value(sdo_seq_object *my_object, char *xpath, long sequence_index, Type::Types type_enum, zval *z_value, sdo_write_type write_type TSRMLS_DC) { zval temp_zval; + char *class_name, *space; try { Sequence& seq = *my_object->seqp; @@ -257,7 +267,9 @@ switch (type_enum) { case Type::OtherTypes: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'OtherTypes'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::BigDecimalType: case Type::BigIntegerType: @@ -385,19 +397,21 @@ "Class %s is not an instance of %s", Z_OBJCE(temp_zval)->name, sdo_dataobjectimpl_class_entry->name); } else { - sdo_do_object *value_object = (sdo_do_object *)zend_object_store_get_object(&temp_zval TSRMLS_CC); + DataObjectPtr dop = sdo_do_get(&temp_zval TSRMLS_CC); if (write_type == TYPE_APPEND) { - seq.addDataObject(xpath, value_object->dop); + seq.addDataObject(xpath, dop); } else if (write_type == TYPE_INSERT) { - seq.addDataObject(sequence_index, xpath, value_object->dop); + seq.addDataObject(sequence_index, xpath, dop); } else { - seq.setDataObjectValue(sequence_index, value_object->dop); + seq.setDataObjectValue(sequence_index, dop); }; } break; case Type::ChangeSummaryType: - php_error(E_ERROR, "%s:%i: unexpected DataObject type 'ChangeSummaryType'", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__); break; case Type::TextType: convert_to_string(&temp_zval); @@ -410,7 +424,9 @@ } break; default: - php_error(E_ERROR, "%s:%i: unexpected DataObject type %i", CLASS_NAME, __LINE__, type_enum); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type %i", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, type_enum); } zval_dtor(&temp_zval); } catch (SDORuntimeException e) { @@ -432,10 +448,6 @@ sequence_index = Z_LVAL_P(offset); my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } try { return_value = sdo_sequence_valid(my_object, sequence_index, check_empty TSRMLS_CC); @@ -488,10 +500,6 @@ } my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } try { if (offset == 0 || Z_TYPE_P(offset) == IS_NULL) { @@ -525,11 +533,7 @@ convert_to_long_ex(&offset); sequence_index = Z_LVAL_P(offset); - my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return; - } + my_object = sdo_sequence_get_instance(object TSRMLS_CC); try { if (sequence_index < 0 || sequence_index >= my_object->seqp->size()) { @@ -553,30 +557,26 @@ static HashTable *sdo_sequence_get_properties(zval *object TSRMLS_DC) { sdo_seq_object *my_object; - HashTable *properties; - int entries; - zval *tmp; + HashTable *properties; + int entries; + zval *tmp; + zval z_holder; my_object = sdo_sequence_get_instance(object TSRMLS_CC); - if (my_object == (sdo_seq_object *) NULL) { - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - return 0; - } - ALLOC_HASHTABLE(properties); + + array_init(&z_holder); try { entries = my_object->seqp->size(); - - zend_hash_init(properties, entries, NULL, NULL, 0); - for (long index = 0; index < entries; index++) { tmp = sdo_sequence_read_value(my_object, index TSRMLS_CC); - zend_hash_next_index_insert(properties, &tmp, sizeof (zval *), NULL); + add_next_index_zval(&z_holder, tmp); } } catch (SDORuntimeException e) { sdo_throw_runtimeexception(&e TSRMLS_CC); } + properties = Z_ARRVAL(z_holder); return properties; } /* }}} */ @@ -595,43 +595,37 @@ } my_object = sdo_sequence_get_instance(readobj TSRMLS_CC); - if (my_object == (sdo_seq_object *)NULL) { - ZVAL_NULL(writeobj); - php_error(E_ERROR, "%s:%i: object is not in object store", CLASS_NAME, __LINE__); - rc = FAILURE; - } else { - Sequence& seq = *my_object->seqp; - try { - print_buf << "object(" << CLASS_NAME << ")#" << - readobj->value.obj.handle << " (" << seq.size() << ") {"; - - for (unsigned int i = 0; i < seq.size(); i++) { - if (i > 0) print_buf << "; "; - if (seq.isText(i)) { - print_buf << '\"' << seq.getCStringValue(i) << '\"'; - } else { - const Property& property = seq.getProperty(i); - print_buf << property.getName(); - if (property.isMany()) { - print_buf << '[' << seq.getListIndex(i) << ']'; - } - if (property.getType().isDataType()) { - print_buf << "=>\"" << seq.getCStringValue(i) << '\"'; - } + Sequence& seq = *my_object->seqp; + try { + print_buf << "object(" << CLASS_NAME << ")#" << + readobj->value.obj.handle << " (" << seq.size() << ") {"; + + for (unsigned int i = 0; i < seq.size(); i++) { + if (i > 0) print_buf << "; "; + if (seq.isText(i)) { + print_buf << '\"' << seq.getCStringValue(i) << '\"'; + } else { + const Property& property = seq.getProperty(i); + print_buf << property.getName(); + if (property.isMany()) { + print_buf << '[' << seq.getListIndex(i) << ']'; } + if (property.getType().isDataType()) { + print_buf << "=>\"" << seq.getCStringValue(i) << '\"'; + } } - - print_buf << '}'; - - string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; - 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; } - } + + print_buf << '}'; + + string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/; + 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; + } switch(type) { case IS_STRING: @@ -659,7 +653,14 @@ /* {{{ sdo_sequence_get_iterator */ +#if (PHP_MAJOR_VERSION < 6) zend_object_iterator *sdo_sequence_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) { +#else +zend_object_iterator *sdo_sequence_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { + if (by_ref) { + php_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } +#endif sdo_seq_iterator *iterator = (sdo_seq_iterator *)emalloc(sizeof(sdo_seq_iterator)); object->refcount++; @@ -775,7 +776,6 @@ zend_hash_destroy(my_object->zo.properties); FREE_HASHTABLE(my_object->zo.properties); my_object->seqp = NULL; - my_object->dop = NULL; efree(object); } @@ -805,20 +805,22 @@ /* {{{ sdo_sequence_new */ -void sdo_sequence_new(zval *me, SequencePtr seqp, DataObjectPtr dop TSRMLS_DC) +void sdo_sequence_new(zval *me, SequencePtr seqp TSRMLS_DC) { sdo_seq_object *my_object; + char *class_name, *space; Z_TYPE_P(me) = IS_OBJECT; if (object_init_ex(me, sdo_sequenceimpl_class_entry) == FAILURE) { - php_error(E_ERROR, "%s:%i: object_init failed", CLASS_NAME, __LINE__); + class_name = get_active_class_name(&space TSRMLS_CC); + php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", + class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); ZVAL_NULL(me); return; } my_object = (sdo_seq_object *)zend_object_store_get_object(me TSRMLS_CC); my_object->seqp = seqp; - my_object->dop = dop; } /* }}} */ @@ -878,61 +880,14 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ -/* {{{ SDO_SequenceImpl::getPropertyIndex +/* {{{ SDO_SequenceImpl::move */ -PHP_METHOD(SDO_SequenceImpl, getPropertyIndex) -{ - sdo_seq_object *my_object; - long sequence_index; - - php_error(E_WARNING, - "SDO_Sequence::getPropertyIndex() is deprecated, and will be removed in the next release."); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sequence_index) == FAILURE) - return; - - my_object = sdo_sequence_get_instance(getThis() TSRMLS_CC); - try { - if (my_object->seqp->isText(sequence_index)) { - RETVAL_LONG(-1); - } else { - const Property& property = my_object->seqp->getProperty(sequence_index); - RETVAL_LONG(property.getContainingType().getPropertyIndex(property.getName())); - } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} - -PHP_METHOD(SDO_SequenceImpl, getPropertyName) -{ - sdo_seq_object *my_object; - long sequence_index; - - php_error(E_WARNING, - "SDO_Sequence::getPropertyName() is deprecated, and will be removed in the next release. Use SDO_Sequence::getProperty()->getName()"); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sequence_index) == FAILURE) - return; - - my_object = sdo_sequence_get_instance(getThis() TSRMLS_CC); - try { - if (my_object->seqp->isText(sequence_index)) { - RETVAL_NULL(); - } else { - const Property& property = my_object->seqp->getProperty(sequence_index); - RETVAL_STRING((char *)property.getName(), 1); - } - } catch (SDORuntimeException e) { - sdo_throw_runtimeexception(&e TSRMLS_CC); - } -} - PHP_METHOD(SDO_SequenceImpl, move) { sdo_seq_object *my_object; - long toIndex, fromIndex; + long toIndex, fromIndex; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &toIndex, &fromIndex) == FAILURE) return; @@ -944,18 +899,21 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ +/* {{{ SDO_SequenceImpl::insert + */ PHP_METHOD(SDO_SequenceImpl, insert) { sdo_seq_object *my_object; - zval *z_value; - zval *z_property = NULL; - zval *z_sequence_index = NULL; - long sequence_index; - const Property *property_p; + zval *z_value; + zval *z_property = NULL; + zval *z_sequence_index = NULL; + long sequence_index; + const Property *property_p; sdo_write_type write_type; - Type::Types type_enum; - const char *xpath; + Type::Types type_enum; + const char *xpath; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &z_value, &z_sequence_index, &z_property) == FAILURE) @@ -978,7 +936,8 @@ type_enum = Type::TextType; xpath = NULL; } else { - if (sdo_parse_offset_param (my_object->dop, z_property, &property_p, &xpath, 0, 0 TSRMLS_CC) == FAILURE) + if (sdo_parse_offset_param (my_object->seqp->getDataObject(), + z_property, &property_p, &xpath, 0, 0 TSRMLS_CC) == FAILURE) return; if (property_p == NULL) { @@ -996,7 +955,10 @@ sdo_throw_runtimeexception(&e TSRMLS_CC); } } +/* }}} */ +/* {{{ SDO_SequenceImpl::count + */ PHP_METHOD(SDO_SequenceImpl, count) { long count = 0; @@ -1004,6 +966,7 @@ sdo_sequence_count_elements(getThis(), &count TSRMLS_CC); RETVAL_LONG(count); } +/* }}} */ /* * Local variables: http://cvs.php.net/viewcvs.cgi/pecl/sdo/config.m4?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/config.m4 diff -u pecl/sdo/config.m4:1.12 pecl/sdo/config.m4:1.13 --- pecl/sdo/config.m4:1.12 Wed Jan 25 17:07:22 2006 +++ pecl/sdo/config.m4 Mon Feb 20 18:50:25 2006 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.12 2006/01/25 17:07:22 cem Exp $ +dnl $Id: config.m4,v 1.13 2006/02/20 18:50:25 mfp Exp $ PHP_ARG_ENABLE(sdo, sdo , [ --enable-sdo Enable sdo support]) @@ -31,7 +31,7 @@ sdo_lib_srcs="commonj/sdo/ChangedDataObjectListImpl.cpp commonj/sdo/ChangeSummary.cpp commonj/sdo/ChangeSummaryImpl.cpp commonj/sdo/CopyHelper.cpp commonj/sdo/DASProperty.cpp commonj/sdo/DASType.cpp commonj/sdo/DASValue.cpp commonj/sdo/DASValues.cpp commonj/sdo/DataFactory.cpp commonj/sdo/DataFactoryImpl.cpp commonj/sdo/DataGraph.cpp commonj/sdo/DataGraphImpl.cpp commonj/sdo/DataObject.cpp commonj/sdo/DataObjectImpl.cpp commonj/sdo/DataObjectList.cpp commonj/sdo/DataObjectListImpl.cpp commonj/sdo/DefaultLogWriter.cpp commonj/sdo/EqualityHelper.cpp commonj/sdo/HelperProvider.cpp commonj/sdo/Logger.cpp commonj/sdo/LogWriter.cpp commonj/sdo/ParserErrorSetter.cpp commonj/sdo/Property.cpp commonj/sdo/PropertyDefinition.cpp commonj/sdo/PropertyImpl.cpp commonj/sdo/PropertyList.cpp commonj/sdo/PropertySetting.cpp commonj/sdo/RefCountingObject.cpp commonj/sdo/RefCountingPointer.cpp commonj/sdo/SAX2Attribute.cpp commonj/sdo/SAX2Attributes.cpp commonj/sdo/SAX2Namespaces.cpp commonj/s! do/SAX2Parser.cpp commonj/sdo/SchemaInfo.cpp commonj/sdo/SdoCheck.cpp commonj/sdo/SDODate.cpp commonj/sdo/SdoRuntime.cpp commonj/sdo/SDORuntimeException.cpp commonj/sdo/SDOSAX2Parser.cpp commonj/sdo/SDOSchemaSAX2Parser.cpp commonj/sdo/SDOXMLBufferWriter.cpp commonj/sdo/SDOXMLFileWriter.cpp commonj/sdo/SDOXMLStreamWriter.cpp commonj/sdo/SDOXMLString.cpp commonj/sdo/SDOXMLWriter.cpp commonj/sdo/SDOXSDBufferWriter.cpp commonj/sdo/SDOXSDFileWriter.cpp commonj/sdo/SDOXSDStreamWriter.cpp commonj/sdo/SDOXSDWriter.cpp commonj/sdo/Sequence.cpp commonj/sdo/SequenceImpl.cpp commonj/sdo/Setting.cpp commonj/sdo/SettingList.cpp commonj/sdo/Type.cpp commonj/sdo/TypeDefinition.cpp commonj/sdo/TypeDefinitions.cpp commonj/sdo/TypeImpl.cpp commonj/sdo/TypeList.cpp commonj/sdo/XMLDocument.cpp commonj/sdo/XMLDocumentImpl.cpp commonj/sdo/XMLHelper.cpp commonj/sdo/XMLHelperImpl.cpp commonj/sdo/XMLQName.cpp commonj/sdo/XpathHelper.cpp commonj/sdo/XSDHelper.cpp commonj/sdo/XSDHelperImpl.cpp commonj! /sdo/XSDPropertyInfo.cpp commonj/sdo/XSDTypeInfo.cpp commonj/sdo/xmlda s/XMLDASCheck.cpp commonj/sdo/xmldas/XMLDAS.cpp commonj/sdo/xmldas/XMLDASImpl.cpp" -PHP_NEW_EXTENSION(sdo, sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp $sdo_lib_srcs, $ext_shared,,-I@ext_srcdir@) +PHP_NEW_EXTENSION(sdo, sdo.cpp SDO_CPPException.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_Exception.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp $sdo_lib_srcs, $ext_shared,,-I@ext_srcdir@) PHP_ADD_BUILD_DIR($ext_builddir/commonj/sdo) PHP_ADD_BUILD_DIR($ext_builddir/commonj/sdo/xmldas) http://cvs.php.net/viewcvs.cgi/pecl/sdo/config.w32?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/config.w32 diff -u pecl/sdo/config.w32:1.7 pecl/sdo/config.w32:1.8 --- pecl/sdo/config.w32:1.7 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/config.w32 Mon Feb 20 18:50:25 2006 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.7 2005/12/02 17:33:47 mfp Exp $ +// $Id: config.w32,v 1.8 2006/02/20 18:50:25 mfp Exp $ // vim:ft=javascript ARG_ENABLE("sdo", "enable sdo support", "no"); @@ -10,7 +10,7 @@ /* first build the sdo core extension ... */ EXTENSION('sdo', - 'sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp', + 'sdo.cpp SDO_DAS_ChangeSummary.cpp SDO_DAS_DataFactory.cpp SDO_DAS_Setting.cpp SDO_DataObject.cpp SDO_List.cpp SDO_Model_Type.cpp SDO_Model_Property.cpp SDO_Model_ReflectionDataObject.cpp SDO_Sequence.cpp sdo_utils.cpp SDO_Exception.cpp SDO_CPPException.cpp', 'yes', '/GX /D SDO_EXPORTS /D XMLDAS_EXPORTS'); http://cvs.php.net/viewcvs.cgi/pecl/sdo/das_xml.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/das_xml.cpp diff -u pecl/sdo/das_xml.cpp:1.4 pecl/sdo/das_xml.cpp:1.5 --- pecl/sdo/das_xml.cpp:1.4 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/das_xml.cpp Mon Feb 20 18:50:25 2006 @@ -15,12 +15,12 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: das_xml.cpp,v 1.4 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: das_xml.cpp,v 1.5 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -77,10 +77,10 @@ PHP_MINIT_FUNCTION(sdo_das_xml) { - initialize_sdo_das_xml_class(TSRMLS_C); - initialize_sdo_das_xml_document_class(TSRMLS_C); - initialize_sdo_das_xml_parserexception_class(TSRMLS_C); - initialize_sdo_das_xml_fileexception_class(TSRMLS_C); + sdo_das_xml_minit(TSRMLS_C); + sdo_das_xml_document_minit(TSRMLS_C); + sdo_das_xml_parserexception_minit(TSRMLS_C); + sdo_das_xml_fileexception_minit(TSRMLS_C); return SUCCESS; } @@ -92,11 +92,11 @@ PHP_MINFO_FUNCTION(sdo_das_xml) { php_info_print_table_start(); - php_info_print_table_header(2, "sdo_das_xml support", "enabled"); - php_info_print_table_header(2, "sdo_das_xml version", SDO_DAS_XML_VERSION); + php_info_print_table_row(2, "sdo_das_xml support", "enabled"); + php_info_print_table_row(2, "sdo_das_xml version", SDO_DAS_XML_VERSION); php_info_print_table_end(); } -/* }}} */ +/* }}} */ /* * Local variables: http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo.h?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/php_sdo.h diff -u pecl/sdo/php_sdo.h:1.8 pecl/sdo/php_sdo.h:1.9 --- pecl/sdo/php_sdo.h:1.8 Tue Jan 17 11:43:16 2006 +++ pecl/sdo/php_sdo.h Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_sdo.h,v 1.8 2006/01/17 11:43:16 cem Exp $ */ +/* $Id: php_sdo.h,v 1.9 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_H #define PHP_SDO_H @@ -50,8 +50,21 @@ PHP_METHOD(SDO_PropertyAccess, __get); PHP_METHOD(SDO_PropertyAccess, __set); +/* {{{ proto string SDO_DataObject::getTypeName() +Return the name of the type for this SDO_DataObject. +A convenience method corresponding to +SDO_Model_ReflectionDataObject::getType().getName() +*/ +PHP_METHOD(SDO_DataObject, getTypeName); +/* }}} */ -PHP_METHOD(SDO_DataObject, getType); /* deprecated */ +/* {{{ proto string SDO_DataObject::getTypeNamespaceURI() +Return the namespace URI of the type for this SDO_DataObject. +A convenience method corresponding to +SDO_Model_ReflectionDataObject::getType().getNamespaceURI() +*/ +PHP_METHOD(SDO_DataObject, getTypeNamespaceURI); +/* }}} */ /* {{{ proto SDO_Sequence SDO_DataObject::getSequence() Return the SDO_Sequence for this SDO_DataObject. Accessing the SDO_DataObject @@ -91,8 +104,6 @@ PHP_METHOD(SDO_DataObject, getContainer); /* }}} */ -PHP_METHOD(SDO_DataObject, getContainmentPropertyName); /* deprecated */ - /* {{{ proto SDO_Model_Property SDO_Sequence::getProperty(integer sequence_index) Return the property for the specified sequence index. @@ -105,9 +116,6 @@ PHP_METHOD(SDO_Sequence, getProperty); /* }}} */ -PHP_METHOD(SDO_Sequence, getPropertyIndex); /*deprecated */ -PHP_METHOD(SDO_Sequence, getPropertyName); /* deprecated */ - /* {{{ proto void SDO_Sequence::move(integer toIndex, integer fromIndex) Modify the position of the item in the sequence, without altering the value of the property in the SDO_DataObject. @@ -121,7 +129,7 @@ PHP_METHOD(SDO_Sequence, move); /* }}} */ -/* {{{ proto void SDO_Sequnece::insert(mixed value [, integer sequenceIndex, mixed propertyIdentifier]) +/* {{{ proto void SDO_Sequence::insert(mixed value [, integer sequence_index, mixed property_identifier]) Insert a new element at a specified position in the sequence. All subsequent sequence items are moved up. The new value to be inserted. This can be either a primitive or an SDO_DataObject @@ -155,20 +163,20 @@ PHP_METHOD(SDO_List, count); -/* {{{ proto void SDO_DataFactory::create(string namespaceURI, string typeName) -Create an SDO_DataObject of the type specified by typeName with the given namespace URI. +/* {{{ proto void SDO_DataFactory::create(string type_namespace_uri, string type_name) +Create an SDO_DataObject of the type specified by type_name with the given namespace URI. For example, the following creates a new SDO_DataObject of type 'CompanyType' where that type belongs to the namespace 'CompanyNS' $df->create('CompanyNS', 'CompanyType'); -The namespace of the type +The namespace URI of the type The name of the type Returns the newly created SDO_DataObject -Throws SDO_TypeNotFoundException if the namespaceURI and typeName do not correspond to a type known to this factory +Throws SDO_TypeNotFoundException if the namespace URI and type name do not correspond to a type known to this factory */ PHP_METHOD(SDO_DataFactory, create); /* }}} */ @@ -186,7 +194,7 @@ PHP_METHOD(SDO_DAS_DataFactory, getDataFactory); /* }}} */ -/* {{{ proto void SDO_DAS_DataFactory::addType(string namespaceURI, string typeName [, array options]) +/* {{{ proto void SDO_DAS_DataFactory::addType(string type_namespace_uri, string type_name [, array options]) Add a new type to the SDO_DAS_DataFactory, defined by its namespace and type name. @@ -206,21 +214,21 @@ PHP_METHOD(SDO_DAS_DataFactory, addType); /* }}} */ -/* {{{ proto void SDO_DAS_DataFactory::addPropertyToType(string parentNamespaceURI, string parentTypeName, string propertyName, string propertyNamespaceURI, string propertyTypeName [, array options]) +/* {{{ proto void SDO_DAS_DataFactory::addPropertyToType(string parent_type_namespace_uri, string parent_type_name, string property_name, string type_namespace_uri, string type_name [, array options]) Add a property to a type. The type must already be known to the SDO_DAS_DataFactory (i.e. have been added using addType()). The property becomes a property of the type. This is how the graph model for the structure of an SDO_DataObject is built. -The namespaceURI for the parent type +The namespace URI for the parent type -The typeName for the parent type +The type name for the parent type The name of by which the property will be known -The namespaceURI for the type of the property +The namespace URI for the type of the property -The typeName for the type of the property +The type name for the type of the property Optional associative array of optional arguments for the new property. Valid keys are: @@ -231,8 +239,8 @@ "default" to specifiy a default value for the property. "Default" is a mixed type argument, and omitting a default means the property does not have one. "opposite" to specify the property at the other end of a bi-directional relationship. Opposite is an array of three values -required to identify the opposite property. The first two are namespaceURI and type name and identify the type which contains -the opposite property, the thirs value is the property name of the opposite property. +required to identify the opposite property. The first two are namespace URI and type name and identify the type which contains +the opposite property, the third value is the property name of the opposite property. Example: to add a 'name' property to a Person type: $df->addPropertyToType('PersonNS', 'PersonType', @@ -280,7 +288,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangedDataObjects); /* }}} */ -/* {{{ proto integer SDO_DAS_ChangeSummary::getChangeType(SDO_DataObject dataObject) +/* {{{ proto integer SDO_DAS_ChangeSummary::getChangeType(SDO_DataObject data_object) Get the type of change which has been made to the supplied SDO_DataObject. The SDO_DataObject which has been changed @@ -292,7 +300,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getChangeType); /* }}} */ -/* {{{ proto SDO_List SDO_DAS_ChangeSummary::getOldValues(SDO_DataObject dataObject) +/* {{{ proto SDO_List SDO_DAS_ChangeSummary::getOldValues(SDO_DataObject data_object) Get a list of the old values for a given changed SDO_DataObject. The data object which has been changed. @@ -302,7 +310,7 @@ PHP_METHOD(SDO_DAS_ChangeSummary, getOldValues); /* }}} */ -/* {{{ proto SDO_DataObject SDO_DAS_ChangeSummary::getOldContainer(SDO_DataObject dataObject) +/* {{{ proto SDO_DataObject SDO_DAS_ChangeSummary::getOldContainer(SDO_DataObject data_object) Get the old container (SDO_DataObject) for a deleted SDO_DataObject. The SDO_DataObject which has been deleted. @@ -365,7 +373,7 @@ PHP_METHOD(SDO_Model_Type, getNamespaceURI); /* }}} */ -/* {{{ proto boolean SDO_Model_Type::isInstance(SDO_DataObject dataObject) +/* {{{ proto boolean SDO_Model_Type::isInstance(SDO_DataObject data_object) Returns true if the object is an instance of the type. The SDO_DataObject to test. @@ -402,12 +410,20 @@ /* }}} */ /* {{{ proto boolean SDO_Model_Type::isOpenType() -Returns true if this type corresponds to a an SDO_DataObject which allows +Returns true if this type corresponds to an SDO_DataObject which allows open content, that is, aditional properties to be added to an instance. */ PHP_METHOD(SDO_Model_Type, isOpenType); /* }}} */ +/* {{{ proto boolean SDO_Model_Type::isAbstractType() +Returns true if this type is abstract, that is, no SDO_DataObject +of this type can be instantiated, though other types may inherit +from it. +*/ +PHP_METHOD(SDO_Model_Type, isAbstractType); +/* }}} */ + /* {{{ proto SDO_Model_Type SDO_Model_Type::getBaseType() Get the base (parent) type for this type. Returns NULL if this type does not inherit from any other type. @@ -509,13 +525,63 @@ PHP_METHOD(SDO_Model_ReflectionDataObject, getContainmentProperty); /* }}} */ + +/* {{{ proto SDO_Exception::getCause() +Returns the cause of this exception or NULL if the cause is nonexistent or unknown. +*/ +PHP_METHOD(SDO_Exception, getCause); +/* }}} */ + +/* {{{ proto SDO_CPPException::getClass() +Returns the name of the C++ exception class . +*/ +PHP_METHOD(SDO_CPPException, getClass); +/* }}} */ + +/* {{{ proto SDO_CPPException::getFile() +Returns the C++ file where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getFile); +/* }}} */ + +/* {{{ proto SDO_CPPException::getLine() +Returns the C++ line number where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getLine); +/* }}} */ + +/* {{{ proto SDO_CPPException::getFunction() +Returns the name of the C++ function where the error occurred. +*/ +PHP_METHOD(SDO_CPPException, getFunction); +/* }}} */ + +/* {{{ proto SDO_CPPException::getMessage() +Returns the detailed error text from the C++ exception. +*/ +PHP_METHOD(SDO_CPPException, getMessage); +/* }}} */ + +/* {{{ proto SDO_CPPException::getSeverity() +Returns the severity level from the C++ exception. +*/ +PHP_METHOD(SDO_CPPException, getSeverity); +/* }}} */ + +/* {{{ proto string SDO_CPPException::__toString() +Return a string representation of the object. +*/ +PHP_METHOD(SDO_CPPException, __toString); +/* }}} */ + /* {{{ Implementation methods */ PHP_METHOD(SDO_DAS_DataFactoryImpl, create); PHP_METHOD(SDO_DAS_DataFactoryImpl, addType); PHP_METHOD(SDO_DAS_DataFactoryImpl, addPropertyToType); PHP_METHOD(SDO_DataObjectImpl, __construct); -PHP_METHOD(SDO_DataObjectImpl, getType); +PHP_METHOD(SDO_DataObjectImpl, getTypeName); +PHP_METHOD(SDO_DataObjectImpl, getTypeNamespaceURI); PHP_METHOD(SDO_DataObjectImpl, getSequence); PHP_METHOD(SDO_DataObjectImpl, createDataObject); PHP_METHOD(SDO_DataObjectImpl, clear); @@ -542,6 +608,7 @@ PHP_METHOD(SDO_Model_TypeImpl, isDataType); PHP_METHOD(SDO_Model_TypeImpl, isSequencedType); PHP_METHOD(SDO_Model_TypeImpl, isOpenType); +PHP_METHOD(SDO_Model_TypeImpl, isAbstractType); PHP_METHOD(SDO_Model_TypeImpl, getBaseType); PHP_METHOD(SDO_Model_PropertyImpl, __construct); http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_das_xml.h?r1=1.6&r2=1.7&diff_format=u Index: pecl/sdo/php_sdo_das_xml.h diff -u pecl/sdo/php_sdo_das_xml.h:1.6 pecl/sdo/php_sdo_das_xml.h:1.7 --- pecl/sdo/php_sdo_das_xml.h:1.6 Thu Jan 26 14:18:44 2006 +++ pecl/sdo/php_sdo_das_xml.h Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_das_xml.h,v 1.6 2006/01/26 14:18:44 mfp Exp $ */ +/* $Id: php_sdo_das_xml.h,v 1.7 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_DAS_XML_H #define PHP_SDO_DAS_XML_H @@ -31,6 +31,18 @@ #define SDO_DAS_XML_VERSION "0.7.1" +#ifdef PHP_WIN32 +# if defined (SDO_DAS_XML_EXPORTS) +# define PHP_SDO_DAS_XML_API __declspec(dllexport) +# elif defined(COMPILE_DL_SDO_DAS_XML) +# define PHP_SDO_DAS_XML_API __declspec(dllimport) +# else +# define PHP_SDO_DAS_XML_API +# endif +#else +#define PHP_SDO_DAS_XML_API +#endif + PHP_MINIT_FUNCTION(sdo_das_xml); PHP_MINFO_FUNCTION(sdo_das_xml); @@ -38,32 +50,21 @@ PHP_METHOD(SDO_DAS_XML, __construct); PHP_METHOD(SDO_DAS_XML, create); PHP_METHOD(SDO_DAS_XML, addTypes); -PHP_METHOD(SDO_DAS_XML, loadFromFile); -PHP_METHOD(SDO_DAS_XML, loadFromString); +PHP_METHOD(SDO_DAS_XML, loadFile); +PHP_METHOD(SDO_DAS_XML, loadString); +PHP_METHOD(SDO_DAS_XML, saveFile); +PHP_METHOD(SDO_DAS_XML, saveString); +PHP_METHOD(SDO_DAS_XML, createDocument); PHP_METHOD(SDO_DAS_XML, createDataObject); -PHP_METHOD(SDO_DAS_XML, saveDocumentToString); -PHP_METHOD(SDO_DAS_XML, saveDocumentToFile); -PHP_METHOD(SDO_DAS_XML, saveDataObjectToString); -PHP_METHOD(SDO_DAS_XML, saveDataObjectToFile); -PHP_METHOD(SDO_DAS_XML, getTypes); PHP_METHOD(SDO_DAS_XML, __toString); -//PHP_METHOD(SDO_DAS_XML, getProperty); - /* SDO_DAS_XML_Document Class methods declarations */ PHP_METHOD(SDO_DAS_XML_Document, getRootDataObject); PHP_METHOD(SDO_DAS_XML_Document, getRootElementURI); PHP_METHOD(SDO_DAS_XML_Document, getRootElementName); -PHP_METHOD(SDO_DAS_XML_Document, getEncoding); -PHP_METHOD(SDO_DAS_XML_Document, setEncoding); -PHP_METHOD(SDO_DAS_XML_Document, getXMLDeclaration); PHP_METHOD(SDO_DAS_XML_Document, setXMLDeclaration); -PHP_METHOD(SDO_DAS_XML_Document, getXMLVersion); PHP_METHOD(SDO_DAS_XML_Document, setXMLVersion); -PHP_METHOD(SDO_DAS_XML_Document, getSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, setSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, getNoNamespaceSchemaLocation); -PHP_METHOD(SDO_DAS_XML_Document, setNoNamespaceSchemaLocation); +PHP_METHOD(SDO_DAS_XML_Document, setEncoding); #endif /* PHP_SDO_DAS_XML_H */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_das_xml_int.h?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/php_sdo_das_xml_int.h diff -u pecl/sdo/php_sdo_das_xml_int.h:1.9 pecl/sdo/php_sdo_das_xml_int.h:1.10 --- pecl/sdo/php_sdo_das_xml_int.h:1.9 Thu Jan 26 14:18:44 2006 +++ pecl/sdo/php_sdo_das_xml_int.h Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_das_xml_int.h,v 1.9 2006/01/26 14:18:44 mfp Exp $ */ +/* $Id: php_sdo_das_xml_int.h,v 1.10 2006/02/20 18:50:25 mfp Exp $ */ #ifndef _PHP_SDO_DEFS_H #define _PHP_SDO_DEFS_H @@ -43,39 +43,34 @@ /***************** Dependencies between files within XML_DAS ********/ /* The following four are called from das_xml.cpp's MINIT, and will be found in SDO_DAS_XML., SDO_DAS_XML_Document., and xmldas_utils.cpp */ -void initialize_sdo_das_xml_class(TSRMLS_D); -void initialize_sdo_das_xml_document_class(TSRMLS_D); -void initialize_sdo_das_xml_parserexception_class(TSRMLS_D); -void initialize_sdo_das_xml_fileexception_class(TSRMLS_D); +void sdo_das_xml_minit(TSRMLS_D); +void sdo_das_xml_document_minit(TSRMLS_D); +void sdo_das_xml_parserexception_minit(TSRMLS_D); +void sdo_das_xml_fileexception_minit(TSRMLS_D); /* The following three are defined in xmldas_utils.cpp - they logically belong in a xmldas_utils.h file */ -void sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); -void sdo_das_xml_throw_fileexception(char* filename TSRMLS_DC); -void sdo_das_xml_throw_parserexception(char* filename TSRMLS_DC); +zval *sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +zval *sdo_das_xml_throw_fileexception(char* filename TSRMLS_DC); +zval *sdo_das_xml_throw_parserexception(char* filename TSRMLS_DC); + +extern PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_class_entry; +extern PHP_SDO_DAS_XML_API zend_class_entry *sdo_das_xml_document_class_entry; /******************* Our data types ***********************************/ /* SDO_DAS_XML */ typedef struct { - zend_object z_obj; - XMLHelperPtr xmlHelper; - XSDHelperPtr xsdHelper; - SDOXMLString targetNamespaceURI; - zval *php_das_df; - DataFactoryPtr dataFactory; // Hydra dF + zend_object zo; + XMLHelperPtr xmlHelperPtr; + XSDHelperPtr xsdHelperPtr; + zval z_df; } xmldas_object; /* SDO_DAS_XML_Document */ typedef struct { - zend_object z_obj; - XMLDocumentPtr xdoch; + zend_object zo; + XMLDocumentPtr xmlDocumentPtr; } xmldocument_object; -/* SDO_DAS_DataFactory */ -typedef struct { - zend_object zo; - DataFactoryPtr dfp; -} sdo_das_df_object; - #endif /*_PHP_SDO_DEFS_H*/ /* http://cvs.php.net/viewcvs.cgi/pecl/sdo/php_sdo_int.h?r1=1.12&r2=1.13&diff_format=u Index: pecl/sdo/php_sdo_int.h diff -u pecl/sdo/php_sdo_int.h:1.12 pecl/sdo/php_sdo_int.h:1.13 --- pecl/sdo/php_sdo_int.h:1.12 Wed Jan 25 17:08:02 2006 +++ pecl/sdo/php_sdo_int.h Mon Feb 20 18:50:25 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_sdo_int.h,v 1.12 2006/01/25 17:08:02 cem Exp $ */ +/* $Id: php_sdo_int.h,v 1.13 2006/02/20 18:50:25 mfp Exp $ */ #ifndef PHP_SDO_INT_H #define PHP_SDO_INT_H @@ -44,15 +44,6 @@ #define SDO_TOSTRING_MAX 1024 -/** - * The internal structure for an SDO_DataObjectImpl - * This extends the standard zend_object - */ -typedef struct { - zend_object zo; /* The standard zend_object */ - DataObjectPtr dop; /* The C++ DataObject */ -} sdo_do_object; - enum sdo_changesummary_type { CS_NONE = 0, CS_MODIFICATION = 1, @@ -94,12 +85,15 @@ extern PHP_SDO_API zend_class_entry *sdo_invalidconversionexception_class_entry; extern PHP_SDO_API zend_class_entry *sdo_indexoutofboundsexception_class_entry; extern PHP_SDO_API zend_class_entry *sdo_unsupportedoperationexception_class_entry; +extern PHP_SDO_API zend_class_entry *sdo_cppexception_class_entry; extern PHP_SDO_API void sdo_das_df_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_das_df_new(zval *me, DataFactoryPtr dfp TSRMLS_DC); +extern PHP_SDO_API DataFactoryPtr sdo_das_df_get(zval *me TSRMLS_DC); extern PHP_SDO_API void sdo_do_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_do_new(zval *me, DataObjectPtr dop TSRMLS_DC); +extern PHP_SDO_API DataObjectPtr sdo_do_get(zval *me TSRMLS_DC); extern PHP_SDO_API void sdo_list_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_dataobjectlist_new(zval *me, const Type& typeh, DataObjectList *listh TSRMLS_DC); @@ -114,7 +108,7 @@ extern PHP_SDO_API void sdo_das_setting_new(zval *me, Setting *setting TSRMLS_DC); extern PHP_SDO_API void sdo_sequence_minit(zend_class_entry *tmp TSRMLS_DC); -extern PHP_SDO_API void sdo_sequence_new(zval *me, SequencePtr seqp, DataObjectPtr dop TSRMLS_DC); +extern PHP_SDO_API void sdo_sequence_new(zval *me, SequencePtr seqp TSRMLS_DC); extern PHP_SDO_API void sdo_model_type_minit(zend_class_entry *tmp TSRMLS_DC); extern PHP_SDO_API void sdo_model_type_new(zval *me, const Type *typep TSRMLS_DC); @@ -127,18 +121,19 @@ extern PHP_SDO_API void sdo_model_rdo_minit(zend_class_entry *tmp TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_propertytnotfoundexception(SDOPropertyNotFoundException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_typenotfoundexception(SDOTypeNotFoundException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_unsupportedoperationexception(SDOUnsupportedOperationException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_invalidconversionexception(SDOInvalidConversionException *e TSRMLS_DC); -extern PHP_SDO_API void sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +extern PHP_SDO_API zval *sdo_throw_exception(zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC); +extern PHP_SDO_API zval *sdo_throw_exception_ex(zend_class_entry *ce, long code, zval *z_cause TSRMLS_DC, char *format, ...); +extern PHP_SDO_API void sdo_exception_minit(zend_class_entry *tmp TSRMLS_DC); +extern PHP_SDO_API void sdo_exception_new(zval *me, zend_class_entry *ce, const char *message, long code, zval *cause TSRMLS_DC); +extern PHP_SDO_API function_entry *sdo_exception_get_methods(); +extern PHP_SDO_API zval *sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC); +extern PHP_SDO_API void sdo_cppexception_minit(zend_class_entry *tmp TSRMLS_DC); +extern PHP_SDO_API void sdo_cppexception_new(zval *me, SDORuntimeException *cpp_exception TSRMLS_DC); extern PHP_SDO_API void sdo_make_long_class_constant(zend_class_entry *ce, char *name, long value); extern PHP_SDO_API xmldas::XMLDAS *sdo_get_XMLDAS(); -extern PHP_SDO_API function_entry *sdo_get_exception_methods(); - extern PHP_SDO_API int sdo_parse_offset_param(DataObjectPtr dop, zval *z_offset, const Property **return_property, const char **return_xpath, int property_required, int quiet TSRMLS_DC); extern PHP_SDO_API Type::Types sdo_map_zval_type (zval *z_value); http://cvs.php.net/viewcvs.cgi/pecl/sdo/sdo.cpp?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/sdo.cpp diff -u pecl/sdo/sdo.cpp:1.8 pecl/sdo/sdo.cpp:1.9 --- pecl/sdo/sdo.cpp:1.8 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/sdo.cpp Mon Feb 20 18:50:25 2006 @@ -20,7 +20,7 @@ */ -static char rcs_id[] = "$Id: sdo.cpp,v 1.8 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: sdo.cpp,v 1.9 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> @@ -72,6 +72,7 @@ PHP_SDO_API zend_class_entry *sdo_invalidconversionexception_class_entry; PHP_SDO_API zend_class_entry *sdo_indexoutofboundsexception_class_entry; PHP_SDO_API zend_class_entry *sdo_unsupportedoperationexception_class_entry; +PHP_SDO_API zend_class_entry *sdo_cppexception_class_entry; /* }}} */ /* {{{ single SDO_DataObject parameter */ @@ -102,12 +103,12 @@ ZEND_END_ARG_INFO(); function_entry sdo_dataobject_methods[] = { - ZEND_ABSTRACT_ME(SDO_DataObject, getType, 0) + ZEND_ABSTRACT_ME(SDO_DataObject, getTypeName, 0) + ZEND_ABSTRACT_ME(SDO_DataObject, getTypeNamespaceURI, 0) ZEND_ABSTRACT_ME(SDO_DataObject, getSequence, 0) ZEND_ABSTRACT_ME(SDO_DataObject, createDataObject, arginfo_sdo_dataobject_createdataobject) ZEND_ABSTRACT_ME(SDO_DataObject, clear, 0) ZEND_ABSTRACT_ME(SDO_DataObject, getContainer, 0) - ZEND_ABSTRACT_ME(SDO_DataObject, getContainmentPropertyName, 0) {NULL, NULL, NULL} }; /* }}} */ @@ -130,8 +131,6 @@ function_entry sdo_sequence_methods[] = { ZEND_ABSTRACT_ME(SDO_Sequence, getProperty, arginfo_sdo_sequence_getproperty) - ZEND_ABSTRACT_ME(SDO_Sequence, getPropertyIndex, arginfo_sdo_sequence_getproperty) - ZEND_ABSTRACT_ME(SDO_Sequence, getPropertyName, arginfo_sdo_sequence_getproperty) ZEND_ABSTRACT_ME(SDO_Sequence, move, arginfo_sdo_sequence_move) ZEND_ABSTRACT_ME(SDO_Sequence, insert, arginfo_sdo_sequence_insert) ZEND_ABSTRACT_ME(SDO_Sequence, count, 0) @@ -155,7 +154,7 @@ /* {{{ SDO_DataFactory methods */ static ZEND_BEGIN_ARG_INFO(arginfo_sdo_datafactory_create, 0) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_END_ARG_INFO(); @@ -174,16 +173,16 @@ /* {{{ SDO_DAS_DataFactory methods */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_sdo_das_datafactory_addType, 0, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); static ZEND_BEGIN_ARG_INFO_EX(arginfo_sdo_das_datafactory_addPropertyToType, 0, ZEND_RETURN_VALUE, 5) - ZEND_ARG_INFO(0, parent_namespace_uri) + ZEND_ARG_INFO(0, parent_type_namespace_uri) ZEND_ARG_INFO(0, parent_type_name) ZEND_ARG_INFO(0, property_name) - ZEND_ARG_INFO(0, namespace_uri) + ZEND_ARG_INFO(0, type_namespace_uri) ZEND_ARG_INFO(0, type_name) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO(); @@ -236,12 +235,12 @@ ZEND_ME(SDO_DataObjectImpl, __set, arginfo___set, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, count, 0, ZEND_ACC_PUBLIC) /* inherited from SDO_DataObject ... */ - ZEND_ME(SDO_DataObjectImpl, getType, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DataObjectImpl, getTypeName, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_DataObjectImpl, getTypeNamespaceURI, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, getSequence, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, createDataObject, arginfo_sdo_dataobject_createdataobject, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, clear, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_DataObjectImpl, getContainer, 0, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_DataObjectImpl, getContainmentPropertyName, 0, ZEND_ACC_PUBLIC) /* inherited from SDO_DAS_DataObject ... */ ZEND_ME(SDO_DataObjectImpl, getChangeSummary, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} @@ -251,8 +250,6 @@ /* {{{ SDO_SequenceImpl methods */ function_entry sdo_sequenceimpl_methods[] = { ZEND_ME(SDO_SequenceImpl, getProperty, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_SequenceImpl, getPropertyIndex, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) - ZEND_ME(SDO_SequenceImpl, getPropertyName, arginfo_sdo_sequence_getproperty, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, move, arginfo_sdo_sequence_move, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, insert, arginfo_sdo_sequence_insert, ZEND_ACC_PUBLIC) ZEND_ME(SDO_SequenceImpl, count, 0, ZEND_ACC_PUBLIC) @@ -274,6 +271,7 @@ ZEND_ABSTRACT_ME(SDO_Model_Type, isDataType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, isSequencedType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, isOpenType, 0) + ZEND_ABSTRACT_ME(SDO_Model_Type, isAbstractType, 0) ZEND_ABSTRACT_ME(SDO_Model_Type, getBaseType, 0) {NULL, NULL, NULL} }; @@ -288,6 +286,7 @@ ZEND_ME(SDO_Model_TypeImpl, isDataType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, isSequencedType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, isOpenType, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_Model_TypeImpl, isAbstractType, 0, ZEND_ACC_PUBLIC) ZEND_ME(SDO_Model_TypeImpl, getBaseType, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -338,17 +337,29 @@ }; /* }}} */ -/* {{{ SDO_Exception methods - * These are used for all SDO exceptions, none of them have any methods other than inherited ones - */ +/* {{{ SDO_Exception methods */ function_entry sdo_exception_methods[] = { + ZEND_ME(SDO_Exception, getCause, 0, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; +/* }}} */ + +/* {{{ SDO_CPPException methods */ +function_entry sdo_cppexception_methods[] = { + ZEND_ME(SDO_CPPException, getClass, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getFile, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getLine, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getFunction, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getMessage, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, getSeverity, 0, ZEND_ACC_PUBLIC) + ZEND_ME(SDO_CPPException, __toString, 0, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ -/* {{{ sdo_get_exception_methods +/* {{{ sdo_exception_get_methods */ -PHP_SDO_API function_entry *sdo_get_exception_methods() +PHP_SDO_API function_entry *sdo_exception_get_methods() { return sdo_exception_methods; } @@ -483,14 +494,7 @@ /* class SDO_Exception extends Exception */ INIT_CLASS_ENTRY(ce, "SDO_Exception", sdo_exception_methods); - sdo_exception_class_entry = zend_register_internal_class_ex( - &ce, -#if (PHP_MAJOR_VERSION < 6) - zend_exception_get_default(), -#else - zend_exception_get_default(TSRMLS_C), -#endif - NULL TSRMLS_CC); + sdo_exception_minit(&ce TSRMLS_CC); /* class SDO_PropertyNotFoundException extends SDO_Exception */ INIT_CLASS_ENTRY(ce, "SDO_PropertyNotFoundException", sdo_exception_methods); @@ -522,6 +526,9 @@ sdo_unsupportedoperationexception_class_entry = zend_register_internal_class_ex( &ce, sdo_exception_class_entry, NULL TSRMLS_CC); + /* class SDO_CPPException */ + INIT_CLASS_ENTRY(ce, "SDO_CPPException", sdo_cppexception_methods); + sdo_cppexception_minit(&ce TSRMLS_CC); return SUCCESS; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/sdo_utils.cpp?r1=1.6&r2=1.7&diff_format=u Index: pecl/sdo/sdo_utils.cpp diff -u pecl/sdo/sdo_utils.cpp:1.6 pecl/sdo/sdo_utils.cpp:1.7 --- pecl/sdo/sdo_utils.cpp:1.6 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/sdo_utils.cpp Mon Feb 20 18:50:25 2006 @@ -20,7 +20,7 @@ */ -static char rcs_id[] = "$Id: sdo_utils.cpp,v 1.6 2006/01/17 09:41:27 cem Exp $"; +static char rcs_id[] = "$Id: sdo_utils.cpp,v 1.7 2006/02/20 18:50:25 mfp Exp $"; /* * Utility functions for internal use by the SDO extension @@ -32,94 +32,11 @@ #endif #include "php.h" -#include "zend_exceptions.h" #include "php_sdo_int.h" static xmldas::XMLDAS *xmldasp = NULL; -/* {{{ sdo_throw_exception - * rethrows a C++ SDO exception with a PHP SDO exception wrapper - */ -static void sdo_throw_exception(zend_class_entry *ce, SDORuntimeException *e, char *extra TSRMLS_DC) -{ - if (extra) - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s: %s\n Filename %s\n At line %ld in function %s\n Message %s\n", - extra, e->getEClassName(), e->getFileName(), e->getLineNumber(), e->getFunctionName(), e->getMessageText()); - else - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n Filename %s\n At line %ld in function %s\n Message %s\n", - e->getEClassName(), e->getFileName(), e->getLineNumber(), e->getFunctionName(), e->getMessageText()); -} -/* }}} */ - -/* {{{ sdo_throw_typenotfoundexception - */ -void sdo_throw_typenotfoundexception(SDOTypeNotFoundException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_typenotfoundexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_propertynotfoundexception - */ -void sdo_throw_propertynotfoundexception(SDOPropertyNotFoundException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_propertynotfoundexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_unsupportedoperationexception - */ -void sdo_throw_unsupportedoperationexception(SDOUnsupportedOperationException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_unsupportedoperationexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_invalidconversionexception - */ -void sdo_throw_invalidconversionexception(SDOInvalidConversionException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_invalidconversionexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_indexoutofboundsexception - */ -void sdo_throw_indexoutfboundsexception(SDOIndexOutOfRangeException *e TSRMLS_DC) -{ - sdo_throw_exception(sdo_indexoutofboundsexception_class_entry, e, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ sdo_throw_runtimeexception - * maps a C++ SDO exception to a PHP SDO exception and throws it - */ -void sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) -{ - zend_class_entry *exception_class; - const char *exception_type = e->getEClassName(); - - if (strcmp(exception_type, "SDOUnsupportedOperationException") == 0) - exception_class = sdo_unsupportedoperationexception_class_entry; - else if (strcmp(exception_type, "SDOPropertyNotFoundException") == 0 || - strcmp(exception_type, "SDOPathNotFoundException") == 0) - exception_class = sdo_propertynotfoundexception_class_entry; - else if (strcmp(exception_type, "SDOTypeNotFoundException") == 0) - exception_class = sdo_typenotfoundexception_class_entry; - else if (strcmp(exception_type, "SDOIndexOutOfRangeException") == 0) - exception_class = sdo_indexoutofboundsexception_class_entry; - else if (strcmp(exception_type, "SDOInvalidConversionException") == 0) - exception_class = sdo_invalidconversionexception_class_entry; - else if (strcmp(exception_type, "SDOPropertyNotSetException") == 0) - exception_class = sdo_propertynotsetexception_class_entry; - else - exception_class = sdo_exception_class_entry; - - sdo_throw_exception(exception_class, e, NULL TSRMLS_CC); -} -/* }}} */ - /* {{{ sdo_make_long_class_constant * creates a class constant */ @@ -164,26 +81,23 @@ case IS_NULL: if (!quiet) { class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_WARNING, "%s%s%s(): parameter is NULL", + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): parameter is NULL", class_name, space, get_active_function_name(TSRMLS_C)); } return FAILURE; case IS_STRING: xpath = Z_STRVAL_P(z_offset); - + /* If the type is open, then it's OK for the xpath offset to * specify an unknown property. But even an open type may have * defined properties, so we still need to try for one. */ - try { + if (property_required || dop->hasProperty(xpath)) { + /* exception will be thrown if xpath is invalid */ property_p = &dop->getProperty(xpath); - } catch (SDORuntimeException e) { - if (property_required) { - throw e; - return FAILURE; - } else { - property_p = NULL; - } + } else { + property_p = NULL; } break; case IS_LONG: @@ -210,8 +124,9 @@ case IS_OBJECT: if (!instanceof_function(Z_OBJCE_P(z_offset), sdo_model_property_class_entry TSRMLS_CC)) { if (!quiet) { - class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_WARNING, "%s%s%s(): expects object parameter to be SDO_Model_Property, %s given", + class_name = get_active_class_name(&space TSRMLS_CC); + sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC, + "%s%s%s(): expects object parameter to be SDO_Model_Property, %s given", class_name, space, get_active_function_name(TSRMLS_C), Z_OBJCE_P(z_offset)->name); } @@ -223,7 +138,7 @@ default: if (!quiet) { class_name = get_active_class_name(&space TSRMLS_CC); - php_error(E_ERROR, "%s%s%s(): invalid dimension type %i", + php_error(E_ERROR, "%s%s%s(): internal error - invalid dimension type %i", class_name, space, get_active_function_name(TSRMLS_C), Z_TYPE_P(z_offset)); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/xmldas_utils.cpp?r1=1.8&r2=1.9&diff_format=u Index: pecl/sdo/xmldas_utils.cpp diff -u pecl/sdo/xmldas_utils.cpp:1.8 pecl/sdo/xmldas_utils.cpp:1.9 --- pecl/sdo/xmldas_utils.cpp:1.8 Fri Dec 2 17:33:47 2005 +++ pecl/sdo/xmldas_utils.cpp Mon Feb 20 18:50:25 2006 @@ -15,11 +15,11 @@ | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ -| Author: Anantoju V Srinivas (Srini), Matthew Peters | +| Author: Anantoju V Srinivas(Srini), Matthew Peters, Caroline Maynard | +----------------------------------------------------------------------+ */ -static char rcs_id[] = "$Id: xmldas_utils.cpp,v 1.8 2005/12/02 17:33:47 mfp Exp $"; +static char rcs_id[] = "$Id: xmldas_utils.cpp,v 1.9 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 /* disable warning about identifier lengths in browser information */ @@ -27,7 +27,7 @@ #include <iostream> #include <math.h> #include "zend_config.w32.h" -#endif +#endif #include "php_sdo_das_xml_int.h" @@ -36,75 +36,47 @@ zend_class_entry *sdo_das_xml_parserexception_ce = NULL; zend_class_entry *sdo_das_xml_fileexception_ce = NULL; -/* {{{ initialize_sdo_das_parserexception_class +/* {{{ sdo_das_parserexception_minit */ -void initialize_sdo_das_xml_parserexception_class(TSRMLS_D) +void sdo_das_xml_parserexception_minit(TSRMLS_D) { - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_ParserException", sdo_get_exception_methods()); + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_ParserException", sdo_exception_get_methods()); sdo_das_xml_parserexception_ce = zend_register_internal_class_ex(&ce, NULL, "sdo_exception" TSRMLS_CC); } /* }}} */ -/* {{{ initialize_sdo_das_parserexception_class +/* {{{ sdo_das_parserexception_minit */ -void initialize_sdo_das_xml_fileexception_class(TSRMLS_D) +void sdo_das_xml_fileexception_minit(TSRMLS_D) { - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_FileException", sdo_get_exception_methods()); + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "SDO_DAS_XML_FileException", sdo_exception_get_methods()); sdo_das_xml_fileexception_ce = zend_register_internal_class_ex(&ce, NULL, "sdo_exception" TSRMLS_CC); } /* }}} */ -/* {{{ sdo_das_xml_throw_exception - * Throws C++ SDO exception as PHP exception - */ -static void -sdo_das_xml_throw_exception(zend_class_entry *ce, SDORuntimeException *e, char *extra TSRMLS_DC) -{ - if (extra) { - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s: %s\n Filename %s\n At line %ld in function %s\n Message %s\n", - extra, e->getEClassName(), e->getFileName(), - e->getLineNumber(), e->getFunctionName(), - e->getMessageText()); - } else { - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n Filename %s\n At line %ld in function %s\n Message %s\n", - e->getEClassName(), e->getFileName(), - e->getLineNumber(), e->getFunctionName(), - e->getMessageText()); - } -} -/* }}} */ - /* {{{ sdo_das_xml_throw_runtimeexception */ -void -sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) +zval *sdo_das_xml_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) { - const char *exception_type = e->getEClassName(); - sdo_throw_runtimeexception(e TSRMLS_CC); + return sdo_throw_runtimeexception(e TSRMLS_CC); } /* }}} */ /* {{{ sdo_das_xml_throw_parserexception */ -void -sdo_das_xml_throw_parserexception(char * msg TSRMLS_DC) +zval *sdo_das_xml_throw_parserexception(char *msg TSRMLS_DC) { - zend_class_entry *ce = sdo_das_xml_parserexception_ce; - - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "%s\n", msg); + return zend_throw_exception(sdo_das_xml_parserexception_ce, msg, 0 TSRMLS_CC); } /* }}} */ /* {{{ sdo_das_xml_throw_fileexception */ -void sdo_das_xml_throw_fileexception(char *filename TSRMLS_DC) +zval *sdo_das_xml_throw_fileexception(char *filename TSRMLS_DC) { - zend_class_entry *ce = sdo_das_xml_fileexception_ce; - - zend_throw_exception_ex(ce, 0 TSRMLS_CC, "File \"%s\" could not be found.\n", filename); + return zend_throw_exception_ex(sdo_das_xml_fileexception_ce, + 0 TSRMLS_CC, "File \"%s\" could not be found", filename); } /* }}} */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational.php?r1=1.9&r2=1.10&diff_format=u Index: pecl/sdo/DAS/Relational.php diff -u pecl/sdo/DAS/Relational.php:1.9 pecl/sdo/DAS/Relational.php:1.10 --- pecl/sdo/DAS/Relational.php:1.9 Fri Jan 20 12:34:43 2006 +++ pecl/sdo/DAS/Relational.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: Relational.php,v 1.9 2006/01/20 12:34:43 mfp Exp $ +$Id: Relational.php,v 1.10 2006/02/20 18:50:25 mfp Exp $ */ require_once 'SDO/DAS/Relational/Exception.php'; @@ -145,7 +145,7 @@ $dbh->commit(); return $root; } - + /** * Given an SQL query in the form of a prepared PDO statement and a value list, execute it, * normalise the result set into a data graph and return it. @@ -160,13 +160,9 @@ $dbh->commit(); return $root; } - + public function normaliseResultSet($pdo_stmt, $column_specifier) { - if (gettype(PDO_FETCH_ASSOC) == 'string') { - include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; - } else { - include_once "SDO/DAS/Relational/PDOConstants.underscore.inc.php"; - } + include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; if ($column_specifier == null) { $all_rows = $pdo_stmt->fetchAll(SDO_DAS_Relational_PDO_FETCH_ASSOC); } else { @@ -243,7 +239,7 @@ throw new SDO_DAS_Relational_Exception('The result set from ExecuteQuery contained a column with name ' . $col . ' but there is no table with a column with this name.'); case 1: foreach ($table_names_with_this_column as $table_name => $property_name) // only one entry - $parsed_row[$table_name][$property_name] = $value; + $parsed_row[$table_name][$property_name] = $value; break; default: throw new SDO_DAS_Relational_Exception('The result set from ExecuteQuery contained a column with name ' . $col . ' but there is more than one table with a column with this name. You need to pass a column specifier to resolve the ambiguity.'); @@ -332,11 +328,11 @@ if ($setting->isSet()) { $original_value = $setting->getValue(); echo ", which had original value "; - ob_start(); - var_dump($original_value); - $content = ob_get_contents(); - ob_end_clean(); - echo "$content\n"; + ob_start(); + var_dump($original_value); + $content = ob_get_contents(); + ob_end_clean(); + echo "$content\n"; } else { echo ", which was originally not set\n"; } @@ -383,8 +379,8 @@ private static function isRoot($do) { - $reflection_do = new SDO_Model_ReflectionDataObject($do); - $type = $reflection_do->getType(); + $rdo = new SDO_Model_ReflectionDataObject($do); + $type = $rdo->getType(); return ($type->namespaceURI == SDO_DAS_Relational::DAS_NAMESPACE && $type->name == SDO_DAS_Relational::DAS_ROOT_TYPE); } @@ -392,7 +388,7 @@ { return $df->create(SDO_DAS_Relational::DAS_NAMESPACE, SDO_DAS_Relational::DAS_ROOT_TYPE); } - + public function getObjectModel() { return $this->object_model; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/DataObjectHelper.php?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/DAS/Relational/DataObjectHelper.php diff -u pecl/sdo/DAS/Relational/DataObjectHelper.php:1.5 pecl/sdo/DAS/Relational/DataObjectHelper.php:1.6 --- pecl/sdo/DAS/Relational/DataObjectHelper.php:1.5 Fri Jan 20 12:33:58 2006 +++ pecl/sdo/DAS/Relational/DataObjectHelper.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: DataObjectHelper.php,v 1.5 2006/01/20 12:33:58 mfp Exp $ +$Id: DataObjectHelper.php,v 1.6 2006/02/20 18:50:25 mfp Exp $ */ /** @@ -54,11 +54,11 @@ { $type = self::getApplicationType($data_object); $pk_property_name = $object_model->getPropertyRepresentingPrimaryKeyFromType($type); - if (!isset($data_object[$pk_property_name])) { - return null; - } else { + if (isset($data_object[$pk_property_name])) { $pk = $data_object[$pk_property_name]; return $pk; + } else { + return null; } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/InsertAction.php?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/DAS/Relational/InsertAction.php diff -u pecl/sdo/DAS/Relational/InsertAction.php:1.7 pecl/sdo/DAS/Relational/InsertAction.php:1.8 --- pecl/sdo/DAS/Relational/InsertAction.php:1.7 Wed Oct 19 11:35:42 2005 +++ pecl/sdo/DAS/Relational/InsertAction.php Mon Feb 20 18:50:25 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: InsertAction.php,v 1.7 2005/10/19 11:35:42 cem Exp $ +$Id: InsertAction.php,v 1.8 2006/02/20 18:50:25 mfp Exp $ */ /** @@ -159,11 +159,7 @@ private function storeThisObjectsPrimaryKey($dbh) { - if (gettype(PDO_FETCH_ASSOC) == 'string') { - include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; - } else { - include_once "SDO/DAS/Relational/PDOConstants.underscore.inc.php"; - } + include_once "SDO/DAS/Relational/PDOConstants.colon.inc.php"; $type = SDO_DAS_Relational_DataObjectHelper::getApplicationType($this->do); $pk_property_name = $this->object_model->getPropertyRepresentingPrimaryKeyFromType($type); http://cvs.php.net/viewcvs.cgi/pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql diff -u pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.3 pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.4 --- pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql:1.3 Tue Jan 17 09:47:58 2006 +++ pecl/sdo/DAS/Relational/Scenarios/companydb_db2.sql Mon Feb 20 18:50:25 2006 @@ -1,17 +1,17 @@ -connect to company - -drop table company -drop table department -drop table employee - -create table company ( id integer not null generated by default as identity, \ - name varchar(20), employee_of_the_month integer, \ - primary key(id)) - -create table department ( id integer not null generated by default as identity, \ - name varchar(20), location varchar(10), \ - number integer, co_id integer, primary key(id) ) - -create table employee ( id integer not null generated by default as identity, \ - name varchar(20), SN char(4), \ +connect to company + +drop table company +drop table department +drop table employee + +create table company ( id integer not null generated by default as identity, \ + name varchar(20), employee_of_the_month integer, \ + primary key(id)) + +create table department ( id integer not null generated by default as identity, \ + name varchar(20), location varchar(10), \ + number integer, co_id integer, primary key(id) ) + +create table employee ( id integer not null generated by default as identity, \ + name varchar(20), SN char(4), \ manager smallint, dept_id integer, primary key(id)) \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp diff -u pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.4 pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/ChangeSummaryImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/ChangeSummaryImpl.h" @@ -191,11 +191,11 @@ for (int j=0 ; j < slist.size();j++) { - if (!strcmp(slist[j].getProperty().getName(), + if (!strcmp(slist.get(j)->getProperty().getName(), prop.getName()) - && slist[j].getIndex() == + && slist.get(j)->getIndex() == index) { // these are settings of the same prop/index, we @@ -271,7 +271,7 @@ if (!ob->isSet(pl[i])) { - sl.append(Setting(false,false, 0,0,pl[i],0)); + sl.append(new Setting(false,false, 0,0,pl[i],0)); continue; } if (pl[i].isMany()) @@ -283,18 +283,18 @@ // needs to be the data object in cases where... if (pl[i].getType().isDataType()) { setPropValue(&value,&len,ob,pl[j]); - sl.append(Setting(true,false,value,len,pl[i],j)); + sl.append(new Setting(true,false,value,len,pl[i],j)); } else { value = (void*)dol[j]; - sl.append(Setting(true,false,value,0,pl[i],j)); + sl.append(new Setting(true,false,value,0,pl[i],j)); } } } else { setPropValue(&value,&len,ob,pl[i]); - sl.append(Setting(true,ob->isNull(pl[i]),value,len,pl[i],0)); + sl.append(new Setting(true,ob->isNull(pl[i]),value,len,pl[i],0)); } } @@ -315,17 +315,18 @@ { for (int i=0;i<sl.size();i++) { - if (!strcmp(slist[j].getProperty().getName(), - sl[i].getProperty().getName()) + if (!strcmp(slist.get(j)->getProperty().getName(), + sl.get(i)->getProperty().getName()) - && slist[j].getIndex() == - sl[i].getIndex()) + && slist.get(j)->getIndex() == + sl.get(i)->getIndex()) { // these are settings of the same prop/index, we // need the old value to get transferred. sl.remove(i); - sl.insert(i,slist[j]); + sl.insert(i,new Setting(*(slist.get(j)))); + } } } @@ -801,7 +802,7 @@ for (int i=0;i<slist.size();i++) { - if (!strcmp(slist[i].getProperty().getName(),prop.getName())) + if (!strcmp(slist.get(i)->getProperty().getName(),prop.getName())) { LOGINFO(INFO,"ChangeSummary: Change of a property which was already changed - ignore"); return; @@ -814,7 +815,7 @@ if (!ob->isSet(prop)) { - slist.append(Setting(false,false,0,0,prop,0)); + slist.append(new Setting(false,false,0,0,prop,0)); return; } @@ -828,7 +829,7 @@ DataObjectList& dol = ob->getList(prop); if (dol.size() == 0) { - slist.append(Setting(false,false,0,0,prop,0)); + slist.append(new Setting(false,false,0,0,prop,0)); return; } for (int i=0;i< dol.size(); i++) @@ -837,18 +838,18 @@ if (prop.getType().isDataType()) { setManyPropValue(&value, &len, (DataObjectImpl*)ob, (DataObjectImpl*)dob, prop); - slist.append(Setting(true,false,value,len,prop,i)); + slist.append(new Setting(true,false,value,len,prop,i)); } else{ value = (void*)dob; - slist.append(Setting(true,false,value,0,prop,i)); + slist.append(new Setting(true,false,value,0,prop,i)); } } } else { setPropValue(&value,&len,ob,prop); - slist.append(Setting(true,ob->isNull(prop),value,len,prop,0)); + slist.append(new Setting(true,ob->isNull(prop),value,len,prop,0)); } return; @@ -1130,8 +1131,8 @@ for (int i=0;i < sl.size(); i++) { if (!strcmp(property.getName(), - sl[i].getProperty().getName())) - return (sl[i]); + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); } } @@ -1142,8 +1143,8 @@ for (int i=0;i < sl.size(); i++) { if (!strcmp(property.getName(), - sl[i].getProperty().getName())) - return (sl[i]); + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); } } @@ -1347,7 +1348,7 @@ unsigned int len = stringConvert(&datavalue, (const char*)value , p); - slist.append(Setting(true,false,datavalue,len,p,index)); + slist.append(new Setting(true,false,datavalue,len,p,index)); // The datavalue will be freed by the deletion of the setting later } @@ -1388,7 +1389,7 @@ // against existing settings - slist.append(Setting(true,false,(void*)indob,0,p,index)); + slist.append(new Setting(true,false,(void*)indob,0,p,index)); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataFactoryImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataFactoryImpl.cpp diff -u pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.4 pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/DataFactoryImpl.cpp:1.4 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataFactoryImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ ////////////////////////////////////////////////////////////////////// // DataFactoryImpl.cpp: implementation of the DataFactory class. @@ -358,9 +358,9 @@ if(typeIter == types.end()) { string msg("Type not found: "); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += inTypeName; + if (inTypeName != 0)msg += inTypeName; SDO_THROW_EXCEPTION("addPropertyToType", SDOTypeNotFoundException, msg.c_str()); @@ -381,9 +381,9 @@ if (typeIter2 == types.end()) { string msg("Type not found: "); - msg += propTypeUri; + if (propTypeUri != 0)msg += propTypeUri; msg += " "; - msg += propTypeName; + if (propTypeName != 0)msg += propTypeName; SDO_THROW_EXCEPTION("addPropertyToType", SDOTypeNotFoundException, msg.c_str()); } @@ -902,9 +902,9 @@ if (type == 0) { string msg("Type not found :"); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += inTypeName; + if (inTypeName != 0)msg += inTypeName; SDO_THROW_EXCEPTION("getTypeImpl" , SDOTypeNotFoundException, msg.c_str()); } @@ -1059,7 +1059,7 @@ string msg("Instantiation of unknown type :"); if (uri != 0) msg += uri; msg += " "; - msg += typeName; + if (typeName != 0)msg += typeName; SDO_THROW_EXCEPTION("create" , SDOTypeNotFoundException, msg.c_str()); } @@ -1067,9 +1067,9 @@ if (ti->isAbstractType()) { string msg("Instantiation of abstract type :"); - msg += uri; + if (uri != 0)msg += uri; msg += " "; - msg += typeName; + if (typeName != 0)msg += typeName; SDO_THROW_EXCEPTION("create" , SDOUnsupportedOperationException, msg.c_str()); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObject.h?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObject.h diff -u pecl/sdo/commonj/sdo/DataObject.h:1.4 pecl/sdo/commonj/sdo/DataObject.h:1.5 --- pecl/sdo/commonj/sdo/DataObject.h:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObject.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECT_H_ #define _DATAOBJECT_H_ @@ -109,7 +109,11 @@ virtual SDO_API PropertyList getInstanceProperties() = 0; - + /** + * See if the property currently exists + */ + + virtual SDO_API bool hasProperty(const char* name) = 0; /** * These are just like getType().getProperty(), but may return * values other than the property list for open types. http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.5 pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.6 --- pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.5 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/DataObjectImpl.h" @@ -1228,9 +1228,26 @@ d->setNull(); } else { - const Property& p = d->getProperty(prop); + const PropertyImpl* p = d->getPropertyImpl(prop); + if (p == 0) + { + if(d->getType().isOpenType()) + { + string msg("Cannot set unassigned open property to null:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOUnsupportedOperationException, + msg.c_str()); + } + else + { + string msg("Property Not Found:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOPropertyNotFoundException, + msg.c_str()); + } + } delete prop; - d->setNull(p); + d->setNull((Property&)*p); return; } } @@ -1398,6 +1415,18 @@ return (Property&)*pi; } + /** + * See if the property currently exists + */ + + bool DataObjectImpl::hasProperty(const char* name) + { + PropertyImpl* pi = getPropertyImpl(name); + if (pi == 0) return false; + return true; + } + + PropertyImpl* DataObjectImpl::getPropertyImpl(unsigned int index) { PropertyList props = getType().getProperties(); @@ -2351,8 +2380,11 @@ char *c1 = strchr(c,']'); if (c1 != 0)*c1 = 0; unsigned int i = atoi(++c); - DataObjectList& li = d->getList(p); - li.remove(i); + if (i > 0){ + i--; + DataObjectList& li = d->getList(p); + li.remove(i); + } delete prop; return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.h?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectImpl.h:1.4 pecl/sdo/commonj/sdo/DataObjectImpl.h:1.5 --- pecl/sdo/commonj/sdo/DataObjectImpl.h:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTIMPL_H_ #define _DATAOBJECTIMPL_H_ @@ -389,6 +389,11 @@ virtual DataObjectPtr createDataObject(const Property& property); + /** + * See if the property currently exists + */ + + virtual bool hasProperty(const char* name); virtual void detach(); @@ -552,7 +557,7 @@ virtual bool remove(DataObjectImpl* indol); virtual bool isSet(const Property& prop, unsigned int propertyIndex); - + virtual DataObjectImpl* getDataObjectImpl(const char* path); virtual DataObjectImpl* getDataObjectImpl(unsigned int propertyIndex); virtual DataObjectImpl* getDataObjectImpl(const Property& property); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectList.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectList.h diff -u pecl/sdo/commonj/sdo/DataObjectList.h:1.2 pecl/sdo/commonj/sdo/DataObjectList.h:1.3 --- pecl/sdo/commonj/sdo/DataObjectList.h:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectList.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTLIST_H_ #define _DATAOBJECTLIST_H_ @@ -166,6 +166,25 @@ */ virtual SDO_API DataObjectPtr remove (unsigned int index) = 0; + + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual SDO_API const Type& getType() = 0; + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual SDO_API const Type::Types getTypeEnum() = 0; + }; }; }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectListImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectListImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.4 pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/DataObjectListImpl.cpp:1.4 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/DataObjectListImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/DataObjectListImpl.h" @@ -164,10 +164,39 @@ } + +const Type& DataObjectListImpl::getType() +{ + if (typeUnset) + { + string msg("The list property is open, and the type of the contents has not bee determined yet."); + SDO_THROW_EXCEPTION("Get Type", SDOTypeNotFoundException, + msg.c_str()); + } + return theFactory->getType(typeURI, typeName); +} + + +const Type::Types DataObjectListImpl::getTypeEnum() +{ + if (typeUnset) + { + return Type::UndefinedOpenPropertyType; + + } + return theFactory->getType(typeURI, typeName).getTypeEnum(); +} + + void DataObjectListImpl::insert (unsigned int index, DataObjectPtr d) { if (typeUnset)setType(d->getType().getURI(),d->getType().getName()); + checkFactory(d); + + checkType(theFactory->getType(typeURI,typeName), + d->getType()); + if (container != 0) { container->logChange(pindex); @@ -240,40 +269,67 @@ } + void DataObjectListImpl::checkFactory(DataObjectPtr dob) + { + + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dob; + + if (d->getDataFactory() == theFactory) return; + + string msg("Insertion from incompatible factory "); + const Type& t = d->getType(); + msg += t.getURI(); + msg += "#"; + msg += t.getName(); + msg += " into list "; + msg += typeURI; + msg += "#"; + msg += typeName; + SDO_THROW_EXCEPTION("checkFactory", SDOInvalidConversionException, + msg.c_str()); + } + + void DataObjectListImpl::checkType(const Type& listType, const Type& objectType) { if (listType.equals(objectType)) return; const TypeImpl* ti = ((DataFactoryImpl*)theFactory)->findTypeImpl (objectType.getURI(),objectType.getName()); - - do + if (ti != 0) { - ti = (const TypeImpl*)ti->getBaseType(); - if (ti == 0) break; - if (listType.equals(*ti)) return; - } while (ti != 0); - - // allow types of any substitutes - if (container != 0) - { - PropertyImpl* pi = - container->getPropertyImpl(pindex); - if (pi != 0) + do { - unsigned int subcount = pi->getSubstitutionCount(); - for (int i=0;i<subcount;i++) + ti = (const TypeImpl*)ti->getBaseType(); + if (ti == 0) break; + if (listType.equals(*ti)) return; + } while (ti != 0); + + // allow types of any substitutes + if (container != 0) + { + PropertyImpl* pi = + container->getPropertyImpl(pindex); + if (pi != 0) { - const Type* tsub = pi->getSubstitutionType(i); - if (tsub != 0 && tsub->equals(objectType)) return; + unsigned int subcount = pi->getSubstitutionCount(); + for (int i=0;i<subcount;i++) + { + const Type* tsub = pi->getSubstitutionType(i); + if (tsub != 0 && tsub->equals(objectType)) return; + } } } } // no match.. string msg("Insertion of object of incompatible type "); + msg += objectType.getURI(); + msg += "#"; msg += objectType.getName(); - msg += " into property of type "; + msg += " into list of type "; + msg += listType.getURI(); + msg += "#"; msg += listType.getName(); SDO_THROW_EXCEPTION("TypeCheck", SDOInvalidConversionException, msg.c_str()); @@ -332,6 +388,7 @@ } } + checkFactory(d); checkType(theFactory->getType(typeURI,typeName), d->getType()); @@ -939,6 +996,15 @@ void DataObjectListImpl::setDataObject(unsigned int index, DataObjectPtr dob) { + + if (dob != 0) + { + checkFactory(dob); + + checkType(theFactory->getType(typeURI,typeName), + dob->getType()); + } + validateIndex(index); if (container != 0) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/DataObjectListImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectListImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.3 pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.4 --- pecl/sdo/commonj/sdo/DataObjectListImpl.h:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/DataObjectListImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _DATAOBJECTLISTIMPL_H_ #define _DATAOBJECTLISTIMPL_H_ @@ -140,9 +140,27 @@ virtual DataObjectPtr remove (unsigned int index); + virtual void checkFactory(DataObjectPtr dob); virtual void checkType(const Type& listType, const Type& objectType); virtual void setType(const char* uri, const char* name); + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual const Type& getType(); + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual const Type::Types getTypeEnum(); private: http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/PropertyImpl.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/PropertyImpl.cpp diff -u pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.4 pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.5 --- pecl/sdo/commonj/sdo/PropertyImpl.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/PropertyImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include <iostream> using namespace std; @@ -147,8 +147,8 @@ PropertyImpl::~PropertyImpl() { - if (name != 0) delete name; - if (defvalue != 0) delete defvalue; + if (name != 0) delete (char*)name; + if (defvalue != 0) delete (char*)defvalue; if (stringdef != 0) delete stringdef; for (int i = 0; i < aliases.size();i++) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SAX2Namespaces.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SAX2Namespaces.cpp diff -u pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.3 pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.4 --- pecl/sdo/commonj/sdo/SAX2Namespaces.cpp:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SAX2Namespaces.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SAX2Namespaces.h" @@ -73,7 +73,7 @@ { // add will not overwrite if it already exists namespaceMap[nsIter->first] = nsIter->second; - } + } return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.3 pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.3 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOSAX2Parser.h" @@ -775,22 +775,31 @@ // NOTE: always creating DO doesn't cater for DataType as top element - newDO = dataFactory->create(typeURI, typeName); - - // set the property setting if the root is an extended primitive const Type& tp = dataFactory->getType(typeURI,typeName); - // get the type definition, and see if its an extended primitive. - - XSDTypeInfo* typeInfo = (XSDTypeInfo*) - ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); - if (typeInfo) + if (tp.isDataType()) + { + newDO = dataFactory->create(tns, "RootType"); + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + } + else { - const TypeDefinition& typeDefinition = typeInfo->getTypeDefinition(); - if (typeDefinition.isExtendedPrimitive) + + newDO = dataFactory->create(typeURI, typeName); + + // get the type definition, and see if its an extended primitive. + + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo) { - // The name of this element is the name of a property on the current DO - currentPropertySetting = PropertySetting(newDO, localname, - bToBeNull); + const TypeDefinition& typeDefinition = typeInfo->getTypeDefinition(); + if (typeDefinition.isExtendedPrimitive) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + } } } @@ -833,7 +842,17 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; - } + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit5"); return; } @@ -904,6 +923,16 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit6"); return; } @@ -922,6 +951,16 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit7"); return; } @@ -942,6 +981,17 @@ ignoreTag.uri = URI; ignoreTag.prefix = prefix; ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) + { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit8"); return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp?r1=1.5&r2=1.6&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.5 pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.6 --- pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.5 Wed Jan 25 17:05:39 2006 +++ pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/25 17:05:39 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOSchemaSAX2Parser.h" #include "commonj/sdo/XSDPropertyInfo.h" @@ -70,6 +70,8 @@ { bInSchema = true; // Handle namespace definitions + + schemaInfo.getSchemaNamespaces().merge(namespaces); // Handle attributes @@ -80,7 +82,8 @@ schemaInfo.setTargetNamespaceURI(attributes[i].getValue()); } } - + + currentType.uri = schemaInfo.getTargetNamespaceURI(); currentType.name = "RootType"; currentType.localname="RootType"; @@ -138,6 +141,14 @@ startGroup(localname, prefix, URI, namespaces, attributes); } // end Group handling + else if (localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + if (setter) + { + setter->setError("Schema contains group or attributeGroup which are not yet implemented"); + } + } /////////////////////////////////////////////////////////////////////// // Handle simpleType // These become new types @@ -785,7 +796,7 @@ } // ============================================================================ - // setType + // setType // ============================================================================ void SDOSchemaSAX2Parser::setType( PropertyDefinition& property, @@ -943,6 +954,14 @@ if (qname.getURI().equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) { uri = Type::SDOTypeNamespaceURI; + if (qname.getLocalName().equalsIgnoreCase("ID")) + { + name = "String"; + } + if (qname.getLocalName().equalsIgnoreCase("NCName")) + { + name = "String"; + } if (qname.getLocalName().equalsIgnoreCase("string")) { name = "String"; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.2 pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.3 --- pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLStreamWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXMLStreamWriter.h" #include <sstream> @@ -37,9 +37,9 @@ { } - int SDOXMLStreamWriter::write(XMLDocumentPtr doc) + int SDOXMLStreamWriter::write(XMLDocumentPtr doc, int indent) { - int rc = SDOXMLBufferWriter::write(doc); + int rc = SDOXMLBufferWriter::write(doc, indent); // Now stream the buffer outXmlStream << getBuffer(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.2 pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.3 --- pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h:1.2 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLStreamWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXMLSTREAMWRITER_H_ #define _SDOXMLSTREAMWRITER_H_ @@ -42,7 +42,7 @@ SDOXMLStreamWriter(std::ostream& outXML, DataFactoryPtr dataFactory = NULL); virtual ~SDOXMLStreamWriter(); - int write(XMLDocumentPtr doc); + int write(XMLDocumentPtr doc, int indent = -1); private: std::ostream& outXmlStream; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.cpp?r1=1.4&r2=1.5&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.4 pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.5 --- pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.4 Tue Jan 17 09:41:27 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:27 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXMLWriter.h" #include "commonj/sdo/SDOXMLString.h" @@ -64,7 +64,7 @@ } } - int SDOXMLWriter::write(XMLDocumentPtr doc) + int SDOXMLWriter::write(XMLDocumentPtr doc, int indent) { if (!doc) { @@ -85,8 +85,22 @@ //namespaceStack.push(namespaces); namespaceMap.empty(); - //xmlTextWriterSetIndent(writer, 1); - //xmlTextWriterSetIndentString(writer, SDOXMLString(" ")); + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;i<indent;i++)chars[i] = ' '; + chars[indent] = 0; + xmlTextWriterSetIndentString(writer, SDOXMLString(chars)); + delete chars; + } + else + { + xmlTextWriterSetIndentString(writer, SDOXMLString("")); + } + } if (doc->getXMLDeclaration()) { @@ -148,41 +162,41 @@ { try { - if (sl[j].getProperty().isMany()) + if (sl.get(j)->getProperty().isMany()) { // manys are elements continue; } - if (sl[j].getProperty().getType().isDataType()) + if (sl.get(j)->getProperty().getType().isDataType()) { // data types are OK rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } else { - DataObjectPtr dob = sl[j].getDataObjectValue(); + DataObjectPtr dob = sl.get(j)->getDataObjectValue(); if (dob) { if (cs->isDeleted(dob)) { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString(cs->getOldXpath(dob))); } else { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString(dob->objectToXPath())); } } else { rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), + SDOXMLString(sl.get(j)->getProperty().getName()), SDOXMLString("")); } } @@ -218,33 +232,33 @@ { // single values will have been covered by the attributes. - if (!sl[j].getProperty().isMany()) continue; + if (!sl.get(j)->getProperty().isMany()) continue; - if (sl[j].getProperty().getType().isDataType()) + if (sl.get(j)->getProperty().getType().isDataType()) { rc = xmlTextWriterWriteElement( writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } // if datatype else { - DataObjectPtr dob2 = sl[j].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(j)->getDataObjectValue(); if (!dob2) { continue; } if (cs->isDeleted(dob2)) { - handleChangeSummaryDeletedObject(sl[j].getProperty().getName(), cs,dob2); + handleChangeSummaryDeletedObject(sl.get(j)->getProperty().getName(), cs,dob2); } else { rc = xmlTextWriterStartElement( writer, - SDOXMLString(sl[j].getProperty().getName())); + SDOXMLString(sl.get(j)->getProperty().getName())); rc = xmlTextWriterWriteAttribute( writer, SDOXMLString("sdo:ref"), @@ -296,26 +310,26 @@ for (int j=0;j< sl.size(); j++) { - //if (!sl[j].isSet()) + //if (!sl.get(j)->isSet()) //{ // // unset properties dont need recording - ah but they do! // // continue; //} - if ( sl[j].getProperty().isMany()) + if ( sl.get(j)->getProperty().isMany()) { // manys are elements continue; } - if (!sl[j].getProperty().getType().isDataType()) + if (!sl.get(j)->getProperty().getType().isDataType()) { // data objects are element in a deleted data object. continue; } rc = xmlTextWriterWriteAttribute(writer, - SDOXMLString(sl[j].getProperty().getName()), - SDOXMLString(sl[j].getCStringValue())); + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); } // for attributes @@ -329,14 +343,14 @@ for (k=sl.size()-1;k>=0; k--) { - if ( !sl[k].getProperty().getType().isDataType() && - sl[k].getProperty().isMany()) + if ( !sl.get(k)->getProperty().getType().isDataType() && + sl.get(k)->getProperty().isMany()) { // its a dataobject type - DataObjectPtr dob2 = sl[k].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); if (!dob2) continue; if (!cs->isDeleted(dob2)) continue; - handleChangeSummaryDeletedObject(sl[k]. + handleChangeSummaryDeletedObject(sl.get(k)-> getProperty().getName(),cs,dob2); } } // for attributes @@ -344,27 +358,27 @@ for (k=0;k< sl.size(); k++) { - if ( !sl[k].getProperty().getType().isDataType()) + if ( !sl.get(k)->getProperty().getType().isDataType()) { - if (sl[k].getProperty().isMany()) continue; + if (sl.get(k)->getProperty().isMany()) continue; // its a single valued dataobject type - DataObjectPtr dob2 = sl[k].getDataObjectValue(); + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); if (!dob2) continue; if (!cs->isDeleted(dob2)) continue; - handleChangeSummaryDeletedObject(sl[k]. + handleChangeSummaryDeletedObject(sl.get(k)-> getProperty().getName(),cs,dob2); } else { - if ( !sl[k].getProperty().isMany()) continue; + if ( !sl.get(k)->getProperty().isMany()) continue; // could only be many valued data type rc = xmlTextWriterWriteElement(writer, - SDOXMLString(sl[k].getProperty().getName()), - SDOXMLString(sl[k].getCStringValue())); + SDOXMLString(sl.get(k)->getProperty().getName()), + SDOXMLString(sl.get(k)->getCStringValue())); } } // for attributes } @@ -661,7 +675,13 @@ if (isRoot) { tnsURI=elementURI; - rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + if (elementURI.equals("")) { + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, NULL); + } + else + { + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + } if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); } @@ -672,7 +692,7 @@ SDOXMLString theName=elementName; - if (!elementURI.isNull() && !elementURI.equals(tnsURI)) + if (!elementURI.isNull() && !elementURI.equals(tnsURI) && !elementURI.equals("")) { std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); if (it != namespaceMap.end()) @@ -757,6 +777,7 @@ for (it = namespaceMap.begin();it != namespaceMap.end(); ++it) { + if ((*it).first.equals("")) continue; SDOXMLString space = SDOXMLString("xmlns:") + (*it).second; rc = xmlTextWriterWriteAttribute(writer, space, (*it).first); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.2 pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.3 --- pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXMLWRITER_H_ #define _SDOXMLWRITER_H_ @@ -50,7 +50,7 @@ virtual ~SDOXMLWriter(); - int write(XMLDocumentPtr doc); + int write(XMLDocumentPtr doc, int indent=-1); protected: void setWriter(xmlTextWriterPtr textWriter); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.3 pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDStreamWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXSDStreamWriter.h" #include <sstream> @@ -38,9 +38,9 @@ } int SDOXSDStreamWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops) + const propertyMap& openprops, int indent) { - int rc = SDOXSDBufferWriter::write(types, targetNamespaceURI, openprops); + int rc = SDOXSDBufferWriter::write(types, targetNamespaceURI, openprops, indent); // Now stream the buffer outXmlStream << getBuffer(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h diff -u pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.3 pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.4 --- pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDStreamWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXSDSTREAMWRITER_H_ #define _SDOXSDSTREAMWRITER_H_ @@ -43,7 +43,7 @@ virtual ~SDOXSDStreamWriter(); int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops); + const propertyMap& openprops, int indent = -1); private: std::ostream& outXmlStream; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDWriter.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.3 pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.4 --- pecl/sdo/commonj/sdo/SDOXSDWriter.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDWriter.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDOXSDWriter.h" #include "iostream" @@ -159,7 +159,7 @@ //////////////////////////////////////// int SDOXSDWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops) + const propertyMap& openprops, int indent) { int i; if (writer == NULL) @@ -170,7 +170,23 @@ int rc = 0; - + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;i<indent;i++)chars[i] = ' '; + chars[indent] = 0; + xmlTextWriterSetIndentString(writer, SDOXMLString(chars)); + delete chars; + } + else + { + xmlTextWriterSetIndentString(writer, SDOXMLString("")); + } + } + // -------------------------------------------------------------- // Write the <schema> definition including namespace information // -------------------------------------------------------------- http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SDOXSDWriter.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXSDWriter.h diff -u pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.3 pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.4 --- pecl/sdo/commonj/sdo/SDOXSDWriter.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SDOXSDWriter.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDOXSDWRITER_H_ #define _SDOXSDWRITER_H_ @@ -48,7 +48,7 @@ virtual ~SDOXSDWriter(); int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, - const propertyMap& openprops); + const propertyMap& openprops, int indent = -1); protected: void setWriter(xmlTextWriterPtr textWriter); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SchemaInfo.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SchemaInfo.h diff -u pecl/sdo/commonj/sdo/SchemaInfo.h:1.2 pecl/sdo/commonj/sdo/SchemaInfo.h:1.3 --- pecl/sdo/commonj/sdo/SchemaInfo.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SchemaInfo.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SCHEMAINFO_H_ #define _SCHEMAINFO_H_ @@ -49,7 +49,7 @@ private: SAX2Namespaces schemaNamespaces; - SDOXMLString targetNamespaceURI; + SDOXMLString targetNamespaceURI; }; } // End - namespace sdo http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/Sequence.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/Sequence.h diff -u pecl/sdo/commonj/sdo/Sequence.h:1.2 pecl/sdo/commonj/sdo/Sequence.h:1.3 --- pecl/sdo/commonj/sdo/Sequence.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/Sequence.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SEQUENCE_H_ #define _SEQUENCE_H_ @@ -67,6 +67,12 @@ SDO_API virtual const Property& getProperty(unsigned int index) = 0; /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject() = 0; + + /** * * The element of that property if it was many valued. Zero if the * property was single valued. http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SequenceImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/SequenceImpl.cpp diff -u pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.3 pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/SequenceImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SequenceImpl.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/Property.h" @@ -55,7 +55,7 @@ SequenceImpl::SequenceImpl(DataObject* indo) { - the_do = indo; + the_do = (DataObjectImpl*)indo; } SequenceImpl::SequenceImpl(SequenceImpl* inseq) @@ -69,6 +69,16 @@ return the_list.size(); } + + /** + * Return the data object associated with this sequence + */ + + const DataObjectPtr SequenceImpl::getDataObject() + { + return the_do; + } + const Property& SequenceImpl::getProperty(unsigned int index) { SEQUENCE_ITEM_LIST::iterator i; @@ -432,11 +442,74 @@ } +#define doadder(primtype,primval)\ + bool SequenceImpl::add##primtype(const char* propertyName, primval v)\ + {\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName, v->getType());\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v)\ + {\ + return add##primtype(the_do->getProperty(propertyIndex), v);\ + }\ + bool SequenceImpl::add##primtype(const Property& p, primval v)\ + {\ + if (p.isMany())\ + {\ + DataObjectList& dol = the_do->getList(p);\ + dol.append((primval)v);\ + /* the_list.push_back(seq_item(&p,dol.size()-1));*/\ + return true;\ + }\ + SEQUENCE_ITEM_LIST::iterator i;\ + for (i=the_list.begin();i != the_list.end();++i) {\ + const Property* pp = (*i).getProp();\ + if (pp == 0) continue;\ + if (!strcmp(pp->getName(),p.getName()))\ + {\ + SDO_THROW_EXCEPTION("add", SDOUnsupportedOperationException,\ + "Sequence::add of property which already exists in sequence");\ + }\ + }\ + the_do->set##primtype(p,v);\ + the_list.push_back(seq_item(&p,0));\ + return true;\ + } + #define adder(primtype,primval)\ bool SequenceImpl::add##primtype(const char* propertyName, primval v)\ {\ - return add##primtype(the_do->getProperty(propertyName),v);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v);\ }\ bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v)\ {\ @@ -476,13 +549,28 @@ adder(Float, float); adder(Double, long double); adder(Date, const SDODate); -adder(DataObject, RefCountingPointer<DataObject>); +doadder(DataObject, RefCountingPointer<DataObject>); #define charAdder(primtype,primval)\ bool SequenceImpl::add##primtype(const char* propertyName, primval v, unsigned int len)\ {\ - return add##primtype(the_do->getProperty(propertyName),v, len);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype((const Property&)*p,v, len);\ }\ bool SequenceImpl::add##primtype(unsigned int propertyIndex, primval v, unsigned int len)\ {\ @@ -517,11 +605,87 @@ charAdder ( Bytes , const char* ); - #define inserter(primtype,primval)\ bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v)\ {\ - return add##primtype(index,the_do->getProperty(propertyName),v);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v)\ + {\ + return add##primtype(index,the_do->getProperty(propertyIndex), v);\ + }\ + bool SequenceImpl::add##primtype(unsigned int index, const Property& p, primval v)\ + {\ + SEQUENCE_ITEM_LIST::iterator i;\ + SEQUENCE_ITEM_LIST::iterator i2 = the_list.end();\ + int j;\ + if (index >= the_list.size()) {\ + return add##primtype(p,v);\ + }\ + if (p.isMany())\ + {\ + DataObjectList& dol = the_do->getList(p);\ + dol.append((primval)v);\ + j = 0;\ + for (i=the_list.begin();(j < index) && (i != the_list.end());++i) {\ + j++;\ + }\ + /*the_list.insert(i,seq_item(&p,dol.size()-1));*/\ + return true;\ + }\ + j = 0;\ + for (i=the_list.begin();i != the_list.end();++i) {\ + const Property* pp = (*i).getProp();\ + if (pp == 0) continue;\ + if (!strcmp(pp->getName(),p.getName()))\ + {\ + SDO_THROW_EXCEPTION("Insert", SDOUnsupportedOperationException,\ + "Sequence::insert of property which already exists in sequence");\ + }\ + if (j == index) {\ + i2 = i;\ + }\ + j++;\ + }\ + the_do->set##primtype(p,v);\ + the_list.insert(i2,seq_item(&p,0));\ + return true;\ + } + +#define doinserter(primtype,primval)\ + bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v)\ + {\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName, v->getType());\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v);\ }\ bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v)\ {\ @@ -575,14 +739,29 @@ inserter(Float, float); inserter(Double, long double); inserter(Date, const SDODate); -inserter(DataObject, RefCountingPointer<DataObject>); +doinserter(DataObject, RefCountingPointer<DataObject>); #define charInserter(primtype,primval)\ bool SequenceImpl::add##primtype(unsigned int index, const char* propertyName, primval v, unsigned int len)\ {\ - return add##primtype(index,the_do->getProperty(propertyName),v, len);\ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName);\ + if (p == 0)\ + {\ + if (the_do->getType().isOpenType())\ + {\ + p = the_do->define ##primtype (propertyName);\ + }\ + if (p == 0)\ + {\ + string msg("Cannot find property:");\ + msg += propertyName;\ + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException,\ + msg.c_str());\ + }\ + }\ + return add##primtype(index,(const Property&)*p,v, len);\ }\ bool SequenceImpl::add##primtype(unsigned int index, unsigned int propertyIndex, primval v, unsigned int len)\ {\ http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SequenceImpl.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SequenceImpl.h diff -u pecl/sdo/commonj/sdo/SequenceImpl.h:1.2 pecl/sdo/commonj/sdo/SequenceImpl.h:1.3 --- pecl/sdo/commonj/sdo/SequenceImpl.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SequenceImpl.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SEQUENCEIMPL_H_ #define _SEQUENCEIMPL_H_ @@ -34,7 +34,7 @@ namespace sdo{ class Property; /* forward declaration */ -class DataObject; +class DataObjectImpl; /** SequenceImpl implements the abstract class Sequence. * @@ -57,6 +57,12 @@ /////////////////////////////////////////////////////////////////////////// virtual const Property& getProperty(unsigned int index); + /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject(); + /////////////////////////////////////////////////////////////////////////// // Returns the property for the given entry index. /////////////////////////////////////////////////////////////////////////// @@ -294,7 +300,7 @@ SequenceImpl(); - DataObject* the_do; + DataObjectImpl* the_do; class seq_item { public: http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SettingList.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SettingList.cpp diff -u pecl/sdo/commonj/sdo/SettingList.cpp:1.2 pecl/sdo/commonj/sdo/SettingList.cpp:1.3 --- pecl/sdo/commonj/sdo/SettingList.cpp:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SettingList.cpp Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #include "commonj/sdo/SDORuntimeException.h" @@ -27,9 +27,9 @@ namespace sdo { -SettingList::SettingList(SETTING_VECTOR p) : slist (p) -{ -} +//SettingList::SettingList(SETTING_VECTOR p) : slist (p) +//{ +//} /*SettingList::SettingList(const SettingList &pin) { @@ -44,13 +44,26 @@ SettingList::~SettingList() { + while (slist.size() > 0) + { + Setting* s = slist[0]; + slist.erase(slist.begin()); + delete s; + } + } Setting& SettingList::operator[] (int pos) const { validateIndex(pos); - return (Setting&)slist[pos]; + return (*slist[pos]); +} + +Setting* SettingList::get(int pos) +{ + validateIndex(pos); + return (slist[pos]); } int SettingList::size () const @@ -58,17 +71,17 @@ return slist.size(); } -SETTING_VECTOR SettingList::getVec() const -{ - return slist; -} +//SETTING_VECTOR SettingList::getVec() const +//{ +// return slist; +//} -void SettingList::insert (unsigned int index, const Setting& d) +void SettingList::insert (unsigned int index, Setting* d) { slist.insert(slist.begin()+index, d); } -void SettingList::append (const Setting& d) +void SettingList::append ( Setting* d) { slist.insert(slist.end(),d); } @@ -76,7 +89,9 @@ void SettingList::remove(unsigned int index) { validateIndex(index); + const Setting* s = slist[index]; slist.erase(slist.begin()+index); + delete s; return; } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/SettingList.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/SettingList.h diff -u pecl/sdo/commonj/sdo/SettingList.h:1.2 pecl/sdo/commonj/sdo/SettingList.h:1.3 --- pecl/sdo/commonj/sdo/SettingList.h:1.2 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/SettingList.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef SETTINGLIST_H #define SETTINGLIST_H @@ -28,7 +28,7 @@ namespace commonj{ namespace sdo{ -typedef std::vector<Setting> SETTING_VECTOR; +typedef std::vector< Setting*> SETTING_VECTOR; /** SettingList is a list of settings returned by a change summary */ @@ -37,7 +37,7 @@ { public: - SettingList(SETTING_VECTOR sl); + //SettingList(SETTING_VECTOR sl); SettingList(); virtual ~SettingList(); @@ -47,7 +47,7 @@ * This gives access to elements of the list */ - virtual Setting& operator[] (int pos) const; + SDO_API virtual Setting& operator[] (int pos) const; /** size() returns the number of settings * @@ -55,16 +55,16 @@ * These may be creations, deletions or changes. */ - virtual int size () const; + SDO_API virtual int size () const; - virtual void insert (unsigned int index, const Setting& d); - virtual void append (const Setting& d); + virtual void insert (unsigned int index, Setting* d); + virtual void append ( Setting* d); virtual void remove (unsigned int index); + virtual Setting* get (int pos); private: SETTING_VECTOR slist; - SETTING_VECTOR getVec() const; void validateIndex(int index) const; }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/Type.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/Type.h diff -u pecl/sdo/commonj/sdo/Type.h:1.3 pecl/sdo/commonj/sdo/Type.h:1.4 --- pecl/sdo/commonj/sdo/Type.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/Type.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _SDO_TYPE_H_ #define _SDO_TYPE_H_ @@ -73,6 +73,7 @@ DataObjectType, ChangeSummaryType, TextType, + UndefinedOpenPropertyType, num_types }; http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelper.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelper.h diff -u pecl/sdo/commonj/sdo/XMLHelper.h:1.3 pecl/sdo/commonj/sdo/XMLHelper.h:1.4 --- pecl/sdo/commonj/sdo/XMLHelper.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelper.h Mon Feb 20 18:50:25 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:25 $ */ #ifndef _XMLHELPER_H_ #define _XMLHELPER_H_ @@ -45,7 +45,11 @@ * Returns a pointer to the root data object */ - SDO_API virtual XMLDocumentPtr loadFile( + SDO_API virtual XMLDocumentPtr createDocument( + const char* elementname = 0, + const char* rootElementURI=0) = 0; + + SDO_API virtual XMLDocumentPtr loadFile( const char* xmlFile, const char* targetNamespaceURI=0) = 0; SDO_API virtual XMLDocumentPtr load( @@ -60,12 +64,14 @@ * save - Serializes the datagraph to the XML file */ - SDO_API virtual void save(XMLDocumentPtr doc, const char* xmlFile) = 0; + SDO_API virtual void save(XMLDocumentPtr doc, const char* xmlFile, + int indent = -1) = 0; SDO_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) = 0; + const char* xmlFile, + int indent = -1) = 0; /** save saves the graph to XML @@ -73,23 +79,26 @@ * save - Serializes the datagraph to the XML stream */ - SDO_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml) = 0; + SDO_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1) = 0; SDO_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) = 0; + std::ostream& outXml, + int indent = -1) = 0; /** save saves the graph to XML * * save - Serializes the datagraph to a string */ - SDO_API virtual char* save(XMLDocumentPtr doc) = 0; + SDO_API virtual char* save(XMLDocumentPtr doc, int indent = -1) = 0; SDO_API virtual char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) = 0; + const char* rootElementName, + int indent = -1) = 0; /** createDocument creates an XMLDocument * http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelperImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelperImpl.cpp diff -u pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.3 pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/XMLHelperImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelperImpl.cpp Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! #include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! @@ -93,6 +93,76 @@ return new XMLDocumentImpl(dataObject, rootElementURI, rootElementName); } + + XMLDocumentPtr XMLHelperImpl::createDocument(const char* elementname, + const char* rootElementURI) + { + DataFactory* dp = (DataFactory*)getDataFactory(); + if (dp != 0) + { + const TypeImpl* rType = NULL; + if (rootElementURI != 0) + { + rType = ((DataFactoryImpl*)dp)->findTypeImpl + (rootElementURI, "RootType"); + } + else + { + const TypeList& tl = dp->getTypes(); + for (int i=0;i<tl.size();i++) + { + if (!strcmp("RootType",tl[i].getName())) + { + rType = ((DataFactoryImpl*)dp)->findTypeImpl + (tl[i].getURI(), "RootType"); + break; + } + } + } + if (rType) + { + if (elementname && strlen(elementname) != 0) + { + PropertyImpl* pl = rType->getPropertyImpl(elementname); + if (pl != 0) + { + const Type& tp = pl->getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), /*tp.getName()*/ elementname); + } + else + { + string msg("createDocument - cannot find element "); + msg += elementname; + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + } + else + { + const Property& pl = rType->getProperty((unsigned int)0); + const Type& tp = pl.getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), /*tp.getName()*/ pl.getName()); + } + } + else + { + string msg("createDocument - unable to find root type in namespace "); + if (rootElementURI != 0) + msg += rootElementURI; + else + msg += " NULL"; + + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + } + return 0; + } + XMLDocumentPtr XMLHelperImpl::createDocument( DataObjectPtr dataObject, const char* rootElementURI, @@ -137,42 +207,47 @@ return load(str, targetNamespaceURI); } - void XMLHelperImpl::save(XMLDocumentPtr doc, const char* xmlFile) + void XMLHelperImpl::save(XMLDocumentPtr doc, const char* xmlFile, int indent) { SDOXMLFileWriter writer(xmlFile, dataFactory); - writer.write(doc); + writer.write(doc, indent); } void XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) + const char* xmlFile, + int indent) { - save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile); + save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile, + indent); } // Serializes the datagraph to a stream - void XMLHelperImpl::save(XMLDocumentPtr doc, std::ostream& outXml) + void XMLHelperImpl::save(XMLDocumentPtr doc, std::ostream& outXml, + int indent) { SDOXMLStreamWriter writer(outXml, dataFactory); - writer.write(doc); + writer.write(doc, indent); } void XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) + std::ostream& outXml, + int indent ) { - save(createDocument(dataObject,rootElementURI, rootElementName), outXml); + save(createDocument(dataObject,rootElementURI, rootElementName), outXml, indent); } // Serializes the datagraph to a string - char* XMLHelperImpl::save(XMLDocumentPtr doc) + char* XMLHelperImpl::save(XMLDocumentPtr doc, + int indent) { SDOXMLBufferWriter writer(dataFactory); - writer.write(doc); + writer.write(doc, indent); SDOXMLString ret = writer.getBuffer(); char* retString = new char[strlen(ret) +1]; strcpy(retString, ret); @@ -181,9 +256,11 @@ char* XMLHelperImpl::save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) + const char* rootElementName, + int indent) { - return save(createDocument(dataObject,rootElementURI, rootElementName)); + return save(createDocument(dataObject,rootElementURI, rootElementName), + indent); } int XMLHelperImpl::getErrorCount() const http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XMLHelperImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XMLHelperImpl.h diff -u pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.3 pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.4 --- pecl/sdo/commonj/sdo/XMLHelperImpl.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XMLHelperImpl.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XMLHELPERIMPL_H_ #define _XMLHELPERIMPL_H_ @@ -63,7 +63,11 @@ * Returns a pointer to the root data object */ - virtual XMLDocumentPtr loadFile( + virtual XMLDocumentPtr createDocument( + const char* elementname= 0, + const char* rootElementURI=0); + + virtual XMLDocumentPtr loadFile( const char* xmlFile, const char* targetNamespaceURI = 0); virtual XMLDocumentPtr load( @@ -83,34 +87,37 @@ * save - Serializes the datagraph to the XML file */ - void save(XMLDocumentPtr doc, const char* xmlFile); + void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile); + const char* xmlFile, int indent = -1); /** save saves the graph to XML * * save - Serializes the datagraph to a stream */ - void save(XMLDocumentPtr doc, std::ostream& outXml); + void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml); + std::ostream& outXml, + int indent = -1); /** save saves the graph to XML * * save - Serializes the datagraph to a string */ - char* save(XMLDocumentPtr doc); + char* save(XMLDocumentPtr doc,int indent = -1); char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName); + const char* rootElementName, + int indent = -1); private: int parse(const char* source); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelper.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelper.h diff -u pecl/sdo/commonj/sdo/XSDHelper.h:1.3 pecl/sdo/commonj/sdo/XSDHelper.h:1.4 --- pecl/sdo/commonj/sdo/XSDHelper.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelper.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XSDHELPER_H_ #define _XSDHELPER_H_ @@ -65,15 +65,18 @@ SDO_API virtual char* generate( const TypeList& types, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; SDO_API virtual void generate( const TypeList& types, std::ostream& outXsd, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; SDO_API virtual void generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI = "") = 0; + const char* targetNamespaceURI = "", + int indent = -1) = 0; /***********************************/ /* Destructor */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelperImpl.cpp?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelperImpl.cpp diff -u pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.3 pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.4 --- pecl/sdo/commonj/sdo/XSDHelperImpl.cpp:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelperImpl.cpp Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! #include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! @@ -521,36 +521,39 @@ void XSDHelperImpl::generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDFileWriter writer(fileName); DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); } void XSDHelperImpl::generate( const TypeList& types, std::ostream& outXml, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDStreamWriter writer(outXml); DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); } char* XSDHelperImpl::generate( const TypeList& types, - const char* targetNamespaceURI + const char* targetNamespaceURI, + int indent ) { SDOXSDBufferWriter writer; DataFactory* fac = dataFactory; writer.write(types, targetNamespaceURI, - ((DataFactoryImpl*)fac)->getOpenProperties()); + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); SDOXMLString ret = writer.getBuffer(); char* retString = new char[strlen(ret) +1]; strcpy(retString, ret); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/XSDHelperImpl.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/commonj/sdo/XSDHelperImpl.h diff -u pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.3 pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.4 --- pecl/sdo/commonj/sdo/XSDHelperImpl.h:1.3 Tue Jan 17 09:41:28 2006 +++ pecl/sdo/commonj/sdo/XSDHelperImpl.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Rev$ $Date: 2006/01/17 09:41:28 $ */ +/* $Rev$ $Date: 2006/02/20 18:50:26 $ */ #ifndef _XSDHELPERIMPL_H_ #define _XSDHELPERIMPL_H_ @@ -94,17 +94,20 @@ virtual char* generate( const TypeList& types, - const char* targetNamespaceURI = "" + const char* targetNamespaceURI = "", + int indent = -1 ); void generate( const TypeList& types, std::ostream& outXsd, - const char* targetNamespaceURI = "" + const char* targetNamespaceURI = "", + int indent = -1 ); virtual void generateFile( const TypeList& types, const char* fileName, - const char* targetNamespaceURI = ""); + const char* targetNamespaceURI = "", + int indent = -1); virtual DataFactoryPtr getDataFactory(); http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDAS.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDAS.h diff -u pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDAS.h:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDAS.h Mon Feb 20 18:50:26 2006 @@ -15,7 +15,7 @@ * limitations under the License. */ -/* $Id: XMLDAS.h,v 1.2 2006/01/17 09:41:34 cem Exp $ */ +/* $Id: XMLDAS.h,v 1.3 2006/02/20 18:50:26 mfp Exp $ */ #ifndef _XMLDAS_H_ #define _XMLDAS_H_ @@ -92,35 +92,35 @@ /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to the XML file /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual void save(DataGraphPtr doc, const char* xmlFile) = 0; - XMLDAS_API virtual void save(XMLDocumentPtr doc, const char* xmlFile) = 0; + XMLDAS_API virtual void save(DataGraphPtr doc, const char* xmlFile, int indent = -1) = 0; + XMLDAS_API virtual void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1) = 0; XMLDAS_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) = 0; + const char* xmlFile, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to a stream /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual void save(DataGraphPtr doc, std::ostream& outXml) = 0; - XMLDAS_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml) = 0; + XMLDAS_API virtual void save(DataGraphPtr doc, std::ostream& outXml, int indent = -1) = 0; + XMLDAS_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml, int indent = -1) = 0; XMLDAS_API virtual void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) = 0; + std::ostream& outXml, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // save - Serializes the datagraph to a string /////////////////////////////////////////////////////////////////////// - XMLDAS_API virtual char* save(DataGraphPtr doc) = 0; - XMLDAS_API virtual char* save(XMLDocumentPtr doc) = 0; + XMLDAS_API virtual char* save(DataGraphPtr doc, int indent = -1) = 0; + XMLDAS_API virtual char* save(XMLDocumentPtr doc, int indent = -1) = 0; XMLDAS_API virtual char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) = 0; + const char* rootElementName, int indent = -1) = 0; /////////////////////////////////////////////////////////////////////// // createDocument http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp diff -u pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.cpp Mon Feb 20 18:50:26 2006 @@ -205,78 +205,78 @@ return load(str); } - void XMLDASImpl::save(DataGraphPtr doc, const char* xmlFile) + void XMLDASImpl::save(DataGraphPtr doc, const char* xmlFile, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - xmlHelper->save(xd, 0,0, xmlFile); + xmlHelper->save(xd, 0,0, xmlFile, indent); // end the tag } - void XMLDASImpl::save(XMLDocumentPtr doc, const char* xmlFile) + void XMLDASImpl::save(XMLDocumentPtr doc, const char* xmlFile, int indent) { - xmlHelper->save(doc, xmlFile); + xmlHelper->save(doc, xmlFile, indent); } void XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile) + const char* xmlFile, int indent) { - xmlHelper->save(dataObject,rootElementURI, rootElementName, xmlFile); + xmlHelper->save(dataObject,rootElementURI, rootElementName, xmlFile, indent); } // Serializes the datagraph to a stream - void XMLDASImpl::save(DataGraphPtr doc, ostream& outXml) + void XMLDASImpl::save(DataGraphPtr doc, ostream& outXml, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - xmlHelper->save(xd, 0,0,outXml); + xmlHelper->save(xd, 0,0,outXml, indent); // end the tag } - void XMLDASImpl::save(XMLDocumentPtr doc, ostream& outXml) + void XMLDASImpl::save(XMLDocumentPtr doc, ostream& outXml, int indent) { - xmlHelper->save(doc, outXml); + xmlHelper->save(doc, outXml, indent); } void XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml) + std::ostream& outXml, int indent) { - xmlHelper->save(dataObject, rootElementURI, rootElementName, outXml); + xmlHelper->save(dataObject, rootElementURI, rootElementName, outXml, indent); } // Serializes the datagraph to a string - char* XMLDASImpl::save(DataGraphPtr doc) + char* XMLDASImpl::save(DataGraphPtr doc, int indent) { DataObjectPtr xd = graphToDataObject(doc); // write the datagraph tag // write the model // write the dataobjects - return xmlHelper->save(xd,0,0); + return xmlHelper->save(xd,0,0, indent); // end the tag } - char* XMLDASImpl::save(XMLDocumentPtr doc) + char* XMLDASImpl::save(XMLDocumentPtr doc, int indent) { - return xmlHelper->save(doc); + return xmlHelper->save(doc, indent); } char* XMLDASImpl::save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName) + const char* rootElementName, int indent) { - return xmlHelper->save(dataObject, rootElementURI, rootElementName); + return xmlHelper->save(dataObject, rootElementURI, rootElementName, indent); } http://cvs.php.net/viewcvs.cgi/pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h diff -u pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.2 pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.3 --- pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h:1.2 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/commonj/sdo/xmldas/XMLDASImpl.h Mon Feb 20 18:50:26 2006 @@ -86,30 +86,30 @@ // save // Serializes the datagraph to the XML file - void save(DataGraphPtr doc, const char* xmlFile); - void save(XMLDocumentPtr doc, const char* xmlFile); + void save(DataGraphPtr doc, const char* xmlFile, int indent = -1); + void save(XMLDocumentPtr doc, const char* xmlFile, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - const char* xmlFile); + const char* xmlFile, int indent = -1); // Serializes the datagraph to a stream - void save(DataGraphPtr doc, std::ostream& outXml); - void save(XMLDocumentPtr doc, std::ostream& outXml); + void save(DataGraphPtr doc, std::ostream& outXml, int indent = -1); + void save(XMLDocumentPtr doc, std::ostream& outXml, int indent = -1); void save( DataObjectPtr dataObject, const char* rootElementURI, const char* rootElementName, - std::ostream& outXml); + std::ostream& outXml, int indent = -1); // Serializes the datagraph to a string - char* save(DataGraphPtr doc); - char* save(XMLDocumentPtr doc); + char* save(DataGraphPtr doc, int indent = -1); + char* save(XMLDocumentPtr doc, int indent = -1); char* save( DataObjectPtr dataObject, const char* rootElementURI, - const char* rootElementName); + const char* rootElementName, int indent = -1); // getDataFactory http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/test.inc?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/test.inc diff -u /dev/null pecl/sdo/tests/test.inc:1.4 --- /dev/null Mon Feb 20 18:50:27 2006 +++ pecl/sdo/tests/test.inc Mon Feb 20 18:50:26 2006 @@ -0,0 +1,54 @@ +<?php +/* create a DataFactory */ +$dmsDf = SDO_DAS_DataFactory :: getDataFactory(); + +define('ROOT_NS', 'phpt'); +define('COMPANY_NS', 'companyNS'); +define('ROOT_TYPE', 'RootType'); +define('COMPANY_TYPE', 'CompanyType'); +define('DEPARTMENT_TYPE', 'DepartmentType'); +define('EMPLOYEE_TYPE', 'EmployeeType'); + +// Create the types +$dmsDf->addType(ROOT_NS, ROOT_TYPE); +$dmsDf->addType(COMPANY_NS, COMPANY_TYPE); +$dmsDf->addType(COMPANY_NS, DEPARTMENT_TYPE); +$dmsDf->addType(COMPANY_NS, EMPLOYEE_TYPE); + +// add properties to the root type +$dmsDf->addPropertyToType(ROOT_NS, ROOT_TYPE, 'company', COMPANY_NS, COMPANY_TYPE); + +// add properties to the company type +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'departments', COMPANY_NS, DEPARTMENT_TYPE, array('many'=>true)); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'employeeOfTheMonth', COMPANY_NS, EMPLOYEE_TYPE, array('containment'=>false)); +$dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'CEO', COMPANY_NS, EMPLOYEE_TYPE); + +// add properties to the department type +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'location', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'number', SDO_TYPE_NAMESPACE_URI, 'Integer'); +$dmsDf->addPropertyToType(COMPANY_NS, DEPARTMENT_TYPE, 'employees', COMPANY_NS, EMPLOYEE_TYPE, array('many'=>true)); + +// add properties to employee type +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'name', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'SN', SDO_TYPE_NAMESPACE_URI, 'String'); +$dmsDf->addPropertyToType(COMPANY_NS, EMPLOYEE_TYPE, 'manager', SDO_TYPE_NAMESPACE_URI, 'Boolean'); + +// Test creation of a data object +$company = $dmsDf->create(COMPANY_NS, COMPANY_TYPE); +$company->name = 'MegaCorp'; + +// Test creation of a child data object +$department = $company->createDataObject('departments'); +$department->name = 'Shoe'; + +// Test creation of a child data object +$employee = $department->createDataObject('employees'); +$employee->name = "Sarah Jones"; +$company->employeeOfTheMonth = $employee; + +// Test use of non-containment reference +$ceo = $company->createDataObject('CEO'); +$ceo->name = "Fred Smith"; +?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/001.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/001.phpt diff -u pecl/sdo/tests/001.phpt:1.1 pecl/sdo/tests/001.phpt:1.2 --- pecl/sdo/tests/001.phpt:1.1 Mon Jul 18 16:16:43 2005 +++ pecl/sdo/tests/001.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- Check for sdo presence +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/002.phpt?r1=1.2&r2=1.3&diff_format=u Index: pecl/sdo/tests/002.phpt diff -u pecl/sdo/tests/002.phpt:1.2 pecl/sdo/tests/002.phpt:1.3 --- pecl/sdo/tests/002.phpt:1.2 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/002.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO getType test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- @@ -12,4 +14,4 @@ ?> --EXPECT-- -companyNS:CompanyType \ No newline at end of file +companyNS:CompanyType http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/003.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/003.phpt diff -u pecl/sdo/tests/003.phpt:1.1 pecl/sdo/tests/003.phpt:1.2 --- pecl/sdo/tests/003.phpt:1.1 Mon Jul 18 16:16:43 2005 +++ pecl/sdo/tests/003.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO var_dump test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- @@ -39,4 +41,4 @@ ["name"]=> string(10) "Fred Smith" } -} \ No newline at end of file +} http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/004.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/004.phpt diff -u pecl/sdo/tests/004.phpt:1.1 pecl/sdo/tests/004.phpt:1.2 --- pecl/sdo/tests/004.phpt:1.1 Mon Aug 8 15:08:54 2005 +++ pecl/sdo/tests/004.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- Check for sdo_das_xml presence +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo_das_xml")) print "skip"; ?> --FILE-- http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/005.phpt?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/005.phpt diff -u pecl/sdo/tests/005.phpt:1.3 pecl/sdo/tests/005.phpt:1.4 --- pecl/sdo/tests/005.phpt:1.3 Wed Oct 5 09:56:14 2005 +++ pecl/sdo/tests/005.phpt Mon Feb 20 18:50:26 2006 @@ -1,12 +1,14 @@ --TEST-- SDO_DAS_XML load test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo")) print "skip"; ?> --FILE-- <?php $dirname = dirname($_SERVER['SCRIPT_FILENAME']); $xmldas = SDO_DAS_XML::create("${dirname}/company.xsd"); - $xdoc = $xmldas->loadFromFile("${dirname}/company.xml"); + $xdoc = $xmldas->loadFile("${dirname}/company.xml"); $do = $xdoc->getRootDataObject(); print_r($do); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/006.phpt?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/006.phpt diff -u pecl/sdo/tests/006.phpt:1.1 pecl/sdo/tests/006.phpt:1.2 --- pecl/sdo/tests/006.phpt:1.1 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/tests/006.phpt Mon Feb 20 18:50:26 2006 @@ -1,5 +1,7 @@ --TEST-- SDO reflection test +--INI-- +display_errors=off --SKIPIF-- <?php if (!extension_loaded("sdo") || phpversion('sdo') < '0.7.1') print "skip"; ?> @@ -34,4 +36,4 @@ commonj.sdo:Boolean $manager; } } -} \ No newline at end of file +} http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/SDOAPITest.php?r1=1.7&r2=1.8&diff_format=u Index: pecl/sdo/tests/SDOAPITest.php diff -u pecl/sdo/tests/SDOAPITest.php:1.7 pecl/sdo/tests/SDOAPITest.php:1.8 --- pecl/sdo/tests/SDOAPITest.php:1.7 Tue Jan 17 09:41:34 2006 +++ pecl/sdo/tests/SDOAPITest.php Mon Feb 20 18:50:26 2006 @@ -168,6 +168,10 @@ public function testDataObject() { $this->company = $this->dmsDf->create(COMPANY_NS, COMPANY_TYPE); + // check the type + $this->assertEquals(COMPANY_TYPE, $this->company->getTypeName(), 'getTypeName() failed.'); + $this->assertEquals(COMPANY_NS, $this->company->getTypeNamespaceURI(), 'getTypeNamespaceURI() failed.'); + // Test array operator and setting a property $this->company[0] = 'Acme'; $this->assertEquals('Acme', $this->company[0], 'Property set/get through [] failed.'); @@ -565,7 +569,6 @@ $this->assertEquals(SDO_DAS_ChangeSummary::NONE, $ct, 'Change type set but no changes have been made.'); // make some changes - $oldSN = $simon->SN; $simon->SN = '061130'; $david = $department->createDataObject('employees'); @@ -1156,21 +1159,15 @@ $all_props = $do_type->getProperties(); $this->assertEquals(count($all_props), count($this->company), 'Different number of properties in reflected data object'); - - $iters = 0; - foreach ($all_props as $do_property) { - $do = $this->company[$do_property->name]; - $iters ++; - } - $this->assertEquals(count($all_props), $iters, - 'SDO_Model_ReflectionDataObject iteration test failed - incorrect number of interations.'); - $this->assertTrue($iters > 0, - 'SDO_Model_ReflectionDataObject iteration test failed - zero iterations performed.'); /* Create a dataobject using a SDO_Model_Property */ $department_property = $do_type->getProperty('departments'); $department2 = $this->company->createDataObject($department_property); $department2->name = 'IT'; + $this->assertEquals($department_property->getType()->getName(), $department2->getTypeName(), + 'type name is different from reflected type name'); + $this->assertEquals($department_property->getType()->getNamespaceURI(), $department2->getTypeNamespaceURI(), + 'type namespace URI is different from reflected type namespace URI'); $this->assertEquals($department2->getContainer(), $this->company, 'getContainer() test failed for object created using reflected property'); } @@ -1261,24 +1258,24 @@ /* first add an existing property */ $seq->insert('Sequence name=>'); $seq->insert('OpenSeqName', NULL, 'name'); - $this->assertEquals($open->name, 'OpenSeqName', 'sequence and property access not equal;'); + $this->assertEquals('OpenSeqName', $open->name, 'sequence and property access not equal;'); // FAILED: can't yet set open type through sequence interface // /* now add an unknown property to the open type */ // $seq->insert(' stringA=>'); // $seq->insert('StringValue', NULL, 'stringA'); -// $this->assertEquals($open->stringA, 'StringValue', 'sequence and property access for open type not equal;'); +// $this->assertEquals('StringValue', $open->stringA, 'sequence and property access for open type not equal;'); // // $seq->insert(' numberA=>'); // $seq->insert(42, NULL, 'numberA'); -// $this->assertEquals($open->numberA, 42, 'sequence and property access for open type not equal;'); +// $this->assertEquals(42, $open->numberA, 'sequence and property access for open type not equal;'); // // /* add an unknown data object property */ $employee = $this->dmsDf->create(COMPANY_NS, EMPLOYEE_TYPE); // $seq->insert($employee, NULL, 'object'); // $index = $seq->count() - 1; $employee->name = 'Alien'; -// $this->assertEquals($seq[$index]->name, 'Alien', 'sequence and property access for open type not equal;'); +// $this->assertEquals('Alien', $seq[$index]->name, 'sequence and property access for open type not equal;'); /* bypass the above problem by pre-initializing the open types through the DataObject interface. * Then we can test setting them through the sequence @@ -1289,15 +1286,60 @@ $seq->insert(' numberB=>'); $seq->insert(42, NULL, 'numberB'); - $this->assertEquals($open->numberB, 42, 'sequence and property access for open type not equal;'); + $this->assertEquals(42, $open->numberB, 'sequence and property access for open type not equal;'); $seq->insert(' stringB=>'); $seq->insert('StringValue', NULL, 'stringB'); - $this->assertEquals($open->stringB, 'StringValue', 'sequence and property access for open type not equal;'); + $this->assertEquals('StringValue', $open->stringB, 'sequence and property access for open type not equal;'); $seq->insert(' object=>'); $seq->insert($employee, NULL, 'object'); - $this->assertEquals($open->object->name, 'Alien', 'sequence and property access for open type not equal;'); + $this->assertEquals('Alien', $open->object->name, 'sequence and property access for open type not equal;'); + } + + public function testDerivedType() { + $this->dmsDf->addType(COMPANY_NS, 'DerivedStringType', array('basetype'=>array(SDO_TYPE_NAMESPACE_URI, 'String'))); + $this->dmsDf->addType(COMPANY_NS, 'BaseObjectType', array('abstract'=>true)); + $this->dmsDf->addType(COMPANY_NS, 'DerivedObjectType', array('basetype'=>array(COMPANY_NS, 'BaseObjectType'))); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedString', COMPANY_NS, 'DerivedStringType'); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'derivedObject', COMPANY_NS, 'DerivedObjectType'); + $this->dmsDf->addPropertyToType(COMPANY_NS, COMPANY_TYPE, 'abstractObject', COMPANY_NS, 'BaseObjectType'); + + $company = $this->dmsDf->create(COMPANY_NS, COMPANY_TYPE); + $company->name = "ACME Corp"; + $company->derivedString = 'Special string'; + + $do = $this->dmsDf->create(COMPANY_NS, 'DerivedObjectType'); + try { + $this->dmsDf->create(COMPANY_NS, 'BaseObjectType'); + $this->assertTrue(false, 'Succeeded in instantiating an abstract type.'); + } catch (SDO_UnsupportedOperationException $e) { + } catch (SDO_Exception $e) { + $this->assertTrue(false, 'Incorrect exception thrown from creating an object of an abstract type:'.$e->getMessage()); + } + + /* It's OK to assign an object of a derived type to a property of an abstract type */ + $company->abstractObject = $do; + + $rcompany = new SDO_Model_ReflectionDataObject($company); + $special_type = $rcompany->getType()->getProperty('derivedString')->getType(); + $base_type = $special_type->getBaseType(); + $this->assertEquals(SDO_TYPE_NAMESPACE_URI, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type'); + $this->assertEquals('String', $base_type->getName(), 'incorrect name for base type'); + $this->assertTrue($base_type->isDataType(), 'incorrect data type for base type'); + + $rdo = new SDO_Model_ReflectionDataObject($do); + $derived_type = $rdo->getType(); + $this->assertFalse($derived_type->isAbstractType(), 'non-abstract type passes isAbstractType()'); + $this->assertTrue($derived_type->isInstance($do), 'object of derived type fails DerivedType::isInstance()'); + + $base_type = $derived_type->getBaseType(); + $this->assertEquals(COMPANY_NS, $base_type->getNamespaceURI(), 'incorrect namespaceURI for base type'); + $this->assertEquals('BaseObjectType', $base_type->getName(), 'incorrect name for base type'); + $this->assertFalse($base_type->isDataType(), 'incorrect data type for base type'); + $this->assertTrue($base_type->isAbstractType(), 'abstract type fails isAbstractType()'); + $this->assertTrue($base_type->isInstance($do), 'object of derived type fails BaseType::isInstance()'); + } } http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example1.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example1.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example1.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example1.php Mon Feb 20 18:50:26 2006 @@ -1,12 +1,15 @@ <?php +/** + * Load, update, and save an XML document + */ try { $xmldas = SDO_DAS_XML::create("letter.xsd"); - $xdoc = $xmldas->loadFromFile("letter.xml"); - $do = $xdoc->getRootDataObject(); - $do->date = "September 03, 2004"; - $do->firstName = "Anantoju"; - $do->lastName = "Madhu"; - $xmldas->saveDocumentToFile($xdoc, "letter-out.xml"); + $document = $xmldas->loadFile("letter.xml"); + $root_data_object = $document->getRootDataObject(); + $root_data_object->date = "September 03, 2004"; + $root_data_object->firstName = "Anantoju"; + $root_data_object->lastName = "Madhu"; + $xmldas->saveFile($document, "letter-out.xml"); echo "New file has been written:\n"; print file_get_contents("letter-out.xml"); } catch (SDO_Exception $e) { http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example2.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example2.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example2.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example2.php Mon Feb 20 18:50:26 2006 @@ -1,32 +1,28 @@ <?php +/** + * Create an XML document from scratch + */ try { $xmldas = SDO_DAS_XML::create("letter.xsd"); try { - $do = $xmldas->createDataObject("http://letterSchema", "FormLetter"); - $seq = $do->getSequence(); + $doc = $xmldas->createDocument(); + $rdo = $doc->getRootDataObject(); + $seq = $rdo->getSequence(); $seq->insert("April 09, 2005", NULL, 'date'); $seq->insert("Acme Inc. ", NULL, NULL); $seq->insert("United Kingdom. "); $seq->insert("Dear", NULL, NULL); $seq->insert("Tarun", NULL, "firstName"); $seq->insert("Nayaraaa", NULL, "lastName"); - $do->lastName = "Nayar"; + $rdo->lastName = "Nayar"; $seq->insert("Please note that your order number "); $seq->insert(12345); $seq->insert(" has been dispatched today. Thanks for your business with us."); - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - // this has previously been shown with the Type as the third argument . - // This generates XML with a root element name of FormLetter. - // This works and will reload but is probably not what is wanted. - // This should instead be the root element name 'letter' - print($xmldas->saveDataObjectToString($do, $type->getNamespaceURI(), 'letter')); + print($xmldas->saveString($doc)); } catch (SDO_Exception $e) { print($e); } -} catch (SDO_TypeNotFoundException $e) { - print("Type is not defined in the xsd file"); -} catch (SDO_DAS_XML_ParserException $e) { - print("Problem while parsing"); +} catch (SDO_Exception $e) { + print("Problem creating an XML document: " . $e->getMessage()); } ?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example3.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/sdo/tests/XMLDAS/Examples/Example3.php diff -u pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.1 pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.2 --- pecl/sdo/tests/XMLDAS/Examples/Example3.php:1.1 Fri Dec 2 17:33:48 2005 +++ pecl/sdo/tests/XMLDAS/Examples/Example3.php Mon Feb 20 18:50:26 2006 @@ -1,14 +1,10 @@ <?php -try { +/** + * Illustrate the calls that control the XML declaration + */ $xmldas = SDO_DAS_XML::create("letter.xsd"); - $xdoc = $xmldas->loadFromFile("letter.xml"); - print("Encoding is set to : " . $xdoc->getEncoding() . "\n"); - print("XML Version : " . $xdoc->getXMLVersion() . "\n"); - $xdoc->setXMLVersion("1.1"); - print($xmldas->saveDocumentToString($xdoc)); -} catch (SDO_TypeNotFoundException $e) { - print("Type is not defined in the xsd file"); -} catch (SDO_DAS_XML_ParserException $e) { - print("Problem while parsing"); -} + $document = $xmldas->loadFile("letter.xml"); + $document->setXMLVersion("1.1"); + $document->setEncoding("ISO-8859-1"); + print($xmldas->saveString($document)); ?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php?r1=1.3&r2=1.4&diff_format=u Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php diff -u pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.3 pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.4 --- pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php:1.3 Tue Jan 24 14:10:39 2006 +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/XMLDASTest.php Mon Feb 20 18:50:26 2006 @@ -94,7 +94,7 @@ $this->assertFalse($XMLDASTest_error_handler_called, 'Error handler should not have been called for create(). Message was ' . $XMLDASTest_error_handler_msg); } - public function testaddTypes() { + public function testaddTypesAndOpenTypes() { global $XMLDASTest_error_handler_called; global $XMLDASTest_error_handler_severity; global $XMLDASTest_error_handler_msg; @@ -104,23 +104,25 @@ $exception_thrown = false; try { $xmldas = SDO_DAS_XML::create(); - $xmldas->addTypes("menagerie.xsd"); // this is an open type i.e. the xsd specifies it can contain "any" type - $xmldas->addTypes('animalTypes.xsd'); - $xdoc = $xmldas->loadFromFile("menagerie.xml"); - $do = $xdoc->getRootDataObject(); - // check the types were loaded OK - $giraffe = $xmldas->createDataObject('','giraffeType'); - $giraffe->name = "Victor"; - $giraffe->height = 21; - $hippo = $xmldas->createDataObject('','hippoType'); - $hippo->name = "Henry"; - $hippo->weight = 1000; - $snake = $xmldas->createDataObject('','snakeType'); - $snake->name = "Kaa"; - $snake->length = 25; - $do->giraffe = $giraffe; - $do->hippo = $hippo; - $do->snake = $snake; + $xmldas->addTypes('anyElement/jungle.xsd'); // this is an open type i.e. the xsd specifies it can contain "any" type + $xmldas->addTypes('anyElement/animalTypes.xsd'); + $baloo = $xmldas->createDataObject('','bearType'); + $baloo->name = "Baloo"; + $baloo->weight = 800; + + $bagheera = $xmldas->createDataObject('','pantherType'); + $bagheera->name = "Bagheera"; + $bagheera->colour = 'inky black'; + + $kaa = $xmldas->createDataObject('','snakeType'); + $kaa->name = "Kaa"; + $kaa->length = 25; + + $document = $xmldas->createDocument(); + $do = $document->getRootDataObject(); + $do->bear = $baloo; + $do->panther = $bagheera; + $do->snake = $kaa; } catch (Exception $e) { $this->assertTrue(false, "Exception was thrown from addTypes test when it should not have been: ".$e->getMessage()); } @@ -175,7 +177,7 @@ $XMLDASTest_error_handler_called = false; $exception_thrown = false; try { - $xdoc = $xmldas->loadFromFile("what_a_load_of_rubbish.xml"); + $xdoc = $xmldas->loadFile("what_a_load_of_rubbish.xml"); } catch (SDO_DAS_XML_FileException $e) { $exception_thrown = true; } catch (Exception $e) { @@ -194,7 +196,7 @@ ***********************************/ $exception_thrown = false; try { - $xmldas = SDO_DAS_XML::create("parse_errors.xsd"); + $xmldas = SDO_DAS_XML::create('parseErrors/parse_errors.xsd'); } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; } catch (Exception $e) { @@ -203,11 +205,11 @@ $this->assertTrue($exception_thrown, 'SDO_DAS_XML_ParserException should have been thrown'); } - public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFromFile() { + public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFile() { $xmldas = SDO_DAS_XML::create("company.xsd"); $exception_thrown = false; try { - $xdoc = $xmldas->loadFromFile("parse_errors.xml"); + $xdoc = $xmldas->loadFile('parseErrors/parse_errors.xml'); $do = $xdoc->getRootDataObject(); // don't expect to get here } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; @@ -217,11 +219,11 @@ $this->assertTrue($exception_thrown, 'SDO_DAS_XML_ParserException should have been thrown'); } - public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadFromString() { + public function testParseExceptionThrownWhenXmlParseErrorOccursInLoadString() { $xmldas = SDO_DAS_XML::create("company.xsd"); $exception_thrown = false; try { - $xdoc = $xmldas->loadFromString("<ugly<"); + $xdoc = $xmldas->loadString("<ugly<"); $do = $xdoc->getRootDataObject(); // don't expect to get here } catch (SDO_DAS_XML_ParserException $e) { $exception_thrown = true; @@ -243,7 +245,7 @@ // the xsd has a company type that refers to an employe type but doesn't define the employee type $exception_thrown = false; try { - $xmldas = SDO_DAS_XML::create("company_missing_type.xsd"); + $xmldas = SDO_DAS_XML::create('missingType/company_missing_type.xsd'); $this->assertTrue(false, "SDO_DAS_XML::create failed to throw SDO_TypeNotFoundException. "); } catch (SDO_TypeNotFoundException $e) { $exception_thrown = true; @@ -253,12 +255,12 @@ $this->assertTrue($exception_thrown,'SDO_TypeNotFoundException should have been thrown but was not'); } - public function testLoadFromFile_NormalPath_WorksWhenFileIsPresent() { + public function testLoadFile_NormalPath_WorksWhenFileIsPresent() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testLoadFromFile - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testLoadFile - Exception Caught" . $e->getMessage()); } } @@ -272,10 +274,10 @@ </departments> </company> */ - public function testLoadFromFile_LoadedGraphCorrespondsToTheXml() { + public function testLoadFile_LoadedGraphCorrespondsToTheXml() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); $this->assertEquals("MegaCorp", $do->name, 'Company name is not valid.'); $this->assertEquals(1, count($do->departments), 'Wrong number of departments.'); @@ -291,16 +293,16 @@ } } - public function testLoadFromFile_LoadedGraphCorrespondsToTheXmlWithNilSn() { + public function testLoadFile_LoadedGraphCorrespondsToTheXmlWithNilSn() { try { - $xmldas = SDO_DAS_XML::create("company_with_nillable_SN.xsd"); - $xdoc = $xmldas->loadFromFile("company_with_nillable_SN.xml"); + $xmldas = SDO_DAS_XML::create('nillable/company_with_nillable_SN.xsd'); + $xdoc = $xmldas->loadFile('nillable/company_with_nillable_SN.xml'); $do = $xdoc->getRootDataObject(); $department = $do->departments[0]; $jane = $department->employees[0]; $this->assertTrue($jane->SN === null && isset($jane->SN), 'Serial number is not null.'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testLoadFile_Loaded.... - Exception Caught" . $e->getMessage()); } } @@ -316,10 +318,10 @@ } } - public function testSaveDocumentToString_SaveAndReloadWorksCorrectly() { + public function testSaveString_SaveAndReloadWorksCorrectly() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); //Change some values @@ -328,25 +330,25 @@ $do->departments[0]->location = "Bangalore"; //Save the changes to xml string - $str = $xmldas->saveDocumentToString($xdoc); + $str = $xmldas->saveString($xdoc); $this->assertTrue(strrpos($str,'Bangalore') > 0, 'Department location not found in saved xml.'); //Test whether it is save correctly or not? - $xdoc1 = $xmldas->loadFromString($str); + $xdoc1 = $xmldas->loadString($str); $do1 = $xdoc1->getRootDataObject(); $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); $this->assertSame($do->departments[0]->employees[0], $do->employeeOfTheMonth, 'Two ways to reach e.o.t.m do not agree.'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDocumentToString - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testSaveString - Exception Caught" . $e->getMessage()); } } - public function testSaveDocumentToFile_SaveAndReloadWorksCorrectly() { + public function testSaveFile_SaveAndReloadWorksCorrectly() { try { $temp_file = tempnam($_ENV['TMP'], 'SDO'); $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $do = $xdoc->getRootDataObject(); //Change some values @@ -355,274 +357,162 @@ $do->departments[0]->location = "Bangalore"; //Save the changes to xml file - $str = $xmldas->saveDocumentToFile($xdoc, $temp_file); + $str = $xmldas->saveFile($xdoc, $temp_file); //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromFile($temp_file); + $xdoc1 = $xmldas->loadFile($temp_file); $do1 = $xdoc1->getRootDataObject(); unlink($temp_file); $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDocumentToFile - Exception Caught" . $e->getMessage()); - } - } - - public function testSaveDataObjectToString_SaveAndReloadWorksCorrectly() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $do = $xdoc->getRootDataObject(); - - //Change some values - $emp_list = $do->departments[0]->employees; - $do->employeeOfTheMonth = $emp_list[0]; - $do->departments[0]->location = "Bangalore"; - - //Save the changes to xml string - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToString($do, $type->getNamespaceURI(), 'company'); - $this->assertTrue(strrpos($str,'Bangalore') > 0, 'Department location not found in saved xml.'); - - //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromString($str); - $do1 = $xdoc1->getRootDataObject(); - $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'Non-containment reference is not valid.'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'Can not access part of tree from root data object'); - $this->assertSame($do->departments[0]->employees[0], $do->employeeOfTheMonth, 'Two ways to reach e.o.t.m do not agree.'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDataObjectToString - Exception Caught" . $e->getMessage()); - } - } - - public function testSaveDataObjectToFile_SaveAndReloadWorksCorrectly() { - try { - $temp_file = tempnam($_ENV['TMP'], 'SDO'); - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $do = $xdoc->getRootDataObject(); - - //Change some values - $emp_list = $do->departments[0]->employees; - $do->employeeOfTheMonth = $emp_list[0]; - $do->departments[0]->location = "Bangalore"; - - //Save the changes to xml file - $model_reflection_object = new SDO_Model_ReflectionDataObject($do); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToFile($do, $type->getNamespaceURI(), 'company', $temp_file); - - //Test whether it is saved correctly or not - $xdoc1 = $xmldas->loadFromFile($temp_file); - $do1 = $xdoc1->getRootDataObject(); - unlink($temp_file); - $this->assertEquals("John Jones", $do->employeeOfTheMonth->name, 'testSaveDataObjectToFile - Non-containment reference is not valid.'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'testSaveDataObjectToFile - Can not access part of tree from root data object'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testSaveDataObjectToFile - Exception Caught" . $e->getMessage()); - } - } - - public function testCreateDataObjectAndSaveToStringWorksCorrectly() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - - //Create Company object - $cmpny = $xmldas->createDataObject("companyNS", "CompanyType"); - $cmpny->name = "Acme Inc."; - - //Using company object, create department object - $dept = $cmpny->createDataObject("departments"); - $dept->name = "Finance"; - $dept->location = "UK"; - - //Create department object without company object - $dept1 = $xmldas->createDataObject("companyNS", "DepartmentType"); - $dept1->location = "Bangalore"; - $dept1->name = "Sales"; - - //Replace the original department object in the company object - $cmpny->departments[0] = $dept1; - - //Test whether changes are saved properly - $model_reflection_object = new SDO_Model_ReflectionDataObject($cmpny); - $type = $model_reflection_object->getType(); - $str = $xmldas->saveDataObjectToString($cmpny, $type->getNamespaceURI(), 'company'); - $xdoc = $xmldas->loadFromString($str); - $do = $xdoc->getRootDataObject(); - $this->assertEquals("Sales", $do->departments[0]->name, 'testCreateDataObject - Can not access part of tree from root data object'); - $this->assertEquals("Bangalore", $do->departments[0]->location, 'testCreateDataObject - Can not access part of tree from root data object'); - - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testCreateDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testSaveFile - Exception Caught" . $e->getMessage()); } } public function testXMLDocument_getRootObject() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); + $xdoc = $xmldas->loadFile("company.xml"); $this->assertEquals("MegaCorp", $xdoc->getRootDataObject()->name, 'testgetRootDataObject - was not the company'); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ public function testXMLDocument_getRootElementURI() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("CompanyNS", $xdoc->getRootElementURI, 'testgetRootElementURI - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $this->assertEquals("companyNS", $xdoc->getRootElementURI(), 'testgetRootElementURI - wrong answer '); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ public function testXMLDocument_getRootElementName() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("company", $xdoc->getRootElementName, 'testgetRootElementName - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $this->assertEquals("company", $xdoc->getRootElementName(), 'testgetRootElementName - wrong answer '); } catch (SDO_Exception $e) { $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ - public function testXMLDocument_getEncoding() { + public function testSetOnDocumentWorksCorrectly() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals("UTF-8", $xdoc->getEncoding, 'testgetEncoding - wrong answer '); + $xdoc = $xmldas->loadFile("company.xml"); + $xdoc->setXMLVersion("1.1"); + $xdoc->setEncoding("ISO-8859-1"); + $str = $xmldas->saveString($xdoc); + $this->assertTrue(strpos($str, '1.1') > 0, 'XML Version was apparently not set correctly'); + $this->assertTrue(strpos($str, 'ISO-8859-1') > 0, 'Encoding was apparently not set correctly'); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testsetEncoding - Exception Caught" . $e->getMessage()); } } - /* TODO reinstate this test */ - public function testGetXmlDeclaration() { + public function testCreateDocumentNoArgs() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company_noxmldecl.xml"); - throw new PHPUnit2_Framework_IncompleteTestError(); - // $this->assertEquals(false, $xdoc->getXMLDeclaration(), 'testgetXMLDeclaration - should return false'); - } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); - } - } + $xdoc = $xmldas->createDocument(); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); - public function testGetXmlVersion() { - try { - $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $this->assertEquals('1.0', $xdoc->getXMLVersion(), 'testgetXMLVersion - should be 1.0'); + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - public function testGetSchemaLocation() { + public function testCreateDocumentOneArg() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $this->assertEquals(null, $xdoc->getSchemaLocation(), 'testgetSchemaLocation - wrong answer'); + $xdoc = $xmldas->createDocument('company'); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); + + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testGetRootDataObject - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - - public function testSetAndGetEncodingOnDocumentWorksCorrectly() { + public function testCreateDocumentTwoArgs() { try { $xmldas = SDO_DAS_XML::create("company.xsd"); - $xdoc = $xmldas->loadFromFile("company.xml"); - $xdoc->setEncoding("UTF-16"); - $this->assertEquals("UTF-16", $xdoc->getEncoding(), 'testsetEncoding - failed after set to UTF-16;'); - - $xdoc->setEncoding("ISO-8859-1"); - $this->assertEquals("ISO-8859-1", $xdoc->getEncoding(), 'testsetEncoding - failed after set to ISO-8859-1;'); + $xdoc = $xmldas->createDocument('companyNS','company'); + $root_do = $xdoc->getRootDataObject(); + $rdo = new SDO_Model_ReflectionDataObject($root_do); + $type = $rdo->getType(); + $this->assertTrue($type->name == 'CompanyType', 'type of root object should be CompanyType but was ' . $type->name); + $this->assertTrue($type->namespaceURI == 'companyNS', 'name space of root element should be companyNS but was ' . $type->namespaceURI); + $this->assertTrue($xdoc->getRootElementURI() == 'companyNS', 'namespace for the document should be companyNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'company', 'root element name should be company but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testsetEncoding - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "createDocumentNoArgs - Unexpected Exception Caught" . $e->getMessage()); } } - public function testDerivationByExtension() { + public function testExtendedComplexType() { try { - $xmldas = SDO_DAS_XML::create("derivation/extension.xsd"); - $do = $xmldas->createDataObject("", "testExtensionType"); - $author = $do->createDataObject('author'); - $character = $do->createDataObject('character'); - $author->name = "Jane Austen"; - $author->born = "1775"; - $author->dead = "1817"; - $character->name="Elizabeth Bennett"; - $character->qualification="lively playful disposition"; - $this->assertTrue($author->dead == '1817', "testDerivationByExtension - extended element not set correctly"); - $this->assertTrue($character->qualification == 'lively playful disposition', "testDerivationByExtension - extended element not set correctly"); + $xmldas = SDO_DAS_XML::create("extendedComplexType/person.xsd"); + $xdoc = $xmldas->loadFile("extendedComplexType/person.xml"); + $do = $xdoc->getRootDataObject(); + $this->assertTrue($do->first == 'William', 'first name should have been William'); + $this->assertTrue($do->gender == 'male', 'gender should have been male'); + $this->assertTrue($xdoc->getRootElementURI() == 'TNS', 'namespace for the document should be TNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'person', 'root element name should be person but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testDerivationByExtension - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testExtendedComplexType - Unexpected Exception Caught" . $e->getMessage()); } } - - public function testDerivationByRestriction() { + public function testRestrictedComplexType() { try { - $xmldas = SDO_DAS_XML::create("derivation/restriction.xsd"); - $do = $xmldas->createDataObject("", "testRestrictionType"); - $author = $do->createDataObject('author'); - $character = $do->createDataObject('character'); - $author->name = "Jane Austen"; - $author->born = "1775"; - $author->dead = "1817"; - $character->name="Elizabeth Bennett"; - $character->qualification="lively playful disposition"; - $this->assertTrue($author->dead == '1817', "testDerivationByRestriction - extended element not set correctly"); - $this->assertTrue($character->qualification == 'lively playful disposition', "testDerivationByRestriction - extended element not set correctly"); + $xmldas = SDO_DAS_XML::create('restrictedComplexType/name.xsd'); + $xdoc = $xmldas->loadFile('restrictedComplexType/name.xml'); + $do = $xdoc->getRootDataObject(); + $this->assertTrue($do->last == 'Smith', 'last name should have been Smith'); + $this->assertTrue($do->title == 'Mr.', 'title should have been Mr.'); + $this->assertTrue($xdoc->getRootElementURI() == 'TNS', 'namespace for the document should be TNS but was ' . $xdoc->getRootElementURI()); + $this->assertTrue($xdoc->getRootElementName() == 'formalname', 'root element name should be formalname but was ' . $xdoc->getRootElementName()); } catch (SDO_Exception $e) { - $this->assertTrue(false, "testDerivationByRestriction - Exception Caught" . $e->getMessage()); + $this->assertTrue(false, "testRestrictedComplexType - Unexpected Exception Caught" . $e->getMessage()); } } + public function testAbstractTypeCannotBeInstantiated() { + global $XMLDASTest_error_handler_called; + global $XMLDASTest_error_handler_severity; + global $XMLDASTest_error_handler_msg; - public function testAbstractType() { + $xmldas = SDO_DAS_XML::create('abstractComplexType/abstract.xsd'); + set_error_handler('XMLDASTest_user_error_handler'); + $XMLDASTest_error_handler_called = false; + $exception_thrown = false; + $created_first_object_ok = false; try { - $xmldas = SDO_DAS_XML::create("derivation/abstract.xsd"); - // hopefully will not be able to create an object of abstract type - $do = $xmldas->createDataObject("", "testAbstractType"); - - } catch (SDO_Exception $e) { + $person = $xmldas->createDataObject('TNS','fullpersoninfo'); // OK + $created_first_object_ok = true; + $person = $xmldas->createDataObject('TNS','personinfo'); // should fail + } catch (Exception $e) { + $this->assertTrue(strpos($e->getMessage(), 'abstract type') > 0, 'Wrong exception text: ' . $e->getMessage()); $exception_thrown = true; - $msg = $e->getMessage(); } - $this->assertTrue($exception_thrown, "testAbstractType - SDO_Exception should have been thrown"); - $this->assertTrue(strpos($msg,'Instantiation of abstract type') != 0, "testAbstractType - wrong message" . $e->getMessage()); - + $this->assertTrue($created_first_object_ok == true, 'Failed to create object of concrete type OK'); + $this->assertTrue($exception_thrown,'testAbstractTypeCannotBeInstantiated - exception should have been thrown'); } - } - -/* Graveyard -tests no longer in set and get encoding -// FAILS - seems likely that some restriction in libxml2 - -$str = $xmldas->saveDocumentToString($xdoc); -$xdoc1 = $xmldas->loadFromString($str); -$this->assertEquals("ISO-8859-1", $xdoc1->getEncoding(), 'testsetEncoding - failed after write to string;'); - -// FAILED -$xdoc->setEncoding("UTF-16"); -$temp_file = tempnam($_ENV['TMP'], 'SDO'); -$xmldas->saveDocumentToFile($xdoc, $temp_file); -$xdoc2 = $xmldas->loadFromFile($temp_file); -unlink($temp_file); -$this->assertEquals("UTF-16", $xdoc2->getEncoding(), 'testsetEncoding - failed after write to file;'); -*/ - ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_CPPException.cpp?view=markup&rev=1.1 Index: pecl/sdo/SDO_CPPException.cpp +++ pecl/sdo/SDO_CPPException.cpp /* +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2005. | | 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: Caroline Maynard | +----------------------------------------------------------------------+ */ static char rcs_id[] = "$Id: SDO_CPPException.cpp,v 1.1 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> #include <math.h> #include "zend_config.w32.h" #endif #include "php.h" #include "zend_exceptions.h" #include "php_sdo_int.h" #include "commonj/sdo/SDORuntimeException.h" #define CLASS_NAME "SDO_CPPException" static zend_object_handlers sdo_cppexception_object_handlers; /* {{{ sdo_throw_runtimeexception * maps a C++ SDO exception to a PHP SDO exception and throws it */ zval *sdo_throw_runtimeexception(SDORuntimeException *e TSRMLS_DC) { zval *z_cause; zval *z_sdo_exception; zend_class_entry *exception_class; const char *message = e->getMessageText(); const char *exception_type = e->getEClassName(); MAKE_STD_ZVAL(z_cause); sdo_cppexception_new (z_cause, e TSRMLS_CC); if (strcmp(exception_type, "SDOUnsupportedOperationException") == 0) exception_class = sdo_unsupportedoperationexception_class_entry; else if (strcmp(exception_type, "SDOPropertyNotFoundException") == 0 || strcmp(exception_type, "SDOPathNotFoundException") == 0) exception_class = sdo_propertynotfoundexception_class_entry; else if (strcmp(exception_type, "SDOTypeNotFoundException") == 0) exception_class = sdo_typenotfoundexception_class_entry; else if (strcmp(exception_type, "SDOIndexOutOfRangeException") == 0) exception_class = sdo_indexoutofboundsexception_class_entry; else if (strcmp(exception_type, "SDOInvalidConversionException") == 0) exception_class = sdo_invalidconversionexception_class_entry; else if (strcmp(exception_type, "SDOPropertyNotSetException") == 0) exception_class = sdo_propertynotsetexception_class_entry; else exception_class = sdo_exception_class_entry; z_sdo_exception = sdo_throw_exception (exception_class, message, 0, 0 TSRMLS_CC); z_sdo_exception = sdo_throw_exception (exception_class, message, 0, z_cause TSRMLS_CC); zval_ptr_dtor(&z_cause); return z_sdo_exception; } /* }}} */ /* {{{ sdo_cppexception_object_create */ static zend_object_value sdo_cppexception_create_object(zend_class_entry *ce TSRMLS_DC) { zend_object *object; zval *tmp; /* this must be passed to hash_copy, but doesn't seem to be used */ zval z_object; z_object.value.obj = zend_objects_new(&object, ce TSRMLS_CC); z_object.value.obj.handlers = &sdo_cppexception_object_handlers; ALLOC_HASHTABLE(object->properties); zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); return z_object.value.obj; } /* }}} */ /* {{{ sdo_cppexception_get_property */ static void sdo_cppexception_get_property(zval *me, char *name, long name_len, zval *return_value TSRMLS_DC) { zval *value; value = zend_read_property(sdo_cppexception_class_entry, me, name, name_len, 0 TSRMLS_CC); *return_value = *value; zval_copy_ctor(return_value); INIT_PZVAL(return_value); } /* }}} */ /* {{{ sdo_cppexception_cast_object */ static int sdo_cppexception_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) { ostringstream print_buf; zval free_obj; int rc = SUCCESS; if (should_free) { free_obj = *writeobj; } sdo_cppexception_get_property(readobj, "string", sizeof("string") - 1, writeobj TSRMLS_CC); switch(type) { case IS_STRING: convert_to_string(writeobj); break; case IS_BOOL: convert_to_boolean(writeobj); break; case IS_LONG: convert_to_long(writeobj); break; case IS_DOUBLE: convert_to_double(writeobj); break; default: rc = FAILURE; } if (should_free) { zval_dtor(&free_obj); } return rc; } /* }}} */ /* {{{ sdo_cppexception_minit * This clas is not a PHP Exception, merely a wrapper for the data * from a C++ SDORuntimeException. It has similar properties to a * PHP Exception, but there's no debug trace. */ void sdo_cppexception_minit(zend_class_entry *ce TSRMLS_DC) { sdo_cppexception_class_entry = zend_register_internal_class(ce TSRMLS_CC); sdo_cppexception_class_entry->create_object = sdo_cppexception_create_object; memcpy(&sdo_cppexception_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); /*TODO There's a signature change for cast_object in PHP6. */ #if (PHP_MAJOR_VERSION < 6) sdo_cppexception_object_handlers.cast_object = sdo_cppexception_cast_object; #endif zend_declare_property_string(sdo_cppexception_class_entry, "class", sizeof("class") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "file", sizeof("file") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_long(sdo_cppexception_class_entry, "line", sizeof("line") - 1, 0, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "function", sizeof("function") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "message", sizeof("message") - 1, "", ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_long(sdo_cppexception_class_entry, "severity", sizeof("severity") - 1, E_ERROR, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_string(sdo_cppexception_class_entry, "string", sizeof("string") - 1, "", ZEND_ACC_PRIVATE TSRMLS_CC); } /* }}} */ /* {{{ sdo_cppexception_new * Instantiate an SDO_CPPException from an SDORuntimeException */ void sdo_cppexception_new(zval *me, SDORuntimeException *cpp_exception TSRMLS_DC) { const char *eclass = cpp_exception->getEClassName(); const char *function = cpp_exception->getFunctionName(); const char *message = cpp_exception->getMessageText(); const char *file = cpp_exception->getFileName(); long line = cpp_exception->getLineNumber(); char *class_name, *space; long severity; ostringstream print_buf; string print_string; switch(cpp_exception->getSeverity()) { case SDORuntimeException::Normal: severity = E_NOTICE; break; case SDORuntimeException::Warning: severity = E_WARNING; break; case SDORuntimeException::Error: case SDORuntimeException::Severe: default: severity = E_ERROR; break; } if (object_init_ex(me, sdo_cppexception_class_entry) == FAILURE) { class_name = get_active_class_name(&space TSRMLS_CC); php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } if (eclass) { zend_update_property_string(sdo_cppexception_class_entry, me, "class", sizeof("class")-1, (char *)eclass TSRMLS_CC); } if (file) { zend_update_property_string(sdo_cppexception_class_entry, me, "file", sizeof("file")-1, (char *)file TSRMLS_CC); } zend_update_property_long(sdo_cppexception_class_entry, me, "line", sizeof("line")-1, line TSRMLS_CC); if (function) { zend_update_property_string(sdo_cppexception_class_entry, me, "function", sizeof("function")-1, (char *)function TSRMLS_CC); } if (message) { zend_update_property_string(sdo_cppexception_class_entry, me, "message", sizeof("message")-1, (char *)message TSRMLS_CC); } zend_update_property_long(sdo_cppexception_class_entry, me, "severity", sizeof("severity")-1, severity TSRMLS_CC); print_buf << *cpp_exception; print_string = print_buf.str(); zend_update_property_stringl (sdo_cppexception_class_entry, me, "string", sizeof("string") - 1, (char *)print_string.c_str(), print_string.length() TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getClass */ PHP_METHOD(SDO_CPPException, getClass) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "class", sizeof("class") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getFile */ PHP_METHOD(SDO_CPPException, getFile) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "file", sizeof("file") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getLine */ PHP_METHOD(SDO_CPPException, getLine) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "line", sizeof("line") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getFunction */ PHP_METHOD(SDO_CPPException, getFunction) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "function", sizeof("function") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getMessage */ PHP_METHOD(SDO_CPPException, getMessage) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "message", sizeof("message") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::getSeverity */ PHP_METHOD(SDO_CPPException, getSeverity) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } sdo_cppexception_get_property( getThis(), "severity", sizeof("severity") - 1, return_value TSRMLS_CC); } /* }}} */ /* {{{ SDO_CPPException::__toString */ PHP_METHOD(SDO_CPPException, __toString) { sdo_cppexception_cast_object(getThis(), return_value, IS_STRING, 0 TSRMLS_CC); } /* }}} */ /* * 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 */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/SDO_Exception.cpp?view=markup&rev=1.1 Index: pecl/sdo/SDO_Exception.cpp +++ pecl/sdo/SDO_Exception.cpp /* +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2005. | | 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: Caroline Maynard | +----------------------------------------------------------------------+ */ static char rcs_id[] = "$Id: SDO_Exception.cpp,v 1.1 2006/02/20 18:50:25 mfp Exp $"; #ifdef PHP_WIN32 #include <iostream> #include <math.h> #include "zend_config.w32.h" #endif #include "php.h" #include "zend.h" #include "zend_exceptions.h" #include "zend_builtin_functions.h" #include "php_sdo_int.h" #define CLASS_NAME "SDO_Exception" #define MAX_MSG 4096 static zend_class_entry *exception_class_entry; static zend_object_handlers sdo_exception_object_handlers; /* {{{ sdo_exception_object_create */ static zend_object_value sdo_exception_create_object(zend_class_entry *ce TSRMLS_DC) { zend_object *object; zval *tmp; /* this must be passed to hash_copy, but doesn't seem to be used */ zval z_object; zval *z_trace; z_object.value.obj = zend_objects_new(&object, ce TSRMLS_CC); z_object.value.obj.handlers = &sdo_exception_object_handlers; ALLOC_HASHTABLE(object->properties); zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); zend_update_property_string(exception_class_entry, &z_object, "file", sizeof("file") - 1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(exception_class_entry, &z_object, "line", sizeof("line") - 1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); ALLOC_ZVAL(z_trace); z_trace->is_ref = 0; z_trace->refcount = 0; zend_fetch_debug_backtrace(z_trace, 0, 0 TSRMLS_CC); zend_update_property(exception_class_entry, &z_object, "trace", sizeof("trace") - 1, z_trace TSRMLS_CC); return z_object.value.obj; } /* }}} */ /* {{{ sdo_exception_minit */ void sdo_exception_minit(zend_class_entry *ce TSRMLS_DC) { #if (PHP_MAJOR_VERSION < 6) exception_class_entry = zend_exception_get_default(); #else exception_class_entry = zend_exception_get_default(TSRMLS_C); #endif sdo_exception_class_entry = zend_register_internal_class_ex( ce, exception_class_entry, NULL TSRMLS_CC); sdo_exception_class_entry->create_object = sdo_exception_create_object; /* * The SDO_Exception adds a cause property to the base Exception class. * This may be set to any value, normally the original SDO_CPPException. */ zend_declare_property_null(sdo_exception_class_entry, "cause", sizeof("cause") - 1, ZEND_ACC_PUBLIC TSRMLS_CC); memcpy(&sdo_exception_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); sdo_exception_object_handlers.clone_obj = NULL; } /* }}} */ /* {{{ sdo_exception_new * Create a new SDO_Exception of the class specified */ void sdo_exception_new(zval *z_ex, zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC) { char *class_name, *space; Z_TYPE_P(z_ex) = IS_OBJECT; if (object_init_ex(z_ex, ce) == FAILURE) { class_name = get_active_class_name(&space TSRMLS_CC); php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object", class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME); return; } if (message) { zend_update_property_string(exception_class_entry, z_ex, "message", sizeof("message") - 1, (char *)message TSRMLS_CC); } zend_update_property_long(exception_class_entry, z_ex, "code", sizeof("code") - 1, code TSRMLS_CC); if (z_cause) { zend_update_property(sdo_exception_class_entry, z_ex, "cause", sizeof("cause") - 1, z_cause TSRMLS_CC); } } /* }}} */ /* {{{ sdo_throw_exception * Throw an SDO_Exception */ zval *sdo_throw_exception (zend_class_entry *ce, const char *message, long code, zval *z_cause TSRMLS_DC) { zval *z_ex; MAKE_STD_ZVAL(z_ex); sdo_exception_new(z_ex, ce, message, code, z_cause TSRMLS_CC); zend_throw_exception_object (z_ex TSRMLS_CC); return z_ex; } /* }}} */ /* {{{ sdo_throw_exception_ex * Throw an SDO_Exception */ zval *sdo_throw_exception_ex(zend_class_entry *ce, long code, zval *z_cause TSRMLS_DC, char *format, ...) { va_list arg; char *message; zval *z_ex; int len; /* TODO: for some reason I don't understand, I get a link error for * zend_vspprintf. So use a temporary buffer and truncate the message * if necessary. */ message = (char *)emalloc(MAX_MSG); va_start(arg, format); len = snprintf(message, MAX_MSG, format, arg); va_end(arg); z_ex = sdo_throw_exception(ce, message, code, z_cause TSRMLS_CC); efree(message); return z_ex; } /* }}} */ /* {{{ sdo_exception_set_cause */ void sdo_exception_set_cause(zval *me, zval *z_cause TSRMLS_DC) { zend_update_property(sdo_exception_class_entry, me, "cause", sizeof("cause") - 1, z_cause TSRMLS_CC); } /* }}} */ /* {{{ sdo_exception_get_cause */ zval *sdo_exception_get_cause(zval *me TSRMLS_DC) { return zend_read_property(sdo_exception_class_entry, me, "cause", sizeof("cause") - 1, 0 TSRMLS_CC); } /* }}} */ /* {{{ SDO_Exception::getCause */ PHP_METHOD(SDO_Exception, getCause) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } zval *z_cause = sdo_exception_get_cause(getThis() TSRMLS_CC); RETURN_ZVAL(z_cause, 1, 0); } /* }}} */ /* * 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 */ http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/.cvsignore?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/.cvsignore +++ pecl/sdo/tests/XMLDAS/Examples/.cvsignore letter-out.xml http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example4.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/Example4.php +++ pecl/sdo/tests/XMLDAS/Examples/Example4.php <?php /** * Illustrate open types and the use of the addTypes() method */ $xmldas = SDO_DAS_XML::create(); $xmldas->addTypes("jungle.xsd"); // this is an open type i.e. the xsd specifies it can contain "any" type $xmldas->addTypes('animalTypes.xsd'); $baloo = $xmldas->createDataObject('','bearType'); $baloo->name = "Baloo"; $baloo->weight = 800; $bagheera = $xmldas->createDataObject('','pantherType'); $bagheera->name = "Bagheera"; $bagheera->colour = 'inky black'; $kaa = $xmldas->createDataObject('','snakeType'); $kaa->name = "Kaa"; $kaa->length = 25; $document = $xmldas->createDocument(); $do = $document->getRootDataObject(); $do->bear = $baloo; $do->panther = $bagheera; $do->snake = $kaa; print($xmldas->saveString($document,2)); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/Example5.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/Example5.php +++ pecl/sdo/tests/XMLDAS/Examples/Example5.php <?php /** * Finding out what you can about the document and document element * This can be quite hard to understand because there are four calls * Two calls are made against the document * Two calls are made against the root data object and its model * Because of the SDO-XML mapping rules and how the SDO model is derived * from the XML model, only three possible values can come back from these four calls. * Always, $document->getRootElementURI() == (type of root data object)->namespaceURI * Essentiually, it all comes form the first few lines of the xsd: * <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" * xmlns:letter="http://letterSchema" * targetNamespace="http://letterSchema"> * <xsd:element name="letters" type="letter:FormLetter"/> */ $xmldas = SDO_DAS_XML::create("letter.xsd"); $document = $xmldas->loadFile("letter.xml"); $root_do = $document->getRootDataObject(); /** * Incidentally, the root data object type name and * namespaceURI can also be obtained from the type via * a reflection data object built on the root data object */ //$model_rdo = new SDO_Model_ReflectionDataObject($root_do); //$type = $model_rdo->getType(); //echo "The type name of the root data object is " . $type->name . "\n"; //echo "The namespace URI of the root data object is " . $type->namespaceURI . "\n"; /** * The "root element name" is the element name of the document element * in this case 'letters' * This matches the 'name' attribute of the document element in the xsd and matches * the element name from the xml */ echo "The document element name is " . $document->getRootElementName() . "\n"; assert($document->getRootElementName() == 'letters'); // a property of the document /** * The "root element URI" is the namespace part of the element name of the document element * in this case 'http://letterSchema' since 'letters' is in that namespace * This is taken from the xsd and matches the namespace picked up from the xml */ echo "The document element is in the namespace " . $document->getRootElementURI() . "\n"; assert($document->getRootElementURI() == 'http://letterSchema'); // a property of the document /** * The type name is taken from the SDO model * The XML-SDO mapping rules make this either: * The name of the complexType if there is one (in this case there is) * The document element name if there no complexType * This is taken from the xsd */ echo "The type name of the root data object is " . $root_do->getTypeName() . "\n"; assert($root_do->getTypeName() == 'FormLetter'); /** * The type's namespaceURI is taken from the SDO model * The XML-SDO mapping rules ensure that this will always be the same as * the namepace URI of the document element */ echo "The namespaceURI of the root data object is " . $root_do->getTypeNamespaceURI() . "\n"; assert($root_do->getTypeNamespaceURI() == 'http://letterSchema'); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd +++ pecl/sdo/tests/XMLDAS/Examples/animalTypes.xsd <schema xmlns= "http://www.w3.org/2001/XMLSchema"> <complexType name="snakeType"> <sequence> <element name= "name" type="string"/> <element name= "length" type="positiveInteger" /> </sequence> </complexType> <complexType name="bearType"> <sequence> <element name= "name" type="string"/> <element name= "weight" type="positiveInteger" /> </sequence> </complexType> <complexType name="pantherType"> <sequence> <element name= "name" type="string"/> <element name= "colour" type="string" /> </sequence> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/Examples/jungle.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/Examples/jungle.xsd +++ pecl/sdo/tests/XMLDAS/Examples/jungle.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="jungle"> <complexType> <sequence> <any minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> </element> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/abstractComplexType/abstract.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <element name="employee" type="fullpersoninfo"/> <complexType name="personinfo" abstract="true"> <sequence> <element name="firstname" type="string"/> <element name="lastname" type="string"/> </sequence> </complexType> <complexType name="fullpersoninfo"> <complexContent> <extension base="personinfo"> <sequence> <element name="address" type="string"/> <element name="city" type="string"/> <element name="country" type="string"/> </sequence> </extension> </complexContent> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/animalTypes.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <complexType name="snakeType"> <sequence> <element name= "name" type="string"/> <element name= "length" type="positiveInteger" /> </sequence> </complexType> <complexType name="bearType"> <sequence> <element name= "name" type="string"/> <element name= "weight" type="positiveInteger" /> </sequence> </complexType> <complexType name="pantherType"> <sequence> <element name= "name" type="string"/> <element name= "colour" type="string" /> </sequence> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/anyElement/jungle.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="jungle"> <complexType> <sequence> <any minOccurs="0" maxOccurs="unbounded"/> </sequence> </complexType> </element> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xml <?xml version="1.0"?> <person xmlns="TNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance" title="Mr." gender="male"> <first>William</first> <middle>Henry</middle> <last>Harrison</last> <age>223</age> <birthdate>1773-02-09</birthdate> </person> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/extendedComplexType/person.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <complexType name="NameType"> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complexType> <complexType name="PersonType"> <complexContent> <extension base="tns:NameType"> <sequence> <element name="age" type="positiveInteger"/> <element name="birthdate" type="dateTime"/> </sequence> <attribute name="gender" type="string"/> </extension> </complexContent> </complexType> <element name="person" type="tns:PersonType"/> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/missingType/company_missing_type.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="xsd:string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="EmployeeType"> <attribute name="name" type="xsd:string"/> <attribute name="SN" type="xsd:ID"/> <attribute name="manager" type="xsd:boolean"/> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xml <?xml version="1.0" encoding="UTF-8" ?> <!-- This XML has an employee with an SN of nil, which should appear in the SDO as NULL --> <company xmlns="companyNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="MegaCorp" employeeOfTheMonth="#/departments.0/employees.1"> <departments name="Advanced Technologies" location="NY" number="123"> <employees> <name>Jane Doe</name> <SN xsi:nil="true"></SN> </employees> </departments> </company> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/nillable/company_with_nillable_SN.xsd <!-- This XSD recasts the properties of employee to elements in order to allow the SN property to be nillable --> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="DepartmentType"> <sequence> <element name="employees" type="company:EmployeeType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="location" type="string"/> <attribute name="number" type="int"/> </complexType> <complexType name="EmployeeType"> <element name="name" type="string"/> <element name="SN" type="ID" nillable="true"/> <element name="manager" type="boolean"/> </complexType> </schema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xml <?xml version="1.0" encoding="UTF-8" ?> <company xmlns="companyNS" name="MegaCorp" employeeOfTheMonth="#/departments.0/employees.1"> <departments name="Advanced Technologies" location="NY" number="123"> <employees name="John Jones" SN="E0001"/> <employees name="Jane Doe" SN="E0003"/> <employees name="Al Smith" SN="E0004" manager="true"/> </departmentsX> </Xcompany> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/parseErrors/parse_errors.xsd <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <element name="company" type="company:CompanyType"/> <complexType name="CompanyType"> <sequence> <element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="employeeOfTheMonth" type="IDREF" sdoxml:propertyType="company:EmployeeType"/> </complexType> <complexType name="DepartmentType"> <sequence> <element name="employees" type="company:EmployeeType" maxOccurs="unbounded"/> </sequence> <attribute name="name" type="string"/> <attribute name="location" type="string"/> <attribute name="number" type="int"/> </complexType> <complexType name="EmployeeType"> <attribute name="name" type="string"/> <attribute name="SN" type="ID"/> <attribute name="manager" type="boolean"/> </complexType> </XXXXXschema> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/load.php <?php $xmldas = SDO_DAS_XML::create("name.xsd"); print $xmldas; $xdoc = $xmldas->loadFile("name.xml"); $do = $xdoc->getRootDataObject(); var_dump($do); $str = $xmldas->saveString($xdoc,2); print $str; $rdo = new SDO_Model_ReflectionDataObject($do); $do_type = $rdo->getType(); $all_props = $do_type->getProperties(); foreach ($all_props as $do_property) { echo "property " . $do_property->getName() . "\n"; } var_dump($do); ?> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xml <?xml version="1.0"?> <formalname xmlns="TNS" title="Mr."> <last>Smith</last> </formalname> http://cvs.php.net/viewcvs.cgi/pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd?view=markup&rev=1.1 Index: pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd +++ pecl/sdo/tests/XMLDAS/PHPUnitTests/restrictedComplexType/name.xsd <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="TNS" xmlns:tns="TNS"> <complexType name="FormalNameType"> <complexContent> <restriction base="tns:NameType"> <sequence> <element ref="tns:last"/> </sequence> </restriction> </complexContent> </complexType> <complexType name="NameType"> <sequence> <element name="first" type="string"/> <element name="middle" type="string"/> <element name="last" type="string"/> </sequence> <attribute name="title" type="string"/> </complexType> <element name="formalname" type="tns:FormalNameType"/> <element name="last" type="string"/> </schema>