replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / jsonSchemaParser / JsonSchema.h
index fb300ba..15490d1 100755 (executable)
 #include <vector>\r
 #include <map>\r
 #include "Properties.h"\r
-#include "Items.h"\r
 #include "Definitions.h"\r
+#if defined (__TIZENRT__)\r
+#include <apps/netutils/cJSON.h>\r
+#else\r
 #include "cJSON.h"\r
-#include "Helpers.h"\r
-#include "AllowedValues.h"\r
+#endif\r
 #include <memory>\r
 \r
 #include "IncludeResolver.h"\r
@@ -52,14 +53,15 @@ namespace RAML
             /**\r
                   * Constructor of JsonSchema.\r
                   */\r
-            JsonSchema() : m_cjson(NULL), m_includeResolver(NULL)  {}\r
+            JsonSchema() : m_additionalProperties(cJSON_True), m_cjson(NULL), m_includeResolver(NULL)  {}\r
 \r
             /**\r
                   * Constructor of JsonSchema.\r
                   *\r
                   * @param includeResolver - Reference to IncludeResolver for reading external files\r
                   */\r
-            JsonSchema(const IncludeResolverPtr &includeResolver) : m_cjson(NULL),\r
+            JsonSchema(const IncludeResolverPtr &includeResolver) : m_additionalProperties(cJSON_True),\r
+                m_cjson(NULL),\r
                 m_includeResolver(includeResolver) {}\r
 \r
             /**\r
@@ -68,7 +70,8 @@ namespace RAML
                   * @param cjson - pointer to cjson\r
                   * @param includeResolver - Reference to IncludeResolver for reading external files\r
                   */\r
-            JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_cjson(cjson),\r
+            JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_additionalProperties(\r
+                    cJSON_True), m_cjson(cjson),\r
                 m_includeResolver(includeResolver)  { readJson(); }\r
 \r
 \r
@@ -96,7 +99,7 @@ namespace RAML
                  *\r
                  * @return pointer to Properties\r
                  */\r
-            inline PropertiesPtr getProperty(const std::string &name)\r
+            PropertiesPtr getProperty(const std::string &name)\r
             {\r
                 if (m_properties.end() != m_properties.find(name))\r
                 {\r
@@ -110,7 +113,7 @@ namespace RAML
                  *\r
                  * @return map of Properties name and pointer to Properties\r
                  */\r
-            inline std::map<std::string, PropertiesPtr > const &getProperties()\r
+            std::map<std::string, PropertiesPtr > const &getProperties()\r
             {\r
                 return m_properties;\r
             }\r
@@ -120,7 +123,7 @@ namespace RAML
                  *\r
                  * @return map of Definitions name and pointer to Definitions\r
                  */\r
-            inline std::map<std::string, DefinitionsPtr > const &getDefinitions()\r
+            std::map<std::string, DefinitionsPtr > const &getDefinitions()\r
             {\r
                 return m_definition;\r
             }\r
@@ -252,45 +255,56 @@ namespace RAML
                 return  m_additionalProperties;\r
             }\r
 \r
-            /**\r
-                 * This method is for setting Items to JsonSchema.\r
-                 *\r
-                 * @param item -pointer to Items\r
-                 */\r
-            void setItem(const ItemsPtr &item)\r
-            {\r
-                m_items.push_back(item);\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Items from JsonSchema.\r
-                 *\r
-                 * @return vector of Items\r
-                 */\r
-            std::vector<ItemsPtr> const &getItems()\r
+        private:\r
+            class JsonParameters\r
             {\r
-                return m_items;\r
-            }\r
+                public:\r
+                    std::map<std::string, PropertiesPtr > getProperties() const { return m_properties; }\r
+                    void addProperties(const std::string &name, const PropertiesPtr &prop) { m_properties[name] = prop; }\r
+                    void addProperties(const std::map<std::string, PropertiesPtr > &properties)\r
+                    {\r
+                        for (auto prop : properties)\r
+                            m_properties[prop.first] = prop.second;\r
+                    }\r
+                    std::vector<std::string> getRequired() const { return m_required; }\r
+                    void addRequired(const std::string &req) { m_required.push_back(req); }\r
+                    void addRequired(const std::vector<std::string> &required)\r
+                    {\r
+                        for (auto req : required)\r
+                            m_required.push_back(req);\r
+                    }\r
+                    std::string getType() const { return m_type; }\r
+                    void setType(const std::string &type)\r
+                    {\r
+                        if (m_type.empty())\r
+                            m_type = type;\r
+                    }\r
+\r
+                private:\r
+                    std::map<std::string, PropertiesPtr > m_properties;\r
+                    std::vector<std::string> m_required;\r
+                    std::string m_type;\r
+            };\r
 \r
-        private:\r
             void readJson();\r
             DefinitionsPtr readDef(cJSON *childDefinitions, const std::string &defName);\r
             PropertiesPtr readProp(cJSON *childProperties, const std::string &attName );\r
-            void readValues( cJSON *childProperties,  PropertiesPtr property ,\r
+            void readDefaultValue(cJSON *defaultValue,  PropertiesPtr &property, const std::string &attType);\r
+            void readAllowedValues(cJSON *allowedvalues,  PropertiesPtr &property, std::string &attType);\r
+            void readValues( cJSON *childProperties,  PropertiesPtr &property ,\r
                              const std::string &attType);\r
-            void readString( cJSON *childProperties, PropertiesPtr property);\r
-            void readArray( cJSON *childProperties,  PropertiesPtr property);\r
-            void readNumber( cJSON *childProperties,  PropertiesPtr property);\r
-            DefinitionsPtr readRef(std::string m_ref);\r
-\r
-\r
-            void readJsonRef(cJSON *jsonReference);\r
-            void readDefRef(cJSON *defReference, DefinitionsPtr definition);\r
-            void readAllOf(cJSON *allofValues);\r
-            void readDefAllOf(cJSON *allofValues, DefinitionsPtr definition);\r
-            ItemsPtr readItems(cJSON *item);\r
-            void readItemRef(cJSON *itemReference, ItemsPtr item);\r
-            void readItemAllOf(cJSON *allofValues,  ItemsPtr item);\r
+            void readString( cJSON *childProperties, PropertiesPtr &property);\r
+            void readInteger( cJSON *childProperties,  PropertiesPtr &property);\r
+            void readDouble( cJSON *childProperties,  PropertiesPtr &property);\r
+            void readArray( cJSON *childProperties,  PropertiesPtr &property);\r
+            void readItems(cJSON *item, PropertiesPtr &property);\r
+            void readObject(cJSON *childProperties,  PropertiesPtr &property);\r
+\r
+            void readFile(std::string &fileName , JsonParameters &param);\r
+            void readFile(std::string &fileName , std::string &defName , JsonParameters &param);\r
+            void readRef(std::string ref , JsonParameters &param);\r
+            void readJsonRef(cJSON *jsonReference , JsonParameters &param);\r
+            void readAllOf(cJSON *allofValues ,  JsonParameters &allParams);\r
 \r
         private:\r
             std::map<std::string, PropertiesPtr > m_properties;\r
@@ -303,8 +317,9 @@ namespace RAML
             std::string m_type;\r
             cJSON *m_cjson;\r
             std::vector<std::string>  m_required;\r
-            std::vector<ItemsPtr > m_items;\r
+            PropertiesPtr m_property;\r
             IncludeResolverPtr m_includeResolver;\r
+\r
     };\r
 \r
     /** JsonSchemaPtr - shared Ptr to JsonSchema.*/\r