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/11/07 11:21:45 UTC

svn commit: r472054 - in /incubator/tuscany/cpp/sdo/runtime/core: src/commonj/sdo/DataFactoryImpl.cpp src/commonj/sdo/DataFactoryImpl.h test/main.cpp test/sdotest.cpp test/sdotest.h test/sdotest2.cpp

Author: robbinspg
Date: Tue Nov  7 02:21:44 2006
New Revision: 472054

URL: http://svn.apache.org/viewvc?view=rev&rev=472054
Log:
TUSCANY-546 Apply Geoff Winn's patch to releieve restriction on adding Types after a DO has been created.

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/test/main.cpp
    incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
    incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h
    incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp Tue Nov  7 02:21:44 2006
@@ -87,6 +87,8 @@
 DataFactoryImpl::~DataFactoryImpl()
 {
 
+   resolvePending.clear();
+   
     TYPES_MAP::iterator typeIter;
     for (typeIter = types.begin() ; typeIter != types.end() ; ++typeIter)
     {
@@ -144,11 +146,6 @@
 void DataFactoryImpl::copyTypes(const DataFactoryImpl& inmdg)
 {
 
-    if (isResolved)
-    {
-    SDO_THROW_EXCEPTION("copyTypes",
-        SDOUnsupportedOperationException, "Copying Type after data graph completed");
-    }
 
     TYPES_MAP::const_iterator typeIter;
     TYPES_MAP::iterator typeIter2;
@@ -245,12 +242,6 @@
 {
 
 
-    if (isResolved)
-    {
-    SDO_THROW_EXCEPTION("DataFactory::addType",
-        SDOUnsupportedOperationException, "Adding Type after data graph completed");
-    }
-
     if (inTypeName == 0 || strlen(inTypeName) == 0)
     {
     SDO_THROW_EXCEPTION("DataFactory::addType",
@@ -265,6 +256,7 @@
     {
         SDOString fullTypeName = getFullTypeName(uri, inTypeName);
         types[fullTypeName] = new TypeImpl(uri, inTypeName, isSeq, isOp, isAbs, isData, isFromList);
+        resolvePending[fullTypeName] = types[fullTypeName];
     }
 }
 
@@ -309,10 +301,11 @@
     // None of the containing types can have a cs already.
     // None of the properties of this type can hold a type
     // which has a change summary.
-    if (isResolved)
+
+   if (t->isResolved)
     {
-    SDO_THROW_EXCEPTION("DataFactory::addChangeSummary",
-        SDOUnsupportedOperationException, "Adding Change Summary after data graph completed");
+    SDO_THROW_EXCEPTION("DataFactory::checkForValidChangeSummary",
+        SDOUnsupportedOperationException, "Adding Change Summary after type completed");
     }
 
     if (cstypes.size() > 0) {
@@ -373,12 +366,6 @@
                                       bool    rdonly,
                                       bool cont)
 {
-    if (isResolved)
-    {
-    SDO_THROW_EXCEPTION("DataFactory::addPropertyToType",
-        SDOUnsupportedOperationException, "Adding Properties after data graph completed");
-    }
-
 
 
     TYPES_MAP::iterator typeIter, typeIter2;
@@ -469,6 +456,13 @@
         // cannot try to make a property containment on a data type
     }
 */
+
+    if ((typeIter->second)->isResolved)
+    {
+    SDO_THROW_EXCEPTION("DataFactory::addPropertyToType",
+        SDOUnsupportedOperationException, "Adding Properties after type completed");
+    }
+
     ((typeIter->second)->addProperty(propname, *(typeIter2->second),many,rdonly, cont));
     return;
 }
@@ -1365,17 +1359,17 @@
 
 void DataFactoryImpl::resolve()
 {
-    if (isResolved) return; 
 
     TYPES_MAP::iterator typeIter;
-    for (typeIter = types.begin() ; typeIter != types.end();
+    for (typeIter = resolvePending.begin() ; typeIter != resolvePending.end();
     ++typeIter) 
     {
         (typeIter->second)->initCompoundProperties();
         (typeIter->second)->validateChangeSummary();
     }
+    // Need to empty the resolvePending set.
+    resolvePending.clear();
 
-    isResolved = true;
 }
 
 // ===================================================================
@@ -1388,7 +1382,11 @@
 RefCountingPointer<DataObject> DataFactoryImpl::create(const char* uri, const char* typeName) 
 {
 
-    if (!isResolved)
+// New types can always be added now, so if there are any that haven't been
+// resolved, do them now. The isResolved boolean is superseded by the
+// resolvePending set being non-empty.
+
+   if (!resolvePending.empty())
     {
         // Allow creation of types and properties before resolve.
         if (uri != 0 && !strcmp(uri,Type::SDOTypeNamespaceURI.c_str())) {

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.h Tue Nov  7 02:21:44 2006
@@ -675,6 +675,7 @@
 private:
     typedef std::map<std::string, TypeImpl*> TYPES_MAP;
     TYPES_MAP    types;
+    TYPES_MAP    resolvePending; // Set of types that have not yet been resolved.
 
     std::vector<DataFactory*> compatibleFactories;
 

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/main.cpp Tue Nov  7 02:21:44 2006
@@ -171,6 +171,7 @@
     TEST (  sdotest::b45933() );
     TEST (  sdotest::jira490() );
     TEST (  sdotest::jira705() );
+    TEST (  sdotest::jira546() );
     TEST (  sdotest::testXPath() );
 
     cout << "Total tests:" << totaltests << " Tests passed:" << testspassed << endl;

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp Tue Nov  7 02:21:44 2006
@@ -92,7 +92,134 @@
     }
 }
 
+// JIRA 546 relaxes the restriction that when the data factory creates its
+// first data object then the type structure known to that data factory is
+// resolved and becomes read only. So, now we can add types after the first
+// data object is created. We must also show that when data objects are copied
+// from one data factory to another, the correct tests are performed to ensure
+// that the destination factory contains the types required by the incoming
+// data object and if not the copy is rejected.
+int  sdotest::jira546()
+{
 
+    try {
+        DataFactoryPtr mdg;
+
+        mdg  = DataFactory::getDataFactory();
+
+        mdg->addType("myspace","Root1");
+
+        mdg->addType("myspace","Company1");
+
+        mdg->addPropertyToType("myspace","Company1","name1",
+                           "commonj.sdo","String", false, false, false);
+    
+        mdg->addPropertyToType("myspace","Company1","id1",
+                           "commonj.sdo","String", false, false, false);
+
+        mdg->addPropertyToType("myspace","Root1","companies1",
+                           "myspace","Company1", true, false, true);
+
+        const Type& tcc1 = mdg->getType("myspace","Root1");
+
+
+        DataObjectPtr dop1 = mdg->create((Type&)tcc1);
+
+        // The preceding data object creation forced a resolve of the type
+        // system. Can we still extend it?
+
+        mdg->addType("myspace","Root2");
+
+        mdg->addType("myspace","Company2");
+
+        mdg->addPropertyToType("myspace","Company2","name2",
+                           "commonj.sdo","String", false, false, false);
+    
+        mdg->addPropertyToType("myspace","Company2","id2",
+                           "commonj.sdo","String", false, false, false);
+
+        mdg->addPropertyToType("myspace","Root2","companies2",
+                           "myspace","Company2", true, false, true);
+
+        const Type& tcc2 = mdg->getType("myspace","Root2");
+
+        DataObjectPtr dop2 = mdg->create((Type&)tcc2);
+
+    }
+    catch (SDORuntimeException e)
+    {
+        if (!silent) cout << "JIRA-546 test (part 1) failed." << endl;
+        return 0;
+    }
+
+    try {
+       DataFactoryPtr dfp_left = DataFactory::getDataFactory();
+       DataFactoryPtr dfp_right = DataFactory::getDataFactory();
+
+       populateFactory(dfp_left);
+       populateFactory(dfp_right);
+
+       // Extend each data factories with an additional type, the two types
+       // being different. Prior to TUSCANY-546 this would have made them
+       // incompatible.
+
+       dfp_left->addType("Namespace", "LeftType");
+       dfp_left->addPropertyToType("Namespace",
+                                   "LeftType",
+                                   "leftProperty",
+                                   "commonj.sdo",
+                                   "String",
+                                   false,
+                                   false,
+                                   false);
+
+       dfp_right->addType("Namespace", "RightType");
+       dfp_right->addPropertyToType("Namespace",
+                                    "RightType",
+                                    "rightProperty",
+                                    "commonj.sdo",
+                                    "String",
+                                    false,
+                                    false,
+                                    false);
+
+       // Create a data object in the left factory
+       DataObjectPtr root = dfp_left->create("Namespace", "Root");
+       DataObjectPtr project = root->createDataObject("project");
+       project->setCString("id", "The TTP Project");
+       DataObjectPtr str = project->createDataObject("string");
+       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");
+       DataObjectPtr li1 = wp1->createDataObject("lineitems");
+       DataObjectPtr li2 = wp1->createDataObject("lineitems");
+       DataObjectPtr li3 = wp2->createDataObject("lineitems");
+       DataObjectPtr li4 = wp2->createDataObject("lineitems");
+       li1->setCString("itemname", "LineItem 1");
+       li2->setCString("itemname", "LineItem 2");
+       li3->setCString("itemname", "LineItem 3");
+       li4->setCString("itemname", "LineItem 4");
+       DataObjectPtr str1 = li1->createDataObject("string");
+       DataObjectPtr str2 = li2->createDataObject("string");
+       DataObjectPtr str3 = li3->createDataObject("string");
+       DataObjectPtr str4 = li4->createDataObject("string");
+       str1->setCString("value", "String1");
+       str2->setCString("value", "String2");
+       str3->setCString("value", "String3");
+       str4->setCString("value", "String4");
+
+       if (!transferto(root, dfp_right, false)) return 0;
+
+       return 1;
+    }
+    catch (SDORuntimeException e)
+    {
+       if (!silent) cout << "JIRA-546 test (part 2) failed." << endl;
+       return 0;
+    }
+}
 
 int sdotest::changesummarytest()
 {

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.h Tue Nov  7 02:21:44 2006
@@ -43,6 +43,8 @@
         static int  comparefiles(char* fn1, char*fn2);
         static int dumpproperties(FILE *f, DataObjectPtr root);
         static int printset(FILE *f, ChangeSummaryPtr cs);
+        static void populateFactory(DataFactoryPtr dfp);
+      
 
         static int xsdtosdo();
 
@@ -173,6 +175,7 @@
         static int maintest();
         static int jira490();
         static int jira705();
+        static int jira546();
         
         static int b48602();
         static int b48736();

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=472054&r1=472053&r2=472054
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest2.cpp Tue Nov  7 02:21:44 2006
@@ -119,48 +119,57 @@
 
 }
 
-int sdotest::compatiblefactory()
-{
-    DataFactoryPtr f1 = DataFactory::getDataFactory();
+// The compatibleFactory() test creates a series of factories that are either
+// identical or very similar so we need a function that populates a data
+// factory with the common part.
 
-    f1->addType("Namespace","Project");
-    f1->addType("Namespace","WorkPackage");
-    f1->addType("Namespace","LineItem");
-    f1->addType("Namespace","StringHolder");
+void sdotest::populateFactory(DataFactoryPtr dfp)
+{
+   
+   dfp->addType("Namespace", "Project");
+   dfp->addType("Namespace", "WorkPackage");
+   dfp->addType("Namespace", "LineItem");
+   dfp->addType("Namespace", "StringHolder");
  
-    f1->addType("Namespace","Root");
-    f1->addPropertyToType("Namespace","Root","project",
-                           "Namespace","Project", false, false, true);
+   dfp->addType("Namespace", "Root");
+   dfp->addPropertyToType("Namespace","Root","project",
+                         "Namespace","Project", false, false, true);
 
-    f1->addPropertyToType("Namespace","StringHolder","value",
-                           "commonj.sdo","String", false, false, false);
+   dfp->addPropertyToType("Namespace","StringHolder","value",
+                         "commonj.sdo","String", false, false, false);
    
-    f1->addPropertyToType("Namespace","Project","id",
-                           "commonj.sdo","String", false, false, false);
+   dfp->addPropertyToType("Namespace","Project","id",
+                         "commonj.sdo","String", false, false, false);
     
-    f1->addPropertyToType("Namespace","Project","string",
-                           "Namespace","StringHolder", false, false, true);
+   dfp->addPropertyToType("Namespace","Project","string",
+                         "Namespace","StringHolder", false, false, true);
  
-    f1->addPropertyToType("Namespace","WorkPackage","name",
-                           "commonj.sdo","String", false, false, false);
+   dfp->addPropertyToType("Namespace","WorkPackage","name",
+                         "commonj.sdo","String", false, false, false);
     
 
-    f1->addPropertyToType("Namespace","WorkPackage","string",
-                           "Namespace","StringHolder", false, false, true);
+   dfp->addPropertyToType("Namespace","WorkPackage","string",
+                         "Namespace","StringHolder", false, false, true);
+
+   dfp->addPropertyToType("Namespace","LineItem","itemname",
+                         "commonj.sdo","String", false, false, false);
 
-    f1->addPropertyToType("Namespace","LineItem","itemname",
-                           "commonj.sdo","String", false, false, false);
+   dfp->addPropertyToType("Namespace","LineItem","string",
+                         "Namespace","StringHolder", false, false, true);
 
-    f1->addPropertyToType("Namespace","LineItem","string",
-                           "Namespace","StringHolder", false, false, true);
+   dfp->addPropertyToType("Namespace","Project","packages",
+                         "Namespace","WorkPackage", true, false, true);
 
-    f1->addPropertyToType("Namespace","Project","packages",
-                           "Namespace","WorkPackage", true, false, true);
+   dfp->addPropertyToType("Namespace","WorkPackage","lineitems",
+                         "Namespace","LineItem", true, false, true);
+   
+}
 
-    f1->addPropertyToType("Namespace","WorkPackage","lineitems",
-                           "Namespace","LineItem", true, false, true);
+int sdotest::compatiblefactory()
+{
+    DataFactoryPtr f1 = DataFactory::getDataFactory();
+    populateFactory(f1);
 
-  
     // project
     //    id (string)
     //    string (StringHolder)
@@ -178,45 +187,7 @@
     // factories 1 and 2 are compatible
 
     DataFactoryPtr f2 = DataFactory::getDataFactory();
-    
-    f2->addType("Namespace","Project");
-    f2->addType("Namespace","WorkPackage");
-    f2->addType("Namespace","LineItem");
-    f2->addType("Namespace","StringHolder");
- 
-    f2->addType("Namespace","Root");
-    f2->addPropertyToType("Namespace","Root","project",
-                           "Namespace","Project", false, false, true);
-
- 
-    f2->addPropertyToType("Namespace","StringHolder","value",
-                           "commonj.sdo","String", false, false, false);
-   
-    f2->addPropertyToType("Namespace","Project","id",
-                           "commonj.sdo","String", false, false, false);
-    
-    f2->addPropertyToType("Namespace","Project","string",
-                           "Namespace","StringHolder", false, false, true);
- 
-    f2->addPropertyToType("Namespace","WorkPackage","name",
-                           "commonj.sdo","String", false, false, false);
-    
-
-    f2->addPropertyToType("Namespace","WorkPackage","string",
-                           "Namespace","StringHolder", false, false, true);
-
-    f2->addPropertyToType("Namespace","LineItem","itemname",
-                           "commonj.sdo","String", false, false, false);
-
-    f2->addPropertyToType("Namespace","LineItem","string",
-                           "Namespace","StringHolder", false, false, true);
-
-    f2->addPropertyToType("Namespace","Project","packages",
-                           "Namespace","WorkPackage", true, false, true);
-
-    f2->addPropertyToType("Namespace","WorkPackage","lineitems",
-                           "Namespace","LineItem", true, false, true);
-
+    populateFactory(f2);    
 
     // factory 3 has no project type
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org