• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
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) ||
56            (_pExtendsComponentType && _pExtendsComponentType->getMappingData(strKey, pStrValue));
57 }
58 
hasMappingData() const59 bool CComponentType::hasMappingData() const
60 {
61     // Try myself first then extended component type
62     return base::hasMappingData() ||
63            (_pExtendsComponentType && _pExtendsComponentType->hasMappingData());
64 }
65 
getFormattedMapping() const66 std::string CComponentType::getFormattedMapping() const
67 {
68     return base::getFormattedMapping(_pExtendsComponentType);
69 }
70 
fromXml(const CXmlElement & xmlElement,CXmlSerializingContext & serializingContext)71 bool CComponentType::fromXml(const CXmlElement &xmlElement,
72                              CXmlSerializingContext &serializingContext)
73 {
74     // Context
75     CXmlParameterSerializingContext &parameterBuildContext =
76         static_cast<CXmlParameterSerializingContext &>(serializingContext);
77 
78     const CComponentLibrary *pComponentLibrary = parameterBuildContext.getComponentLibrary();
79 
80     // Populate children
81     if (!base::fromXml(xmlElement, serializingContext)) {
82 
83         return false;
84     }
85 
86     // Check for Extends attribute (extensions will be populated after and not before)
87     if (xmlElement.hasAttribute("Extends")) {
88 
89         std::string strExtendsType;
90         xmlElement.getAttribute("Extends", strExtendsType);
91 
92         _pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType);
93 
94         if (!_pExtendsComponentType) {
95 
96             serializingContext.setError("ComponentType " + strExtendsType + " referred to by " +
97                                         xmlElement.getPath() + " not found!");
98 
99             return false;
100         }
101 
102         if (_pExtendsComponentType == this) {
103 
104             serializingContext.setError("Recursive ComponentType definition of " +
105                                         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 nullptr;
133 }
134