1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
21 #include "RamlResource.h"
\r
26 std::string RamlResource::getDisplayName() const
\r
28 return m_displayName;
\r
30 void RamlResource::setDisplayName(const std::string &displayName)
\r
32 m_displayName = displayName;
\r
34 std::string RamlResource::getDescription() const
\r
36 return m_description;
\r
38 void RamlResource::setDescription(const std::string &description)
\r
40 m_description = description;
\r
42 std::string RamlResource::getParentUri() const
\r
46 void RamlResource::setParentUri(const std::string &parentUri)
\r
48 m_parentUri = parentUri;
\r
50 std::string RamlResource::getRelativeUri() const
\r
52 return m_relativeUri;
\r
54 void RamlResource::setRelativeUri(const std::string &relativeUri)
\r
56 m_relativeUri = relativeUri;
\r
58 std::map<std::string, UriParameterPtr> const &RamlResource::getUriParameters() const
\r
60 return m_uriParameters;
\r
62 void RamlResource::setUriParameter(const std::string ¶mName,
\r
63 const UriParameterPtr &uriParameter)
\r
65 m_uriParameters[paramName] = uriParameter;
\r
67 std::map<std::string, UriParameterPtr > const &RamlResource::getBaseUriParameters() const
\r
69 return m_baseUriParameters;
\r
71 void RamlResource::setBaseUriParameter(const std::string ¶mName,
\r
72 const UriParameterPtr &baseUriParameter)
\r
74 m_baseUriParameters[paramName] = baseUriParameter;
\r
76 ActionPtr RamlResource::getAction(ActionType actionType)
\r
78 return m_actions[actionType];
\r
81 std::map<ActionType , ActionPtr> const &RamlResource::getActions() const
\r
85 void RamlResource::setAction(const ActionType &actiontype , const ActionPtr &action )
\r
87 m_actions[actiontype] = action;
\r
89 std::map<std::string, std::shared_ptr<RamlResource> > const &RamlResource::getResources() const
\r
93 void RamlResource::setResource(const std::string &resourceName,
\r
94 const std::shared_ptr<RamlResource> &resources)
\r
96 m_resources[resourceName] = resources;
\r
98 std::list<std::string> const &RamlResource::getTraits() const
\r
102 void RamlResource::setTrait(const std::string &trait)
\r
104 m_traits.push_back(trait);
\r
106 std::string RamlResource::getResourceType() const
\r
108 return m_resourceType;
\r
110 void RamlResource::setResourceType(const std::string &type)
\r
112 m_resourceType = type;
\r
114 std::string RamlResource::getResourceUri() const
\r
116 return (m_parentUri + m_relativeUri);
\r
118 void RamlResource::readResource(const std::string resourceKey, const YAML::Node &yamlNode,
\r
119 const std::string &parentUri)
\r
121 m_relativeUri = resourceKey;
\r
122 m_parentUri = parentUri;
\r
123 for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )
\r
125 std::string key = READ_NODE_AS_STRING(it->first);
\r
127 if (key == Keys::DisplayName)
\r
128 setDisplayName(READ_NODE_AS_STRING(it->second));
\r
129 else if (key == Keys::Description)
\r
130 setDescription(READ_NODE_AS_STRING(it->second));
\r
131 else if (std::find(Keys::ActionType.begin(), Keys::ActionType.end(), key) !=
\r
132 Keys::ActionType.end())
\r
134 ActionType actionType = GET_ACTION_TYPE(key);
\r
136 setAction(actionType, std::make_shared<Action>(actionType, it->second,
\r
137 m_includeResolver));
\r
139 else if (key == Keys::UriParameters)
\r
141 YAML::Node paramNode = it->second;
\r
142 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )
\r
144 setUriParameter(READ_NODE_AS_STRING(tt->first),
\r
145 std::make_shared<UriParameter>(tt->second));
\r
148 else if (key == Keys::BaseUriParameters)
\r
150 YAML::Node paramNode = it->second;
\r
151 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )
\r
153 setBaseUriParameter(READ_NODE_AS_STRING(tt->first),
\r
154 std::make_shared<UriParameter>(tt->second));
\r
157 else if (key == Keys::IsTrait)
\r
159 YAML::Node traitNode = it->second;
\r
160 for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )
\r
162 setTrait(READ_NODE_AS_STRING(*tt));
\r
165 else if (key == Keys::Type)
\r
167 setResourceType(READ_NODE_AS_STRING(it->second));
\r
169 else if (key.compare(0, Keys::Resource.length(), Keys::Resource) == 0)
\r
171 setResource(key, std::make_shared<RamlResource>(key, it->second, m_includeResolver,
\r
172 getResourceUri()));
\r