1 /*
2 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #include "ComponentType.h"
31 #include "ComponentLibrary.h"
32 #include "TypeElement.h"
33 #include "XmlParameterSerializingContext.h"
34 #include <assert.h>
35
36 #define base CTypeElement
37
CComponentType(const std::string & strName)38 CComponentType::CComponentType(const std::string& strName) : base(strName), _pExtendsComponentType(NULL)
39 {
40 }
41
getKind() const42 std::string CComponentType::getKind() const
43 {
44 return "ComponentType";
45 }
46
childrenAreDynamic() const47 bool CComponentType::childrenAreDynamic() const
48 {
49 return true;
50 }
51
getMappingData(const std::string & strKey,const std::string * & pStrValue) const52 bool CComponentType::getMappingData(const std::string& strKey, const std::string*& pStrValue) const
53 {
54 // Try myself first then extended component type
55 return base::getMappingData(strKey, pStrValue) || (_pExtendsComponentType && _pExtendsComponentType->getMappingData(strKey, pStrValue));
56 }
57
hasMappingData() const58 bool CComponentType::hasMappingData() const
59 {
60 // Try myself first then extended component type
61 return base::hasMappingData() || (_pExtendsComponentType && _pExtendsComponentType->hasMappingData());
62 }
63
getFormattedMapping() const64 std::string CComponentType::getFormattedMapping() const
65 {
66 // Try myself first then associated component type
67 std::string strValue = base::getFormattedMapping();
68 if (_pExtendsComponentType) {
69
70 strValue += _pExtendsComponentType->getFormattedMapping();
71 }
72
73 return strValue;
74 }
75
fromXml(const CXmlElement & xmlElement,CXmlSerializingContext & serializingContext)76 bool CComponentType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
77 {
78 // Context
79 CXmlParameterSerializingContext& parameterBuildContext = static_cast<CXmlParameterSerializingContext&>(serializingContext);
80
81 const CComponentLibrary* pComponentLibrary = parameterBuildContext.getComponentLibrary();
82
83 // Populate children
84 if (!base::fromXml(xmlElement, serializingContext)) {
85
86 return false;
87 }
88
89 // Check for Extends attribute (extensions will be populated after and not before)
90 if (xmlElement.hasAttribute("Extends")) {
91
92 std::string strExtendsType = xmlElement.getAttributeString("Extends");
93
94 _pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType);
95
96 if (!_pExtendsComponentType) {
97
98 serializingContext.setError("ComponentType " + strExtendsType + " referred to by " + xmlElement.getPath() + " not found!");
99
100 return false;
101 }
102
103 if (_pExtendsComponentType == this) {
104
105 serializingContext.setError("Recursive ComponentType definition of " + xmlElement.getPath());
106
107 return false;
108 }
109 }
110
111 return true;
112 }
113
populate(CElement * pElement) const114 void CComponentType::populate(CElement* pElement) const
115 {
116 // Populate children
117 base::populate(pElement);
118
119 // Manage extended type
120 if (_pExtendsComponentType) {
121
122 // Populate from extended type
123 _pExtendsComponentType->populate(pElement);
124 }
125 }
126
doInstantiate() const127 CInstanceConfigurableElement* CComponentType::doInstantiate() const
128 {
129 // Not supposed to be called directly (instantiation made through CComponentInstance object)
130 assert(0);
131
132 return NULL;
133 }
134