You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ro...@apache.org on 2007/06/14 19:15:30 UTC
svn commit: r547318 - in /incubator/tuscany/cpp/sdo/runtime/core:
src/commonj/sdo/ test/
Author: robbinspg
Date: Thu Jun 14 10:15:28 2007
New Revision: 547318
URL: http://svn.apache.org/viewvc?view=rev&rev=547318
Log:
Improve support for loading XML without schema
If the root element is not defined by a schema then an OpenDataObject is created.
elements will be added as Properties of Type OpenDataObject and attributes as Properties of Type
commonj/sdo#string
Modified:
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.h
incubator/tuscany/cpp/sdo/runtime/core/test/doctest.xml
incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp
incubator/tuscany/cpp/sdo/runtime/core/test/pete.xml
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp
incubator/tuscany/cpp/sdo/runtime/core/test/testerrors.txt
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp Thu Jun 14 10:15:28 2007
@@ -75,10 +75,6 @@
// abstract
addType(Type::SDOTypeNamespaceURI,"ChangeSummary");
- rootElementName.erase();
-
-
-
}
// ===================================================================
@@ -97,24 +93,6 @@
delete typeIter->second;
}
}
-
- rootElementName.erase();
-
-}
-
-// ===================================================================
-// get the root element name
-// ===================================================================
-// const char* DataFactoryImpl::getRootElementName() const
-const SDOString& DataFactoryImpl::getRootElementName() const
-{
- return rootElementName;
-}
-
-
-void DataFactoryImpl::setRootElementName(const SDOString& ren)
-{
- rootElementName = ren;
}
// ===================================================================
@@ -123,7 +101,6 @@
DataFactoryImpl::DataFactoryImpl(const DataFactoryImpl& inmdg)
{
isResolved = false;
- setRootElementName(inmdg.getRootElementName());
copyTypes(inmdg);
}
@@ -135,7 +112,6 @@
if (this != &inmdg)
{
copyTypes(inmdg);
- setRootElementName(inmdg.getRootElementName());
}
return *this;
}
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h Thu Jun 14 10:15:28 2007
@@ -661,8 +661,6 @@
void removeOpenProperty(const SDOString& name);
const propertyMap& getOpenProperties();
virtual const TypeImpl& getTypeImpl(const SDOString& uri, const SDOString& inTypeName) const;
- virtual const SDOString& getRootElementName() const;
- virtual void setRootElementName(const SDOString& ren);
virtual bool generateInterface(const char* fileroot, const char* factoryname);
virtual bool generateInterface(const SDOString& fileroot, const SDOString& factoryname);
@@ -675,8 +673,6 @@
TYPES_MAP resolvePending; // Set of types that have not yet been resolved.
std::vector<DataFactory*> compatibleFactories;
-
- SDOString rootElementName;
propertyMap openProperties;
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp Thu Jun 14 10:15:28 2007
@@ -56,7 +56,9 @@
ignoreEvents(false),
dealingWithChangeSummary(false),
csbuilder(0),
- SAX2Parser(insetter)
+ SAX2Parser(insetter),
+ rootElementName(""),
+ rootElementURI("")
{
@@ -82,9 +84,20 @@
changeSummary = false;
IDMap.empty();
IDRefs.empty();
+ rootElementURI = "";
+ rootElementName = "";
}
-
+ void SDOSAX2Parser::setRootElementName(const SDOXMLString& name)
+ {
+ rootElementName = name;
+ }
+
+ void SDOSAX2Parser::setRootElementURI(const SDOXMLString& uri)
+ {
+ rootElementURI = uri;
+ }
+
void SDOSAX2Parser::startDocument()
{
LOGINFO(INFO,"SDOSAX2Parser: startDocument");
@@ -815,19 +828,31 @@
if (!targetNamespaceURI.isNull() && !targetNamespaceURI.equals(""))
{
tns = targetNamespaceURI;
+ rootElementURI = tns;
+ }
+ else
+ {
+ rootElementURI = URI;
}
// Check for localname as a property of the RootType
// if we do not already know the type
if (typeName.isNull())
{
- const Type& rootType = dataFactory->getType(tns, "RootType");
- propertyName = getSDOName(rootType, localname);
- const Type& newType =
- ((TypeImpl&)(rootType)).getRealPropertyType(propertyName);
+ try {
+ const Type& rootType = dataFactory->getType(tns, "RootType");
+ propertyName = getSDOName(rootType, localname);
+ const Type& newType =
+ ((TypeImpl&)(rootType)).getRealPropertyType(propertyName);
- typeURI = newType.getURI();
- typeName = newType.getName();
+ typeURI = newType.getURI();
+ typeName = newType.getName();
+ }
+ catch (const SDOTypeNotFoundException&)
+ {
+ typeURI = Type::SDOTypeNamespaceURI.c_str();
+ typeName = "OpenDataObject";
+ }
}
// Create the root DataObject
@@ -840,7 +865,7 @@
else
{
DataFactory* df = dataFactory;
- ((DataFactoryImpl*)df)->setRootElementName((const char*)localname);
+ rootElementName = localname;
}
// NOTE: always creating DO doesn't cater for DataType as top element
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h Thu Jun 14 10:15:28 2007
@@ -106,9 +106,16 @@
friend std::istream& operator>>(std::istream& input, SDOSAX2Parser& parser);
friend std::istringstream& operator>>(std::istringstream& input, SDOSAX2Parser& parser);
+ void setRootElementName(const SDOXMLString& name);
+ const SDOXMLString& getRootElementName() const {return rootElementName;}
+ void setRootElementURI(const SDOXMLString& uri);
+ const SDOXMLString& getRootElementURI() const {return rootElementURI;}
+
private:
SDOXMLString targetNamespaceURI;
+ SDOXMLString rootElementName;
+ SDOXMLString rootElementURI;
DataFactoryPtr dataFactory;
DataObjectPtr& rootDataObject;
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp Thu Jun 14 10:15:28 2007
@@ -67,60 +67,7 @@
return dataFactory;
}
- XMLDocumentPtr XMLHelperImpl::createDocument(DataObjectPtr dataObject)
- {
-
- SDOXMLString rootElementName = "";
- SDOXMLString rootElementURI = "";
- if (dataObject)
- {
- // Set the root element name to the name of the containment property
- // or null if there is no container
- try
- {
- DataObjectPtr cont = dataObject->getContainer();
- if (cont != 0)
- {
- const Property& containmentProp = dataObject->getContainmentProperty();
- rootElementName = containmentProp.getName();
- rootElementURI = cont->getType().getURI();
- }
- else
- {
- DataFactory* df = dataFactory;
- rootElementURI = dataObject->getType().getURI();
- rootElementName = ((DataFactoryImpl*)df)->getRootElementName().c_str();
- }
- }
- catch (SDOPropertyNotFoundException&)
- {}
- }
-
- return new XMLDocumentImpl(dataObject, rootElementURI, rootElementName);
- }
-
-// const TypeImpl* XMLHelperImpl::findRoot(DataFactory* df,
-// const char* rootElementURI)
-// {
-// if (rootElementURI != 0)
-// {
-// return ((DataFactoryImpl*)df)->findTypeImpl
-// (rootElementURI, "RootType");
-// }
-
-// const TypeList& tl = df->getTypes();
-// for (int i=0;i<tl.size();i++)
-// {
-// if (!strcmp("RootType",tl[i].getName()))
-// {
-// return ((DataFactoryImpl*)df)->findTypeImpl(tl[i].getURI(), "RootType");
-// }
-// }
-
-// return 0;
-
-// }
const TypeImpl* XMLHelperImpl::findRoot(DataFactory* df,
const SDOString& rootElementURI)
{
@@ -171,56 +118,6 @@
}
}
-// XMLDocumentPtr XMLHelperImpl::createDocument(const char* elementname,
-// const char* rootElementURI)
-// {
-// DataFactory* dp = (DataFactory*)getDataFactory();
-// if (dp == 0) return 0;
-
-// const TypeImpl* rType = findRoot(dp,rootElementURI);
-// if (rType == 0)
-// {
-// std::string msg("createDocument - cannot find element ");
-// if (elementname != 0) msg += elementname;
-// SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException,
-// msg.c_str());
-// }
-
-// if ((elementname != 0) && (strlen(elementname) != 0))
-// {
-// PropertyImpl* pl = rType->getPropertyImpl(elementname);
-// if (pl == 0)
-// {
-// std::string msg("createDocument - cannot find element ");
-// msg += elementname;
-// SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException,
-// msg.c_str());
-// }
-
-// const Type& tp = pl->getType();
-// DataObjectPtr dob = dp->create(tp);
-// return new XMLDocumentImpl(dob,
-// tp.getURI(), /*tp.getName()*/ elementname);
-// }
-// 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());
-// }
-
-// std::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());
-// }
-
- // +++
XMLDocumentPtr XMLHelperImpl::createDocument(const SDOString& elementname,
const SDOString& rootElementURI)
@@ -251,7 +148,7 @@
const Type& tp = pl->getType();
DataObjectPtr dob = dp->create(tp);
return new XMLDocumentImpl(dob,
- tp.getURI(), /*tp.getName()*/
+ tp.getURI(),
elementname.c_str());
}
else
@@ -260,7 +157,7 @@
const Type& tp = pl.getType();
DataObjectPtr dob = dp->create(tp);
return new XMLDocumentImpl(dob,
- tp.getURI(), /*tp.getName()*/ pl.getName());
+ tp.getURI(), pl.getName());
}
std::string msg("createDocument - unable to find root type in namespace ");
@@ -269,8 +166,6 @@
msg.c_str());
}
- // ---
-
XMLDocumentPtr XMLHelperImpl::createDocument(
DataObjectPtr dataObject,
const char* rootElementURI,
@@ -292,14 +187,17 @@
{
DataObjectPtr rootDataObject;
clearErrors();
- SDOSAX2Parser sdoParser(getDataFactory(), targetNamespaceURI, rootDataObject,
- this);
+ SDOSAX2Parser sdoParser(getDataFactory(),
+ targetNamespaceURI,
+ rootDataObject,
+ this);
if (sdoParser.parse(xmlFile) == 0)
{
- return createDocument(rootDataObject);
+ return createDocument(rootDataObject, (SDOString)sdoParser.getRootElementURI(), sdoParser.getRootElementName());
}
return 0;
}
+
XMLDocumentPtr XMLHelperImpl::loadFile(
const SDOString& xmlFile,
const SDOString& targetNamespaceURI)
@@ -312,7 +210,7 @@
this);
if (sdoParser.parse(xmlFile.c_str()) == 0)
{
- return createDocument(rootDataObject);
+ return createDocument(rootDataObject, (SDOString)sdoParser.getRootElementURI(), sdoParser.getRootElementName());
}
return 0;
}
@@ -323,12 +221,15 @@
const char* targetNamespaceURI)
{
DataObjectPtr rootDataObject;
- SDOSAX2Parser sdoParser(getDataFactory(), targetNamespaceURI, rootDataObject,
- this);
+ SDOSAX2Parser sdoParser(getDataFactory(),
+ targetNamespaceURI,
+ rootDataObject,
+ this);
clearErrors();
inXml>>sdoParser;
- return createDocument(rootDataObject);
- }
+ return createDocument(rootDataObject, (SDOString)sdoParser.getRootElementURI(), sdoParser.getRootElementName());
+ }
+
XMLDocumentPtr XMLHelperImpl::load(
std::istream& inXml,
const SDOString& targetNamespaceURI)
@@ -340,7 +241,7 @@
this);
clearErrors();
inXml>>sdoParser;
- return createDocument(rootDataObject);
+ return createDocument(rootDataObject, (SDOString)sdoParser.getRootElementURI(), sdoParser.getRootElementName());
}
XMLDocumentPtr XMLHelperImpl::load(
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.h?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XMLHelperImpl.h Thu Jun 14 10:15:28 2007
@@ -172,12 +172,8 @@
DataFactoryPtr dataFactory;
SDOXMLString targetNamespaceURI;
- XMLDocumentPtr createDocument(DataObjectPtr dataObject);
-
-// const TypeImpl* findRoot(DataFactory* df,
-// const char* rootElementURI);
- const TypeImpl* findRoot(DataFactory* df,
- const SDOString& rootElementURI);
+ const TypeImpl* findRoot(DataFactory* df,
+ const SDOString& rootElementURI);
DataFactoryPtr getDataFactory();
};
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/doctest.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/doctest.xml?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/doctest.xml (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/doctest.xml Thu Jun 14 10:15:28 2007
@@ -18,7 +18,7 @@
under the License.
-->
-<company targetNameSpace="hghgh" xmlns="companyNS" name="MegaCorp" employeeOfTheMonth="#/departments.0/employees.1">
+<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" />
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp Thu Jun 14 10:15:28 2007
@@ -185,6 +185,8 @@
TEST ( sdotest::jira1174() );
TEST ( sdotest::jira1238() );
+ TEST ( sdotest::loadWithoutSchema() );
+
} catch(...)
{
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/pete.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/pete.xml?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/pete.xml (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/pete.xml Thu Jun 14 10:15:28 2007
@@ -19,7 +19,7 @@
-->
<StockQuotes>
-<Stock>
+<Stock fred="joe">
<Symbol>IBM</Symbol>
<Last>79.78</Last>
<Date>5/24/2006</Date>
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h Thu Jun 14 10:15:28 2007
@@ -209,4 +209,5 @@
static int eBayTest();
static int jira1174();
static int jira1238();
+ static int loadWithoutSchema();
};
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp Thu Jun 14 10:15:28 2007
@@ -1891,3 +1891,20 @@
return 0;
}
}
+
+int sdotest::loadWithoutSchema()
+{
+
+ try {
+ XMLHelperPtr xmh = HelperProvider::getXMLHelper();
+
+ XMLDocumentPtr doc = xmh->loadFile("stock.wsdl");
+
+ return 1;
+ }
+ catch (SDORuntimeException e)
+ {
+ cout << "Exception in loadWithoutSchema" << e << endl;
+ return 0;
+ }
+}
\ No newline at end of file
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/testerrors.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/testerrors.txt?view=diff&rev=547318&r1=547317&r2=547318
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/testerrors.txt (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/testerrors.txt Thu Jun 14 10:15:28 2007
@@ -3,5 +3,3 @@
Premature end of data in tag schema line 22
-XML reported some errors:
-Parser found unknown element company
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org