Author: jsdelfino
Date: Mon Sep 11 22:54:28 2006
New Revision: 442461

URL: http://svn.apache.org/viewvc?view=rev&rev=442461
Log:
ComponentType files are now optional. The Ruby implementation now automaticall 
creates a default serviceType and referenceTypes as needed. Simplified the 
RubyCalculator sample which now does not contain any C++ artifacts anymore.

Removed:
    
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.componentType
    
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/DivideImpl.componentType
Modified:
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Component.cpp
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
    
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
    
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h
    
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
    
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
    
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/Makefile.am

Modified: 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Component.cpp
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Component.cpp?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Component.cpp 
(original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Component.cpp 
Mon Sep 11 22:54:28 2006
@@ -68,7 +68,13 @@
                 }
                 else
                 {
-                    return services[serviceName];
+                    Service* service = services[serviceName];
+                    if (service == NULL)
+                    {
+                        // A service with an empty name will match any service 
name 
+                        service = services[""];
+                    }
+                    return service;
                 }
             }
             

Modified: 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h 
(original)
+++ 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h 
Mon Sep 11 22:54:28 2006
@@ -76,7 +76,7 @@
                  * Add a new service type to this component type.
                  * @param serviceType The service type to add.
                  */
-                SCA_API void addServiceType(ServiceType* serviceType);
+                SCA_API virtual void addServiceType(ServiceType* serviceType);
 
                 /**
                  * Find an existing service type on this component type.
@@ -85,20 +85,20 @@
                  * only one service type it will be returned.
                  * @return The found service, or 0 if not found.
                  */
-                SCA_API ServiceType* findServiceType(const string& 
serviceName);
+                SCA_API virtual ServiceType* findServiceType(const string& 
serviceName);
 
                 /**
                  * Add a new reference type to this component type.
                  * @param referenceType The reference type to add.
                  */
-                SCA_API void addReferenceType(ReferenceType* referenceType);
+                SCA_API virtual void addReferenceType(ReferenceType* 
referenceType);
 
                 /**
                  * Find an existing reference type on this component type.
                  * @param referenceName The name of the reference type to find.
                  * @return The found reference type, or 0 if not found.
                  */
-                SCA_API ReferenceType* findReferenceType(const string& 
referenceName);
+                SCA_API virtual ReferenceType* findReferenceType(const string& 
referenceName);
 
                 /**
                  * Returns the service types defined on this component.
@@ -123,7 +123,7 @@
                  * @param defaultValue The default value if the property does 
not have a
                  * value set.
                  */
-                SCA_API void addPropertyType(const string& name,
+                SCA_API virtual void addPropertyType(const string& name,
                     const string& type,
                     bool many,
                     commonj::sdo::DataObjectPtr defaultValue);
@@ -133,7 +133,7 @@
                  * in this component type.
                  * @return The data factory.
                  */
-                SCA_API commonj::sdo::DataFactoryPtr getPropertyDataFactory();
+                SCA_API virtual commonj::sdo::DataFactoryPtr 
getPropertyDataFactory();
 
                 /**
                  * Initialize a component of this type.

Modified: 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp 
(original)
+++ 
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp 
Mon Sep 11 22:54:28 2006
@@ -354,26 +354,37 @@
                     // Load the .componentType
                     // -----------------------
                     string typeFileName = composite->getRoot() + "/" + 
componentType->getName() + ".componentType";
-                    try 
+
+                    // Check that the component type file exists
+                    //TODO We need a better and portable way to do this
+                    string dirName;
+                    string fileName;                    
+                    Utils::rTokeniseString("/", typeFileName, dirName, 
fileName);
+                    Files files(dirName, fileName, false);
+                    if (files.size() !=0)
                     {
-                        XMLDocumentPtr componentTypeFile = 
getXMLHelper()->loadFile(typeFileName.c_str());
-                        if (!componentTypeFile || 
componentTypeFile->getRootDataObject() == 0)
+                        try 
                         {
-                            LOGERROR_1(0, "ModelLoader::addComponent: Unable 
to load file: %s", typeFileName.c_str());
-                        }
-                        else
-                        {                                            
-                            
//Utils::printDO(componentTypeFile->getRootDataObject());
-                            
//commonj::sdo::SDOUtils::printDataObject(componentTypeFile->getRootDataObject());
-                            addServiceTypes(composite, componentType, 
componentTypeFile->getRootDataObject());
-                            addReferenceTypes(composite, componentType, 
componentTypeFile->getRootDataObject());
-                            addPropertyTypes(componentType, 
componentTypeFile->getRootDataObject());
+                            XMLDocumentPtr componentTypeFile = 
getXMLHelper()->loadFile(typeFileName.c_str());
+                            if (!componentTypeFile || 
componentTypeFile->getRootDataObject() == 0)
+                            {
+                                // Component type files are optional
+                                LOGINFO_1(0, "ModelLoader::addComponent: 
Unable to load file: %s", typeFileName.c_str());
+                            }
+                            else
+                            {                                            
+                                
//Utils::printDO(componentTypeFile->getRootDataObject());
+                                
//commonj::sdo::SDOUtils::printDataObject(componentTypeFile->getRootDataObject());
+                                addServiceTypes(composite, componentType, 
componentTypeFile->getRootDataObject());
+                                addReferenceTypes(composite, componentType, 
componentTypeFile->getRootDataObject());
+                                addPropertyTypes(componentType, 
componentTypeFile->getRootDataObject());
+                            }
+                        } catch (SDORuntimeException& ex) 
+                        {
+                            LOGERROR_2(0, "ModelLoader::addComponent (%s): 
Exception caught: %s",
+                                typeFileName.c_str(), ex.getMessageText());
+                            throw 
SystemConfigurationException(ex.getMessageText());
                         }
-                    } catch (SDORuntimeException& ex) 
-                    {
-                        LOGERROR_2(0, "ModelLoader::addComponent (%s): 
Exception caught: %s",
-                            typeFileName.c_str(), ex.getMessageText());
-                        throw 
SystemConfigurationException(ex.getMessageText());
                     }    
                 }
                 else
@@ -385,6 +396,20 @@
                     throw SystemConfigurationException(message.c_str());
                 }
                 
+                // First check that references exist, some component types
+                // will create all used references automatically
+                DataObjectList& refs = componentDO->getList("reference");
+                for (int i=0; i<refs.size(); i++)
+                {
+                    string refName = refs[i]->getCString("name");
+                    if (!componentType->findReferenceType(refName))
+                    {
+                        // Configuration error: reference is not defined
+                        string message = "Undefined reference: " + refName;
+                        throw SystemConfigurationException(message.c_str());
+                    }
+                }
+                
                 // Create the component
                 Component* component = new Component(composite, 
componentDO->getCString("name"), componentType);
                 composite->addComponent(component);
@@ -404,7 +429,6 @@
                 // ----------
                 // References
                 // ----------
-                DataObjectList& refs = componentDO->getList("reference");
                 for (int i=0; i<refs.size(); i++)
                 {
                     // 
----------------------------------------------------------

Modified: 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
 (original)
+++ 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
 Mon Sep 11 22:54:28 2006
@@ -51,7 +51,6 @@
                 component = service->getComponent();
                 implementation = (RubyImplementation*)component->getType();
                 interf = service->getType()->getInterface();
-                remotable = interf->isRemotable();
                 
                 LOGEXIT(1,"RubyServiceWrapper::constructor");
                 

Modified: 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h
 (original)
+++ 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h
 Mon Sep 11 22:54:28 2006
@@ -76,11 +76,6 @@
                 Component* component;
     
                 /**
-                 * Set to true if the service is remotable.
-                 */
-                bool remotable;
-                
-                /**
                  * A pointer to the interface which the service exposes.
                  */
                 Interface* interf;

Modified: 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
 (original)
+++ 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
 Mon Sep 11 22:54:28 2006
@@ -24,7 +24,9 @@
 #include "tuscany/sca/model/Component.h"
 #include "tuscany/sca/model/Composite.h"
 #include "tuscany/sca/model/Service.h"
+#include "tuscany/sca/model/ServiceType.h"
 #include "tuscany/sca/model/Reference.h"
+#include "tuscany/sca/model/ReferenceType.h"
 #include "tuscany/sca/util/Utils.h"
 
 namespace tuscany
@@ -59,6 +61,9 @@
                 // Load the Ruby implementation class                
                 implementationClass = rb_path2class(className.c_str());
                 
+                // Create a default service
+                ServiceType* defaultServiceType = new ServiceType(this, "", 
NULL, NULL);
+                addServiceType(defaultServiceType);
             }
 
             RubyImplementation::~RubyImplementation()
@@ -90,6 +95,20 @@
                     reference->setBinding(binding);
                     refiter++;
                 }
+            }
+            
+            // Override this method to add reference types as they are needed
+            ReferenceType* RubyImplementation::findReferenceType(const string& 
referenceName)
+            {
+                ReferenceType* referenceType = 
ComponentType::findReferenceType(referenceName);
+    
+                if (referenceType == NULL)
+                {
+                    referenceType = new ReferenceType(this, referenceName, 
NULL, NULL, ReferenceType::ONE_ONE);
+                    addReferenceType(referenceType);
+                }
+                
+                return referenceType;
             }
             
         } // End namespace ruby

Modified: 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
 (original)
+++ 
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
 Mon Sep 11 22:54:28 2006
@@ -61,7 +61,7 @@
                  * Initialize a component of this type.
                  * @param component The component to initialize.
                  */
-                virtual void initializeComponent(Component* component);
+                SCA_API virtual void initializeComponent(Component* component);
 
                 /**
                  * Returns the name of the Ruby module.
@@ -85,6 +85,13 @@
                  * Returns the Ruby implementation class
                  */
                 VALUE getImplementationClass() const { return 
implementationClass; }
+
+                /**
+                 * Find an existing reference type on this component type.
+                 * @param referenceName The name of the reference type to find.
+                 * @return The found reference type, or 0 if not found.
+                 */
+                SCA_API virtual ReferenceType* findReferenceType(const string& 
referenceName);
 
             private:
                 

Modified: 
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/Makefile.am?view=diff&rev=442461&r1=442460&r2=442461
==============================================================================
--- 
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/Makefile.am 
(original)
+++ 
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/Makefile.am 
Mon Sep 11 22:54:28 2006
@@ -1,5 +1,5 @@
 deploydir=$(prefix)/samples/RubyCalculator/deploy
 compositedir=$(deploydir)/packages/sample.calculator
 
-composite_DATA = *.composite *.componentType *.wsdl *.rb
-EXTRA_DIST = *.composite *.componentType *.wsdl *.rb
+composite_DATA = *.composite *.wsdl *.rb
+EXTRA_DIST = *.composite *.wsdl *.rb



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to