summaryrefslogtreecommitdiffstats
path: root/tags/native-sca-1.0.incubating-M3-RC4/runtime/core/src/tuscany/sca/model/ComponentType.h
blob: 86f17890e9f2739f4876b2981b15311bc7f22283 (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
/*
 * 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_componenttype_h
#define tuscany_sca_model_componenttype_h

#include <string>
#include <map>

#include "commonj/sdo/SDO.h"

#include "tuscany/sca/model/ReferenceType.h"

namespace tuscany
{
    namespace sca
    {
        namespace model
        {
            class ServiceType;
            class ReferenceType;
            class Interface;
            class Component;
            class Composite;

            /**
             * Component type represents the configurable aspects of an implementation.
             * A component type consists of services that are offered, references to other services
             * that can be wired and properties that can be set. The settable properties and the settable
             * references to services are configured by a component which uses the implementation.
             * The component type can be thought of as the contract which is honoured by an implementation.
             */
            class ComponentType
            {
            public:
             
                /**
                 * Constructor
                 */
                SCA_API ComponentType(Composite* composite, const std::string& name);

                /**
                 * Destructor.
                 */
                SCA_API virtual ~ComponentType();
                
                /**
                 * Returns the name of the component type
                 */
                SCA_API const std::string& getName() const { return name; };
                
                /**
                 * Returns the composite containing this component type
                 */
                SCA_API Composite* getComposite() const { return composite; };

                /**
                 * Add a new service type to this component type.
                 * @param serviceType The service type to add.
                 */
                SCA_API virtual void addServiceType(ServiceType* serviceType);

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

                /**
                 * Add a new reference type to this component type.
                 * @param referenceType The reference type to add.
                 */
                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 virtual ReferenceType* findReferenceType(const std::string& referenceName);

                /**
                 * Returns the service types defined on this component.
                 * @return The service types defined on this component.
                 */
                typedef std::map<std::string, ServiceType*> SERVICETYPE_MAP;
                SERVICETYPE_MAP getServiceTypes() const { return serviceTypes; }; 
                                            
                /**
                 * Returns the reference types defined on this component.
                 * @return The reference types defined on this component.
                 */
                typedef std::map<std::string, ReferenceType*> REFERENCETYPE_MAP;
                REFERENCETYPE_MAP getReferenceTypes() const { return referenceTypes; };                
            
                /**
                 * Add a new property type to this component type. Property types are added
                 * one at a time. The property definitions usually come from a component type file.
                 * @param name The name of the property type.
                 * @param type The full name of the property data type (including uri and local name).
                 * @param many True if this is a many valued property.
                 * @param defaultValue The default value if the property does not have a
                 * value set.
                 */
                SCA_API virtual void addPropertyType(const std::string& name,
                    const std::string& type,
                    bool many,
                    commonj::sdo::DataObjectPtr* defaultValue);
    
                /**
                 * Find an existing property type on this component type.
                 * @param propertyName The name of the property type to find.
                 * @return The found property, or 0 if not found.
                 */
                SCA_API virtual const commonj::sdo::Property* findPropertyType(const std::string& propertyName);

                /**
                 * Return the SDO data factory which has the types of the properties defined
                 * in this component type.
                 * @return The data factory.
                 */
                SCA_API virtual commonj::sdo::DataFactoryPtr getPropertyDataFactory();

                /**
                 * Initialize a component of this type.
                 * @param component The component to initialize.
                 */
                SCA_API virtual void initializeComponent(Component* component);

            private:
            
                /**
                 * The name of the component type
                 */
                std::string name;
                
                /**
                 * The composite containing this component type
                 */
                 Composite* composite;
                
                /**
                 * Map of all the service types defined on this component.
                 */
                SERVICETYPE_MAP serviceTypes;

                /**
                 * Map of all the reference types defined on this component.
                 */
                REFERENCETYPE_MAP referenceTypes;

                /**
                 * SDO data factory which has all the types of the properties defined in
                 * this component type
                 */
                commonj::sdo::DataFactoryPtr propertyFactory;

           };

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

#endif // tuscany_sca_model_componenttype_h