summaryrefslogtreecommitdiffstats
path: root/tags/cpp-0.1.incubating-M1-RC3b/sca/runtime/core/src/tuscany/sca/model/Component.h
blob: f40690c85902f6c814ea14f8864f86b79fe94cad (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
/*
 *
 *  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 $ */

#ifndef tuscany_sca_model_component_h
#define tuscany_sca_model_component_h

#include <string>
using std::string;

#include <map>

#include "tuscany/sca/model/Service.h"
#include "tuscany/sca/model/Implementation.h"
#include "tuscany/sca/model/ServiceReference.h"

#include "commonj/sdo/SDO.h"
using commonj::sdo::DataObjectPtr;
using commonj::sdo::DataFactoryPtr;

namespace tuscany
{
    namespace sca
    {
        namespace model
        {

            class Module;

            /**
             * Information about an SCA component.
             */
            class Component
            {
            public:
                /**
                 * Constructor
                 * @param name The name of the component.
                 * @param module The module containing this component.
                 */
                Component(const std::string& name, Module* module);

                /**
                 * Destructor.
                 */
                virtual ~Component();

                /**
                 * Returns the name of the component.
                 * @return The name of the component.
                 */
                const string& getName() {return name;}

                /** 
                 * Get the module containing this component.
                 * @return The containing module.
                 */
                Module* getModule() {return containingModule;}

                /**
                 * Add a new service to this component.
                 * @param serviceName The name of the service to add.
                 * @return The newly added service.
                 */
                Service* addService(const std::string& serviceName);

                /**
                 * Find an existing service on this component.
                 * @param serviceName The name of the service to find.
                 * If the serviceName is the zero length string then if there is
                 * only one service it will be returned.
                 * @return The found service, or 0 if not found.
                 */
                Service* findService(const std::string& serviceName);

                /**
                 * Add a new reference to this component.
                 * @param referenceName The name of the reference to add.
                 * @return The newly added reference.
                 */
                ServiceReference* addReference(const std::string& referenceName);

                /**
                 * Find an existing reference on this component.
                 * @param referenceName The name of the reference to find.
                 * @return The found reference, or 0 if not found.
                 */
                ServiceReference* findReference(const std::string& referenceName);

                /**
                 * Set the details of the implementation of this component.
                 * @param impl The details of the implementation.
                 */
                void setImplementation(Implementation* impl);

                /**
                 * Returns the details of the implementation of this component.
                 * @return The details of the implementation.
                 */
                Implementation* getImplementation() {return implementation;}

                /**
                 * Add a new property to this component. Properties are 
                 * added one at a time. The property definitions come from the component
                 * type file.
                 * @param name The name of the property.
                 * @param type The full name of the type (including uri and local name).
                 * @param many True if this is a many valued property.
                 * @param required True if this property must have a value set.
                 * @param defaultValue The default value if the property does not have a
                 * value set.
                 */
                void addProperty(const string& name,
                    const string& type,
                    bool many,
                    bool required,
                    const char* defaultValue = 0);
    
                /**
                 * Add the property values to the properties defined on this 
                 * component. The values will come from the sca.module file.
                 * @param properties A data object representing all the values set
                 * for this component.
                 */
                void addProperties(DataObjectPtr properties);

                /**
                 * Returns a data object from which all the properties and their
                 * values can be accessed.
                 * @return A data object holding the property values.
                 */
                DataObjectPtr getProperties();
            private:
                /**
                 * Name of the component.
                 */
                string name;

                /**
                 * Module containing this component for navigating up the tree.
                 */
                Module* containingModule;

                /**
                 * Information about the implementation of this component.
                 */
                Implementation* implementation;

                typedef std::map<std::string, Service*> SERVICE_MAP;
                /**
                 * Map of all the services defined on this component.
                 */
                SERVICE_MAP services;

                typedef std::map<std::string, ServiceReference*> REFERENCE_MAP;
                /**
                 * Map of all the references defined on this component.
                 */
                REFERENCE_MAP references;

                /**
                 * SDO data factory which has all the property types defined from
                 * the component type file
                 */
                DataFactoryPtr propertyFactory;

                /**
                 * Return the SDO data factory which has the property types defined
                 * in it.
                 * @return The data factory.
                 */
                DataFactoryPtr getPropertyDataFactory();

                /**
                 * The properties and their values for this component.
                 */ 
                DataObjectPtr properties;

           };

        } // End namespace model

    } // End namespace sca
} // End namespace tuscany

#endif // tuscany_sca_model_component_h