summaryrefslogtreecommitdiffstats
path: root/tags/native-sca-1.0.incubating-M3-RC4/runtime/core/src/tuscany/sca/model/Component.h
blob: 882d79a94c1f89a5dcf32954a0d3c9752b563b0e (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
/*
 * 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_model_component_h
#define tuscany_sca_model_component_h

#include <string>
#include <map>

#include "commonj/sdo/SDO.h"

#include "tuscany/sca/export.h"


namespace tuscany
{
    namespace sca
    {
        namespace model
        {

            class Composite;
            class ComponentType;
            class Reference;
            class ReferenceType;
            class Service;
            class ServiceType;

            /**
             * A component is a configured instance of an implementation. Components provide
             * and consume services. More than one component can use and configure the same
             * implementation, where each component configures the implementation differently.
             * For example each component may configure a reference of the same implementation
             * to consume a different service.
             */
            class Component
            {
            public:
            
                /**
                 * Constructor
                 * @param composite The composite containing the component.
                 * @param name The name of the component.
                 */
                SCA_API Component(Composite *composite, const std::string& name, ComponentType *type);

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

                /**
                 * Returns the name of this component.
                 * @return the name of this component
                 */
                SCA_API const std::string& getName() const { return name; }
            
                /**
                 * Returns the composite containing this component.
                 * @return The composite containing this component.
                 */
                SCA_API Composite* getComposite() const { return composite; }
            
                /**
                 * Returns the type of this component.
                 * @return The type of this component.
                 */
                SCA_API ComponentType* getType() const { return type; }
                
                /**
                 * Add a new service to this component.
                 * @param service The service to add.
                 */
                SCA_API void addService(Service* service);

                /**
                 * 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.
                 */
                SCA_API Service* findService(const std::string& serviceName);

                /**
                 * Add a new reference to this component.
                 * @param reference The reference to add.
                 */
                SCA_API void addReference(Reference* reference);

                /**
                 * 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.
                 */
                SCA_API Reference* findReference(const std::string& referenceName);

                /**
                 * Returns all the services defined on this component.
                 * @return All the services defined on this component.
                 */
                typedef std::map<std::string, Service*> SERVICE_MAP;
                SCA_API const SERVICE_MAP& getServices() const { return services; }; 

                /**
                 * Returns all the references defined on this component.
                 * @return All the references defined on this component.
                 */
                typedef std::map<std::string, Reference*> REFERENCE_MAP;
                SCA_API const REFERENCE_MAP& getReferences() const { return references; }; 
                
                /**
                 * Set the value of a property defined on this component. The values
                 * will usually come from a component declaration in a composite file.
                 * @param name The name of the property.
                 * @param value The value of the property.
                 */
                SCA_API void setProperty(const std::string& name, commonj::sdo::DataObjectPtr value);

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

            private:
                
                /**
                 * Name of the component.
                 */
                std::string name;
                
                /**
                 * Composite containing the component.
                 */
                 Composite* composite;

                /**
                 * Type of the component.
                 */
                ComponentType* type;

                /**
                 * Map of all the services defined on this component.
                 */
                SERVICE_MAP services;

                /**
                 * Map of all the references defined on this component.
                 */
                REFERENCE_MAP references;

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

           };

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

#endif // tuscany_sca_model_component_h