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 2006/12/06 11:23:32 UTC
svn commit: r483011 - in /incubator/tuscany/cpp/sdo/runtime/core:
src/commonj/sdo/ test/
Author: robbinspg
Date: Wed Dec 6 02:23:28 2006
New Revision: 483011
URL: http://svn.apache.org/viewvc?view=rev&rev=483011
Log:
TUSCANY-950 Copy non-containment references
Modified:
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.cpp?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.cpp Wed Dec 6 02:23:28 2006
@@ -29,6 +29,8 @@
#include "commonj/sdo/CopyHelper.h"
+#include <iostream>
+using namespace std;
namespace commonj{
namespace sdo{
@@ -262,7 +264,9 @@
*/
DataObjectPtr CopyHelper::copy(DataObjectPtr dataObject)
{
- return internalCopy(dataObject, true);
+ DataObjectPtr newob = internalCopy(dataObject, true);
+ resolveReferences(dataObject, newob);
+ return newob;
}
DataObjectPtr CopyHelper::internalCopy(DataObjectPtr dataObject,
@@ -325,15 +329,10 @@
if (seqProperty.isReference())
{
// add just the reference into the sequence
- // doesn't seem to bother in the non sequenced
- // code so need to check with SDO people
- // In the mean time I'll thrown and exception
- // just in case we get here
- std::string msg("Attempt to close sequenced data object which has non containment reference ");
- msg += (const char *)seqPropertyName;
- SDO_THROW_EXCEPTION("internalCopy",
- SDOUnsupportedOperationException,
- msg.c_str());
+ // This will be resolved to a new reference later
+ // This is really bad but we need to add something to the
+ // sequence here to maintain the ordering
+ toSequence->addDataObject(seqProperty, 0);
}
else
{
@@ -378,15 +377,31 @@
{
DataObjectList& dolold = dataObject->getList(pl[i]);
DataObjectList& dolnew = newob->getList(pl[i]);
- for (unsigned int i=0;i< dolold.size(); i++)
- {
- dolnew.append(internalCopy(dolold[i],true));
+ for (unsigned int li=0;li< dolold.size(); li++)
+ {
+ // references are maintained to the old object if it
+ // is outside of the copy tree
+ if (pl[i].isReference())
+ {
+ // have to resolve references in a 2nd pass
+ }
+ else
+ {
+ dolnew.append(internalCopy(dolold[li],true));
+ }
}
}
else
{
DataObjectPtr dob = dataObject->getDataObject(pl[i]);
- newob->setDataObject(pl[i],internalCopy(dob,true));
+ if (pl[i].isReference())
+ {
+ // have to resolve references in a 2nd pass
+ }
+ else
+ {
+ newob->setDataObject(pl[i],internalCopy(dob,true));
+ }
}
}
}
@@ -409,6 +424,131 @@
return newob;
}
+
+ void CopyHelper::resolveReferences(DataObjectPtr oldDO, DataObjectPtr newDO)
+ {
+ // Iterate through the properties to find references.
+ // If the reference is to a DataObject with the copied tree then we can
+ // set it to reference the DO in the new tree, otherwise it is left unset.
+
+ findReferences(oldDO, newDO, oldDO, newDO);
+
+ }
+
+ void CopyHelper::findReferences(DataObjectPtr oldDO, DataObjectPtr newDO,
+ DataObjectPtr obj, DataObjectPtr newObj)
+ {
+ if ( obj->getType().isSequencedType() )
+ {
+ Sequence* fromSequence = obj->getSequence();
+ int sequence_length = fromSequence->size();
+
+ Sequence* toSequence = newObj->getSequence();
+
+ for (int i=0;i < sequence_length; i++)
+ {
+ if (!fromSequence->isText(i) )
+ {
+ const Property& seqProperty = fromSequence->getProperty(i);
+ SDOXMLString seqPropertyName = seqProperty.getName();
+ const Type& seqPropertyType = seqProperty.getType();
+
+ if (seqProperty.isReference())
+ {
+ DataObjectPtr ref = findReference(oldDO, newDO, fromSequence->getDataObjectValue(i));
+ if (ref)
+ {
+ if (seqProperty.isMany())
+ {
+ int index = fromSequence->getListIndex(i);
+ newObj->getList(seqProperty).setDataObject(index, ref);
+ }
+ else
+ {
+ toSequence->setDataObjectValue(i, ref);
+ }
+
+ }
+ }
+ else if (seqPropertyType.isDataObjectType())
+ {
+ findReferences(oldDO, newDO, fromSequence->getDataObjectValue(i), toSequence->getDataObjectValue(i));
+ }
+ }
+
+ } // for all elements in sequence
+
+ }
+ else
+ {
+ PropertyList pl = obj->getInstanceProperties();
+ for (unsigned int i=0;i < pl.size(); i++)
+ {
+ if (!obj->isSet(pl[i]))
+ continue;
+
+ if (!pl[i].getType().isDataObjectType())
+ continue;
+
+ if (pl[i].isMany())
+ {
+ DataObjectList& dolold = obj->getList(pl[i]);
+ DataObjectList& dolnew = newObj->getList(pl[i]);
+ for (unsigned int li=0;li< dolold.size(); li++)
+ {
+ if (pl[i].isReference())
+ {
+ DataObjectPtr ref = findReference(oldDO, newDO, dolold[li]);
+ if (ref)
+ {
+ dolnew.setDataObject(li, ref);
+ }
+ }
+ else
+ {
+ findReferences(oldDO, newDO, dolold[li], dolnew[li]);
+ }
+ }
+ }
+ else
+ {
+ if (pl[i].isReference())
+ {
+ DataObjectPtr ref = findReference(oldDO, newDO, obj->getDataObject(pl[i]));
+ if (ref)
+ {
+ newObj->setDataObject(pl[i], ref);
+ }
+ }
+ else
+ {
+ findReferences(oldDO, newDO, obj->getDataObject(pl[i]), newObj->getDataObject(pl[i]));
+ }
+ }
+ }
+ }
+ }
+
+ DataObjectPtr CopyHelper::findReference(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr ref)
+ {
+ SDOString rootXPath = oldDO->objectToXPath();
+ SDOString refXPath = ref->objectToXPath();
+
+ DataObjectPtr newRef;
+ if (refXPath.find(refXPath) == 0)
+ {
+ SDOString relXPath = refXPath.substr(rootXPath.length());
+ if (relXPath == "")
+ newRef = newDO;
+ if (relXPath.find("/") == 0)
+ relXPath = relXPath.substr(1);
+ newRef = newDO->getDataObject(relXPath);
+ }
+
+ return newRef;
+ }
+
+
}
};
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.h?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/CopyHelper.h Wed Dec 6 02:23:28 2006
@@ -65,6 +65,9 @@
static void transfersequenceitem(Sequence *to, Sequence *from, const Property& p, int index);
static DataObjectPtr internalCopy(DataObjectPtr dataObject, bool fullCopy);
+ static void resolveReferences(DataObjectPtr oldDO, DataObjectPtr newDO);
+ static void findReferences(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr obj, DataObjectPtr newObj);
+ static DataObjectPtr findReference(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr ref);
};
};
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=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp Wed Dec 6 02:23:28 2006
@@ -98,7 +98,7 @@
}
}
- rootElementName.erase();
+ rootElementName.erase();
}
@@ -267,7 +267,7 @@
bool isData,
bool isFromList)
{
- addType(uri.c_str(), inTypeName.c_str(), isSeq, isOp, isAbs, isData, isFromList);
+ addType(uri.c_str(), inTypeName.c_str(), isSeq, isOp, isAbs, isData, isFromList);
}
// ===================================================================
@@ -724,7 +724,7 @@
const Type& DataFactoryImpl::getType(const SDOString& uri, const SDOString& inTypeName) const
{
- return getType(uri.c_str(), inTypeName.c_str());
+ return getType(uri.c_str(), inTypeName.c_str());
}
// ===================================================================
@@ -778,16 +778,16 @@
}
void DataFactoryImpl::setBaseType(const SDOString& typeuri,
- const SDOString& typenam,
- const SDOString& baseuri,
- const SDOString& basename,
- bool isRestriction)
-{
- setBaseType(typeuri.c_str(),
- typenam.c_str(),
- baseuri.c_str(),
- basename.c_str(),
- isRestriction);
+ const SDOString& typenam,
+ const SDOString& baseuri,
+ const SDOString& basename,
+ bool isRestriction)
+{
+ setBaseType(typeuri.c_str(),
+ typenam.c_str(),
+ baseuri.c_str(),
+ basename.c_str(),
+ isRestriction);
}
@@ -1302,7 +1302,7 @@
const SDOString& typenam,
const SDOString& alias)
{
- setAlias(typeuri.c_str(), typenam.c_str(), alias.c_str());
+ setAlias(typeuri.c_str(), typenam.c_str(), alias.c_str());
}
// ===================================================================
@@ -1325,7 +1325,7 @@
const SDOString& propname,
const SDOString& alias)
{
- setAlias(typeuri.c_str(), typenam.c_str(), propname.c_str(), alias.c_str());
+ setAlias(typeuri.c_str(), typenam.c_str(), propname.c_str(), alias.c_str());
}
// ===================================================================
@@ -1682,6 +1682,8 @@
{
if (pl[i].getType().isDataObjectType())
{
+ if (pl[i].isReference())
+ continue;
if (!checkType(pl[i].getType())) return false;
}
}
@@ -2176,7 +2178,7 @@
bool DataFactoryImpl::generateInterface(const SDOString& fileroot, const SDOString& factoryname)
{
- return generateInterface(fileroot.c_str(), factoryname.c_str());
+ return generateInterface(fileroot.c_str(), factoryname.c_str());
}
std::ostream& DataFactoryImpl::printSelf(std::ostream &os)
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp Wed Dec 6 02:23:28 2006
@@ -944,7 +944,7 @@
void DataObjectImpl::undefineProperty(unsigned int index)
{
- if (index < openBase) return;
+ if (index < openBase) return;
unsigned int point = index - openBase;
if (point >= openProperties.size()) return;
@@ -1592,32 +1592,32 @@
}
/**
- * 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
- */
+ * 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;
+ unsigned int index;
- try
- {
+ 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 likely 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() )
- {
+ }
+ 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 likely 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 = NULL;
// need to treat many valued properties specially
@@ -1629,19 +1629,19 @@
}
else
{
- prop = defineProperty(p.getName(), p.getType());
+ prop = defineProperty(p.getName(), p.getType());
}
index = getPropertyIndex(p);
- }
- else
- {
- throw e;
- }
- }
+ }
+ else
+ {
+ throw e;
+ }
+ }
- return index;
- }
+ return index;
+ }
const Property& DataObjectImpl::getProperty(unsigned int index)
@@ -2279,9 +2279,9 @@
DataObjectList& dol = d->getList((Property&)*p);
long idx;
DataObjectImpl* dx = d->findDataObject(prop,&idx);
- // fix this. This is the only place the 2nd parm to findDataObject
- // is used. Need a better way to do this
- unsigned int index = (unsigned int)idx;
+ // fix this. This is the only place the 2nd parm to findDataObject
+ // is used. Need a better way to do this
+ unsigned int index = (unsigned int)idx;
if (index >= 0)
{
if(index < dol.size())
@@ -2347,6 +2347,9 @@
{
isData = true;
}
+
+ if (pl[i].isReference())
+ continue;
if (!d->isSet(pl[i]) || d->isNull(pl[i]))
{
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp Wed Dec 6 02:23:28 2006
@@ -540,8 +540,27 @@
SDOSchemaSAX2Parser& schemaParser,
SDOXMLString& schemaLocation)
{
- int i,j,k;
+ 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(schemaLocation, sl);
+ if (-1 != schemaParser.parse((const char*)absoluteUri)) {
+ if (absoluteUri) xmlFree(absoluteUri);
+ return 1;
+ }
+ }
+ catch (SDORuntimeException e)
+ {
+ }
+
+ if (absoluteUri) xmlFree(absoluteUri);
+
+ int i,j,k;
i = sl.lastIndexOf('/');
j = sl.lastIndexOf('\\');
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp Wed Dec 6 02:23:28 2006
@@ -194,7 +194,15 @@
out << cc;
out << endl;
incr++;
- printDataObject(out, dol[j],incr);
+ if (pl[i].isReference())
+ {
+ printTabs(out, incr);
+ out << "Reference Value: " << dol[j]->objectToXPath() <<endl;
+ }
+ else
+ {
+ printDataObject(out, dol[j],incr);
+ }
incr--;
out << endl;
}
@@ -217,7 +225,15 @@
else
{
incr++;
- printDataObject(out, dataObject->getDataObject(pl[i]),incr);
+ if (pl[i].isReference())
+ {
+ printTabs(out, incr);
+ out << "Reference Value: " << dataObject->getDataObject(pl[i])->objectToXPath() <<endl;
+ }
+ else
+ {
+ printDataObject(out, dataObject->getDataObject(pl[i]),incr);
+ }
incr--;
}
}
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp?view=diff&rev=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp Wed Dec 6 02:23:28 2006
@@ -188,11 +188,13 @@
DataObjectPtr project = root->createDataObject("project");
project->setCString("id", "The TTP Project");
DataObjectPtr str = project->createDataObject("string");
+ str->setDataObject("proj", project);
str->setCString("value", "The Recursive Acronym Project");
DataObjectPtr wp1 = project->createDataObject("packages");
DataObjectPtr wp2 = project->createDataObject("packages");
wp1->setCString("name", "Work Package 1");
wp2->setCString("name", "Work Package 2");
+ project->setDataObject("wp", wp2);
DataObjectPtr li1 = wp1->createDataObject("lineitems");
DataObjectPtr li2 = wp1->createDataObject("lineitems");
DataObjectPtr li3 = wp2->createDataObject("lineitems");
@@ -211,7 +213,6 @@
str4->setCString("value", "String4");
if (!transferto(root, dfp_right, false)) return 0;
-
return 1;
}
catch (SDORuntimeException e)
@@ -9147,14 +9148,14 @@
unsigned int j = 0;
if ((i = myXSDHelper->getErrorCount()) > 0)
{
- cout << "XSD Loading reported some errors:" << endl;
- for (j=0;j<i;j++)
- {
- const char *m = myXSDHelper->getErrorMessage(j);
- if (m != 0) cout << m;
- cout << endl;
- return 0;
- }
+ cout << "XSD Loading reported some errors:" << endl;
+ for (j=0;j<i;j++)
+ {
+ const char *m = myXSDHelper->getErrorMessage(j);
+ if (m != 0) cout << m;
+ cout << endl;
+ return 0;
+ }
}
/**
@@ -9172,14 +9173,14 @@
*/
if ((i = myXMLHelper->getErrorCount()) > 0)
{
- cout << "XML Loading reported some errors:" << endl;
- for (j=0;j<i;j++)
- {
- const char *m = myXMLHelper->getErrorMessage(j);
- if (m != 0) cout << m;
- cout << endl;
- return 0;
- }
+ cout << "XML Loading reported some errors:" << endl;
+ for (j=0;j<i;j++)
+ {
+ const char *m = myXMLHelper->getErrorMessage(j);
+ if (m != 0) cout << m;
+ cout << endl;
+ return 0;
+ }
}
DataObjectPtr original = myXMLDocument->getRootDataObject();
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=483011&r1=483010&r2=483011
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp Wed Dec 6 02:23:28 2006
@@ -134,10 +134,15 @@
dfp->addType("Namespace", "Root");
dfp->addPropertyToType("Namespace","Root","project",
"Namespace","Project", false, false, true);
+ dfp->addPropertyToType("Namespace","Project","wp",
+ "Namespace","WorkPackage", false, false, false);
dfp->addPropertyToType("Namespace","StringHolder","value",
"commonj.sdo","String", false, false, false);
+ dfp->addPropertyToType("Namespace","StringHolder","proj",
+ "Namespace","Project", false, false, false);
+
dfp->addPropertyToType("Namespace","Project","id",
"commonj.sdo","String", false, false, false);
@@ -526,7 +531,7 @@
unsigned int i,j;
- int rc;
+ int rc;
try {
@@ -1497,7 +1502,7 @@
xsh->defineFile("tuscany963.xsd");
XMLHelperPtr myXMLHelper = HelperProvider::getXMLHelper(mdg);
XMLDocumentPtr myXMLDocument = myXMLHelper->loadFile("tuscany963.xml");
- myXMLHelper->save(myXMLDocument, "tuscany963.out.xml");
+ myXMLHelper->save(myXMLDocument, "tuscany963.out.xml");
return comparefiles("tuscany963.out.xml" ,"tuscany963.out.xml.txt");
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org