You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2006/12/14 21:12:14 UTC

svn commit: r487334 - in /incubator/tuscany/cpp/sca/runtime/core/src: Makefile.am tuscany/sca/util/SDOUtils.cpp tuscany/sca/util/SDOUtils.h

Author: jsdelfino
Date: Thu Dec 14 12:12:13 2006
New Revision: 487334

URL: http://svn.apache.org/viewvc?view=rev&rev=487334
Log:
Adding an SDOUtils class with an SDO visitor to help navigate an SDO graph

Added:
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp   (with props)
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h   (with props)
Modified:
    incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am

Modified: incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am?view=diff&rev=487334&r1=487333&r2=487334
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am Thu Dec 14 12:12:13 2006
@@ -63,6 +63,7 @@
 tuscany/sca/util/Library.cpp \
 tuscany/sca/util/Logger.cpp \
 tuscany/sca/util/LogWriter.cpp \
+tuscany/sca/util/SDOUtils.cpp \
 tuscany/sca/util/Utils.cpp
 
 libtuscany_sca_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo

Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp?view=auto&rev=487334
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp Thu Dec 14 12:12:13 2006
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *   
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#if defined(WIN32)  || defined (_WINDOWS)
+#pragma warning(disable: 4786)
+#endif
+
+#include "tuscany/sca/util/SDOUtils.h"
+
+using namespace std;
+using namespace commonj::sdo;
+namespace tuscany
+{
+    namespace sca
+    {
+        
+        /**
+         * Constructor
+         */
+        SDOVisitor::SDOVisitor()
+        {
+        }
+        
+        /**
+         * Destructor
+         */
+        SDOVisitor::~SDOVisitor()
+        {
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, bool boolData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, char byteData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, const char* bytesData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, wchar_t charData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, const SDODate& dateData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, long double doubleData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, float floatData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, long intData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, short shortData)
+        {
+            return SDOVisitor::RESULT_NOT_SUPPORTED;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, const string& stringData)
+        {
+            return SDOVisitor::RESULT_CONTINUE;
+        }
+        
+        SDOVisitor::RESULT SDOVisitor::visit(DataObjectPtr parent, const Property& property, DataObjectPtr dataObjectData)
+        {
+            return SDOVisitor::RESULT_CONTINUE;
+        }
+        
+        SDOVisitor::RESULT SDOUtils::accept(DataObjectPtr dataObject, SDOVisitor& visitor, SDOVisitor::DEPTH depth)
+        {
+            SDOVisitor::RESULT result = SDOVisitor::RESULT_CONTINUE;
+
+            const Type& type = dataObject->getType();
+            if (type.isSequencedType())
+            {
+                Sequence* sequence = dataObject->getSequence();
+                int size = sequence->size();
+                for (int i = 0; i < size; i++)
+                {
+                    if (sequence->isText(i))
+                    {
+                        const string text(sequence->getCStringValue(i)); 
+                        result = visitor.visit(dataObject, *(Property*)NULL, (const string&)text);
+                    } 
+                    else 
+                    {
+                        const Property& seqProperty = sequence->getProperty(i); 
+                        const Type& seqType = seqProperty.getType();
+                        if (seqType.isDataObjectType())
+                        {                                
+                            DataObjectPtr dob;
+                            if (seqProperty.isMany())
+                            {
+                                int index = sequence->getListIndex(i);
+                                dob = dataObject->getList(seqProperty)[index];
+                            }
+                            else
+                            {
+                                dob = dataObject->getDataObject(seqProperty);
+                            }
+                            
+                            if (dob)
+                            {
+                                result = visitor.visit(dataObject, seqProperty, (DataObjectPtr)dob);
+                            }
+                        } 
+                        else
+                        {
+                            Type::Types t = seqProperty.getTypeEnum(); 
+                            switch (t)
+                            {
+                            case Type::BooleanType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (bool)sequence->getBooleanValue(i));
+                                }
+                                break;
+                            case Type::ByteType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (char)sequence->getByteValue(i));
+                                }
+                                break;
+                            case Type::CharacterType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (wchar_t)sequence->getCharacterValue(i));
+                                }
+                                break;
+                            case Type::IntegerType: 
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (long)sequence->getIntegerValue(i));
+                                }
+                                break;
+                            case Type::ShortType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (short)sequence->getShortValue(i));
+                                }
+                                break;
+                            case Type::DoubleType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (long double)sequence->getDoubleValue(i));
+                                }
+                                break;
+                            case Type::FloatType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (float)sequence->getFloatValue(i));
+                                }
+                                break;
+                            case Type::LongType:
+                                {
+                                    result = visitor.visit(dataObject, seqProperty, (long)sequence->getLongValue(i));
+                                }
+                                break;
+                            case Type::DateType:
+                                {
+                                    const SDODate date = sequence->getDateValue(i);
+                                    result = visitor.visit(dataObject, seqProperty, (const time_t)date.getTime());
+                                }
+                                break;
+                            case Type::BigDecimalType: 
+                            case Type::BigIntegerType: 
+                            case Type::UriType:
+                            case Type::StringType:
+                                {
+                                    ;
+                                    const string stringData(sequence->getCStringValue(i));
+                                    result = visitor.visit(dataObject, seqProperty, (const string&)stringData);
+                                }
+                                break;
+                            case Type::BytesType:
+                                {
+                                    unsigned int len = sequence->getLength(i);
+                                    char* byteData = new char[len];
+                                    sequence->getBytesValue(i, byteData, len);
+                                    result = visitor.visit(dataObject, seqProperty, byteData);
+                                    delete byteData;
+                                }
+                                break;
+                            default:
+                                result = SDOVisitor::RESULT_NOT_SUPPORTED;
+                                break;
+                            }
+                            if (result == SDOVisitor::RESULT_NOT_SUPPORTED)
+                            {
+                                ;
+                                const string stringData(sequence->getCStringValue(i));
+                                result = visitor.visit(dataObject, seqProperty, (const string&)stringData);
+                            }
+                        } 
+                    }
+                    if (result == SDOVisitor::RESULT_STOP)
+                        return result;
+                }
+            }
+            else
+            {
+                PropertyList pl = dataObject->getInstanceProperties();
+                for (unsigned int i = 0; i < pl.size(); i++)
+                {
+                    if (dataObject->isSet(pl[i]))
+                    {
+                        if (pl[i].getType().isDataObjectType()) 
+                        {
+                            if (pl[i].isMany())
+                            {
+                                DataObjectList& doList = dataObject->getList(pl[i]);
+                                for (unsigned int li = 0; li < doList.size(); li++)
+                                {
+                                    DataObjectPtr dob = doList[li];
+                                    result = visitor.visit(dataObject, pl[i], (DataObjectPtr)dob);
+                                    if (result == SDOVisitor::RESULT_STOP)
+                                        return result;
+                                }
+                            }
+                            else 
+                            {
+                                DataObjectPtr dob = dataObject->getDataObject(pl[i]);
+                                result = visitor.visit(dataObject, pl[i], (DataObjectPtr)dob);
+                            }
+                        }
+                        else 
+                        {
+                            if (pl[i].isMany())
+                            {
+                                Type::Types t = pl[i].getTypeEnum();
+                                DataObjectList& doList = dataObject->getList(pl[i]);
+                                for (unsigned int li = 0; li < doList.size(); li++)
+                                {
+                                    switch (t)
+                                    {
+                                    case Type::BooleanType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (bool)doList.getBoolean(li));
+                                        }
+                                        break;
+                                    case Type::ByteType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (char)doList.getByte(li));
+                                        }
+                                        break;
+                                    case Type::CharacterType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (wchar_t)doList.getCharacter(li));
+                                        }
+                                        break;
+                                    case Type::IntegerType: 
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (long)doList.getInteger(li));
+                                        }
+                                        break;
+                                    case Type::ShortType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (short)doList.getShort(li));
+                                        }
+                                        break;
+                                    case Type::DoubleType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (long double)doList.getDouble(li));
+                                        }
+                                        break;
+                                    case Type::FloatType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (float)doList.getFloat(li));
+                                        }
+                                        break;
+                                    case Type::LongType:
+                                        {
+                                            result = visitor.visit(dataObject, pl[i], (long)doList.getLong(li));
+                                        }
+                                        break;
+                                    case Type::DateType:
+                                        {
+                                            const SDODate date = doList.getDate(li);
+                                            result = visitor.visit(dataObject, pl[i], (const time_t)date.getTime());
+                                        }
+                                        break;
+                                    case Type::BigDecimalType: 
+                                    case Type::BigIntegerType: 
+                                    case Type::UriType:
+                                    case Type::StringType:
+                                        {
+                                            const string stringData(doList.getCString(li));
+                                            result = visitor.visit(dataObject, pl[i], (const string&)stringData);
+                                        }
+                                        break;
+                                    case Type::BytesType:
+                                        {
+                                            unsigned int len = doList.getLength(li);
+                                            char* byteData = new char[len];
+                                            doList.getBytes(li, byteData, len);
+                                            result = visitor.visit(dataObject, pl[i], byteData);
+                                            delete byteData;
+                                        }
+                                        break;
+                                    default:
+                                        result = SDOVisitor::RESULT_NOT_SUPPORTED;
+                                        break;
+                                    }
+                                    if (result == SDOVisitor::RESULT_NOT_SUPPORTED)
+                                    {
+                                        const string stringData(doList.getCString(li));
+                                        result = visitor.visit(dataObject, pl[i], (const string&)stringData);
+                                    }
+                                    if (result == SDOVisitor::RESULT_STOP)
+                                        return result;
+                                }
+                            }
+                            else 
+                            {
+                                Type::Types t = pl[i].getTypeEnum();
+                                switch (t)
+                                {
+                                case Type::BooleanType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (bool)dataObject->getBoolean(pl[i]));
+                                    }
+                                    break;
+                                case Type::ByteType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (char)dataObject->getByte(pl[i]));
+                                    }
+                                    break;
+                                case Type::CharacterType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (wchar_t)dataObject->getCharacter(pl[i]));
+                                    }
+                                    break;
+                                case Type::IntegerType: 
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (long)dataObject->getInteger(pl[i]));
+                                    }
+                                    break;
+                                case Type::ShortType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (short)dataObject->getShort(pl[i]));
+                                    }
+                                    break;
+                                case Type::DoubleType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (long double)dataObject->getDouble(pl[i]));
+                                    }
+                                    break;
+                                case Type::FloatType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (float)dataObject->getFloat(pl[i]));
+                                    }
+                                    break;
+                                case Type::LongType:
+                                    {
+                                        result = visitor.visit(dataObject, pl[i], (long)dataObject->getLong(pl[i]));
+                                    }
+                                    break;
+                                case Type::DateType:
+                                    {
+                                        const SDODate date = dataObject->getDate(pl[i]);
+                                        result = visitor.visit(dataObject, pl[i], (const time_t)date.getTime());
+                                    }
+                                    break;
+                                case Type::BigDecimalType: 
+                                case Type::BigIntegerType: 
+                                case Type::UriType:
+                                case Type::StringType:
+                                    {
+                                        const string stringData(dataObject->getCString(pl[i]));
+                                        result = visitor.visit(dataObject, pl[i], (const string&)stringData);
+                                    }
+                                    break;
+                                case Type::BytesType:
+                                    {
+                                        unsigned int len = dataObject->getLength(pl[i]);
+                                        char* byteData = new char[len];
+                                        dataObject->getBytes(pl[i], byteData, len);
+                                        result = visitor.visit(dataObject, pl[i], byteData);
+                                        delete byteData;
+                                    }
+                                    break;
+                                default:
+                                    result = SDOVisitor::RESULT_NOT_SUPPORTED;
+                                    break;
+                                }
+                                if (result == SDOVisitor::RESULT_NOT_SUPPORTED)
+                                {
+                                    const string stringData(dataObject->getCString(pl[i]));
+                                    result = visitor.visit(dataObject, pl[i], (const string&)stringData);
+                                }
+                            }
+                        }
+                    }
+                    if (result == SDOVisitor::RESULT_STOP)
+                        return result;
+                } 
+            }
+    
+            return SDOVisitor::RESULT_CONTINUE;
+        }
+        
+    } // End namespace sca
+} // End namespace tuscany
+

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h?view=auto&rev=487334
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h Thu Dec 14 12:12:13 2006
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *   
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_sca_util_sdovisitor_h
+#define tuscany_sca_util_sdovisitor_h
+
+#include <string>
+using std::string;
+#include <vector>
+using std::vector;
+#include <time.h>
+
+#include "commonj/sdo/SDO.h"
+
+#include "tuscany/sca/export.h"
+
+namespace tuscany
+{
+    namespace sca
+    {
+        /**
+         * An SDO visitor interface
+         */
+        class SCA_API SDOVisitor
+        {
+        public:
+            /**
+             * Constructor.
+             */
+            SDOVisitor();
+
+            /**
+             * Destructor.
+             */ 
+            virtual ~SDOVisitor();
+
+            /**
+             * Visit depth
+             */
+            enum DEPTH
+            {
+                DEPTH_ZERO = 0,
+                DEPTH_ONE,
+                DEPTH_INFINITE
+            };
+
+            /**
+             * Visit status
+             */
+            enum RESULT
+            {
+                RESULT_CONTINUE = 0,
+                RESULT_STOP,
+                RESULT_NOT_SUPPORTED
+            };
+
+            /**
+             * Visit an SDO.
+             */
+            virtual RESULT visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, bool boolData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, char byteData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, const char* bytesData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, wchar_t charData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, const commonj::sdo::SDODate& dateData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, long double doubleData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, float floatData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, long intData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, short shortData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, const string& stringData);
+            virtual RESULT  visit(commonj::sdo::DataObjectPtr parent, const commonj::sdo::Property& property, commonj::sdo::DataObjectPtr dataObjectData);
+        };
+
+        /**
+         * SDO utilities.
+         */
+        class SCA_API SDOUtils
+        {
+        public:
+
+            static SDOVisitor::RESULT accept(commonj::sdo::DataObjectPtr dataObject, SDOVisitor& visitor, SDOVisitor::DEPTH depth);
+
+        };
+
+    } // End namespace sca
+} // End namespace tuscany
+#endif // tuscany_sca_sdovisitor_file_h

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/SDOUtils.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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