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/21 19:52:33 UTC

svn commit: r477820 - in /incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo: DataObjectImpl.cpp DataObjectImpl.h

Author: robbinspg
Date: Tue Nov 21 10:52:32 2006
New Revision: 477820

URL: http://svn.apache.org/viewvc?view=rev&rev=477820
Log:
TUSCANY-873 - apply Simon Laws' patch for copying open types

Modified:
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.h

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=477820&r1=477819&r2=477820
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.cpp Tue Nov 21 10:52:32 2006
@@ -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)

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.h?view=diff&rev=477820&r1=477819&r2=477820
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataObjectImpl.h Tue Nov 21 10:52:32 2006
@@ -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);



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