X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Framlparser%2Framl%2Fmodel%2FRaml.h;h=482919b80cef9459fb2ded5f9c7545a01f8bc2fe;hb=refs%2Ftags%2Fsubmit%2Ftizen_4.0%2F20171010.021147;hp=c3c537c1690385852ca37b0f1a7dd2cd5ad09da7;hpb=f156a5121851f45a6f803be854197d5d3c6184e2;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/ramlparser/raml/model/Raml.h b/service/simulator/ramlparser/raml/model/Raml.h index c3c537c..482919b 100755 --- a/service/simulator/ramlparser/raml/model/Raml.h +++ b/service/simulator/ramlparser/raml/model/Raml.h @@ -8,7 +8,7 @@ * 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 + * 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, @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Raml.h + * + * @brief This file provides data Model for RAML file. + */ + #ifndef RAML_H #define RAML_H @@ -40,68 +46,259 @@ #include "DocumentationItem.h" #include "yaml-cpp/yaml.h" -#include "Utils.h" +#include "yaml-cpp/exceptions.h" +#include "RamlExceptions.h" +#include "RamlUtils.h" +#if defined (__TIZENRT__) +#include +#else #include "cJSON.h" +#endif namespace RAML { + /** + * @class Raml + * @brief This class provides data Model for RAML file. + */ class Raml { public: + /** + * This method is for getting Title from Raml. + * + * @return Title as string. + */ virtual std::string getTitle() const; + + /** + * This method is for setting Title to Raml. + * + * @param title - Title as string + */ virtual void setTitle(const std::string &title); + /** + * This method is for getting Version from Raml. + * + * @return Version as string. + */ virtual std::string getVersion() const; + + /** + * This method is for setting Version to Raml. + * + * @param version - Version as string + */ virtual void setVersion(const std::string &version); + /** + * This method is for getting BaseUri from Raml. + * + * @return BaseUri as string. + */ virtual std::string getBaseUri() const; + + /** + * This method is for setting BaseUri to Raml. + * + * @param baseUri - BaseUri as string + */ virtual void setBaseUri(const std::string &baseUri); - virtual std::list getProtocols() const; + /** + * This method is for getting Protocols from Raml. + * + * @return list of Protocols as string. + */ + virtual std::list const &getProtocols() const; + + /** + * This method is for setting Protocols to Raml. + * + * @param protocol - Protocol as string + */ virtual void setProtocol(const std::string &protocol); - virtual std::map getBaseUriParameters() const; - virtual void setBaseUriParameter(const std::string ¶mName, const UriParameter &uriParameter); + /** + * This method is for getting BaseUriParameter from Raml. + * + * @return map of BaseUriParameter name and Pointer to UriParameter. + */ + virtual std::map const &getBaseUriParameters() const; + + /** + * This method is for setting BaseUriParameter to Raml. + * + * @param paramName - name of BaseUriParameter as string + * @param uriParameter - pointer to UriParameter + */ + virtual void setBaseUriParameter(const std::string ¶mName, + const UriParameterPtr &uriParameter); + + /** + * This method is for getting MediaType from Raml. + * + * @return Title as string. + */ virtual std::string getMediaType() const; + + /** + * This method is for setting MediaType to Raml. + * + * @param mediaType - MediaType as string + */ virtual void setMediaType(const std::string &mediaType); - virtual std::list > getSchemas() const; - virtual void setSchema(const std::pair &schema); + /** + * This method is for getting Schemas from Raml. + * + * @return list of Schemas name and Pointer to Schema as pair. + */ + virtual std::list > const &getSchemas() const; + + /** + * This method is for setting Schemas to Raml. + * + * @param schemaName - name of schema as string + * @param schema - pointer to Schema + */ + virtual void setSchema(const std::string &schemaName, const SchemaPtr &schema); + + /** + * This method is for getting ResourceTypes from Raml. + * + * @return list of ResourceTypes name and Pointer to RamlResource as pair. + */ + virtual std::list > const &getResourceTypes() const; + + /** + * This method is for setting ResourceTypes to Raml. + * + * @param typeName - name of ResourceType as string + * @param resourceType - pointer to RamlResource + */ + virtual void setResourceType(const std::string &typeName, + const RamlResourcePtr &resourceType); + + /** + * This method is for getting Traits from Raml. + * + * @return list of Traits name and Pointer to Action as pair. + */ + virtual std::list > const &getTraits() const; - virtual std::list > getResourceTypes() const; - virtual void setResourceType(const std::pair &resourceType); + /** + * This method is for setting Traits to Raml. + * + * @param traitName - name of Trait as string + * @param trait - pointer to Action + */ + virtual void setTrait(const std::string &traitName, const ActionPtr &trait); - virtual std::list > getTraits() const; - virtual void setTrait(const std::pair &trait); + /** + * This method is for getting Resource from Raml. + * + * @param resourceName - name of Resource as string + * + * @return Pointer to Resource + */ + virtual RamlResourcePtr getResource(const std::string &resourceName); - virtual RamlResource &getResource(std::string resourceName); - virtual std::map getResources() const; - virtual void setResource(const std::string &resourceKey, const RamlResource &resource); + /** + * This method is for getting Resource from Raml. + * + * @return map of Resource name and Pointer to Resource + */ + virtual std::map const &getResources() const; - virtual void setDocumentationItem(const DocumentationItem &documentationItem); - virtual std::list getDocumentation() const; + /** + * This method is for setting Resource to Raml. + * + * @param resourceKey - name of Resource as string + * @param resource - pointer to Resource + */ + virtual void setResource(const std::string &resourceKey, + const RamlResourcePtr &resource); + /** + * This method is for setting DocumentationItem to Raml. + * + * @param documentationItem - pointer to DocumentationItem + */ + virtual void setDocumentationItem(const std::shared_ptr &documentationItem); + + /** + * This method is for getting DocumentationItem from Raml. + * + * @return list of DocumentationItem + */ + virtual std::list > const &getDocumentation() const; + + /** + * This method is for setting Raml object reading from Yaml nodes + * + * @param yamlNode - Reference to YamlNode for reading into Raml object + */ void readRamlFromYaml(const YAML::Node &yamlNode); - Raml() : m_includeResolver(new IncludeResolver()) {} - Raml(std::string &resourceLocation) : m_includeResolver(new IncludeResolver(resourceLocation)) {} + + /** + * Constructor of Raml. + */ + Raml() : m_includeResolver(std::make_shared()) {} + + /** + * Constructor of Raml. + * + * @param fileLocation - RAML configuration file path. + * @param ramlName - RAML configuration file Name + * + * NOTE: Constructor would throw RamlException if any error occured. + */ + Raml(const std::string &fileLocation, const std::string &ramlName) + : m_includeResolver(std::make_shared(fileLocation)) + { + try + { + YAML::Node yamlRootNode = YAML::LoadFile(fileLocation + ramlName); + readRamlFromYaml(yamlRootNode); + } + catch (YAML::ParserException &e) + { + throw RamlParserException(e.mark, e.msg); + } + catch (YAML::RepresentationException &e) + { + throw RamlRepresentationException(e.mark, e.msg); + } + catch (YAML::BadFile &e) + { + throw RamlBadFile(e.mark, e.msg); + } + catch (JsonException &e) + { + throw; + } + } private: std::string m_title; std::string m_version; std::string m_baseUri; std::list m_protocols; - std::map m_baseUriParameters; + std::map m_baseUriParameters; std::string m_mediaType; - std::list > m_schemas; - std::list > m_resourceTypes; - std::list > m_traits; - std::map m_resources; - std::list m_documentation; - IncludeResolver *m_includeResolver; + std::list > m_schemas; + std::list > m_resourceTypes; + std::list > m_traits; + std::map m_resources; + std::list > m_documentation; + IncludeResolverPtr m_includeResolver; }; + /** RamlPtr - shared Ptr to Raml.*/ typedef std::shared_ptr RamlPtr; }