cvs: pecl(BRANCH_1_0_5) /sdo/commonj/sdo ChangeSummaryBuilder.h DataObjectImpl.cpp DataObjectImpl.h SDORuntimeException.cpp SDOSAX2Parser.cpp
SDOSchemaSAX2Parser.cpp SDOXMLWriter.cpp SDOXMLWriter.h
| From: | Caroline Maynard | Date: | Wed, 22 Nov 2006 11:13:04 +0000 |
| Subject: | cvs: pecl(BRANCH_1_0_5) /sdo/commonj/sdo ChangeSummaryBuilder.h DataObjectImpl.cpp DataObjectImpl.h SDORuntimeException.cpp SDOSAX2Parser.cpp SDOSchemaSAX2Parser.cpp SDOXMLWriter.cpp SDOXMLWriter.h |
||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-6659@lists.php.net to get a copy of this message | ||
cem Wed Nov 22 11:13:04 2006 UTC
Modified files: (Branch: BRANCH_1_0_5)
/pecl/sdo/commonj/sdo ChangeSummaryBuilder.h DataObjectImpl.cpp
DataObjectImpl.h SDORuntimeException.cpp
SDOSAX2Parser.cpp SDOSchemaSAX2Parser.cpp
SDOXMLWriter.cpp SDOXMLWriter.h
Log:
Update to Tuscany SDO C++ revision 477891
http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h diff -u pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.1 pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.2 --- pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 452786 $ $Date: 2006/11/22 11:13:03 $ */ #ifndef _CHANGESUMMARYBUILDER_H_ http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.cpp?r1=1.13.4.1&r2=1.13.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.1 pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.2 --- pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.1 Thu Nov 9 13:29:53 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452883 $ $Date: 2006/11/09 13:29:53 $ */ +/* $Rev: 477820 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/DataObjectImpl.h" @@ -495,7 +495,7 @@ #define setPrimitiveFromProperty(primval,primtype)\ void DataObjectImpl::set ##primval (const Property& property, primtype value)\ {\ - set ##primval (getPropertyIndex(property),value);\ + set ##primval (getPropertyIndexInternal(property),value);\ } /** @def setCharsFromProperty @@ -506,7 +506,7 @@ #define setCharsFromProperty(primval,primtype)\ void DataObjectImpl::set ##primval (const Property& property, primtype value, unsigned int len)\ {\ - set ##primval (getPropertyIndex(property),value, len);\ + set ##primval (getPropertyIndexInternal(property),value, len);\ } @@ -1283,7 +1283,7 @@ void DataObjectImpl::setCString(const Property& property, const SDOString& value) { - setCString(getPropertyIndex(property), value); + setCString(getPropertyIndexInternal(property), value); } // null support @@ -1378,7 +1378,7 @@ } void DataObjectImpl::setNull(const Property& property) { - setNull(getPropertyIndex(property)); + setNull(getPropertyIndexInternal(property)); } void DataObjectImpl::setNull(const char* path) @@ -1608,6 +1608,46 @@ msg.c_str()); } + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + unsigned int DataObjectImpl::getPropertyIndexInternal(const Property& p) + { + unsigned int index; + + try + { + index = getPropertyIndex(p); + } + catch ( SDOPropertyNotFoundException e ) + { + // this could mean that this data object has an open + // type. getPropertyIndex fails in this case because it + // tries to access the index of the property + // and it doesn't exist because it hasn't been created yet. + // This new method is used where properties are being set + // based on existing property objects. This is like to + // occur when a data object is being copied. In this case + // we want properties that are open to be copied also + // so we need to create the property and provide the index + if ( this->getType().isOpenType() ) + { + const Property *prop = defineProperty(p.getName(), p.getType()); + index = getPropertyIndex(p); + } + else + { + throw e; + } + } + + return index; + } + + const Property& DataObjectImpl::getProperty(unsigned int index) { PropertyImpl* pi = getPropertyImpl(index); @@ -2451,7 +2491,7 @@ void DataObjectImpl::setDataObject(const Property& prop, DataObjectPtr value) { - unsigned int propertyIndex = getPropertyIndex(prop); + unsigned int propertyIndex = getPropertyIndexInternal(prop); if (value != 0) http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.h?r1=1.11.4.1&r2=1.11.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.1 pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.2 --- pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.h Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477820 $ $Date: 2006/11/22 11:13:03 $ */ #ifndef _DATAOBJECTIMPL_H_ #define _DATAOBJECTIMPL_H_ @@ -597,6 +597,13 @@ virtual std::ostream& printSelf(std::ostream &os); private: + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + virtual unsigned int getPropertyIndexInternal(const Property& p); virtual void validateIndex(unsigned int index); virtual void checkFactory(DataObjectPtr dob, unsigned int propertyIndex); http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDORuntimeException.cpp?r1=1.6.4.1&r2=1.6.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDORuntimeException.cpp diff -u pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.1 pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.2 --- pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDORuntimeException.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 473864 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDORuntimeException.h" @@ -37,6 +37,10 @@ message_text = new char[strlen(msg_text)+1]; strcpy(message_text,msg_text); + locations[0].file = 0; + locations[0].line = 0; + locations[0].function = 0; + } // end SDORuntimeException constuctor // ======================================================================== @@ -51,13 +55,22 @@ strcpy(class_name, c.getEClassName()); message_text = new char[strlen(c.getMessageText())+1]; strcpy(message_text,c.getMessageText()); - for (int i=0;i<c.location_set;i++) + if (c.location_set) + { + for (int i=0;i<c.location_set;i++) + { + locations[i].file = new char[strlen(c.locations[i].file) + 1]; + strcpy(locations[i].file,c.locations[i].file); + locations[i].line = c.locations[i].line; + locations[i].function = new char[strlen(c.locations[i].function) + 1]; + strcpy(locations[i].function, c.locations[i].function); + } + } + else { - locations[i].file = new char[strlen(c.locations[i].file) + 1]; - strcpy(locations[i].file,c.locations[i].file); - locations[i].line = c.locations[i].line; - locations[i].function = new char[strlen(c.locations[i].function) + 1]; - strcpy(locations[i].function, c.locations[i].function); + locations[0].file = 0; + locations[0].line = 0; + locations[0].function = 0; } } http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp?r1=1.7.4.1&r2=1.7.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.1 pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.2 --- pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDOSAX2Parser.h" @@ -632,6 +632,10 @@ documentNamespaces = namespaces; setNamespaces = false; } + else + { + documentNamespaces.merge(namespaces); + } if (ignoreEvents) { @@ -1175,15 +1179,13 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString("value", currentPropertySetting.value); - seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { DataObjectList& dl = currentPropertySetting.dataObject-> getList((const char*)"value"); -// dl.append((const char*)currentPropertySetting.value); - dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); } } @@ -1193,8 +1195,7 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString("value", currentPropertySetting.value); - seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { @@ -1231,8 +1232,7 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString(currentPropertySetting.name, currentPropertySetting.value); - seq->addCString(currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString(currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str()); } // Always set the property as a String. SDO will do the conversion @@ -1245,8 +1245,7 @@ { DataObjectList& dl = currentPropertySetting.dataObject-> getList((const char*)currentPropertySetting.name); -// dl.append((const char*)currentPropertySetting.value); - dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp?r1=1.11.4.1&r2=1.11.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.1 pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.2 --- pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477840 $ $Date: 2006/11/22 11:13:03 $ */ #include "libxml/uri.h" #include "commonj/sdo/SDOSchemaSAX2Parser.h" @@ -540,59 +540,29 @@ SDOSchemaSAX2Parser& schemaParser, SDOXMLString& schemaLocation) { - int i,j,k; - SDOXMLString sl = getCurrentFile(); - - i = sl.lastIndexOf('/'); - j = sl.lastIndexOf('\\'); - if ((j > i) || (i < 0))i=j; - if (i>=0) - { - sl = sl.substring(0,i+1) + schemaLocation; - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - k = schemaLocation.lastIndexOf('/'); - j = schemaLocation.lastIndexOf('\\'); - if ((j > k) || (k < 0))k=j; - if (k>=0) - { - sl = sl.substring(0,i+1) + schemaLocation.substring(0,k+1); - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - } - } - try { - if (-1 != schemaParser.parse((const char *)schemaLocation)) - return 1; - } - catch (SDORuntimeException e) - { - } - k = schemaLocation.lastIndexOf('/'); - j = schemaLocation.lastIndexOf('\\'); - if ((j > k) || (k < 0))k=j; - if (k>=0) - { - sl = schemaLocation.substring(0,k+1); - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - } - return 0; + int i,j; + xmlChar *absoluteUri; + + SDOXMLString sl = getCurrentFile(); + + /* + * Build an absolute URL using the current file as the base and + * the schemaLocation as the relative part, using the rules in + * RFC 2396 5.2. Resolving Relative References to Absolute Form + */ + try { + absoluteUri = xmlBuildURI((const xmlChar *)schemaLocation, (const xmlChar *)sl); + if (-1 != schemaParser.parse((const char *)absoluteUri)) { + xmlFree(absoluteUri); + return 1; + } + } + catch (SDORuntimeException e) + { + } + if (absoluteUri) xmlFree(absoluteUri); + + return 0; } http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.cpp?r1=1.8.4.1&r2=1.8.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.1 pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.2 --- pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDOXMLWriter.h" #include "commonj/sdo/SDOXMLString.h" @@ -573,14 +573,17 @@ { std::map<SDOXMLString,SDOXMLString>::iterator it; SDOXMLString uri = dob->getType().getURI(); - - it = namespaceMap.find(uri); - if (it == namespaceMap.end()) + SDOXMLString typeName = dob->getType().getName(); + if (!(uri.equals("commonj.sdo") && typeName.equals("OpenDataObject"))) { - char buf[20]; - sprintf(buf,"%d",++spacescount); - SDOXMLString s = SDOXMLString("tns") + buf; - namespaceMap.insert(make_pair(uri,s)); + it = namespaceMap.find(uri); + if (it == namespaceMap.end()) + { + char buf[20]; + sprintf(buf,"%d",++spacescount); + SDOXMLString s = SDOXMLString("tns") + buf; + namespaceMap.insert(make_pair(uri,s)); + } } PropertyList pl = dob->getInstanceProperties(); @@ -640,14 +643,18 @@ ////////////////////////////////////////////////////////////////////////// void SDOXMLWriter::writeXmlnsXsi() { + return; SDOXMLString xsins("http://www.w3.org/2001/XMLSchema-instance"); std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(xsins); if (it == namespaceMap.end()) { - SDOXMLString prefix("xmlns:xsi"); - xmlTextWriterWriteAttribute(writer, - prefix, xsins); + namespaceMap.insert(make_pair( + SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"), + SDOXMLString("xsi"))); +// SDOXMLString prefix("xmlns:xsi"); +// xmlTextWriterWriteAttribute(writer, +// prefix, xsins); } } @@ -668,7 +675,26 @@ if (dataObject == 0) return 0; - + // Don't write the element URI if the element is a child of an open type + // and not one of the declared properties + SDOXMLString uri = elementURI; + if (!isRoot && !writeXSIType) + { + DataObject* dob = dataObject; + DataObjectImpl* cont = + ((DataObjectImpl*)dob)->getContainerImpl(); + if (cont != 0) + { + if (cont->getType().isOpenType()) + { + if (cont->getTypeImpl().getPropertyImpl(elementName) == 0) + { + uri = ""; + } + } + } + } + //SDOXMLString uri; //if (!elementURI.equals(namespaceUriStack.top())) //{ @@ -686,7 +712,7 @@ if (dataObject->isNull("")) { rc = xmlTextWriterStartElementNS(writer, - NULL, elementName, elementURI); + NULL, elementName, uri); if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", @@ -700,18 +726,16 @@ rc = xmlTextWriterEndElement(writer); } else - { - writeXMLElement( - writer, - elementName, - dataObject->getCString("")); -/* - xmlTextWriterWriteElement( - writer, - elementName, - SDOXMLString(dataObject->getCString(""))); -*/ - } + { + writeXMLElement(writer, + elementName, + dataObject->getCString("")); + /* + xmlTextWriterWriteElement(writer, + elementName, + SDOXMLString(dataObject->getCString(""))); + */ + } // need to pop stacks before returning //if (!uri.isNull()) @@ -723,18 +747,18 @@ } - //namespaceStack.push(namespaces); + //namespaceStack.push(namespaces); if (isRoot) { - tnsURI=elementURI; - if (elementURI.equals("")) { + tnsURI=uri; + if (uri.equals("")) { rc = xmlTextWriterStartElementNS(writer, NULL, elementName, NULL); } else { - rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, uri); } if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); @@ -746,9 +770,9 @@ SDOXMLString theName=elementName; - if (!elementURI.isNull() && !elementURI.equals(tnsURI) && !elementURI.equals("")) + if (!uri.isNull() && !uri.equals(tnsURI) && !uri.equals("")) { - std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri); if (it != namespaceMap.end()) { theName = (*it).second; @@ -787,12 +811,19 @@ if (isRoot) { - std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri); if (it == namespaceMap.end()) { SDOXMLString s = SDOXMLString("tns"); namespaceMap.insert(make_pair(elementURI,s)); } + it = namespaceMap.find(SDOXMLString("http://www.w3.org/2001/XMLSchema-instance")); + if (it == namespaceMap.end()) + { + namespaceMap.insert(make_pair( + SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"), + SDOXMLString("xsi"))); + } DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dataObject; spacescount = 1; addToNamespaces(d); @@ -844,7 +875,7 @@ ////////////////////////////////////////////////////////////////////////// - // write out the type if the xsi:type if the containing type is open + // write out the type if the xsi:type of the containing type is open // and the property is not one of the declared properties ////////////////////////////////////////////////////////////////////////// if (!writeXSIType) @@ -870,9 +901,25 @@ //{ if (cont->getTypeImpl().getPropertyImpl(elementName) == 0) { + const SDOXMLString& typeURI = dataObject->getType().getURI(); + const SDOXMLString& typeName = dataObject->getType().getName(); + + SDOXMLString theName=typeName; + + if (!typeURI.isNull() && !typeURI.equals(tnsURI) && !typeURI.equals("")) + { + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(typeURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += typeName; + } + } + rc = xmlTextWriterWriteAttribute(writer, (const unsigned char*)"xsi:type", - (const unsigned char*)dataObject->getType().getName()); + (const unsigned char*)theName); writeXmlnsXsi(); } @@ -945,13 +992,13 @@ // prefix = namespaces.findPrefix(qname.getURI()); //} - //if (prefix != 0 && !(*prefix).equals("")) + //if (prefix != 0 && !(*prefix).equals("")) std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(qname.getURI()); if (it != namespaceMap.end()) { - propertyValue = (*it).second + ":" + qname.getLocalName(); - } + propertyValue = (*it).second + ":" + qname.getLocalName(); + } else { char buffer[20]; @@ -959,7 +1006,7 @@ sprintf(buffer, "%d", j++); pref += buffer; rc = xmlTextWriterWriteAttributeNS(writer, - SDOXMLString("xmlns"), pref, NULL, qname.getURI()); + SDOXMLString("xmlns"), pref, NULL, qname.getURI()); propertyValue = pref + ":" + qname.getLocalName(); } @@ -1151,18 +1198,16 @@ } else { - writeXMLElement( - writer, - propertyName, - dataObject->getCString(pl[i])); + writeXMLElement(writer, + propertyName, + dataObject->getCString(pl[i])); -/* - xmlTextWriterWriteElement( - writer, - propertyName, - SDOXMLString(dataObject->getCString(pl[i]))); -*/ + /* + xmlTextWriterWriteElement(writer, + propertyName, + SDOXMLString(dataObject->getCString(pl[i]))); + */ } } } @@ -1170,11 +1215,12 @@ } } } + rc = xmlTextWriterEndElement(writer); return rc; - //namespaces = namespaceStack.top(); - //namespaceStack.pop(); + //namespaces = namespaceStack.top(); + //namespaceStack.pop(); //if (!uri.isNull()) //{ // namespaceUriStack.pop(); @@ -1242,73 +1288,73 @@ } } - /** - * A wrapper for the libxml2 function xmlTextWriterWriteElement - * it detects CDATA sections before wrting out element contents - */ - int SDOXMLWriter::writeXMLElement( - xmlTextWriterPtr writer, - const xmlChar *name, - const char *content) - { - int rc = 0; - rc = xmlTextWriterStartElement(writer, name); - rc = xmlTextWriterWriteRaw(writer, SDOXMLString(content)); - rc = xmlTextWriterEndElement(writer); -/* A more complex version that doesn't work! - SDOString contentString(content); - - // write the start of the element. we could write a mixture of - // text and CDATA before writing the end element - rc = xmlTextWriterStartElement(writer, name); - - // Iterate along the string writing out text and CDATA sections - // separately using the appropriate libxml2 calls - std::string::size_type start = 0; - std::string::size_type end = contentString.find(PropertySetting::XMLCDataStartMarker, 0); - std::string::size_type length = 0; - - // loop while we still find a CDATA section that needs writing - while ( end != std::string::npos ) - { - // write out text from current pos to start of CDATA section - length = end - start; - rc = xmlTextWriterWriteString(writer, - SDOXMLString(contentString.substr(start, length).c_str())); - - // find the end of the CDATA section - start = end; - end = contentString.find(PropertySetting::XMLCDataEndMarker, start); - - if ( end != std::string::npos ) - { - // we only nudge the start marker on to the end of the CDATA marker here - // so that if we fail to find the end CDATA marker the whole string gets - // printed out by virtue of the line that follows the while loop - start = start + strlen(PropertySetting::XMLCDataStartMarker); - - // write our the text from the CDATA section - length = end - start; - rc = xmlTextWriterWriteCDATA(writer, - SDOXMLString(contentString.substr(start, length).c_str())); - - // set current pos to end of CDATA section and - // start looking for the start marker again - start = end + strlen(PropertySetting::XMLCDataEndMarker); - end = contentString.find(PropertySetting::XMLCDataStartMarker, start); - } - } - - // write out text following the last CDATA section - rc = xmlTextWriterWriteString(writer, - SDOXMLString(contentString.substr(start).c_str())); - - // close off the element - rc = xmlTextWriterEndElement(writer); -*/ - return rc; - } + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before wrting out element contents + */ + int SDOXMLWriter::writeXMLElement(xmlTextWriterPtr writer, + const xmlChar *name, + const char *content) + { + int rc = 0; + rc = xmlTextWriterStartElement(writer, name); + rc = xmlTextWriterWriteRaw(writer, SDOXMLString(content)); + rc = xmlTextWriterEndElement(writer); + /* A more complex version that doesn't work! + SDOString contentString(content); + + // write the start of the element. we could write a mixture of + // text and CDATA before writing the end element + rc = xmlTextWriterStartElement(writer, name); + + // Iterate along the string writing out text and CDATA sections + // separately using the appropriate libxml2 calls + std::string::size_type start = 0; + std::string::size_type end = contentString.find(PropertySetting::XMLCDataStartMarker, 0); + std::string::size_type length = 0; + + // loop while we still find a CDATA section that needs writing + while ( end != std::string::npos ) + { + // write out text from current pos to start of CDATA section + length = end - start; + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // find the end of the CDATA section + start = end; + end = contentString.find(PropertySetting::XMLCDataEndMarker, start); + + if ( end != std::string::npos ) + { + // we only nudge the start marker on to the end of the CDATA marker here + // so that if we fail to find the end CDATA marker the whole string gets + // printed out by virtue of the line that follows the while loop + start = start + strlen(PropertySetting::XMLCDataStartMarker); + + // write our the text from the CDATA section + length = end - start; + rc = xmlTextWriterWriteCDATA(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // set current pos to end of CDATA section and + // start looking for the start marker again + start = end + strlen(PropertySetting::XMLCDataEndMarker); + end = contentString.find(PropertySetting::XMLCDataStartMarker, start); + } + } + + // write out text following the last CDATA section + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start).c_str())); + + // close off the element + rc = xmlTextWriterEndElement(writer); + */ + return rc; + } } // End - namespace sdo } // End - namespace commonj + http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.h?r1=1.5.4.1&r2=1.5.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.1 pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.2 --- pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.1 Thu Nov 9 13:29:51 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.h Wed Nov 22 11:13:04 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:51 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:04 $ */ #ifndef _SDOXMLWRITER_H_ #define _SDOXMLWRITER_H_ @@ -92,14 +92,13 @@ bool writeXSIType = false, bool isRoot = false); - /** - * A wrapper for the libxml2 function xmlTextWriterWriteElement - * it detects CDATA sections before wrting out element contents - */ - int writeXMLElement( - xmlTextWriterPtr writer, - const xmlChar *name, - const char *content); + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before wrting out element contents + */ + int writeXMLElement(xmlTextWriterPtr writer, + const xmlChar *name, + const char *content); SchemaInfo* schemaInfo; DataFactoryPtr dataFactory;
http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h diff -u pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.1 pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.2 --- pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h:1.4.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/ChangeSummaryBuilder.h Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 452786 $ $Date: 2006/11/22 11:13:03 $ */ #ifndef _CHANGESUMMARYBUILDER_H_ http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.cpp?r1=1.13.4.1&r2=1.13.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.cpp diff -u pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.1 pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.2 --- pecl/sdo/commonj/sdo/DataObjectImpl.cpp:1.13.4.1 Thu Nov 9 13:29:53 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452883 $ $Date: 2006/11/09 13:29:53 $ */ +/* $Rev: 477820 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/disable_warn.h" #include "commonj/sdo/DataObjectImpl.h" @@ -495,7 +495,7 @@ #define setPrimitiveFromProperty(primval,primtype)\ void DataObjectImpl::set ##primval (const Property& property, primtype value)\ {\ - set ##primval (getPropertyIndex(property),value);\ + set ##primval (getPropertyIndexInternal(property),value);\ } /** @def setCharsFromProperty @@ -506,7 +506,7 @@ #define setCharsFromProperty(primval,primtype)\ void DataObjectImpl::set ##primval (const Property& property, primtype value, unsigned int len)\ {\ - set ##primval (getPropertyIndex(property),value, len);\ + set ##primval (getPropertyIndexInternal(property),value, len);\ } @@ -1283,7 +1283,7 @@ void DataObjectImpl::setCString(const Property& property, const SDOString& value) { - setCString(getPropertyIndex(property), value); + setCString(getPropertyIndexInternal(property), value); } // null support @@ -1378,7 +1378,7 @@ } void DataObjectImpl::setNull(const Property& property) { - setNull(getPropertyIndex(property)); + setNull(getPropertyIndexInternal(property)); } void DataObjectImpl::setNull(const char* path) @@ -1608,6 +1608,46 @@ msg.c_str()); } + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + unsigned int DataObjectImpl::getPropertyIndexInternal(const Property& p) + { + unsigned int index; + + try + { + index = getPropertyIndex(p); + } + catch ( SDOPropertyNotFoundException e ) + { + // this could mean that this data object has an open + // type. getPropertyIndex fails in this case because it + // tries to access the index of the property + // and it doesn't exist because it hasn't been created yet. + // This new method is used where properties are being set + // based on existing property objects. This is like to + // occur when a data object is being copied. In this case + // we want properties that are open to be copied also + // so we need to create the property and provide the index + if ( this->getType().isOpenType() ) + { + const Property *prop = defineProperty(p.getName(), p.getType()); + index = getPropertyIndex(p); + } + else + { + throw e; + } + } + + return index; + } + + const Property& DataObjectImpl::getProperty(unsigned int index) { PropertyImpl* pi = getPropertyImpl(index); @@ -2451,7 +2491,7 @@ void DataObjectImpl::setDataObject(const Property& prop, DataObjectPtr value) { - unsigned int propertyIndex = getPropertyIndex(prop); + unsigned int propertyIndex = getPropertyIndexInternal(prop); if (value != 0) http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/DataObjectImpl.h?r1=1.11.4.1&r2=1.11.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/DataObjectImpl.h diff -u pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.1 pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.2 --- pecl/sdo/commonj/sdo/DataObjectImpl.h:1.11.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/DataObjectImpl.h Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477820 $ $Date: 2006/11/22 11:13:03 $ */ #ifndef _DATAOBJECTIMPL_H_ #define _DATAOBJECTIMPL_H_ @@ -597,6 +597,13 @@ virtual std::ostream& printSelf(std::ostream &os); private: + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + virtual unsigned int getPropertyIndexInternal(const Property& p); virtual void validateIndex(unsigned int index); virtual void checkFactory(DataObjectPtr dob, unsigned int propertyIndex); http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDORuntimeException.cpp?r1=1.6.4.1&r2=1.6.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDORuntimeException.cpp diff -u pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.1 pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.2 --- pecl/sdo/commonj/sdo/SDORuntimeException.cpp:1.6.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDORuntimeException.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 473864 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDORuntimeException.h" @@ -37,6 +37,10 @@ message_text = new char[strlen(msg_text)+1]; strcpy(message_text,msg_text); + locations[0].file = 0; + locations[0].line = 0; + locations[0].function = 0; + } // end SDORuntimeException constuctor // ======================================================================== @@ -51,13 +55,22 @@ strcpy(class_name, c.getEClassName()); message_text = new char[strlen(c.getMessageText())+1]; strcpy(message_text,c.getMessageText()); - for (int i=0;i<c.location_set;i++) + if (c.location_set) + { + for (int i=0;i<c.location_set;i++) + { + locations[i].file = new char[strlen(c.locations[i].file) + 1]; + strcpy(locations[i].file,c.locations[i].file); + locations[i].line = c.locations[i].line; + locations[i].function = new char[strlen(c.locations[i].function) + 1]; + strcpy(locations[i].function, c.locations[i].function); + } + } + else { - locations[i].file = new char[strlen(c.locations[i].file) + 1]; - strcpy(locations[i].file,c.locations[i].file); - locations[i].line = c.locations[i].line; - locations[i].function = new char[strlen(c.locations[i].function) + 1]; - strcpy(locations[i].function, c.locations[i].function); + locations[0].file = 0; + locations[0].line = 0; + locations[0].function = 0; } } http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp?r1=1.7.4.1&r2=1.7.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.1 pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.2 --- pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp:1.7.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOSAX2Parser.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDOSAX2Parser.h" @@ -632,6 +632,10 @@ documentNamespaces = namespaces; setNamespaces = false; } + else + { + documentNamespaces.merge(namespaces); + } if (ignoreEvents) { @@ -1175,15 +1179,13 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString("value", currentPropertySetting.value); - seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { DataObjectList& dl = currentPropertySetting.dataObject-> getList((const char*)"value"); -// dl.append((const char*)currentPropertySetting.value); - dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); } } @@ -1193,8 +1195,7 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString("value", currentPropertySetting.value); - seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { @@ -1231,8 +1232,7 @@ if (currentPropertySetting.dataObject->getType().isSequencedType()) { SequencePtr seq = currentPropertySetting.dataObject->getSequence(); -// seq->addCString(currentPropertySetting.name, currentPropertySetting.value); - seq->addCString(currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str()); + seq->addCString(currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str()); } // Always set the property as a String. SDO will do the conversion @@ -1245,8 +1245,7 @@ { DataObjectList& dl = currentPropertySetting.dataObject-> getList((const char*)currentPropertySetting.name); -// dl.append((const char*)currentPropertySetting.value); - dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); } else { http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp?r1=1.11.4.1&r2=1.11.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp diff -u pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.1 pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.2 --- pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp:1.11.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOSchemaSAX2Parser.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477840 $ $Date: 2006/11/22 11:13:03 $ */ #include "libxml/uri.h" #include "commonj/sdo/SDOSchemaSAX2Parser.h" @@ -540,59 +540,29 @@ SDOSchemaSAX2Parser& schemaParser, SDOXMLString& schemaLocation) { - int i,j,k; - SDOXMLString sl = getCurrentFile(); - - i = sl.lastIndexOf('/'); - j = sl.lastIndexOf('\\'); - if ((j > i) || (i < 0))i=j; - if (i>=0) - { - sl = sl.substring(0,i+1) + schemaLocation; - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - k = schemaLocation.lastIndexOf('/'); - j = schemaLocation.lastIndexOf('\\'); - if ((j > k) || (k < 0))k=j; - if (k>=0) - { - sl = sl.substring(0,i+1) + schemaLocation.substring(0,k+1); - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - } - } - try { - if (-1 != schemaParser.parse((const char *)schemaLocation)) - return 1; - } - catch (SDORuntimeException e) - { - } - k = schemaLocation.lastIndexOf('/'); - j = schemaLocation.lastIndexOf('\\'); - if ((j > k) || (k < 0))k=j; - if (k>=0) - { - sl = schemaLocation.substring(0,k+1); - try { - if (-1 != schemaParser.parse((const char *)sl)) - return 1; - } - catch (SDORuntimeException e) - { - } - } - return 0; + int i,j; + xmlChar *absoluteUri; + + SDOXMLString sl = getCurrentFile(); + + /* + * Build an absolute URL using the current file as the base and + * the schemaLocation as the relative part, using the rules in + * RFC 2396 5.2. Resolving Relative References to Absolute Form + */ + try { + absoluteUri = xmlBuildURI((const xmlChar *)schemaLocation, (const xmlChar *)sl); + if (-1 != schemaParser.parse((const char *)absoluteUri)) { + xmlFree(absoluteUri); + return 1; + } + } + catch (SDORuntimeException e) + { + } + if (absoluteUri) xmlFree(absoluteUri); + + return 0; } http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.cpp?r1=1.8.4.1&r2=1.8.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.cpp diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.1 pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.2 --- pecl/sdo/commonj/sdo/SDOXMLWriter.cpp:1.8.4.1 Thu Nov 9 13:29:52 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.cpp Wed Nov 22 11:13:03 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:52 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:03 $ */ #include "commonj/sdo/SDOXMLWriter.h" #include "commonj/sdo/SDOXMLString.h" @@ -573,14 +573,17 @@ { std::map<SDOXMLString,SDOXMLString>::iterator it; SDOXMLString uri = dob->getType().getURI(); - - it = namespaceMap.find(uri); - if (it == namespaceMap.end()) + SDOXMLString typeName = dob->getType().getName(); + if (!(uri.equals("commonj.sdo") && typeName.equals("OpenDataObject"))) { - char buf[20]; - sprintf(buf,"%d",++spacescount); - SDOXMLString s = SDOXMLString("tns") + buf; - namespaceMap.insert(make_pair(uri,s)); + it = namespaceMap.find(uri); + if (it == namespaceMap.end()) + { + char buf[20]; + sprintf(buf,"%d",++spacescount); + SDOXMLString s = SDOXMLString("tns") + buf; + namespaceMap.insert(make_pair(uri,s)); + } } PropertyList pl = dob->getInstanceProperties(); @@ -640,14 +643,18 @@ ////////////////////////////////////////////////////////////////////////// void SDOXMLWriter::writeXmlnsXsi() { + return; SDOXMLString xsins("http://www.w3.org/2001/XMLSchema-instance"); std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(xsins); if (it == namespaceMap.end()) { - SDOXMLString prefix("xmlns:xsi"); - xmlTextWriterWriteAttribute(writer, - prefix, xsins); + namespaceMap.insert(make_pair( + SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"), + SDOXMLString("xsi"))); +// SDOXMLString prefix("xmlns:xsi"); +// xmlTextWriterWriteAttribute(writer, +// prefix, xsins); } } @@ -668,7 +675,26 @@ if (dataObject == 0) return 0; - + // Don't write the element URI if the element is a child of an open type + // and not one of the declared properties + SDOXMLString uri = elementURI; + if (!isRoot && !writeXSIType) + { + DataObject* dob = dataObject; + DataObjectImpl* cont = + ((DataObjectImpl*)dob)->getContainerImpl(); + if (cont != 0) + { + if (cont->getType().isOpenType()) + { + if (cont->getTypeImpl().getPropertyImpl(elementName) == 0) + { + uri = ""; + } + } + } + } + //SDOXMLString uri; //if (!elementURI.equals(namespaceUriStack.top())) //{ @@ -686,7 +712,7 @@ if (dataObject->isNull("")) { rc = xmlTextWriterStartElementNS(writer, - NULL, elementName, elementURI); + NULL, elementName, uri); if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", @@ -700,18 +726,16 @@ rc = xmlTextWriterEndElement(writer); } else - { - writeXMLElement( - writer, - elementName, - dataObject->getCString("")); -/* - xmlTextWriterWriteElement( - writer, - elementName, - SDOXMLString(dataObject->getCString(""))); -*/ - } + { + writeXMLElement(writer, + elementName, + dataObject->getCString("")); + /* + xmlTextWriterWriteElement(writer, + elementName, + SDOXMLString(dataObject->getCString(""))); + */ + } // need to pop stacks before returning //if (!uri.isNull()) @@ -723,18 +747,18 @@ } - //namespaceStack.push(namespaces); + //namespaceStack.push(namespaces); if (isRoot) { - tnsURI=elementURI; - if (elementURI.equals("")) { + tnsURI=uri; + if (uri.equals("")) { rc = xmlTextWriterStartElementNS(writer, NULL, elementName, NULL); } else { - rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI); + rc = xmlTextWriterStartElementNS(writer, NULL, elementName, uri); } if (rc < 0) { SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); @@ -746,9 +770,9 @@ SDOXMLString theName=elementName; - if (!elementURI.isNull() && !elementURI.equals(tnsURI) && !elementURI.equals("")) + if (!uri.isNull() && !uri.equals(tnsURI) && !uri.equals("")) { - std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri); if (it != namespaceMap.end()) { theName = (*it).second; @@ -787,12 +811,19 @@ if (isRoot) { - std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI); + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri); if (it == namespaceMap.end()) { SDOXMLString s = SDOXMLString("tns"); namespaceMap.insert(make_pair(elementURI,s)); } + it = namespaceMap.find(SDOXMLString("http://www.w3.org/2001/XMLSchema-instance")); + if (it == namespaceMap.end()) + { + namespaceMap.insert(make_pair( + SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"), + SDOXMLString("xsi"))); + } DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dataObject; spacescount = 1; addToNamespaces(d); @@ -844,7 +875,7 @@ ////////////////////////////////////////////////////////////////////////// - // write out the type if the xsi:type if the containing type is open + // write out the type if the xsi:type of the containing type is open // and the property is not one of the declared properties ////////////////////////////////////////////////////////////////////////// if (!writeXSIType) @@ -870,9 +901,25 @@ //{ if (cont->getTypeImpl().getPropertyImpl(elementName) == 0) { + const SDOXMLString& typeURI = dataObject->getType().getURI(); + const SDOXMLString& typeName = dataObject->getType().getName(); + + SDOXMLString theName=typeName; + + if (!typeURI.isNull() && !typeURI.equals(tnsURI) && !typeURI.equals("")) + { + std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(typeURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += typeName; + } + } + rc = xmlTextWriterWriteAttribute(writer, (const unsigned char*)"xsi:type", - (const unsigned char*)dataObject->getType().getName()); + (const unsigned char*)theName); writeXmlnsXsi(); } @@ -945,13 +992,13 @@ // prefix = namespaces.findPrefix(qname.getURI()); //} - //if (prefix != 0 && !(*prefix).equals("")) + //if (prefix != 0 && !(*prefix).equals("")) std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(qname.getURI()); if (it != namespaceMap.end()) { - propertyValue = (*it).second + ":" + qname.getLocalName(); - } + propertyValue = (*it).second + ":" + qname.getLocalName(); + } else { char buffer[20]; @@ -959,7 +1006,7 @@ sprintf(buffer, "%d", j++); pref += buffer; rc = xmlTextWriterWriteAttributeNS(writer, - SDOXMLString("xmlns"), pref, NULL, qname.getURI()); + SDOXMLString("xmlns"), pref, NULL, qname.getURI()); propertyValue = pref + ":" + qname.getLocalName(); } @@ -1151,18 +1198,16 @@ } else { - writeXMLElement( - writer, - propertyName, - dataObject->getCString(pl[i])); + writeXMLElement(writer, + propertyName, + dataObject->getCString(pl[i])); -/* - xmlTextWriterWriteElement( - writer, - propertyName, - SDOXMLString(dataObject->getCString(pl[i]))); -*/ + /* + xmlTextWriterWriteElement(writer, + propertyName, + SDOXMLString(dataObject->getCString(pl[i]))); + */ } } } @@ -1170,11 +1215,12 @@ } } } + rc = xmlTextWriterEndElement(writer); return rc; - //namespaces = namespaceStack.top(); - //namespaceStack.pop(); + //namespaces = namespaceStack.top(); + //namespaceStack.pop(); //if (!uri.isNull()) //{ // namespaceUriStack.pop(); @@ -1242,73 +1288,73 @@ } } - /** - * A wrapper for the libxml2 function xmlTextWriterWriteElement - * it detects CDATA sections before wrting out element contents - */ - int SDOXMLWriter::writeXMLElement( - xmlTextWriterPtr writer, - const xmlChar *name, - const char *content) - { - int rc = 0; - rc = xmlTextWriterStartElement(writer, name); - rc = xmlTextWriterWriteRaw(writer, SDOXMLString(content)); - rc = xmlTextWriterEndElement(writer); -/* A more complex version that doesn't work! - SDOString contentString(content); - - // write the start of the element. we could write a mixture of - // text and CDATA before writing the end element - rc = xmlTextWriterStartElement(writer, name); - - // Iterate along the string writing out text and CDATA sections - // separately using the appropriate libxml2 calls - std::string::size_type start = 0; - std::string::size_type end = contentString.find(PropertySetting::XMLCDataStartMarker, 0); - std::string::size_type length = 0; - - // loop while we still find a CDATA section that needs writing - while ( end != std::string::npos ) - { - // write out text from current pos to start of CDATA section - length = end - start; - rc = xmlTextWriterWriteString(writer, - SDOXMLString(contentString.substr(start, length).c_str())); - - // find the end of the CDATA section - start = end; - end = contentString.find(PropertySetting::XMLCDataEndMarker, start); - - if ( end != std::string::npos ) - { - // we only nudge the start marker on to the end of the CDATA marker here - // so that if we fail to find the end CDATA marker the whole string gets - // printed out by virtue of the line that follows the while loop - start = start + strlen(PropertySetting::XMLCDataStartMarker); - - // write our the text from the CDATA section - length = end - start; - rc = xmlTextWriterWriteCDATA(writer, - SDOXMLString(contentString.substr(start, length).c_str())); - - // set current pos to end of CDATA section and - // start looking for the start marker again - start = end + strlen(PropertySetting::XMLCDataEndMarker); - end = contentString.find(PropertySetting::XMLCDataStartMarker, start); - } - } - - // write out text following the last CDATA section - rc = xmlTextWriterWriteString(writer, - SDOXMLString(contentString.substr(start).c_str())); - - // close off the element - rc = xmlTextWriterEndElement(writer); -*/ - return rc; - } + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before wrting out element contents + */ + int SDOXMLWriter::writeXMLElement(xmlTextWriterPtr writer, + const xmlChar *name, + const char *content) + { + int rc = 0; + rc = xmlTextWriterStartElement(writer, name); + rc = xmlTextWriterWriteRaw(writer, SDOXMLString(content)); + rc = xmlTextWriterEndElement(writer); + /* A more complex version that doesn't work! + SDOString contentString(content); + + // write the start of the element. we could write a mixture of + // text and CDATA before writing the end element + rc = xmlTextWriterStartElement(writer, name); + + // Iterate along the string writing out text and CDATA sections + // separately using the appropriate libxml2 calls + std::string::size_type start = 0; + std::string::size_type end = contentString.find(PropertySetting::XMLCDataStartMarker, 0); + std::string::size_type length = 0; + + // loop while we still find a CDATA section that needs writing + while ( end != std::string::npos ) + { + // write out text from current pos to start of CDATA section + length = end - start; + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // find the end of the CDATA section + start = end; + end = contentString.find(PropertySetting::XMLCDataEndMarker, start); + + if ( end != std::string::npos ) + { + // we only nudge the start marker on to the end of the CDATA marker here + // so that if we fail to find the end CDATA marker the whole string gets + // printed out by virtue of the line that follows the while loop + start = start + strlen(PropertySetting::XMLCDataStartMarker); + + // write our the text from the CDATA section + length = end - start; + rc = xmlTextWriterWriteCDATA(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // set current pos to end of CDATA section and + // start looking for the start marker again + start = end + strlen(PropertySetting::XMLCDataEndMarker); + end = contentString.find(PropertySetting::XMLCDataStartMarker, start); + } + } + + // write out text following the last CDATA section + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start).c_str())); + + // close off the element + rc = xmlTextWriterEndElement(writer); + */ + return rc; + } } // End - namespace sdo } // End - namespace commonj + http://cvs.php.net/viewvc.cgi/pecl/sdo/commonj/sdo/SDOXMLWriter.h?r1=1.5.4.1&r2=1.5.4.2&diff_format=u Index: pecl/sdo/commonj/sdo/SDOXMLWriter.h diff -u pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.1 pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.2 --- pecl/sdo/commonj/sdo/SDOXMLWriter.h:1.5.4.1 Thu Nov 9 13:29:51 2006 +++ pecl/sdo/commonj/sdo/SDOXMLWriter.h Wed Nov 22 11:13:04 2006 @@ -17,7 +17,7 @@ * under the License. */ -/* $Rev: 452786 $ $Date: 2006/11/09 13:29:51 $ */ +/* $Rev: 477891 $ $Date: 2006/11/22 11:13:04 $ */ #ifndef _SDOXMLWRITER_H_ #define _SDOXMLWRITER_H_ @@ -92,14 +92,13 @@ bool writeXSIType = false, bool isRoot = false); - /** - * A wrapper for the libxml2 function xmlTextWriterWriteElement - * it detects CDATA sections before wrting out element contents - */ - int writeXMLElement( - xmlTextWriterPtr writer, - const xmlChar *name, - const char *content); + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before wrting out element contents + */ + int writeXMLElement(xmlTextWriterPtr writer, + const xmlChar *name, + const char *content); SchemaInfo* schemaInfo; DataFactoryPtr dataFactory;