summaryrefslogtreecommitdiffstats
path: root/tags/cpp-stable-20060304/sca/runtime/core/src/tuscany/sca/model/Module.cpp
blob: 43702144a236776df15faea7bbe430c4ca051933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 *
 *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
 *
 *  Licensed 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: 2005/12/22 11:33:21 $ */

#include "tuscany/sca/util/Logging.h"
#include "tuscany/sca/util/Utils.h"
#include "tuscany/sca/model/Module.h"


namespace tuscany
{
    namespace sca
    {
        
        namespace model
        {
            
            // Constructor
            Module::Module(const std::string& moduleName) 
                : name(moduleName)
            {
                LOGENTRY(1, "Module::constructor");
                LOGEXIT(1, "Module::constructor");
            }
            
            Module::~Module()
            {
            }
            
            void Module::setRoot(const std::string& rootDirectory)
            {
                moduleRoot = rootDirectory;
            }
            
            
            ///
            /// Add a new component to the module component
            ///
            Component* Module::addComponent(const std::string& name)
            {
                LOGENTRY(1, "Module::addComponent");
                Component* newComponent = new Component(name, this);
                components[name] = newComponent;
                LOGEXIT(1, "Module::addComponent");
                return newComponent;
            }
            
            Component* Module::findComponent(const std::string& name)
            {
                LOGENTRY(1, "Module::findComponent");
                Component* foundComponent = components[name];
                LOGEXIT(1, "Module::findComponent");
                return foundComponent;
            }
            
            Service* Module::findComponentService(const std::string& name)
            {
                LOGENTRY(1, "Module::findComponentService");
                
                Service* service = 0;
                
                string componentName;
                string serviceName;
                Utils::tokeniseUri(name, componentName, serviceName);
                
                // Locate the component
                Component* foundComponent = components[name];
                if (foundComponent)
                {
                    // Locate the service
                    service = foundComponent->findService(serviceName);
                }
                LOGEXIT(1, "Module::findComponentService");
                return service;
            }
            
            ExternalService* Module::findExternalService(const std::string& name)
            {
                LOGENTRY(1, "Module::findExternalService");
                ExternalService* foundService = externalServices[name];
                LOGEXIT(1, "Module::findExternalService");
                return foundService;
            }
            
            
            EntryPoint* Module::addEntryPoint(const std::string& name)
            {
                LOGENTRY(1, "Module::addEntryPoint");
                EntryPoint* ep = new EntryPoint(name);
                entryPoints[name] = ep;
                LOGEXIT(1, "Module::addEntryPoint");
                return findEntryPoint(name);
            }
            
            EntryPoint* Module::findEntryPoint(const std::string& name)
            {
                return entryPoints[name];
            }


            ExternalService* Module::addExternalService(const std::string& name)
            {
                LOGENTRY(1, "Module::addExternalService");
                ExternalService* es = new ExternalService(name, this);
                externalServices[name] = es;
                LOGEXIT(1, "Module::addExternalService");
                return es;
            }
            
            void Module::addWire(const std::string& source, const std::string& target)
            {
                LOGENTRY(1, "Module::addWire");
                wires.push_back(Wire(source, target));
                LOGEXIT(1, "Module::addWire");
            }
            
            
            void Module::resolveWires()
            {
                LOGENTRY(1, "Module::resolveWires");
                 for (WIRES::iterator iter = wires.begin();
                iter != wires.end();
                iter++)
                {
                    // -----------------
                    // Locate the target
                    // -----------------
                    WireTarget* target = findComponentService(iter->getTarget());
                    if (!target)
                    {
                        target = findExternalService(iter->getTarget());
                    }
                    if (!target)
                    {
                        LOGERROR_1(0, "Module::resolveWires: Wire target %s not found", iter->getTarget().c_str());
                    }
                    else
                    {
                        EntryPoint* entrypoint = findEntryPoint(iter->getSourceComponent());
                        if (entrypoint)
                        {
                            entrypoint->addTarget(target);
                        }
                        else
                        {
                            Component* component = findComponent(iter->getSourceComponent());
                            if (component)
                            {
                                ServiceReference* serviceReference = component->findReference(iter->getSourceReference());
                                if (serviceReference)
                                {
                                    serviceReference->addTarget(target);
                                }
                                else
                                {
                                    LOGERROR_1(0, "Module::resolveWires: Wire source reference %s not found", iter->getSourceReference().c_str());
                                }
                            }
                            else
                            {
                                LOGERROR_1(0, "Module::resolveWires: Wire source %s not found", iter->getSourceComponent().c_str());
                            }
                        }
                    }
                }

                LOGEXIT(1, "Module::resolveWires");
            }


            
            void Module::addWsdl(commonj::sdo::DataObjectPtr wsdlModel)
            {
                LOGENTRY(1, "Module::addWsdl");
                Wsdl* wsdl = new Wsdl(wsdlModel);
                wsdls[wsdl->getNamespace()] = wsdl;
                LOGEXIT(1, "Module::addWsdl");

            }

            Wsdl* Module::findWsdl(const std::string& wsdlNamespace )
            {
                return wsdls[wsdlNamespace];

            }


            // Get an XSDHelper - one will be created for each module
            commonj::sdo::XSDHelperPtr Module::getXSDHelper()
            {
                if (xsdHelper == 0)
                {
                    xsdHelper = commonj::sdo::HelperProvider::getXSDHelper();
                }

                return xsdHelper;
            }

            // Get an XMLHelper - one will be created for each module
            commonj::sdo::XMLHelperPtr Module::getXMLHelper()
            {
                if (xmlHelper == 0)
                {
                    xmlHelper = commonj::sdo::HelperProvider::getXMLHelper(getXSDHelper()->getDataFactory());
                }

                return xmlHelper;
            }


            // Get a data factory - the one in the xsd/xml helper
            commonj::sdo::DataFactoryPtr Module::getDataFactory()
            {
                return getXSDHelper()->getDataFactory();
            }
            
        } // End namespace model
        
    } // End namespace sca
} // End namespace tuscany