Adding JsonSchema parser implementation for simulator and Updating Raml Parser.
authorAbitha Shankar <abitha.s@samsung.com>
Sun, 13 Sep 2015 14:21:16 +0000 (19:51 +0530)
committerUze Choi <uzchoi@samsung.com>
Mon, 14 Sep 2015 10:18:05 +0000 (10:18 +0000)
1. source code for Json Schema parsing logic.
2. updating Raml Parser to read all child resources, types and Traits.
3. added smart pointer implemetation for Raml Parser.

Change-Id: I3565b97e8d8ef78f98841469a17230e64112370f
Signed-off-by: Abitha Shankar <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2479
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
46 files changed:
service/simulator/SConscript [changed mode: 0644->0755]
service/simulator/examples/README.txt
service/simulator/examples/resources/light.raml [deleted file]
service/simulator/examples/resources/oic.light.json [deleted file]
service/simulator/ramlparser/SConscript
service/simulator/ramlparser/example/SConscript [new file with mode: 0755]
service/simulator/ramlparser/example/raml_parser.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/IncludeResolver.cpp
service/simulator/ramlparser/raml/IncludeResolver.h
service/simulator/ramlparser/raml/RamlErrorCodes.h [new file with mode: 0755]
service/simulator/ramlparser/raml/RamlExceptions.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/RamlExceptions.h [new file with mode: 0755]
service/simulator/ramlparser/raml/RamlParser.cpp
service/simulator/ramlparser/raml/RamlParser.h
service/simulator/ramlparser/raml/Utils.h
service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Items.h [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/AbstractParam.cpp
service/simulator/ramlparser/raml/model/AbstractParam.h
service/simulator/ramlparser/raml/model/Action.cpp
service/simulator/ramlparser/raml/model/Action.h
service/simulator/ramlparser/raml/model/ActionType.h
service/simulator/ramlparser/raml/model/DocumentationItem.cpp
service/simulator/ramlparser/raml/model/DocumentationItem.h
service/simulator/ramlparser/raml/model/FormParameter.h
service/simulator/ramlparser/raml/model/Header.h
service/simulator/ramlparser/raml/model/QueryParameter.h
service/simulator/ramlparser/raml/model/Raml.cpp
service/simulator/ramlparser/raml/model/Raml.h
service/simulator/ramlparser/raml/model/RamlResource.cpp
service/simulator/ramlparser/raml/model/RamlResource.h
service/simulator/ramlparser/raml/model/RequestResponseBody.cpp
service/simulator/ramlparser/raml/model/RequestResponseBody.h
service/simulator/ramlparser/raml/model/ResourceProperties.cpp [deleted file]
service/simulator/ramlparser/raml/model/ResourceProperties.h [deleted file]
service/simulator/ramlparser/raml/model/Response.cpp
service/simulator/ramlparser/raml/model/Response.h
service/simulator/ramlparser/raml/model/Schema.cpp
service/simulator/ramlparser/raml/model/Schema.h
service/simulator/ramlparser/raml/model/UriParameter.h
service/simulator/src/simulator_resource_creator.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index ce9a46c..7ebb8f1
@@ -29,6 +29,9 @@ lib_env = env.Clone()
 SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
 simulator_env = lib_env.Clone()
 
+#Raml Parser
+SConscript('ramlparser/SConscript')
+
 target_os = env.get('TARGET_OS')
 ######################################################################
 # Build flags
@@ -42,6 +45,7 @@ simulator_env.AppendUnique(CPPPATH = [
                '../../resource/oc_logger/include',
                './ramlparser/raml',
                './ramlparser/raml/model',              
+               './ramlparser/raml/jsonSchemaParser',   
                '../../extlibs/yaml/yaml/include'
                ])
 
@@ -80,5 +84,3 @@ simulator_env.InstallTarget(simulatorsdk, 'libSimulator')
 #Build sample application
 SConscript('examples/server/SConscript')
 SConscript('examples/client-controller/SConscript')
-#Raml Parser
-SConscript('ramlparser/SConscript')
index 1bec229..f0ab383 100755 (executable)
@@ -1,3 +1,3 @@
 Command to run Service Provider with Resource definitions provided throught RAML file :\r
-./simulator-server  ../../../../../../../../service/simulator/examples/resources/light.raml\r
+./simulator-server  PATH-TO-RAML-FILE\r
 \r
diff --git a/service/simulator/examples/resources/light.raml b/service/simulator/examples/resources/light.raml
deleted file mode 100755 (executable)
index db3e037..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#%RAML 0.8
-#RAML for Light Resource
-title: Resource Light
-version: 1.0
-mediaType : application/json
-schemas:
-- 
-  lightPublish: !include oic.light.json
-
-/oic/light:
-  displayName: Resource Light
-  description: |
-    Resource to be exposed by any OIC Device that can act as Light
-  get:
-    description: |
-      Get the attributes of light
-    responses:
-      200:
-        description: |
-          Respond with the selector criteria
-        body:
-          application/json:
-            schema: !include oic.light.json
-            example: |
-              {
-              
-              }
\ No newline at end of file
diff --git a/service/simulator/examples/resources/oic.light.json b/service/simulator/examples/resources/oic.light.json
deleted file mode 100755 (executable)
index fd27af8..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-{\r
-  "title": "light",\r
-  "rt": "oic.light",\r
-  "if": "oic.if.baseline",\r
-  "properties": {\r
-    "power": {\r
-      "type": "string",\r
-      "description": "Light status",\r
-      "values": ["on","off"],\r
-      "default": "on",\r
-      "update_frequency": 1000\r
-    },\r
-    "intensity": {\r
-      "type": "integer",\r
-      "description": "brightness of the light",\r
-      "range": [1,9],\r
-      "default": 1,\r
-      "update_frequency": 1001\r
-    }\r
-  }\r
-}
\ No newline at end of file
index 51e8fdd..0a4aa6e 100755 (executable)
@@ -28,7 +28,7 @@ raml_env = lib_env.Clone()
 # Build flags\r
 ######################################################################\r
 raml_env.AppendUnique(CPPPATH = ['../../../extlibs/timer'])\r
-raml_env.AppendUnique(CPPPATH = ['raml/model','raml', '../../../extlibs/yaml/yaml/src' , '../../../extlibs/yaml/yaml/include'])\r
+raml_env.AppendUnique(CPPPATH = ['raml/model','raml/jsonSchemaParser','raml', '../../../extlibs/yaml/yaml/src' , '../../../extlibs/yaml/yaml/include'])\r
 raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
 raml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
 \r
@@ -41,10 +41,10 @@ raml_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-
 ######################################################################\r
 # Source files and Targets\r
 ######################################################################\r
-raml_src = [env.Glob('raml/model/*.cpp'), env.Glob('raml/*.cpp')]\r
+raml_src = [env.Glob('raml/model/*.cpp'), env.Glob('raml/jsonSchemaParser/*.cpp'), env.Glob('raml/*.cpp')]\r
 ramlsdk = raml_env.SharedLibrary('RamlParser', raml_src)\r
 \r
 raml_env.InstallTarget(ramlsdk, 'libRaml')\r
 \r
 SConscript('../../../extlibs/yaml/SConscript')\r
-\r
+SConscript('example/SConscript')\r
diff --git a/service/simulator/ramlparser/example/SConscript b/service/simulator/ramlparser/example/SConscript
new file mode 100755 (executable)
index 0000000..f26a3c4
--- /dev/null
@@ -0,0 +1,30 @@
+import os\r
+Import('env')\r
+lib_env = env.Clone()\r
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')\r
+raml_env = lib_env.Clone()\r
+\r
+######################################################################\r
+# Build flags\r
+######################################################################\r
+raml_env.AppendUnique(CPPPATH = ['../../../../extlibs/timer'])\r
+raml_env.AppendUnique(CPPPATH = ['../raml/model','../raml/jsonSchemaParser', '../raml' , '../../../../extlibs/yaml/yaml/src' , '../../../../extlibs/yaml/yaml/include'])\r
+raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
+raml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
+\r
+raml_env.AppendUnique(CPPPATH = ['../../../../extlibs/cjson/'])\r
+raml_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])\r
+raml_env.AppendUnique(LIBS = ['pthread'])\r
+raml_env.PrependUnique(LIBS = ['RamlParser','YamlParser'])\r
+\r
+raml_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])\r
+raml_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])\r
+\r
+if raml_env.get('SECURED') == '1':\r
+    raml_env.AppendUnique(LIBS = ['tinydtls'])\r
+######################################################################\r
+# Source files and Targets\r
+######################################################################\r
+raml_parser = raml_env.Program('raml-parser', 'raml_parser.cpp')\r
+\r
+env.AppendTarget('raml_parser')\r
diff --git a/service/simulator/ramlparser/example/raml_parser.cpp b/service/simulator/ramlparser/example/raml_parser.cpp
new file mode 100755 (executable)
index 0000000..9ff56f7
--- /dev/null
@@ -0,0 +1,411 @@
+#include "RamlParser.h"\r
+#include <iostream>\r
+#include <string>\r
+\r
+//#define PRINT_PARAMS\r
+//#define PRINT_PROTOCOLS\r
+//#define PRINT_BASEURI\r
+//#define PRINT_DOCUMENTATION\r
+//#define PRINT_TYPES\r
+//#define PRINT_TRAITS\r
+//#define PRINT_RESOURCE_URI_BASEURI\r
+//#define PRINT_ACTION_QUERY_PARAM\r
+//#define PRINT_RESPONSE_HEADER\r
+//#define PRINT_REQUEST_RESPONSE_BODY_PARAMS\r
+//#define PRINT_ACTION_HEADERS\r
+//#define PRINT_SCHEMAS\r
+#define PRINT_RAML\r
+#define PRINT_JSON\r
+//#define PRINT_JSON_PROPERTIES\r
+\r
+using namespace RAML;\r
+\r
+void printParameters(AbstractParam abstractParam)\r
+{\r
+\r
+#ifdef PRINT_PARAMS\r
+    std::cout << "Description : "  << abstractParam.getDescription()  << std::endl;\r
+    std::cout << "DefaultValue : "  << abstractParam.getDefaultValue()  << std::endl;\r
+    std::cout << "Example : " << abstractParam.getExample()  << std::endl;\r
+    std::cout << "displayName : "  << abstractParam.getDisplayName()  << std::endl;\r
+    std::cout << "Maxlength : "  << abstractParam.getMaxLength()  << std::endl;\r
+    std::cout << "Max : "  << abstractParam.getMaximum()  << std::endl;\r
+    std::cout << "Minlength : "  << abstractParam.getMinLength()  << std::endl;\r
+    std::cout << "Min : "  << abstractParam.getMinimum()  << std::endl;\r
+    std::cout << "Pattern : "  << abstractParam.getPattern()  << std::endl;\r
+    std::cout << "Type : "  << abstractParam.getType()  << std::endl;\r
+    std::cout << "Repeat : "  << abstractParam.isRepeat()  << std::endl;\r
+    std::cout << "Required : "  << abstractParam.isRequired()  << std::endl;\r
+    std::cout << "Enum : "   ;\r
+    for (auto elem : abstractParam.getEnumeration())\r
+        std::cout << elem   << "       ";\r
+    std::cout << std::endl;\r
+#endif\r
+}\r
+\r
+void printRequestResponseBody(const RequestResponseBodyPtr &body)\r
+{\r
+    std::cout << "Body : Type : " << body->getType() << std::endl;\r
+    if ( body->getSchema() == NULL ) return;\r
+    std::cout << "Body : Schema : " << body->getSchema()->getSchema() << std::endl;\r
+    std::cout << "Body : Schema : PROPERTIES :" << std::endl;\r
+\r
+    for ( auto pro : body->getSchema()->getProperties()->getProperties() )\r
+    {\r
+        std::cout << "Name : " << pro.second->getName() << std::endl;\r
+        std::cout << "default : " << pro.second->getValue() << std::endl;\r
+        std::cout << "update_frequency : " << pro.second->getUpdateFrequencyTime() << std::endl;\r
+        int min = 0, max = 0, multipleOf = 0;\r
+        pro.second->getRange(min, max, multipleOf);\r
+\r
+        std::cout << "range_min : " << min << std::endl;\r
+        std::cout << "range_max : " << max << std::endl;\r
+        std::cout << "allowed values : "  << std::endl;\r
+        for (auto v :  pro.second->getAllowedValues())\r
+            std::cout <<  v << "    ";\r
+        std::cout << std::endl;\r
+\r
+    }\r
+    std::cout << "Body : example : " << body->getExample() << std::endl;\r
+\r
+#ifdef PRINT_REQUEST_RESPONSE_BODY_PARAMS\r
+    std::cout << "Body : FormParameters        "  << std::endl;\r
+    for (auto  tw : body->getFormParameters())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tw.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        FormParameter formParameter = *tw.second;\r
+        printParameters((AbstractParam)formParameter);\r
+    }\r
+#endif\r
+}\r
+\r
+\r
+void printResponse(const ResponsePtr &response)\r
+{\r
+    std::cout << "#############################################" << std::endl;\r
+    std::cout << "Response : Description : " << response->getDescription() << std::endl;\r
+\r
+    for (auto  tv :  response->getResponseBody())\r
+        printRequestResponseBody(tv.second);\r
+#ifdef PRINT_RESPONSE_HEADER\r
+    std::cout << "Header" << std::endl;\r
+    for (auto  tw :  response->getHeaders())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tw.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+\r
+        Header header = *tw.second;\r
+        printParameters((AbstractParam)header);\r
+    }\r
+#endif\r
+}\r
+\r
+void printAction(const ActionPtr &action)\r
+{\r
+    std::cout << "Description : " << action->getDescription() << std::endl;\r
+    std::cout << "----Action Body--------------" << std::endl;\r
+    for (auto  tv :  action->getRequestBody())\r
+        printRequestResponseBody(tv.second);\r
+    std::cout << "-----------------------------" << std::endl;\r
+    std::cout << "Responses    " << std::endl;\r
+    for (auto  tu :  action->getResponses())\r
+    {\r
+        std::cout << "Response : " << tu.first << std::endl;\r
+        printResponse(tu.second);\r
+    }\r
+#ifdef PRINT_ACTION_QUERY_PARAM\r
+    std::cout << "QueryParameter" << std::endl;\r
+    for (auto  tw :  action->getQueryParameters())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tw.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        QueryParameter queryParam = *tw.second;\r
+        printParameters((AbstractParam)queryParam);\r
+    }\r
+#endif\r
+#ifdef PRINT_ACTION_HEADERS\r
+    std::cout << "Headers" << std::endl;\r
+    for (auto  tw :  action->getHeaders())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tw.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        Header header = *tw.second;\r
+        printParameters((AbstractParam)header);\r
+    }\r
+#endif\r
+\r
+#ifdef PRINT_TRAITS\r
+\r
+    std::cout << "Traits  " << std::endl;\r
+    std::cout << "-----------------------------" << std::endl;\r
+    for (auto  tt :  action->getTraits())\r
+    {\r
+        std::cout << tt  << "     ";\r
+    }\r
+    std::cout << std::endl << "-----------------------------" << std::endl;\r
+#endif\r
+}\r
+\r
+void printResource(const RamlResourcePtr &resource)\r
+{\r
+    std::cout << "Displayname : " << resource->getDisplayName()   << std::endl;\r
+    std::cout << "Description : " << resource->getDescription()   << std::endl;\r
+#ifdef PRINT_RESOURCE_URI_BASEURI\r
+    std::cout << "#############################################" << std::endl;\r
+    std::cout << "ResourceURI  "   << resource->getResourceUri() << std::endl;\r
+    std::cout << "UriParameters        "    << std::endl;\r
+    for (auto  tt :  resource->getUriParameters())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tt.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        UriParameter uriParameter = *tt.second;\r
+        printParameters((AbstractParam)uriParameter);\r
+    }\r
+    std::cout << "#############################################" << std::endl;\r
+    std::cout << "BaseUriParameters    "    << std::endl;\r
+    for (auto  tt :  resource->getBaseUriParameters())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << tt.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+\r
+        UriParameter uriParameter = *tt.second;\r
+        printParameters((AbstractParam)uriParameter);\r
+    }\r
+#endif\r
+    std::cout << "Actions  " << std::endl;\r
+    for (auto  tt :  resource->getActions())\r
+    {\r
+        std::cout << "#############################################" << std::endl;\r
+        std::cout << "ActionsType  " << std::endl;\r
+        printAction(tt.second);\r
+    }\r
+#ifdef PRINT_TRAITS\r
+    std::cout << "Traits  " << std::endl;\r
+    std::cout << "-----------------------------" << std::endl;\r
+    for (auto  tt :  resource->getTraits())\r
+    {\r
+        std::cout << tt  << "     ";\r
+    }\r
+    std::cout << std::endl << "-----------------------------" << std::endl;\r
+#endif\r
+    std::cout << "Number of Child Resource for " << resource->getDisplayName() << " : " <<\r
+              resource->getResources().size() << std::endl;\r
+\r
+    for (auto  tt :  resource->getResources())\r
+    {\r
+        std::cout << "Child Resource" << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << "ResourceName :" << tt.first << std::endl;\r
+        printResource(tt.second);\r
+    }\r
+\r
+}\r
+void printProperties(Properties *prop)\r
+{\r
+#ifdef PRINT_JSON_PROPERTIES\r
+    std::cout << "-------------------------------" << std::endl;\r
+#endif\r
+    std::cout << "Name: " << prop->getName() << std::endl;\r
+#ifdef PRINT_JSON_PROPERTIES\r
+    std::cout << "-------------------------------" << std::endl;\r
+    std::cout << "Type: " << prop->getType() << std::endl;\r
+    std::cout << "Description: " << prop->getDescription() << std::endl;\r
+    int type = prop->getValueType();\r
+    if (type)\r
+    {\r
+        std::cout << "Defaut: " << prop->getValueString() << std::endl;\r
+        for (auto tt : prop->getAllowedValuesString())\r
+        {\r
+            std::cout << "enum value : " << tt << std::endl;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        std::cout << "Defaut: " << prop->getValueInt() << std::endl;\r
+        for (auto tt : prop->getAllowedValuesString())\r
+        {\r
+            std::cout << "enum value : " << tt << std::endl;\r
+        }\r
+    }\r
+    if (prop->getType() == "array")\r
+    {\r
+        for (auto it : prop->getItems())\r
+        {\r
+            std::cout << "items Type : " << it->getType() << std::endl;\r
+            if (it->getType() == "string")\r
+                for (auto tt : it->getAllowedValuesString())\r
+                {\r
+                    std::cout << "enum value : " << tt << std::endl;\r
+                }\r
+        }\r
+    }\r
+    int min = 0, max = 0, mul = 0;\r
+    prop->getRange(min, max, mul);\r
+    std::cout << "Minimum: " << min << std::endl;\r
+    std::cout << "Maximum: " << max << std::endl;\r
+    std::cout << "MultipleOf: " << mul << std::endl;\r
+#endif\r
+\r
+}\r
+void printJsonSchema(JsonSchemaPtr js)\r
+{\r
+    std::cout << "##############################" << std::endl;\r
+    std::cout << "------JSON Schema Parser------" << std::endl;\r
+    std::cout << "##############################" << std::endl;\r
+\r
+    std::cout << "Id: " << js->getId() << std::endl;\r
+    std::cout << "Schema: " << js->getSchema() << std::endl;\r
+    std::cout << "Title: " << js->getTitle() << std::endl;\r
+    std::cout << "Type: " << js->getType() << std::endl;\r
+    std::cout << "Description: " << js->getDescription() << std::endl;\r
+    std::cout << "AdditionalProperties: " << js->getAdditionalProperties() << std::endl;\r
+\r
+    std::cout << "-------------------------------" << std::endl;\r
+    std::cout << "Definitions." << std::endl;\r
+    for (auto  tt : js->getDefinitions())\r
+    {\r
+        std::cout << "-------------------------------" << std::endl;\r
+        std::cout << tt.first << std::endl;\r
+        for (auto  it : tt.second->getProperties())\r
+        {\r
+            printProperties(it.second);\r
+        }\r
+    }\r
+\r
+    std::cout << "##############################" << std::endl;\r
+    std::cout << "Properties." << std::endl;\r
+    for (auto  it : js->getProperties())\r
+    {\r
+        printProperties(it.second);\r
+    }\r
+    std::cout << "-------------------------------" << std::endl;\r
+    std::cout << "Required." << std::endl;\r
+    std::cout << "-------------------------------" << std::endl;\r
+    for (auto it : js->getRequiredValues())\r
+    {\r
+        std::cout << it << std::endl;\r
+    }\r
+    std::cout << "-------------------------------" << std::endl;\r
+}\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+    if (argc == 1)\r
+    {\r
+        return 0;\r
+    }\r
+    char *value = argv[1];\r
+    std::string s(value);\r
+\r
+    RamlParser *ramlParser = new RamlParser(s);\r
+    RamlPtr m_raml = ramlParser->getRamlPtr();\r
+#ifdef PRINT_RAML\r
+\r
+    std::cout << "#############################################" << std::endl;\r
+    std::cout << "Test Raml Parser" << std::endl;\r
+    std::cout << "#############################################" << std::endl;\r
+\r
+    std::cout << "Title : " << m_raml->getTitle() << std::endl;\r
+    std::cout << "Version : " <<  m_raml->getVersion() << std::endl;\r
+#ifdef PRINT_PROTOCOLS\r
+    std::cout << "Protocols : "   ;\r
+    for (auto  it : m_raml->getProtocols())\r
+    {\r
+        std::cout << it  << "     ";\r
+    }\r
+\r
+    std::cout << std::endl;\r
+#endif\r
+#ifdef PRINT_BASEURI\r
+    std::cout << "BaseUri : " <<  m_raml->getBaseUri() << std::endl;\r
+\r
+    std::cout << "BaseUriParameters : " << std::endl;\r
+    for (auto  it : m_raml->getBaseUriParameters())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << it.first << " : "  << std::endl;\r
+        std::cout << "-----------------------------" << std::endl;\r
+        UriParameter uriParameter = *it.second;\r
+        printParameters((AbstractParam)uriParameter);\r
+    }\r
+#endif\r
+#ifdef PRINT_SCHEMAS\r
+    std::cout << "#############################################" << std::endl;\r
+    std::cout << "Schemas" << std::endl;\r
+    std::cout << "-----------------------------" << std::endl;\r
+    for (auto  it : m_raml->getSchemas())\r
+    {\r
+        std::cout << it.first   << " : " << it.second->getSchema() << std::endl;\r
+    }\r
+#endif\r
+    std::cout << "MediaType : " <<  m_raml->getMediaType() << std::endl;\r
+    std::cout << "#############################################" << std::endl;\r
+#ifdef PRINT_DOCUMENTATION\r
+    std::cout << "#############################################" << std::endl;\r
+\r
+    std::cout << "Documentation" << std::endl;\r
+    std::cout << "-----------------------------" << std::endl;\r
+    for (auto  it : m_raml->getDocumentation())\r
+    {\r
+        std::cout << it->getTitle() << " : " << it->getContent() << std::endl;\r
+    }\r
+    std::cout << "#############################################" << std::endl;\r
+#endif\r
+\r
+    std::cout << "Resources" << std::endl;\r
+    for (auto  it : m_raml->getResources())\r
+    {\r
+        std::cout << "-----------------------------" << std::endl;\r
+        std::cout << "ResourceName :" << it.first << std::endl;\r
+        printResource(it.second);\r
+    }\r
+#ifdef PRINT_TYPES\r
+\r
+    std::cout << "#############################################" << std::endl;\r
+\r
+    std::cout << "ResourceTypes " << std::endl;\r
+    for (auto  it : m_raml->getResourceTypes())\r
+    {\r
+        std::cout << "------------" << it.first << "-----------------" << std::endl;\r
+        printResource(it.second);\r
+    }\r
+#endif\r
+#ifdef PRINT_TRAITS\r
+\r
+    std::cout << "#############################################" << std::endl;\r
+\r
+    std::cout << "Traits " << std::endl;\r
+    for (auto  it : m_raml->getTraits())\r
+    {\r
+        std::cout << "-------------" << it.first << "----------------" << std::endl;\r
+        printAction(it.second);\r
+    }\r
+#endif\r
+#endif\r
+#ifdef PRINT_JSON\r
+    for (auto  it : m_raml->getResources())\r
+    {\r
+        for (auto  tt :  it.second->getActions())\r
+        {\r
+            for (auto  tu :  tt.second->getResponses())\r
+            {\r
+                for (auto  tv :  tu.second->getResponseBody())\r
+                {\r
+                    auto pro = tv.second->getSchema()->getProperties();\r
+                    printJsonSchema(pro);\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+    }\r
+#endif\r
+\r
+}\r
+\r
index 6065224..0dbf0bb 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -26,8 +26,27 @@ namespace RAML
     YAML::Node IncludeResolver::readToYamlNode(const YAML::Node &yamlFile )\r
     {\r
         std::string value = yamlFile.as<std::string>();\r
-        YAML::Node yamlInclueNode = YAML::LoadFile(value);\r
-        return yamlInclueNode;\r
+        try\r
+        {\r
+            YAML::Node yamlInclueNode = YAML::LoadFile(value);\r
+            return yamlInclueNode;\r
+        }\r
+        catch (YAML::ParserException &e)\r
+        {\r
+            throw RamlParserException(e.mark, e.msg);\r
+        }\r
+        catch (YAML::RepresentationException &e)\r
+        {\r
+            throw RamlRepresentationException(e.mark, e.msg);\r
+        }\r
+        catch (YAML::BadFile &e)\r
+        {\r
+            throw RamlBadFile(e.mark, e.msg);\r
+        }\r
+        catch (JsonException &e)\r
+        {\r
+            throw;\r
+        }\r
     }\r
 \r
     IncludeResolver::FileType IncludeResolver::getFileType(const YAML::Node &yamlNode )\r
@@ -64,10 +83,20 @@ namespace RAML
         std::string val = file.as<std::string>();\r
         std::ifstream fin((m_path + val).c_str());\r
         if (!fin)\r
-            throw std::runtime_error("Error Include File not present ");\r
+            throw RamlParserException("Error Include File not present " + m_path + val);\r
         std::stringstream buffer;\r
         buffer << fin.rdbuf();\r
         return buffer.str();\r
     }\r
+    cJSON *IncludeResolver::readToJson(const std::string &jsonFileName)\r
+    {\r
+        std::ifstream fin((m_path + jsonFileName).c_str());\r
+        if (!fin)\r
+            throw JsonException("Error Json Referenced File not present " + m_path + jsonFileName);\r
+        std::stringstream buffer;\r
+        buffer << fin.rdbuf();\r
+        std::string str = buffer.str();\r
+        return cJSON_Parse(str.c_str());\r
+    }\r
 \r
 }\r
index cb2cac3..f659200 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -26,6 +26,7 @@
 #include "Utils.h"\r
 #include <fstream>\r
 #include "yaml-cpp/exceptions.h"\r
+#include "RamlExceptions.h"\r
 \r
 namespace RAML\r
 {\r
@@ -44,12 +45,14 @@ namespace RAML
             cJSON *readToJson(const YAML::Node &jsonFile );\r
             std::string readFromFile(const YAML::Node &file );\r
             FileType getFileType(const YAML::Node &yamlNode );\r
+            cJSON *readToJson(const std::string &jsonFileName);\r
 \r
             IncludeResolver() {}\r
-            IncludeResolver(std::string &path) : m_path(path) {}\r
+            IncludeResolver(const std::string &path) : m_path(path) {}\r
         private:\r
             std::string m_path;\r
     };\r
+    typedef std::shared_ptr<IncludeResolver> IncludeResolverPtr;\r
 \r
 }\r
 #endif\r
diff --git a/service/simulator/ramlparser/raml/RamlErrorCodes.h b/service/simulator/ramlparser/raml/RamlErrorCodes.h
new file mode 100755 (executable)
index 0000000..bb43a69
--- /dev/null
@@ -0,0 +1,31 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RAML_ERROR_CODES_H_\r
+#define RAML_ERROR_CODES_H_\r
+\r
+typedef enum\r
+{\r
+    RAML_PARSER_OK = 0,\r
+\r
+    RAML_FILE_PATH_REQUIRED,\r
+    RAML_PARSER_ERROR = 255\r
+} RamlParserResult;\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/RamlExceptions.cpp b/service/simulator/ramlparser/raml/RamlExceptions.cpp
new file mode 100755 (executable)
index 0000000..63f67dd
--- /dev/null
@@ -0,0 +1,35 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "RamlExceptions.h"\r
+namespace RAML\r
+{\r
+    const char *RamlException::what() const noexcept\r
+    {\r
+        if (m_mark.is_null())\r
+        {\r
+            return m_message.c_str();\r
+        }\r
+        std::stringstream output;\r
+        output << "Error at line " << m_mark.line + 1 << ", column "\r
+               << m_mark.column + 1 << ": " << m_message;\r
+        return output.str().c_str();\r
+    }\r
+}\r
diff --git a/service/simulator/ramlparser/raml/RamlExceptions.h b/service/simulator/ramlparser/raml/RamlExceptions.h
new file mode 100755 (executable)
index 0000000..c6f884b
--- /dev/null
@@ -0,0 +1,73 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RAML_EXCEPTIONS_H_\r
+#define RAML_EXCEPTIONS_H_\r
+\r
+#include <exception>\r
+#include "RamlErrorCodes.h"\r
+#include "yaml-cpp/exceptions.h"\r
+\r
+namespace RAML\r
+{\r
+    class RamlException : public std::exception\r
+    {\r
+        public:\r
+            RamlException(const std::string &message) : m_message(message) {}\r
+            RamlException(const YAML::Mark &mark, const std::string &message): m_message(message),\r
+                m_mark(mark) {}\r
+            virtual const char *what() const noexcept;\r
+            virtual ~RamlException() throw() {}\r
+\r
+        private:\r
+            std::string m_message;\r
+            YAML::Mark m_mark;\r
+    };\r
+\r
+    class RamlParserException : public RamlException\r
+    {\r
+        public:\r
+            RamlParserException(const std::string &message): RamlException(message) {}\r
+            RamlParserException(const YAML::Mark &mark, const std::string &message): RamlException(mark,\r
+                        message) {}\r
+    };\r
+\r
+    class RamlRepresentationException : public RamlException\r
+    {\r
+        public:\r
+            RamlRepresentationException(const std::string &message): RamlException(message) {}\r
+            RamlRepresentationException(const YAML::Mark &mark, const std::string &message): RamlException(mark,\r
+                        message) {}\r
+    };\r
+\r
+    class RamlBadFile : public RamlException\r
+    {\r
+        public:\r
+            RamlBadFile(const std::string &message) : RamlException(message) {}\r
+            RamlBadFile(const YAML::Mark &mark, const std::string &message): RamlException(mark, message) {}\r
+    };\r
+    class JsonException : public RamlException\r
+    {\r
+        public:\r
+            JsonException(const std::string &message) : RamlException(message) {}\r
+\r
+    };\r
+}\r
+#endif\r
index e9e4d0e..38ed45d 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
 \r
 namespace RAML\r
 {\r
-    RamlPtr RamlParser::build()\r
+    RamlPtr RamlParser::getRamlPtr(RamlParserResult &result)\r
     {\r
-        YAML::Node yamlRootNode = YAML::LoadFile(m_fileLocation + m_ramlName);\r
-        m_ramlPtr->readRamlFromYaml(yamlRootNode);\r
-        setDataFromRoot();\r
-        return (m_ramlPtr);\r
-\r
+        result = m_ramlParserResult;\r
+        return m_ramlPtr;\r
     }\r
     RamlPtr RamlParser::getRamlPtr()\r
     {\r
@@ -42,70 +39,66 @@ namespace RAML
         setBodyDefaultMediaType(getRamlPtr()->getResources());\r
         setBodySchema(getRamlPtr()->getResources());\r
     }\r
-    void RamlParser::setBodyDefaultMediaType(std::map<std::string, RamlResource> resource)\r
+    void RamlParser::setBodyDefaultMediaType(const std::map<std::string, RamlResourcePtr> &resource)\r
     {\r
         if (getRamlPtr()->getMediaType().empty())\r
         {\r
             return;\r
         }\r
-        for (auto it : resource)\r
+        for (auto const & it : resource)\r
         {\r
             std::string type = getRamlPtr()->getMediaType();\r
 \r
-            for (auto  action :  it.second.getActions())\r
+            for (auto const & action :  it.second->getActions())\r
             {\r
-                if (action.second.getRequestBody().empty())\r
+                if (action.second->getRequestBody().empty())\r
                 {\r
-                    std::string resName = it.first;\r
-                    getRamlPtr()->getResource(resName).getAction(action.first).setRequestBody(type);\r
+                    action.second->setRequestBody(type);\r
                 }\r
-                for (auto  response : action.second.getResponses())\r
+                for (auto const & response : action.second->getResponses())\r
                 {\r
-                    if (response.second.getResponseBody().empty())\r
+                    if (response.second->getResponseBody().empty())\r
                     {\r
-                        std::string resName = it.first;\r
-                        std::string responseCode = response.first;\r
-                        getRamlPtr()->getResource(resName).getAction(action.first).getResponse(\r
-                            responseCode).setResponseBody(\r
-                                type);\r
+                        response.second->setResponseBody(type);\r
                     }\r
                 }\r
             }\r
+            setBodyDefaultMediaType(it.second->getResources());\r
         }\r
     }\r
-    void RamlParser::setBodySchema(std::map<std::string, RamlResource> resource)\r
+    void RamlParser::setBodySchema(const std::map<std::string, RamlResourcePtr> &resource)\r
     {\r
         if (getRamlPtr()->getSchemas().empty())\r
         {\r
             return;\r
         }\r
-        for (auto  it : resource)\r
+        for (auto const & it : resource)\r
         {\r
-            for (auto  action :  it.second.getActions())\r
+            for (auto const & action :  it.second->getActions())\r
             {\r
-                for (auto  body :  action.second.getRequestBody())\r
+                for (auto const & body :  action.second->getRequestBody())\r
                 {\r
-                    Schema *schema = body.second.getSchema();\r
+                    SchemaPtr schema = body.second->getSchema();\r
 \r
                     if (schema != NULL)\r
                     {\r
                         std::string schemaValue = schema->getSchema();\r
                         auto pos = std::find_if(getRamlPtr()->getSchemas().begin(), getRamlPtr()->getSchemas().end(),\r
-                                                [schemaValue](std::pair<std::string, Schema> const & pair)\r
+                                                [schemaValue](std::pair<std::string, SchemaPtr> const & pair)\r
                         {\r
                             return (pair.first == schemaValue);\r
                         });\r
                         if (pos != getRamlPtr()->getSchemas().end())\r
                         {\r
-                            schema->setSchema((pos->second.getSchema()));\r
+                            schema->setSchema((pos->second->getSchema()));\r
                         }\r
                     }\r
                 }\r
-                for (auto  response : action.second.getResponses())\r
+                for (auto const & response : action.second->getResponses())\r
                 {\r
-                    for (auto  body :  response.second.getResponseBody())\r
+                    for (auto const & body :  response.second->getResponseBody())\r
                     {\r
-                        Schema *schema = body.second.getSchema();\r
+                        SchemaPtr schema = body.second->getSchema();\r
                         if (schema != NULL)\r
                         {\r
                             std::string schemaValue = schema->getSchema();\r
@@ -119,24 +112,25 @@ namespace RAML
                             }\r
                             if (iter != schemas.end())\r
                             {\r
-                                schema->setSchema((*iter).second.getSchema());\r
+                                schema->setSchema((*iter).second->getSchema());\r
                             }\r
                         }\r
                     }\r
                 }\r
             }\r
+            setBodySchema(it.second->getResources());\r
         }\r
     }\r
-    void RamlParser::setTypes(std::map<std::string, RamlResource> resource)\r
+    void RamlParser::setTypes(const std::map<std::string, RamlResourcePtr> &resource)\r
     {\r
         if (getRamlPtr()->getResourceTypes().empty())\r
         {\r
             return;\r
         }\r
-        for (auto  it : resource)\r
+        for (auto const & it : resource)\r
         {\r
-            auto resourceTypes = getRamlPtr()->getResourceTypes();\r
-            std::string typeValue = it.second.getResourceType();\r
+            auto const &resourceTypes = getRamlPtr()->getResourceTypes();\r
+            std::string typeValue = it.second->getResourceType();\r
 \r
             auto iter = resourceTypes.begin();\r
             for (; iter != resourceTypes.end(); iter++)\r
@@ -146,33 +140,30 @@ namespace RAML
             }\r
             if (iter != resourceTypes.end())\r
             {\r
-                std::string resName = it.first;\r
-                RamlResource &res = getRamlPtr()->getResource(resName);\r
-                RamlResource resType =  (*iter).second;\r
-\r
-                if (resType.getActions().empty())\r
+                if ((*iter).second->getActions().empty())\r
                     return;\r
 \r
-                for (auto resActions : resType.getActions())\r
+                for (auto resActions : (*iter).second->getActions())\r
                 {\r
-                    if (res.getActions().count(resActions.first) == 0)\r
-                        res.setAction(resActions.first, resActions.second);\r
+                    if (it.second->getActions().count(resActions.first) == 0)\r
+                        it.second->setAction(resActions.first, std::make_shared<Action>(*(resActions.second)));\r
                 }\r
             }\r
+            setTypes(it.second->getResources());\r
         }\r
     }\r
-    void RamlParser::setTraits(std::map<std::string, RamlResource> resource)\r
+    void RamlParser::setTraits(const std::map<std::string, RamlResourcePtr> &resource)\r
     {\r
         if (getRamlPtr()->getTraits().empty())\r
         {\r
             return;\r
         }\r
-        for (auto  it : resource)\r
+        for (auto const & it : resource)\r
         {\r
-            auto trait = getRamlPtr()->getTraits();\r
-            for (auto act : it.second.getActions())\r
+            auto const &trait = getRamlPtr()->getTraits();\r
+            for (auto const & act : it.second->getActions())\r
             {\r
-                for (std::string  traitValue :  act.second.getTraits())\r
+                for (const std::string & traitValue :  act.second->getTraits())\r
                 {\r
                     auto iter = trait.begin();\r
                     for (; iter != trait.end(); iter++)\r
@@ -182,30 +173,25 @@ namespace RAML
                     }\r
                     if (iter != trait.end())\r
                     {\r
-                        std::string resName = it.first;\r
-                        RamlResource &res = getRamlPtr()->getResource(resName);\r
-                        Action resTrait =  (*iter).second;\r
-\r
-                        Action &action = res.getAction(act.first);\r
-                        for (auto head : resTrait.getHeaders())\r
+                        for (auto head : (*iter).second->getHeaders())\r
                         {\r
-                            if (action.getHeaders().count(head.first) == 0)\r
-                                action.setHeader(head.first, head.second);\r
+                            if (act.second->getHeaders().count(head.first) == 0)\r
+                                act.second->setHeader(head.first, head.second);\r
                         }\r
-                        for (auto query : resTrait.getQueryParameters())\r
+                        for (auto query : (*iter).second->getQueryParameters())\r
                         {\r
-                            if (action.getQueryParameters().count(query.first) == 0)\r
-                                action.setQueryParameter(query.first, query.second);\r
+                            if (act.second->getQueryParameters().count(query.first) == 0)\r
+                                act.second->setQueryParameter(query.first, query.second);\r
                         }\r
-                        for (auto resp : resTrait.getResponses())\r
+                        for (auto resp : (*iter).second->getResponses())\r
                         {\r
-                            if (action.getResponses().count(resp.first) == 0)\r
-                                action.setResponse(resp.first, resp.second);\r
+                            if (act.second->getResponses().count(resp.first) == 0)\r
+                                act.second->setResponse(resp.first, resp.second);\r
                         }\r
                     }\r
                 }\r
             }\r
-            for (std::string  traitValue :  it.second.getTraits())\r
+            for (const std::string & traitValue :  it.second->getTraits())\r
             {\r
                 auto iter = trait.begin();\r
                 for (; iter != trait.end(); iter++)\r
@@ -215,31 +201,27 @@ namespace RAML
                 }\r
                 if (iter != trait.end())\r
                 {\r
-                    std::string resName = it.first;\r
-                    RamlResource &res = getRamlPtr()->getResource(resName);\r
-                    Action resTrait =  (*iter).second;\r
-\r
-                    for (auto act : res.getActions())\r
+                    for (auto act : it.second->getActions())\r
                     {\r
-                        Action &action = res.getAction(act.first);\r
-                        for (auto head : resTrait.getHeaders())\r
+                        for (auto head : (*iter).second->getHeaders())\r
                         {\r
-                            if (action.getHeaders().count(head.first) == 0)\r
-                                action.setHeader(head.first, head.second);\r
+                            if (act.second->getHeaders().count(head.first) == 0)\r
+                                act.second->setHeader(head.first, head.second);\r
                         }\r
-                        for (auto query : resTrait.getQueryParameters())\r
+                        for (auto query : (*iter).second->getQueryParameters())\r
                         {\r
-                            if (action.getQueryParameters().count(query.first) == 0)\r
-                                action.setQueryParameter(query.first, query.second);\r
+                            if (act.second->getQueryParameters().count(query.first) == 0)\r
+                                act.second->setQueryParameter(query.first, query.second);\r
                         }\r
-                        for (auto resp : resTrait.getResponses())\r
+                        for (auto resp : (*iter).second->getResponses())\r
                         {\r
-                            if (action.getResponses().count(resp.first) == 0)\r
-                                action.setResponse(resp.first, resp.second);\r
+                            if (act.second->getResponses().count(resp.first) == 0)\r
+                                act.second->setResponse(resp.first, resp.second);\r
                         }\r
                     }\r
                 }\r
             }\r
+            setTraits(it.second->getResources());\r
         }\r
     }\r
 \r
index 5db9c20..50f3501 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -29,6 +29,9 @@
 #include "Action.h"\r
 #include "Response.h"\r
 #include <map>\r
+#include "RamlErrorCodes.h"\r
+#include "yaml-cpp/exceptions.h"\r
+#include "RamlExceptions.h"\r
 \r
 namespace RAML\r
 {\r
@@ -36,23 +39,53 @@ namespace RAML
     {\r
         private:\r
             void setDataFromRoot();\r
-            void setBodyDefaultMediaType(std::map<std::string, RamlResource> resource);\r
-            void setBodySchema(std::map<std::string, RamlResource> resource);\r
-            void setTypes(std::map<std::string, RamlResource> resource);\r
-            void setTraits(std::map<std::string, RamlResource> resource);\r
+            void setBodyDefaultMediaType(const std::map<std::string, RamlResourcePtr> &resource);\r
+            void setBodySchema(const std::map<std::string, RamlResourcePtr> &resource);\r
+            void setTypes(const std::map<std::string, RamlResourcePtr> &resource);\r
+            void setTraits(const std::map<std::string, RamlResourcePtr> &resource);\r
 \r
         public:\r
-            virtual RamlPtr build();\r
+            virtual RamlPtr getRamlPtr(RamlParserResult &result);\r
             virtual RamlPtr getRamlPtr();\r
-            RamlParser(): m_ramlPtr(new Raml()) {}\r
-            RamlParser(std::string &fileLocation,\r
-                       std::string &ramlName): m_ramlPtr(new Raml(fileLocation)) ,\r
-                m_fileLocation(fileLocation) , m_ramlName(ramlName) {}\r
+            RamlParser(): m_ramlPtr(std::make_shared<Raml>()), m_ramlParserResult(RAML_FILE_PATH_REQUIRED) {}\r
+            RamlParser(const std::string &path): m_ramlParserResult(RAML_PARSER_ERROR)\r
+            {\r
+                if (path.length() > 0)\r
+                {\r
+                    std::size_t found = path.find_last_of("/\\");\r
+                    if (found < path.length())\r
+                    {\r
+                        m_fileLocation = path.substr(0, found) + "/";\r
+                        m_ramlName = path.substr(found + 1);\r
+                        try\r
+                        {\r
+                            m_ramlPtr = std::make_shared<Raml>(m_fileLocation, m_ramlName);\r
+                            setDataFromRoot();\r
+                            m_ramlParserResult = RAML_PARSER_OK;\r
+                        }\r
+                        catch (RamlException &e)\r
+                        {\r
+                            throw;\r
+                        }\r
+                    }\r
+                    else\r
+                    {\r
+                        m_ramlParserResult = RAML_FILE_PATH_REQUIRED;\r
+                        throw RamlBadFile("Raml File Path incorrect");\r
+                    }\r
+                }\r
+                else\r
+                {\r
+                    m_ramlParserResult = RAML_FILE_PATH_REQUIRED;\r
+                    throw RamlBadFile("Raml File Path required");\r
+                }\r
+            }\r
         private:\r
 \r
             RamlPtr m_ramlPtr;\r
             std::string m_fileLocation;\r
             std::string m_ramlName;\r
+            RamlParserResult m_ramlParserResult;\r
     };\r
 \r
 }\r
index 9daef9f..c69470e 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h b/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h
new file mode 100755 (executable)
index 0000000..dc23371
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+#ifndef ALLOWED_VALUES_H_\r
+#define ALLOWED_VALUES_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include <boost/variant.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+#include "Helpers.h"\r
+\r
+namespace RAML\r
+{\r
+    class AllowedValues\r
+    {\r
+        public:\r
+            template <typename T>\r
+            void addValue(const T &value)\r
+            {\r
+                ValueVariant temp = value;\r
+                m_values.push_back(temp);\r
+            }\r
+\r
+            template <typename T>\r
+            void addValues(const std::vector<T> &values)\r
+            {\r
+                for (auto value : values)\r
+                {\r
+                    ValueVariant vValue = value;\r
+                    m_values.push_back(vValue);\r
+                }\r
+            }\r
+\r
+            inline ValueVariant &at(int index)\r
+            {\r
+                return m_values.at(index);\r
+            }\r
+            inline int size() const\r
+            {\r
+                return m_values.size();\r
+            }\r
+\r
+            inline std::vector<ValueVariant> getValues()\r
+            {\r
+                return m_values;\r
+            }\r
+            inline std::vector<int> getValuesInt()\r
+            {\r
+                std::vector<int> values;\r
+                for (auto value : m_values)\r
+                {\r
+                    values.push_back(boost::lexical_cast<int> (value));\r
+                }\r
+                return values;\r
+            }\r
+            inline std::vector<std::string> getValuesString()\r
+            {\r
+                std::vector<std::string> values;\r
+                for (auto value : m_values)\r
+                {\r
+                    values.push_back(boost::lexical_cast<std::string> (value));\r
+                }\r
+                return values;\r
+            }\r
+\r
+        private:\r
+            std::vector<ValueVariant> m_values;\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h
new file mode 100755 (executable)
index 0000000..a1ec9f3
--- /dev/null
@@ -0,0 +1,96 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+#ifndef DEFINITIONS_H_\r
+#define DEFINITIONS_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include "Properties.h"\r
+\r
+namespace RAML\r
+{\r
+    class Definitions\r
+    {\r
+        public:\r
+\r
+            Definitions() = default;\r
+            Definitions(const std::string &name) : m_defName(name) {}\r
+\r
+            inline std::string getName(void) const\r
+            {\r
+                return m_defName;\r
+            }\r
+            inline void setName(const std::string &name)\r
+            {\r
+                m_defName = name;\r
+            }\r
+            inline std::string getType(void) const\r
+            {\r
+                return m_type;\r
+            }\r
+            inline void setType(const std::string &type)\r
+            {\r
+                m_type = type;\r
+            }\r
+            void addProperty(const std::string &propName, Properties *property)\r
+            {\r
+                if (m_properties.end() == m_properties.find(propName))\r
+                {\r
+                    m_properties[propName] =  property;\r
+                }\r
+            }\r
+            void setRequiredValue(const std::string &reqValue)\r
+            {\r
+                if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue))\r
+                {\r
+                    m_required.push_back(reqValue);\r
+                }\r
+            }\r
+            std::vector<std::string> getRequiredValues() const\r
+            {\r
+                return m_required;\r
+            }\r
+            int propertiesSize() const { return m_properties.size(); }\r
+\r
+            inline bool getproperty(const std::string &propName, Properties *value)\r
+            {\r
+                if (m_properties.end() != m_properties.find(propName))\r
+                {\r
+                    value = m_properties[propName];\r
+                    return true;\r
+                }\r
+                return false;\r
+            }\r
+            inline std::map<std::string, Properties *>  getProperties()\r
+            {\r
+                return m_properties;\r
+            }\r
+        private:\r
+            std::map<std::string, Properties *> m_properties;\r
+            std::string m_defName;\r
+            std::string m_type;\r
+            std::vector<std::string> m_required;\r
+\r
+    };\r
+    typedef std::shared_ptr<Definitions> DefinitionsPtr;\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h
new file mode 100755 (executable)
index 0000000..9e25072
--- /dev/null
@@ -0,0 +1,41 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+#ifndef HELPERS_H_\r
+#define HELPERS_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include <boost/variant.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+\r
+namespace RAML\r
+{\r
+\r
+\r
+    typedef boost::variant <\r
+    int,\r
+    double,\r
+    bool,\r
+    std::string\r
+    > ValueVariant;\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h
new file mode 100755 (executable)
index 0000000..b5353bd
--- /dev/null
@@ -0,0 +1,107 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+#ifndef ITEMS_H_\r
+#define ITEMS_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include "Properties.h"\r
+#include "Helpers.h"\r
+#include "AllowedValues.h"\r
+\r
+namespace RAML\r
+{\r
+    class Properties;\r
+    class AllowedValues;\r
+    class Items\r
+    {\r
+        public:\r
+            Items() {}\r
+            void addProperty(const std::string &propName, Properties *property)\r
+            {\r
+                if (m_properties.end() == m_properties.find(propName))\r
+                {\r
+                    m_properties[propName] =  property;\r
+                }\r
+            }\r
+            bool getproperty(const std::string &propName, Properties *value)\r
+            {\r
+                if (m_properties.end() != m_properties.find(propName))\r
+                {\r
+                    value = m_properties[propName];\r
+                    return true;\r
+                }\r
+                return false;\r
+            }\r
+            std::map<std::string, Properties *> getProperties()\r
+            {\r
+                return m_properties;\r
+            }\r
+            void setType(const std::string &type)\r
+            {\r
+                m_type = type;\r
+            }\r
+            std::string getType()\r
+            {\r
+                return m_type;\r
+            }\r
+            void setRequiredValue(const std::string &reqValue)\r
+            {\r
+                if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue))\r
+                {\r
+                    m_required.push_back(reqValue);\r
+                }\r
+            }\r
+            std::vector<std::string> getRequiredValues()\r
+            {\r
+                return m_required;\r
+            }\r
+            template <typename T>\r
+            bool setAllowedValues(const std::vector<T> &values)\r
+            {\r
+                m_allowedValues.addValues(values);\r
+                return true;\r
+            }\r
+            inline int getAllowedValuesSize() const\r
+            {\r
+                return m_allowedValues.size();\r
+            }\r
+            inline std::vector<ValueVariant> getAllowedValues()\r
+            {\r
+                return m_allowedValues.getValues();\r
+            }\r
+            inline std::vector<int> getAllowedValuesInt()\r
+            {\r
+                return m_allowedValues.getValuesInt();\r
+            }\r
+            inline std::vector<std::string> getAllowedValuesString()\r
+            {\r
+                return m_allowedValues.getValuesString();\r
+            }\r
+        private:\r
+            std::map<std::string, Properties *> m_properties;\r
+            std::string m_type;\r
+            std::vector<std::string>  m_required;\r
+            AllowedValues m_allowedValues;\r
+    };\r
+}\r
+#endif\r
+\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp
new file mode 100755 (executable)
index 0000000..f4939ca
--- /dev/null
@@ -0,0 +1,832 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "JsonSchema.h"\r
+using namespace std;\r
+\r
+namespace RAML\r
+{\r
+\r
+    void JsonSchema::readJson()\r
+    {\r
+        if (! m_cjson)\r
+            return;\r
+\r
+        cJSON *jsonId = cJSON_GetObjectItem(m_cjson, "id");\r
+        if (jsonId)\r
+        {\r
+            m_id = jsonId->valuestring;\r
+        }\r
+        cJSON *jsonSchema = cJSON_GetObjectItem(m_cjson, "$schema");\r
+        if (jsonSchema)\r
+        {\r
+            m_schema = jsonSchema->valuestring;\r
+        }\r
+        cJSON *jsonTitle = cJSON_GetObjectItem(m_cjson, "title");\r
+        if (jsonTitle)\r
+        {\r
+            m_title = jsonTitle->valuestring;\r
+        }\r
+        cJSON *jsonType = cJSON_GetObjectItem(m_cjson, "type");\r
+        if (jsonType)\r
+        {\r
+            m_type = jsonType->valuestring;\r
+        }\r
+        cJSON *jsonDescription = cJSON_GetObjectItem(m_cjson, "description");\r
+        if (jsonDescription)\r
+        {\r
+            m_description = jsonDescription->valuestring;\r
+        }\r
+        cJSON *jsonDefinitions = cJSON_GetObjectItem(m_cjson, "definitions");\r
+        if (jsonDefinitions)\r
+        {\r
+            cJSON *childDefinitions = jsonDefinitions->child;\r
+            while (childDefinitions)\r
+            {\r
+                std::string defName = childDefinitions->string;\r
+                addDefinition(defName, readDef(childDefinitions, defName));\r
+                childDefinitions = childDefinitions->next;\r
+            }\r
+        }\r
+        cJSON *jsonProperties = cJSON_GetObjectItem(m_cjson, "properties");\r
+        if (jsonProperties)\r
+        {\r
+            cJSON *childProperties = jsonProperties->child;\r
+            while (childProperties)\r
+            {\r
+                std::string attName = childProperties->string;\r
+                addProperty(attName, readProp(childProperties, attName));\r
+                childProperties = childProperties->next;\r
+            }\r
+        }\r
+        if (m_type == "array")\r
+        {\r
+            cJSON *jsonItems = cJSON_GetObjectItem(m_cjson, "items");\r
+            if (jsonItems)\r
+            {\r
+                if (jsonItems->type == 5)\r
+                {\r
+                    int item_size = cJSON_GetArraySize(jsonItems);\r
+                    int item_index = 0;\r
+                    do\r
+                    {\r
+                        cJSON *item = cJSON_GetArrayItem(jsonItems, item_index);\r
+                        Items *newItem = readItems(item);\r
+                        setItem(newItem);\r
+                    }\r
+                    while ( ++item_index < item_size);\r
+                }\r
+                else\r
+                {\r
+                    Items *newItem = readItems(jsonItems);\r
+                    setItem(newItem);\r
+                }\r
+            }\r
+        }\r
+        cJSON *jsonAdditionalProperties = cJSON_GetObjectItem(m_cjson, "additionalProperties");\r
+        if (jsonAdditionalProperties)\r
+            m_additionalProperties = jsonAdditionalProperties->type;\r
+        else\r
+            m_additionalProperties = cJSON_True;\r
+\r
+        cJSON *jsonReference = cJSON_GetObjectItem(m_cjson, "$ref");\r
+        if (jsonReference)\r
+        {\r
+            readJsonRef(jsonReference);\r
+        }\r
+        cJSON *jsonAllOf = cJSON_GetObjectItem(m_cjson, "allOf");\r
+        if (jsonAllOf)\r
+        {\r
+            readAllOf(jsonAllOf);\r
+        }\r
+        cJSON *jsonRequiredValues = cJSON_GetObjectItem(m_cjson, "required");\r
+        if (jsonRequiredValues)\r
+        {\r
+            int size = cJSON_GetArraySize(jsonRequiredValues);\r
+            int index = 0;\r
+            do\r
+            {\r
+                setRequiredValue(cJSON_GetArrayItem(jsonRequiredValues, index)->valuestring);\r
+            }\r
+            while ( ++index < size);\r
+        }\r
+    }\r
+\r
+    Definitions *JsonSchema::readDef(cJSON *childDefinitions, const std::string &defName)\r
+    {\r
+        Definitions *definition = new Definitions(defName);\r
+\r
+        cJSON *defType = cJSON_GetObjectItem(childDefinitions, "type");\r
+        if (defType)\r
+        {\r
+            std::string type = defType->valuestring;\r
+            definition->setType(type);\r
+        }\r
+        cJSON *defProperties = cJSON_GetObjectItem(childDefinitions, "properties");\r
+        if (defProperties)\r
+        {\r
+            cJSON *childProperties = defProperties->child;\r
+            while (childProperties)\r
+            {\r
+                std::string attName = childProperties->string;\r
+                definition->addProperty(attName, readProp(childProperties, attName));\r
+                childProperties = childProperties->next;\r
+            }\r
+        }\r
+        cJSON *defRequiredValues = cJSON_GetObjectItem(childDefinitions, "required");\r
+        if (defRequiredValues)\r
+        {\r
+            int size = cJSON_GetArraySize(defRequiredValues);\r
+            int index = 0;\r
+            do\r
+            {\r
+                definition->setRequiredValue(cJSON_GetArrayItem(defRequiredValues, index)->valuestring);\r
+            }\r
+            while ( ++index < size);\r
+        }\r
+        cJSON *defReference = cJSON_GetObjectItem(childDefinitions, "$ref");\r
+        if (defReference)\r
+        {\r
+            readDefRef(defReference, definition);\r
+        }\r
+        cJSON *defAllOf = cJSON_GetObjectItem(childDefinitions, "allOf");\r
+        if (defAllOf)\r
+        {\r
+            readDefAllOf(defAllOf, definition);\r
+        }\r
+        return definition;\r
+    }\r
+\r
+    Properties *JsonSchema::readProp(cJSON *childProperties, const std::string &attName )\r
+    {\r
+        Properties *property = new Properties(attName);\r
+\r
+        cJSON *propertyUpdateFrequency = cJSON_GetObjectItem(childProperties, "update_frequency");\r
+        if (propertyUpdateFrequency)\r
+        {\r
+            property->setUpdateFrequencyTime(propertyUpdateFrequency->valueint);\r
+        }\r
+        cJSON *propertyDescription = cJSON_GetObjectItem(childProperties, "description");\r
+        if (propertyDescription)\r
+        {\r
+            property->setDescription(propertyDescription->valuestring);\r
+        }\r
+        cJSON *propertyType = cJSON_GetObjectItem(childProperties, "type");\r
+        if (propertyType)\r
+        {\r
+            std::string attType;\r
+            if (propertyType->type == 4)\r
+            {\r
+                attType = propertyType->valuestring;\r
+                property->setType(attType);\r
+            }\r
+            else if (propertyType->type == 5)\r
+            {\r
+                attType = cJSON_GetArrayItem(propertyType, 0)->valuestring;\r
+                property->setType(attType);\r
+            }\r
+            readValues(childProperties, property, attType);\r
+        }\r
+        cJSON *defaultValue = cJSON_GetObjectItem(childProperties, "default");\r
+        if (defaultValue)\r
+        {\r
+            if (defaultValue->type == 4)\r
+            {\r
+                property->setValue((std::string)defaultValue->valuestring);\r
+            }\r
+            else if (defaultValue->type == 3)\r
+            {\r
+                if (property->getType() == "number")\r
+                    property->setValue((double)defaultValue->valuedouble);\r
+                else\r
+                    property->setValue((int)defaultValue->valueint );\r
+            }\r
+            else if (defaultValue->type == 1)\r
+            {\r
+                property->setValue((bool)true);\r
+            }\r
+            else if (defaultValue->type == 0)\r
+            {\r
+                property->setValue((bool)false);\r
+            }\r
+\r
+        }\r
+        cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "enum");\r
+        if (allowedvalues)\r
+        {\r
+            if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4)\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                std::vector<std::string> allwdValues;\r
+                do\r
+                {\r
+                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
+                }\r
+                while ( ++idx < size);\r
+                property->setAllowedValues(allwdValues);\r
+            }\r
+            else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3)\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                if (property->getType() == "number")\r
+                {\r
+                    std::vector<double> allwdValues;\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble);\r
+                    }\r
+                    while ( ++idx < size);\r
+                    property->setAllowedValues(allwdValues);\r
+                }\r
+                else\r
+                {\r
+                    std::vector<int> allwdValues;\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
+                    }\r
+                    while ( ++idx < size);\r
+                    property->setAllowedValues(allwdValues);\r
+                }\r
+            }\r
+            else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1)\r
+                     || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0))\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                std::vector<bool> allwdValues;\r
+                do\r
+                {\r
+                    if (cJSON_GetArrayItem(allowedvalues, idx)->type)\r
+                        allwdValues.push_back(true);\r
+                    else\r
+                        allwdValues.push_back(false);\r
+                }\r
+                while ( ++idx < size);\r
+                property->setAllowedValues(allwdValues);\r
+            }\r
+        }\r
+        return property;\r
+    }\r
+\r
+    void JsonSchema::readValues(cJSON *childProperties,  Properties *property ,\r
+                                const std::string &attType)\r
+    {\r
+        if (attType == "string")\r
+        {\r
+            readString(childProperties, property);\r
+        }\r
+        else if (attType == "integer")\r
+        {\r
+            readNumber(childProperties, property);\r
+        }\r
+        else if (attType == "array")\r
+        {\r
+            readArray(childProperties, property);\r
+        }\r
+        else if (attType == "number")\r
+        {\r
+            readNumber(childProperties, property);\r
+        }\r
+    }\r
+\r
+    void JsonSchema::readString(cJSON *childProperties, Properties *property)\r
+    {\r
+        cJSON *stringMax = cJSON_GetObjectItem(childProperties, "maxLength");\r
+        if (stringMax)\r
+        {\r
+            cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
+            if (exclusiveMax)\r
+            {\r
+                if (exclusiveMax->type == cJSON_True)\r
+                    property->setMax (--(stringMax->valueint));\r
+                else\r
+                    property->setMax(stringMax->valueint);\r
+            }\r
+            else\r
+                property->setMax(stringMax->valueint);\r
+        }\r
+        cJSON *stringMin = cJSON_GetObjectItem(childProperties, "minLength");\r
+        if (stringMin)\r
+        {\r
+            cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");\r
+            if (exclusiveMin)\r
+            {\r
+                if (exclusiveMin->type == cJSON_True)\r
+                    property->setMin( ++(stringMin->valueint));\r
+                else\r
+                    property->setMin(stringMin->valueint);\r
+            }\r
+            else\r
+                property->setMin(stringMin->valueint);\r
+        }\r
+        cJSON *stringFormat = cJSON_GetObjectItem(childProperties, "format");\r
+        if (stringFormat)\r
+        {\r
+            property->setFormat(stringFormat->valuestring);\r
+        }\r
+        cJSON *stringPattern = cJSON_GetObjectItem(childProperties, "pattern");\r
+        if (stringPattern)\r
+        {\r
+            property->setPattern(stringPattern->valuestring);\r
+        }\r
+    }\r
+\r
+    void JsonSchema::readArray(cJSON *childProperties,  Properties *property)\r
+    {\r
+        cJSON *itemValues = cJSON_GetObjectItem(childProperties, "items");\r
+        if (itemValues)\r
+        {\r
+            if (itemValues->type == 5)\r
+            {\r
+                int item_size = cJSON_GetArraySize(itemValues);\r
+                int item_index = 0;\r
+                do\r
+                {\r
+                    cJSON *item = cJSON_GetArrayItem(itemValues, item_index);\r
+                    Items *newItem = readItems(item);\r
+                    property->setItem(newItem);\r
+                }\r
+                while ( ++item_index < item_size);\r
+            }\r
+            else\r
+            {\r
+                Items *newItem = readItems(itemValues);\r
+                property->setItem(newItem);\r
+            }\r
+        }\r
+        cJSON *itemsMax = cJSON_GetObjectItem(childProperties, "maxItems");\r
+        if (itemsMax)\r
+        {\r
+            cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
+            if (exclusiveMax)\r
+            {\r
+                if (exclusiveMax->type == cJSON_True)\r
+                    property->setMax( --(itemsMax->valueint));\r
+                else\r
+                    property->setMax(itemsMax->valueint);\r
+            }\r
+            else\r
+                property->setMax(itemsMax->valueint);\r
+        }\r
+        cJSON *itemsMin = cJSON_GetObjectItem(childProperties, "minLength");\r
+        if (itemsMin)\r
+        {\r
+            cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");\r
+            if (exclusiveMin)\r
+            {\r
+                if (exclusiveMin->type == cJSON_True)\r
+                    property->setMin( ++(itemsMin->valueint));\r
+                else\r
+                    property->setMin(itemsMin->valueint);\r
+            }\r
+            else\r
+                property->setMin(itemsMin->valueint);\r
+        }\r
+        cJSON *uniqueItems = cJSON_GetObjectItem(childProperties, "uniqueItems");\r
+        if (uniqueItems)\r
+        {\r
+            property->setUnique(uniqueItems->type);\r
+        }\r
+        else\r
+        {\r
+            property->setUnique(cJSON_True);\r
+        }\r
+        cJSON *additionalItems = cJSON_GetObjectItem(childProperties, "additionalItems");\r
+        if (additionalItems)\r
+        {\r
+            property->setAdditionalItems(additionalItems->type);\r
+        }\r
+        else\r
+        {\r
+            property->setAdditionalItems(cJSON_True);\r
+        }\r
+    }\r
+\r
+    void JsonSchema::readNumber(cJSON *childProperties,  Properties *property)\r
+    {\r
+        cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
+        if (Max)\r
+        {\r
+            cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
+            if (exclusiveMax)\r
+            {\r
+                if (exclusiveMax->type == cJSON_True)\r
+                    property->setMax( --(Max->valueint));\r
+                else\r
+                    property->setMax(Max->valueint);\r
+            }\r
+            else\r
+                property->setMax(Max->valueint);\r
+        }\r
+        cJSON *Min = cJSON_GetObjectItem(childProperties, "minimum");\r
+        if (Min)\r
+        {\r
+            cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");\r
+            if (exclusiveMin)\r
+            {\r
+                if (exclusiveMin->type == cJSON_True)\r
+                    property->setMin( ++(Min->valueint));\r
+                else\r
+                    property->setMin(Min->valueint);\r
+            }\r
+            else\r
+                property->setMin(Min->valueint);\r
+        }\r
+        cJSON *multipleOf = cJSON_GetObjectItem(childProperties, "multipleOf");\r
+        if (multipleOf)\r
+        {\r
+            property->setMultipleOf(multipleOf->valueint);\r
+        }\r
+\r
+    }\r
+    Definitions *JsonSchema::readRef(std::string m_ref)\r
+    {\r
+        std::string delimiter1 = "#";\r
+        std::string delimiter2 = "/";\r
+        std::string fileName;\r
+        if (! m_ref.empty())\r
+        {\r
+            std::size_t pos = m_ref.find(delimiter1);\r
+            if ( (pos = m_ref.find(delimiter1)) != std::string::npos)\r
+            {\r
+                fileName = m_ref.substr(0, pos);\r
+                m_ref.erase(0, pos);\r
+            }\r
+            m_ref.erase(0, delimiter1 .length());\r
+            std::string defName;\r
+\r
+            if (! m_ref.empty())\r
+            {\r
+                m_ref.erase(0, delimiter2 .length());\r
+                std::string keyName;\r
+                if ( (pos = m_ref.find(delimiter2)) != std::string::npos)\r
+                {\r
+                    keyName = m_ref.substr(0, pos);\r
+                    m_ref.erase(0, pos + delimiter2.length());\r
+                    if (keyName == "definitions")\r
+                    {\r
+                        if ( (pos = m_ref.find(delimiter2)) != std::string::npos)\r
+                        {\r
+                            defName = m_ref.substr(0, pos);\r
+                        }\r
+                        else if (! m_ref.empty())\r
+                        {\r
+                            defName = m_ref;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+            if (!fileName.empty())\r
+            {\r
+                if (!(defName.empty()))\r
+                {\r
+                    cJSON *m_json = m_includeResolver->readToJson(fileName);\r
+                    JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver);\r
+                    Definitions *definition = Refparser->getDefinition(defName);\r
+                    if (definition == nullptr)\r
+                        throw JsonException("Definition Name Incorrect");\r
+                    return definition;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                if (!(defName.empty()))\r
+                {\r
+                    if (getDefinition(defName) == nullptr)\r
+                        throw JsonException("Definition Name Incorrect");\r
+                    return getDefinition(defName);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    void JsonSchema::readAllOf(cJSON *allofValues)\r
+    {\r
+        int size = cJSON_GetArraySize(allofValues);\r
+        int index = 0;\r
+        do\r
+        {\r
+            cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
+            cJSON *jsonReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
+            if (jsonReference)\r
+            {\r
+                readJsonRef(jsonReference );\r
+            }\r
+            cJSON *jsonRequiredValues = cJSON_GetObjectItem(childAllOf, "required");\r
+            if (jsonRequiredValues)\r
+            {\r
+                int len = cJSON_GetArraySize(jsonRequiredValues);\r
+                int idx = 0;\r
+                do\r
+                {\r
+                    setRequiredValue(cJSON_GetArrayItem(jsonRequiredValues, idx)->valuestring);\r
+                }\r
+                while ( ++idx < len);\r
+            }\r
+        }\r
+        while ( ++index < size);\r
+    }\r
+    void JsonSchema::readJsonRef(cJSON *jsonReference)\r
+    {\r
+        std::string m_ref = jsonReference->valuestring;\r
+        std::map<std::string, Properties *> properties;\r
+        std::vector<std::string> required;\r
+\r
+        std::string web = "http://";\r
+        std::string delimiter = "#";\r
+        std::size_t pos = m_ref.find(web);\r
+\r
+        if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
+        {\r
+            pos = m_ref.find(delimiter);\r
+            if ( pos ==  (m_ref.length() - 1) )\r
+            {\r
+                std::string fileName = m_ref.substr(0, pos);\r
+                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
+                JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver);\r
+\r
+                properties = Refparser->getProperties();\r
+                required = Refparser->getRequiredValues();\r
+            }\r
+            else\r
+            {\r
+                Definitions *definition = readRef(m_ref);\r
+                properties = definition->getProperties();\r
+                required = definition->getRequiredValues();\r
+            }\r
+            for ( auto it : properties)\r
+            {\r
+                std:: string name = it.first;\r
+                addProperty(name, it.second);\r
+            }\r
+            for (auto it : required )\r
+            {\r
+                setRequiredValue(it);\r
+            }\r
+\r
+        }\r
+    }\r
+    void JsonSchema::readDefAllOf(cJSON *allofValues, Definitions *definition)\r
+    {\r
+        int size = cJSON_GetArraySize(allofValues);\r
+        int index = 0;\r
+        do\r
+        {\r
+            cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
+            cJSON *defReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
+            if (defReference)\r
+            {\r
+                readDefRef(defReference , definition);\r
+            }\r
+            cJSON *defRequiredValues = cJSON_GetObjectItem(allofValues, "required");\r
+            if (defRequiredValues)\r
+            {\r
+                int len = cJSON_GetArraySize(defRequiredValues);\r
+                int idx = 0;\r
+                do\r
+                {\r
+                    definition->setRequiredValue(cJSON_GetArrayItem(defRequiredValues, idx)->valuestring);\r
+                }\r
+                while ( ++idx < len);\r
+            }\r
+        }\r
+        while ( ++index < size);\r
+    }\r
+    void JsonSchema::readDefRef(cJSON *defReference, Definitions *definition)\r
+    {\r
+        std::string m_ref = defReference->valuestring;\r
+        std::map<std::string, Properties *> properties;\r
+        std::vector<std::string> required;\r
+        std::string type;\r
+\r
+        std::string web = "http://";\r
+        std::string delimiter = "#";\r
+        std::size_t pos = m_ref.find(web);\r
+\r
+        if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
+        {\r
+            pos = m_ref.find(delimiter);\r
+            if ( pos ==  (m_ref.length() - 1) )\r
+            {\r
+                std::string fileName = m_ref.substr(0, pos);\r
+                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
+                JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver);\r
+\r
+                properties = Refparser->getProperties();\r
+                required = Refparser->getRequiredValues();\r
+                type =    Refparser->getType();\r
+            }\r
+            else\r
+            {\r
+                Definitions *definitionRef = readRef(m_ref);\r
+                properties = definitionRef->getProperties();\r
+                required = definitionRef->getRequiredValues();\r
+                type =    definitionRef->getType();\r
+            }\r
+            for (auto it : properties)\r
+            {\r
+                definition->addProperty(it.first, it.second);\r
+            }\r
+            for ( auto it : required)\r
+            {\r
+                definition->setRequiredValue(it);\r
+            }\r
+            definition->setType(type);\r
+        }\r
+    }\r
+    Items *JsonSchema::readItems(cJSON *item)\r
+    {\r
+        Items *newItem = new Items();\r
+        cJSON *itemType = cJSON_GetObjectItem(item, "type");\r
+        if (itemType)\r
+        {\r
+            std::string type = itemType->valuestring;\r
+            newItem->setType(type);\r
+        }\r
+\r
+        cJSON *itemProperties = cJSON_GetObjectItem(item, "properties");\r
+        if (itemProperties)\r
+        {\r
+            cJSON *childProperties = itemProperties->child;\r
+            while (childProperties)\r
+            {\r
+                std::string attName = childProperties->string;\r
+                Properties *property = readProp(childProperties, attName);\r
+\r
+                newItem->addProperty(attName, property);\r
+                childProperties = childProperties->next;\r
+            }\r
+        }\r
+\r
+        cJSON *allowedvalues = cJSON_GetObjectItem(item, "enum");\r
+        if (allowedvalues)\r
+        {\r
+            if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4)\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                std::vector<std::string> allwdValues;\r
+                do\r
+                {\r
+                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
+                }\r
+                while ( ++idx < size);\r
+                newItem->setAllowedValues(allwdValues);\r
+            }\r
+            else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3)\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                if (newItem->getType() == "number")\r
+                {\r
+                    std::vector<double> allwdValues;\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble);\r
+                    }\r
+                    while ( ++idx < size);\r
+                    newItem->setAllowedValues(allwdValues);\r
+                }\r
+                else\r
+                {\r
+                    std::vector<int> allwdValues;\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
+                    }\r
+                    while ( ++idx < size);\r
+                    newItem->setAllowedValues(allwdValues);\r
+                }\r
+            }\r
+            else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1)\r
+                     || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0))\r
+            {\r
+                int size = cJSON_GetArraySize(allowedvalues);\r
+                int idx = 0;\r
+                std::vector<bool> allwdValues;\r
+                do\r
+                {\r
+                    if (cJSON_GetArrayItem(allowedvalues, idx)->type)\r
+                        allwdValues.push_back(true);\r
+                    else\r
+                        allwdValues.push_back(false);\r
+                }\r
+                while ( ++idx < size);\r
+                newItem->setAllowedValues(allwdValues);\r
+            }\r
+        }\r
+        cJSON *itemRequiredValues = cJSON_GetObjectItem(item, "required");\r
+        if (itemRequiredValues)\r
+        {\r
+            int size = cJSON_GetArraySize(itemRequiredValues);\r
+            int index = 0;\r
+            do\r
+            {\r
+                newItem->setRequiredValue(cJSON_GetArrayItem(itemRequiredValues, index)->valuestring);\r
+            }\r
+            while ( ++index < size);\r
+        }\r
+        cJSON *itemReference = cJSON_GetObjectItem(item, "$ref");\r
+        if (itemReference)\r
+        {\r
+            readItemRef(itemReference , newItem);\r
+        }\r
+        cJSON *itemAllOf = cJSON_GetObjectItem(item, "allOf");\r
+        if (itemAllOf)\r
+        {\r
+            readItemAllOf(itemAllOf , newItem);\r
+        }\r
+        return (newItem);\r
+    }\r
+\r
+    void JsonSchema::readItemRef(cJSON *itemReference, Items *item)\r
+    {\r
+        std::string m_ref = itemReference->valuestring;\r
+        std::map<std::string, Properties *> properties;\r
+        std::vector<std::string> required;\r
+        std::string type;\r
+\r
+        std::string web = "http://";\r
+        std::string delimiter = "#";\r
+        std::size_t pos = m_ref.find(web);\r
+\r
+        if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
+        {\r
+            pos = m_ref.find(delimiter);\r
+            if ( pos ==  (m_ref.length() - 1 ) )\r
+            {\r
+                std::string fileName = m_ref.substr(0, pos);\r
+                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
+                JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver);\r
+\r
+                properties = Refparser->getProperties();\r
+                required = Refparser->getRequiredValues();\r
+                type =    Refparser->getType();\r
+            }\r
+            else\r
+            {\r
+                Definitions *definitionRef = readRef(m_ref);\r
+                properties = definitionRef->getProperties();\r
+                required = definitionRef->getRequiredValues();\r
+                type =    definitionRef->getType();\r
+            }\r
+            for ( auto it : properties)\r
+            {\r
+                std:: string name = it.first;\r
+                item->addProperty(name, it.second);\r
+            }\r
+            for ( auto it : required)\r
+            {\r
+                item->setRequiredValue(it);\r
+            }\r
+            item->setType(type);\r
+        }\r
+    }\r
+\r
+    void JsonSchema::readItemAllOf(cJSON *allofValues,  Items *item)\r
+    {\r
+        int size = cJSON_GetArraySize(allofValues);\r
+        int index = 0;\r
+        do\r
+        {\r
+            cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
+            cJSON *itemReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
+            if (itemReference)\r
+            {\r
+                readItemRef(itemReference, item);\r
+            }\r
+            cJSON *itemRequiredValues = cJSON_GetObjectItem(allofValues, "required");\r
+            if (itemRequiredValues)\r
+            {\r
+                int len = cJSON_GetArraySize(itemRequiredValues);\r
+                int idx = 0;\r
+                do\r
+                {\r
+                    item->setRequiredValue(cJSON_GetArrayItem(itemRequiredValues, idx)->valuestring);\r
+                }\r
+                while ( ++idx < len);\r
+            }\r
+        }\r
+        while ( ++index < size);\r
+    }\r
+}\r
+\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h
new file mode 100755 (executable)
index 0000000..16ddfdc
--- /dev/null
@@ -0,0 +1,172 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef JSON_SCHEMA_H_\r
+#define JSON_SCHEMA_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include "Properties.h"\r
+#include "Items.h"\r
+#include "Definitions.h"\r
+#include "cJSON.h"\r
+#include "Helpers.h"\r
+#include "AllowedValues.h"\r
+\r
+#include "IncludeResolver.h"\r
+\r
+namespace RAML\r
+{\r
+    class JsonSchema\r
+    {\r
+        public:\r
+            JsonSchema() : m_cjson(NULL), m_includeResolver(NULL)  {}\r
+            JsonSchema(const IncludeResolverPtr &includeResolver) : m_cjson(NULL),\r
+                m_includeResolver(includeResolver) {}\r
+            JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_cjson(cjson),\r
+                m_includeResolver(includeResolver)  { readJson(); }\r
+\r
+            void setcJson(cJSON *cjson) {m_cjson = cjson; readJson(); }\r
+            int size() const\r
+            {\r
+                return m_properties.size();\r
+            }\r
+            inline bool getProperty(const std::string &name, Properties *value)\r
+            {\r
+                if (m_properties.end() != m_properties.find(name))\r
+                {\r
+                    value = m_properties[name];\r
+                    return true;\r
+                }\r
+                return false;\r
+            }\r
+            inline std::map<std::string, Properties *> getProperties()\r
+            {\r
+                return m_properties;\r
+            }\r
+            inline std::map<std::string, Definitions *> getDefinitions()\r
+            {\r
+                return m_definition;\r
+            }\r
+            void addProperty(const std::string &name, Properties *property)\r
+            {\r
+                if (m_properties.end() == m_properties.find(name))\r
+                {\r
+                    m_properties[name] = property;\r
+                }\r
+            }\r
+            void setRequiredValue(const std::string &reqValue)\r
+            {\r
+                if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue))\r
+                {\r
+                    m_required.push_back(reqValue);\r
+                }\r
+            }\r
+            std::vector<std::string> getRequiredValues()\r
+            {\r
+                return m_required;\r
+            }\r
+            void addDefinition(const std::string &defName, Definitions *definition)\r
+            {\r
+                if (m_definition.end() == m_definition.find(defName))\r
+                {\r
+                    m_definition[defName] = definition;\r
+                }\r
+            }\r
+            Definitions *getDefinition(const std::string &defName)\r
+            {\r
+                if (m_definition.end() != m_definition.find(defName))\r
+                {\r
+                    return m_definition[defName];\r
+                }\r
+                return nullptr;\r
+            }\r
+            std::string getType()\r
+            {\r
+                return  m_type;\r
+            }\r
+            std::string getId()\r
+            {\r
+                return  m_id;\r
+            }\r
+            std::string getSchema()\r
+            {\r
+                return  m_schema;\r
+            }\r
+            std::string getDescription()\r
+            {\r
+                return  m_description;\r
+            }\r
+            std::string getTitle()\r
+            {\r
+                return  m_title;\r
+            }\r
+\r
+            bool getAdditionalProperties()\r
+            {\r
+                return  m_additionalProperties;\r
+            }\r
+            void setItem(Items *item)\r
+            {\r
+                m_items.push_back(item);\r
+            }\r
+            std::vector<Items *> getItems()\r
+            {\r
+                return m_items;\r
+            }\r
+\r
+            void readJson();\r
+            Definitions *readDef(cJSON *childDefinitions, const std::string &defName);\r
+            Properties *readProp(cJSON *childProperties, const std::string &attName );\r
+            void readValues( cJSON *childProperties,  Properties *property , const std::string &attType);\r
+            void readString( cJSON *childProperties, Properties *property);\r
+            void readArray( cJSON *childProperties,  Properties *property);\r
+            void readNumber( cJSON *childProperties,  Properties *property);\r
+            Definitions *readRef(std::string m_ref);\r
+\r
+\r
+            void readJsonRef(cJSON *jsonReference);\r
+            void readDefRef(cJSON *defReference, Definitions *definition);\r
+            void readAllOf(cJSON *allofValues);\r
+            void readDefAllOf(cJSON *allofValues, Definitions *definition);\r
+            Items *readItems(cJSON *item);\r
+            void readItemRef(cJSON *itemReference, Items *item);\r
+            void readItemAllOf(cJSON *allofValues,  Items *item);\r
+\r
+        private:\r
+            std::map<std::string, Properties *> m_properties;\r
+            std::map<std::string, Definitions *> m_definition;\r
+            std::string m_id;\r
+            std::string m_schema;\r
+            std::string m_title;\r
+            std::string m_description;\r
+            bool m_additionalProperties;\r
+            std::string m_type;\r
+            cJSON *m_cjson;\r
+            std::vector<std::string>  m_required;\r
+            std::vector<Items *> m_items;\r
+            IncludeResolverPtr m_includeResolver;\r
+    };\r
+    typedef std::shared_ptr<JsonSchema> JsonSchemaPtr;\r
+\r
+}\r
+\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h
new file mode 100755 (executable)
index 0000000..b8fbbc7
--- /dev/null
@@ -0,0 +1,216 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef PROPERTIES_H_\r
+#define PROPERTIES_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include <boost/variant.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+#include <limits>\r
+#include "Items.h"\r
+#include "AllowedValues.h"\r
+#include "cJSON.h"\r
+\r
+namespace RAML\r
+{\r
+    class Properties\r
+    {\r
+        public:\r
+            Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX) {}\r
+            Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),\r
+                m_multipleOf(INT_MAX) {}\r
+\r
+            inline std::string getName(void) const\r
+            {\r
+                return m_name;\r
+            }\r
+            inline void setName(const std::string &name)\r
+            {\r
+                m_name = name;\r
+            }\r
+            template <typename T>\r
+            T getValue() const\r
+            {\r
+                T val = T();\r
+                return boost::get<T>(m_value);\r
+            }\r
+\r
+            ValueVariant &getValue()\r
+            {\r
+                return m_value;\r
+            }\r
+\r
+            int getValueType() const\r
+            {\r
+                return m_value.which();\r
+            }\r
+            int getValueInt()\r
+            {\r
+                return boost::lexical_cast<int> (m_value);\r
+            }\r
+            std::string getValueString()\r
+            {\r
+                return boost::lexical_cast<std::string> (m_value);\r
+            }\r
+\r
+            template <typename T>\r
+            void setValue(const T &value)\r
+            {\r
+                m_value = value;\r
+            }\r
+            inline void getRange(int &min, int &max, int &multipleOf) const\r
+            {\r
+                min = m_min;\r
+                max = m_max;\r
+                multipleOf = m_multipleOf;\r
+            }\r
+            inline void setMin(const int &min)\r
+            {\r
+                m_min = min;\r
+            }\r
+            inline void setMax(const int &max)\r
+            {\r
+                m_max = max;\r
+            }\r
+            inline void setMultipleOf(const int &multipleOf)\r
+            {\r
+                m_multipleOf = multipleOf;\r
+            }\r
+\r
+            template <typename T>\r
+            bool setAllowedValues(const std::vector<T> &values)\r
+            {\r
+                ValueVariant temp = values.at(0);\r
+                if (temp.which() != m_value.which())\r
+                {\r
+                    return false;\r
+                }\r
+\r
+                m_allowedValues.addValues(values);\r
+                return true;\r
+            }\r
+            inline int getAllowedValuesSize() const\r
+            {\r
+                return m_allowedValues.size();\r
+            }\r
+            inline std::vector<ValueVariant> getAllowedValues()\r
+            {\r
+                return m_allowedValues.getValues();\r
+            }\r
+            inline std::vector<int> getAllowedValuesInt()\r
+            {\r
+                return m_allowedValues.getValuesInt();\r
+            }\r
+            inline std::vector<std::string> getAllowedValuesString()\r
+            {\r
+                return m_allowedValues.getValuesString();\r
+            }\r
+            inline void setDescription(const std::string &description)\r
+            {\r
+                m_description = description;\r
+            }\r
+            inline std::string getDescription()\r
+            {\r
+                return m_description;\r
+            }\r
+            inline int getUpdateFrequencyTime()\r
+            {\r
+                return m_updateInterval;\r
+            }\r
+            inline void setUpdateFrequencyTime(int interval)\r
+            {\r
+                m_updateInterval = interval;\r
+            }\r
+            void setType(const std::string &type)\r
+            {\r
+                m_type = type;\r
+            }\r
+            std::string getType()\r
+            {\r
+                return m_type;\r
+            }\r
+            void setPattern(const std::string &pattern)\r
+            {\r
+                m_pattern = pattern;\r
+            }\r
+            std::string getPattern()\r
+            {\r
+                return m_pattern;\r
+            }\r
+            void setFormat(const std::string &format)\r
+            {\r
+                m_format = format;\r
+            }\r
+            std::string getFormat()\r
+            {\r
+                return m_format;\r
+            }\r
+            void setItem(Items *item)\r
+            {\r
+                m_items.push_back(item);\r
+            }\r
+            std::vector<Items *> getItems()\r
+            {\r
+                return m_items;\r
+            }\r
+            void setUnique( int value)\r
+            {\r
+                if (value == cJSON_True) m_unique = true;\r
+                else m_unique = false;\r
+            }\r
+\r
+            bool getUnique()\r
+            {\r
+                return m_unique;\r
+            }\r
+\r
+            void setAdditionalItems(int value)\r
+            {\r
+                if (value == cJSON_True) m_additionalItems = true;\r
+                else m_additionalItems = false;\r
+            }\r
+\r
+            bool getAdditionalItems()\r
+            {\r
+                return m_additionalItems;\r
+            }\r
+        private:\r
+            std::string m_name;\r
+            ValueVariant m_value;\r
+            int m_max;\r
+            int m_min;\r
+            int m_multipleOf;\r
+            AllowedValues m_allowedValues;\r
+            int m_updateInterval;\r
+            std::string m_type;\r
+            std::string m_pattern;\r
+            std::string m_format;\r
+            std::string m_description;\r
+            bool m_unique;\r
+            bool m_additionalItems;\r
+            std::vector<Items *> m_items;\r
+    };\r
+    typedef std::shared_ptr<Properties> PropertiesPtr;\r
+\r
+}\r
+#endif\r
index 550af9a..f77add3 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
index fc3533c..7aea032 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
index 346fa9e..15c826a 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -38,55 +38,56 @@ namespace RAML
     {\r
         m_description = description;\r
     }\r
-    std::map<std::string, HeaderAction::getHeaders() const\r
+    std::map<std::string, HeaderPtr > const &Action::getHeaders() const\r
     {\r
         return m_headers;\r
     }\r
-    void Action::setHeader(const std::string &headerName, const Header &header)\r
+    void Action::setHeader(const std::string &headerName, const HeaderPtr &header)\r
     {\r
         m_headers[headerName] = header;\r
     }\r
-    std::map<std::string, QueryParameterAction::getQueryParameters()const\r
+    std::map<std::string, QueryParameterPtr > const &Action::getQueryParameters()const\r
     {\r
         return m_queryParameters;\r
     }\r
-    void Action::setQueryParameter(const std::string &paramName, const QueryParameter &queryParameter)\r
+    void Action::setQueryParameter(const std::string &paramName,\r
+                                   const QueryParameterPtr &queryParameter)\r
     {\r
         m_queryParameters[paramName] = queryParameter;\r
     }\r
-    RequestResponseBody &Action::getRequestBody(std::string bodyType)\r
+    RequestResponseBodyPtr Action::getRequestBody(const std::string &bodyType)\r
     {\r
         return m_requestBody[bodyType];\r
     }\r
 \r
-    std::map<std::string, RequestResponseBodyAction::getRequestBody() const\r
+    std::map<std::string, RequestResponseBodyPtr> const &Action::getRequestBody() const\r
     {\r
         return m_requestBody;\r
     }\r
     void Action::setRequestBody(const std::string &typeName)\r
     {\r
-        m_requestBody[typeName] = *(new RequestResponseBody(typeName));\r
+        m_requestBody[typeName] = std::make_shared<RequestResponseBody>(typeName);\r
     }\r
 \r
-    void Action::setRequestBody(const std::string &typeName , const RequestResponseBody &body)\r
+    void Action::setRequestBody(const std::string &typeName , const RequestResponseBodyPtr &body)\r
     {\r
         m_requestBody[typeName] = body;\r
     }\r
-    Response &Action::getResponse(std::string responseCode)\r
+    ResponsePtr Action::getResponse(const std::string &responseCode)\r
     {\r
         return m_responses[responseCode];\r
     }\r
 \r
-    std::map<std::string, ResponseAction::getResponses() const\r
+    std::map<std::string, ResponsePtr> const &Action::getResponses() const\r
     {\r
         return m_responses;\r
     }\r
-    void Action::setResponse(const std::string &responseCode, const Response &response)\r
+    void Action::setResponse(const std::string &responseCode, const ResponsePtr &response)\r
     {\r
         m_responses[responseCode] = response;\r
     }\r
 \r
-    std::list<std::string> Action::getProtocols() const\r
+    std::list<std::string> const &Action::getProtocols() const\r
     {\r
         return m_protocols;\r
     }\r
@@ -94,17 +95,17 @@ namespace RAML
     {\r
         m_protocols.push_back(protocol);\r
     }\r
-    std::map<std::string, UriParameter > Action::getBaseUriParameters() const\r
+    std::map<std::string, UriParameterPtr > const &Action::getBaseUriParameters() const\r
     {\r
         return m_baseUriParameters;\r
     }\r
     void Action::setBaseUriParameter(const std::string &paramName ,\r
-                                     const UriParameter  &baseUriParameter)\r
+                                     const UriParameterPtr &baseUriParameter)\r
     {\r
         m_baseUriParameters[paramName] = baseUriParameter;\r
     }\r
 \r
-    std::list<std::string> Action::getTraits() const\r
+    std::list<std::string> const &Action::getTraits() const\r
     {\r
         return m_trait;\r
     }\r
@@ -112,10 +113,8 @@ namespace RAML
     {\r
         m_trait.push_back(trait);\r
     }\r
-    void Action::readAction(const ActionType actionType, const YAML::Node &yamlNode,\r
-                            IncludeResolver *includeResolver)\r
+    void Action::readAction(const ActionType actionType, const YAML::Node &yamlNode)\r
     {\r
-        m_includeResolver = includeResolver;\r
         m_type = actionType;\r
         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
         {\r
@@ -129,7 +128,7 @@ namespace RAML
                 for ( YAML::const_iterator tt = responseNode.begin(); tt != responseNode.end(); ++tt )\r
                 {\r
                     std::string responseCode = READ_NODE_AS_STRING(tt->first);\r
-                    setResponse(responseCode, *(new Response(tt->second, m_includeResolver)));\r
+                    setResponse(responseCode, std::make_shared<Response>(tt->second, m_includeResolver));\r
                 }\r
             }\r
             else if (key == Keys::Headers)\r
@@ -137,8 +136,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    Header *header = new Header(tt->second);\r
-                    setHeader(READ_NODE_AS_STRING(tt->first), *header);\r
+                    setHeader(READ_NODE_AS_STRING(tt->first), std::make_shared<Header>(tt->second));\r
                 }\r
             }\r
             else if (key == Keys::QueryParameters)\r
@@ -146,8 +144,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    QueryParameter *queryParameter = new QueryParameter(tt->second);\r
-                    setQueryParameter(READ_NODE_AS_STRING(tt->first), *queryParameter);\r
+                    setQueryParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<QueryParameter>(tt->second));\r
                 }\r
             }\r
             else if (key == Keys::Protocols)\r
@@ -163,8 +160,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    UriParameter *uriParameter = new UriParameter(tt->second);\r
-                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));\r
                 }\r
             }\r
             else if (key == Keys::Body)\r
@@ -174,7 +170,7 @@ namespace RAML
                 for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
                 {\r
                     std::string type = READ_NODE_AS_STRING(tt->first);\r
-                    setRequestBody(type, *(new RequestResponseBody(type, tt->second, m_includeResolver)));\r
+                    setRequestBody(type, std::make_shared<RequestResponseBody>(type, tt->second, m_includeResolver));\r
                 }\r
             }\r
             else if (key == Keys::IsTrait)\r
index c843bf4..348b476 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -42,50 +42,56 @@ namespace RAML
             virtual void setType(const ActionType &type);\r
             virtual std::string getDescription() const;\r
             virtual void setDescription(const std::string &description);\r
-            virtual std::map<std::string, Header> getHeaders() const;\r
-            virtual void setHeader(const std::string &headerName, const Header &header);\r
-            virtual std::map<std::string, QueryParameter> getQueryParameters()const;\r
-            virtual void setQueryParameter(const std::string &paramName, const QueryParameter &queryParameter);\r
-            virtual RequestResponseBody &getRequestBody(std::string bodyType);\r
-            virtual std::map<std::string, RequestResponseBody> getRequestBody() const;\r
+            virtual std::map<std::string, HeaderPtr > const &getHeaders() const;\r
+            virtual void setHeader(const std::string &headerName, const HeaderPtr &header);\r
+            virtual std::map<std::string, QueryParameterPtr > const &getQueryParameters()const;\r
+            virtual void setQueryParameter(const std::string &paramName,\r
+                                           const QueryParameterPtr &queryParameter);\r
+\r
+            virtual RequestResponseBodyPtr getRequestBody(const std::string &bodyType);\r
+            virtual std::map<std::string, RequestResponseBodyPtr> const &getRequestBody() const;\r
             virtual void setRequestBody(const std::string &typeName);\r
-            virtual void setRequestBody(const std::string &typeName , const RequestResponseBody &body);\r
-            virtual Response &getResponse(std::string responseCode);\r
-            virtual std::map<std::string, Response> getResponses() const;\r
-            virtual void setResponse(const std::string &responseCode, const Response &response);\r
-            virtual std::list<std::string> getProtocols() const;\r
+            virtual void setRequestBody(const std::string &typeName , const RequestResponseBodyPtr &body);\r
+\r
+            virtual ResponsePtr getResponse(const std::string &responseCode);\r
+            virtual std::map<std::string, ResponsePtr> const &getResponses() const;\r
+            virtual void setResponse(const std::string &responseCode, const ResponsePtr &response);\r
+            virtual std::list<std::string> const &getProtocols() const;\r
             virtual void setProtocol(const std::string &protocol);\r
-            virtual std::map< std::string, UriParameter > getBaseUriParameters() const;\r
+            virtual std::map< std::string, UriParameterPtr > const &getBaseUriParameters() const;\r
             virtual void setBaseUriParameter(const std::string &paramName ,\r
-                                             const UriParameter  &baseUriParameter);\r
-            virtual std::list<std::string> getTraits() const;\r
+                                             const UriParameterPtr &baseUriParameter);\r
+            virtual std::list<std::string> const &getTraits() const;\r
             virtual void setTrait(const std::string &trait);\r
 \r
 \r
-            Action() { }\r
-            Action(const ActionType actionType, const YAML::Node &yamlNode, IncludeResolver *includeResolver)\r
+            Action(): m_includeResolver(NULL) { }\r
+            Action(const ActionType actionType, const YAML::Node &yamlNode,\r
+                   const IncludeResolverPtr &includeResolver)\r
+                : m_includeResolver(includeResolver)\r
             {\r
-                readAction(actionType, yamlNode, includeResolver);\r
+                readAction(actionType, yamlNode);\r
             }\r
-\r
+            Action(const Action &action) = default;\r
         private:\r
-            virtual void readAction(const ActionType actionType, const YAML::Node &yamlNode,\r
-                                    IncludeResolver *includeResolver);\r
+            virtual void readAction(const ActionType actionType, const YAML::Node &yamlNode);\r
 \r
 \r
         private:\r
             ActionType m_type;\r
             std::string m_description;\r
-            std::map<std::string, Header> m_headers;\r
-            std::map<std::string, QueryParameter> m_queryParameters;\r
-            std::map<std::string, RequestResponseBody> m_requestBody;\r
-            std::map<std::string, Response> m_responses;\r
+            std::map<std::string, HeaderPtr> m_headers;\r
+            std::map<std::string, QueryParameterPtr> m_queryParameters;\r
+            std::map<std::string, RequestResponseBodyPtr> m_requestBody;\r
+            std::map<std::string, ResponsePtr> m_responses;\r
             std::list<std::string> m_protocols;\r
-            std::map< std::string, UriParameter > m_baseUriParameters;\r
+            std::map< std::string, UriParameterPtr > m_baseUriParameters;\r
             std::list<std::string> m_trait;\r
 \r
         private:\r
-            IncludeResolver *m_includeResolver;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
+\r
+    typedef std::shared_ptr<Action> ActionPtr;\r
 }\r
 #endif\r
index 8921b1e..a653390 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
index 4b83366..c2a0793 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
index d432ede..c708e52 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
index b62d954..61d15f1 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -31,6 +31,7 @@ namespace RAML
             FormParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
             FormParameter() {}\r
     };\r
+    typedef std::shared_ptr<FormParameter> FormParameterPtr;\r
 \r
 }\r
 #endif\r
index 47e03f7..3aca86b 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -31,6 +31,7 @@ namespace RAML
             Header(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
             Header() {}\r
     };\r
+    typedef std::shared_ptr<Header> HeaderPtr;\r
 \r
 }\r
 #endif\r
index d414378..1850614 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -31,6 +31,7 @@ namespace RAML
             QueryParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
             QueryParameter() {}\r
     };\r
+    typedef std::shared_ptr<QueryParameter> QueryParameterPtr;\r
 \r
 }\r
 #endif\r
index a9864b4..4e68999 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -50,7 +50,7 @@ namespace RAML
         m_baseUri = baseUri;\r
     }\r
 \r
-    std::list<std::string> Raml::getProtocols() const\r
+    std::list<std::string> const &Raml::getProtocols() const\r
     {\r
         return m_protocols;\r
     }\r
@@ -58,11 +58,11 @@ namespace RAML
     {\r
         m_protocols.push_back(protocol);\r
     }\r
-    std::map<std::string, UriParameterRaml::getBaseUriParameters() const\r
+    std::map<std::string, UriParameterPtr> const &Raml::getBaseUriParameters() const\r
     {\r
         return m_baseUriParameters;\r
     }\r
-    void Raml::setBaseUriParameter(const std::string &paramName, const UriParameter &uriParameter)\r
+    void Raml::setBaseUriParameter(const std::string &paramName, const UriParameterPtr &uriParameter)\r
     {\r
         m_baseUriParameters[paramName] = uriParameter;\r
     }\r
@@ -76,54 +76,54 @@ namespace RAML
         m_mediaType = mediaType;\r
     }\r
 \r
-    std::list<std::pair<std::string, Schema> > Raml::getSchemas() const\r
+    std::list<std::pair<std::string, SchemaPtr> > const &Raml::getSchemas() const\r
     {\r
         return m_schemas;\r
     }\r
 \r
-    void Raml::setSchema(const std::pair<std::string, Schema> &schema)\r
+    void Raml::setSchema(const std::string &schemaName, const SchemaPtr &schema)\r
     {\r
-        m_schemas.push_back(schema);\r
+        m_schemas.push_back(std::make_pair(schemaName, schema));\r
     }\r
 \r
-    std::list<std::pair<std::string, RamlResource> > Raml::getResourceTypes() const\r
+    std::list<std::pair<std::string, RamlResourcePtr> > const &Raml::getResourceTypes() const\r
     {\r
         return m_resourceTypes;\r
     }\r
-    void Raml::setResourceType(const std::pair<std::string, RamlResource> &resourceType)\r
+    void Raml::setResourceType(const std::string &typeName, const RamlResourcePtr &resourceType)\r
     {\r
-        m_resourceTypes.push_back(resourceType);\r
+        m_resourceTypes.push_back(std::make_pair(typeName, resourceType));\r
     }\r
 \r
-    std::list<std::pair<std::string, Action> > Raml::getTraits() const\r
+    std::list<std::pair<std::string, ActionPtr> > const &Raml::getTraits() const\r
     {\r
         return m_traits;\r
     }\r
-    void Raml::setTrait(const std::pair<std::string, Action> &trait)\r
+    void Raml::setTrait(const std::string &traitName, const ActionPtr &trait)\r
     {\r
-        m_traits.push_back(trait);\r
+        m_traits.push_back(std::make_pair(traitName, trait));\r
     }\r
-    RamlResource &Raml::getResource(std::string resourceName)\r
+    RamlResourcePtr Raml::getResource(const std::string &resourceName)\r
     {\r
         return m_resources[resourceName];\r
     }\r
 \r
-    std::map<std::string, RamlResourceRaml::getResources() const\r
+    std::map<std::string, RamlResourcePtr> const &Raml::getResources() const\r
     {\r
         return m_resources;\r
     }\r
 \r
-    void Raml::setResource(const std::string &resourceKey, const RamlResource &resource)\r
+    void Raml::setResource(const std::string &resourceKey, const RamlResourcePtr &resource)\r
     {\r
         m_resources[resourceKey] = resource;\r
     }\r
 \r
-    void Raml::setDocumentationItem(const DocumentationItem &documentationItem)\r
+    void Raml::setDocumentationItem(const std::shared_ptr<DocumentationItem> &documentationItem)\r
     {\r
         m_documentation.push_back(documentationItem);\r
     }\r
 \r
-    std::list<DocumentationItem> Raml::getDocumentation() const\r
+    std::list<std::shared_ptr<DocumentationItem> > const &Raml::getDocumentation() const\r
     {\r
         return m_documentation;\r
     }\r
@@ -151,8 +151,7 @@ namespace RAML
                     YAML::Node paramNode = it->second;\r
                     for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                     {\r
-                        UriParameter *uriParameter = new UriParameter(tt->second);\r
-                        setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                        setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));\r
                     }\r
                 }\r
                 else if (key == Keys::Protocols)\r
@@ -185,7 +184,7 @@ namespace RAML
                                 content = READ_NODE_AS_STRING(tt->second);\r
 \r
                         }\r
-                        setDocumentationItem(*(new DocumentationItem(title, content)));\r
+                        setDocumentationItem(std::make_shared<DocumentationItem>(title, content));\r
                     }\r
                 }\r
                 else if (key == Keys::Schemas)\r
@@ -201,23 +200,20 @@ namespace RAML
                             IncludeResolver::FileType fileType = m_includeResolver->getFileType(tt->second);\r
                             if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE))\r
                             {\r
-                                Schema *schemaPtr = new Schema(m_includeResolver->readFromFile(tt->second));\r
-                                schema = std::make_pair(key, *schemaPtr);\r
+                                setSchema(key, std::make_shared<Schema>(m_includeResolver->readFromFile(tt->second),\r
+                                                                        m_includeResolver));\r
                             }\r
                             else\r
                             {\r
-                                std::string value = READ_NODE_AS_STRING(tt->second);\r
-                                schema = std::make_pair(key, *(new Schema(value)));\r
+                                setSchema(key, std::make_shared<Schema>(READ_NODE_AS_STRING(tt->second), m_includeResolver));\r
                             }\r
-                            setSchema(schema);\r
                         }\r
                     }\r
                 }\r
 \r
                 else if (key.compare(0, Keys::Resource.length(), Keys::Resource)  == 0)\r
                 {\r
-                    RamlResource *resource = new RamlResource(key, it->second, m_includeResolver, getBaseUri());\r
-                    setResource(key, *resource);\r
+                    setResource(key, std::make_shared<RamlResource>(key, it->second, m_includeResolver, getBaseUri()));\r
                 }\r
                 else if (key == Keys::Traits)\r
                 {\r
@@ -227,12 +223,7 @@ namespace RAML
                         for (auto elem : *tt)\r
                         {\r
                             std::string trait = READ_NODE_AS_STRING(elem.first);\r
-                            Action *action = new Action(ActionType::NONE, elem.second , m_includeResolver);\r
-\r
-                            std::pair<std::string, Action> resourceTrait;\r
-                            resourceTrait = std::make_pair(trait, *action);\r
-\r
-                            setTrait(resourceTrait);\r
+                            setTrait(trait, std::make_shared<Action>(ActionType::NONE, elem.second , m_includeResolver));\r
                         }\r
                     }\r
                 }\r
@@ -244,12 +235,8 @@ namespace RAML
                         for (auto elem : *tt)\r
                         {\r
                             std::string type = READ_NODE_AS_STRING(elem.first);\r
-                            RamlResource *resource = new RamlResource(type, elem.second, m_includeResolver, getBaseUri());\r
-\r
-                            std::pair<std::string, RamlResource> resourceType;\r
-                            resourceType = std::make_pair(type, *resource);\r
-\r
-                            setResourceType(resourceType);\r
+                            setResourceType(type, std::make_shared<RamlResource>(type, elem.second, m_includeResolver,\r
+                                            getBaseUri()));\r
 \r
                         }\r
 \r
index c3c537c..6c7454a 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -40,6 +40,8 @@
 \r
 #include "DocumentationItem.h"\r
 #include "yaml-cpp/yaml.h"\r
+#include "yaml-cpp/exceptions.h"\r
+#include "RamlExceptions.h"\r
 #include "Utils.h"\r
 #include "cJSON.h"\r
 \r
@@ -58,48 +60,72 @@ namespace RAML
             virtual std::string getBaseUri() const;\r
             virtual void setBaseUri(const std::string &baseUri);\r
 \r
-            virtual std::list<std::string> getProtocols() const;\r
+            virtual std::list<std::string> const &getProtocols() const;\r
             virtual void setProtocol(const std::string &protocol);\r
 \r
 \r
-            virtual std::map<std::string, UriParametergetBaseUriParameters() const;\r
-            virtual void setBaseUriParameter(const std::string &paramName, const UriParameter &uriParameter);\r
+            virtual std::map<std::string, UriParameterPtr> const &getBaseUriParameters() const;\r
+            virtual void setBaseUriParameter(const std::string &paramName, const UriParameterPtr &uriParameter);\r
 \r
             virtual std::string getMediaType() const;\r
             virtual void setMediaType(const std::string &mediaType);\r
 \r
-            virtual std::list<std::pair<std::string, Schema> > getSchemas() const;\r
-            virtual void setSchema(const std::pair<std::string, Schema> &schema);\r
+            virtual std::list<std::pair<std::string, SchemaPtr> > const &getSchemas() const;\r
+            virtual void setSchema(const std::string &schemaName, const SchemaPtr &schema);\r
 \r
-            virtual std::list<std::pair<std::string, RamlResource> > getResourceTypes() const;\r
-            virtual void setResourceType(const std::pair<std::string, RamlResource> &resourceType);\r
+            virtual std::list<std::pair<std::string, RamlResourcePtr> > const &getResourceTypes() const;\r
+            virtual void setResourceType(const std::string &typeName, const RamlResourcePtr &resourceType);\r
 \r
-            virtual std::list<std::pair<std::string, Action> > getTraits() const;\r
-            virtual void setTrait(const std::pair<std::string, Action> &trait);\r
+            virtual std::list<std::pair<std::string, ActionPtr> > const &getTraits() const;\r
+            virtual void setTrait(const std::string &traitName, const ActionPtr &trait);\r
 \r
-            virtual RamlResource &getResource(std::string resourceName);\r
-            virtual std::map<std::string, RamlResourcegetResources() const;\r
-            virtual void setResource(const std::string &resourceKey, const RamlResource &resource);\r
+            virtual RamlResourcePtr getResource(const std::string &resourceName);\r
+            virtual std::map<std::string, RamlResourcePtr> const &getResources() const;\r
+            virtual void setResource(const std::string &resourceKey, const RamlResourcePtr &resource);\r
 \r
-            virtual void setDocumentationItem(const DocumentationItem &documentationItem);\r
-            virtual std::list<DocumentationItem> getDocumentation() const;\r
+            virtual void setDocumentationItem(const std::shared_ptr<DocumentationItem> &documentationItem);\r
+            virtual std::list<std::shared_ptr<DocumentationItem> > const &getDocumentation() const;\r
 \r
             void readRamlFromYaml(const YAML::Node &yamlNode);\r
-            Raml() : m_includeResolver(new IncludeResolver()) {}\r
-            Raml(std::string &resourceLocation) : m_includeResolver(new IncludeResolver(resourceLocation)) {}\r
+            Raml() : m_includeResolver(std::make_shared<IncludeResolver>()) {}\r
+            Raml(const std::string &fileLocation,\r
+                 const std::string &ramlName) : m_includeResolver(std::make_shared<IncludeResolver>(fileLocation))\r
+            {\r
+                try\r
+                {\r
+                    YAML::Node yamlRootNode = YAML::LoadFile(fileLocation + ramlName);\r
+                    readRamlFromYaml(yamlRootNode);\r
+                }\r
+                catch (YAML::ParserException &e)\r
+                {\r
+                    throw RamlParserException(e.mark, e.msg);\r
+                }\r
+                catch (YAML::RepresentationException &e)\r
+                {\r
+                    throw RamlRepresentationException(e.mark, e.msg);\r
+                }\r
+                catch (YAML::BadFile &e)\r
+                {\r
+                    throw RamlBadFile(e.mark, e.msg);\r
+                }\r
+                catch (JsonException &e)\r
+                {\r
+                    throw;\r
+                }\r
+            }\r
         private:\r
             std::string m_title;\r
             std::string m_version;\r
             std::string m_baseUri;\r
             std::list<std::string> m_protocols;\r
-            std::map<std::string, UriParameter> m_baseUriParameters;\r
+            std::map<std::string, UriParameterPtr> m_baseUriParameters;\r
             std::string m_mediaType;\r
-            std::list <std::pair<std::string, Schema> > m_schemas;\r
-            std::list <std::pair<std::string, RamlResource> > m_resourceTypes;\r
-            std::list <std::pair<std::string, Action> > m_traits;\r
-            std::map<std::string, RamlResource> m_resources;\r
-            std::list<DocumentationItem> m_documentation;\r
-            IncludeResolver *m_includeResolver;\r
+            std::list <std::pair<std::string, SchemaPtr> > m_schemas;\r
+            std::list <std::pair<std::string, RamlResourcePtr> > m_resourceTypes;\r
+            std::list <std::pair<std::string, ActionPtr> > m_traits;\r
+            std::map<std::string, RamlResourcePtr> m_resources;\r
+            std::list<std::shared_ptr<DocumentationItem> > m_documentation;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
 \r
     typedef std::shared_ptr<Raml> RamlPtr;\r
index df5f617..66fc2fc 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
 \r
 namespace RAML\r
 {\r
-    RamlResource *RamlResource::getParentResource()\r
-    {\r
-        return m_parentResource;\r
-    }\r
-    void RamlResource::setParentResource(RamlResource *parentResource)\r
-    {\r
-        m_parentResource = parentResource;\r
-    }\r
-\r
     std::string RamlResource::getDisplayName() const\r
     {\r
         return m_displayName;\r
@@ -64,45 +55,47 @@ namespace RAML
     {\r
         m_relativeUri = relativeUri;\r
     }\r
-    std::map<std::string, UriParameterRamlResource::getUriParameters() const\r
+    std::map<std::string, UriParameterPtr> const &RamlResource::getUriParameters() const\r
     {\r
         return m_uriParameters;\r
     }\r
-    void RamlResource::setUriParameter(const std::string &paramName, const UriParameter &uriParameter)\r
+    void RamlResource::setUriParameter(const std::string &paramName,\r
+                                       const UriParameterPtr &uriParameter)\r
     {\r
         m_uriParameters[paramName] = uriParameter;\r
     }\r
-    std::map<std::string, UriParameter > RamlResource::getBaseUriParameters() const\r
+    std::map<std::string, UriParameterPtr > const &RamlResource::getBaseUriParameters() const\r
     {\r
         return m_baseUriParameters;\r
     }\r
     void RamlResource::setBaseUriParameter(const std::string &paramName,\r
-                                           const UriParameter &baseUriParameter)\r
+                                           const UriParameterPtr &baseUriParameter)\r
     {\r
         m_baseUriParameters[paramName] = baseUriParameter;\r
     }\r
-    Action &RamlResource::getAction(ActionType actionType)\r
+    ActionPtr RamlResource::getAction(ActionType actionType)\r
     {\r
         return m_actions[actionType];\r
     }\r
 \r
-    std::map<ActionType , ActionRamlResource::getActions() const\r
+    std::map<ActionType , ActionPtr> const &RamlResource::getActions() const\r
     {\r
         return m_actions;\r
     }\r
-    void RamlResource::setAction(const ActionType &actiontype , const Action &action )\r
+    void RamlResource::setAction(const ActionType &actiontype , const ActionPtr &action )\r
     {\r
         m_actions[actiontype] = action;\r
     }\r
-    std::map<std::string, RamlResource> RamlResource::getResources() const\r
+    std::map<std::string, std::shared_ptr<RamlResource> > const &RamlResource::getResources() const\r
     {\r
         return m_resources;\r
     }\r
-    void RamlResource::setResource(const std::string &resourceName, const RamlResource &resources)\r
+    void RamlResource::setResource(const std::string &resourceName,\r
+                                   const std::shared_ptr<RamlResource> &resources)\r
     {\r
         m_resources[resourceName] = resources;\r
     }\r
-    std::list<std::string> RamlResource::getTraits() const\r
+    std::list<std::string> const &RamlResource::getTraits() const\r
     {\r
         return m_traits;\r
     }\r
@@ -123,9 +116,8 @@ namespace RAML
         return (m_parentUri + m_relativeUri);\r
     }\r
     void RamlResource::readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
-                                    IncludeResolver *includeResolver, const std::string &parentUri)\r
+                                    const std::string &parentUri)\r
     {\r
-        m_includeResolver = includeResolver;\r
         m_relativeUri = resourceKey;\r
         m_parentUri = parentUri;\r
         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
@@ -140,15 +132,14 @@ namespace RAML
             {\r
                 ActionType actionType = GET_ACTION_TYPE(key);\r
 \r
-                setAction(actionType, *(new Action(actionType, it->second, m_includeResolver)));\r
+                setAction(actionType, std::make_shared<Action>(actionType, it->second, m_includeResolver));\r
             }\r
             else if (key == Keys::UriParameters)\r
             {\r
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    UriParameter *uriParameter = new UriParameter(tt->second);\r
-                    setUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                    setUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));\r
                 }\r
             }\r
             else if (key == Keys::BaseUriParameters)\r
@@ -156,8 +147,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    UriParameter *uriParameter = new UriParameter(tt->second);\r
-                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));\r
                 }\r
             }\r
             else if (key == Keys::IsTrait)\r
@@ -172,6 +162,11 @@ namespace RAML
             {\r
                 setResourceType(READ_NODE_AS_STRING(it->second));\r
             }\r
+            else if (key.compare(0, Keys::Resource.length(), Keys::Resource)  == 0)\r
+            {\r
+                setResource(key, std::make_shared<RamlResource>(key, it->second, m_includeResolver,\r
+                            getResourceUri()));\r
+            }\r
         }\r
     }\r
 \r
index ebcbf3c..c7acf78 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -35,9 +35,6 @@ namespace RAML
     class RamlResource\r
     {\r
         public:\r
-            virtual RamlResource *getParentResource();\r
-            virtual void setParentResource(RamlResource *parentResource);\r
-\r
             virtual std::string getDisplayName() const;\r
             virtual void setDisplayName(const std::string &displayName);\r
 \r
@@ -50,46 +47,52 @@ namespace RAML
             virtual std::string getRelativeUri() const;\r
             virtual void setRelativeUri(const std::string &relativeUri);\r
 \r
-            virtual std::map<std::string, UriParametergetUriParameters() const;\r
-            virtual void setUriParameter(const std::string &paramName, const UriParameter &uriParameter);\r
+            virtual std::map<std::string, UriParameterPtr> const &getUriParameters() const;\r
+            virtual void setUriParameter(const std::string &paramName, const UriParameterPtr &uriParameter);\r
 \r
-            virtual std::map<std::string, UriParameter > getBaseUriParameters() const;\r
+            virtual std::map<std::string, UriParameterPtr > const &getBaseUriParameters() const;\r
             virtual void setBaseUriParameter(const std::string &paramName,\r
-                                             const UriParameter &baseUriParameter);\r
+                                             const UriParameterPtr &baseUriParameter);\r
 \r
-            virtual Action &getAction(ActionType actionType);\r
-            virtual std::map<ActionType , ActiongetActions() const;\r
-            virtual void setAction(const ActionType &actiontype , const Action &action );\r
+            virtual ActionPtr getAction(ActionType actionType);\r
+            virtual std::map<ActionType , ActionPtr> const &getActions() const;\r
+            virtual void setAction(const ActionType &actiontype , const ActionPtr &action );\r
 \r
-            virtual std::map<std::string, RamlResource> getResources() const;\r
-            virtual void setResource(const std::string &resourceName, const RamlResource &resources);\r
+            virtual std::map<std::string, std::shared_ptr<RamlResource> > const &getResources() const;\r
+            virtual void setResource(const std::string &resourceName,\r
+                                     const std::shared_ptr<RamlResource> &resources);\r
 \r
-            virtual std::list<std::string> getTraits() const;\r
+            virtual std::list<std::string> const &getTraits() const;\r
             virtual void setTrait(const std::string &trait);\r
 \r
             virtual std::string getResourceType() const;\r
             virtual void setResourceType(const std::string &type);\r
 \r
             virtual std::string getResourceUri() const;\r
-            RamlResource() {}\r
+            RamlResource(): m_includeResolver(NULL) {}\r
             RamlResource(const std::string resourceKey, const YAML::Node &yamlNode ,\r
-                         IncludeResolver *includeResolver, const std::string &parentUri) { readResource(resourceKey, yamlNode, includeResolver, parentUri); }\r
+                         const IncludeResolverPtr &includeResolver,\r
+                         const std::string &parentUri) : m_includeResolver(includeResolver)\r
+            {\r
+                readResource(resourceKey, yamlNode, parentUri);\r
+            }\r
         private:\r
             void readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
-                              IncludeResolver *includeResolver, const std::string &parentUri);\r
+                              const std::string &parentUri);\r
         private:\r
             std::string m_displayName;\r
             std::string m_description;\r
             std::string m_relativeUri;\r
-            std::map<std::string, UriParameter> m_uriParameters;\r
-            std::map<std::string, UriParameter > m_baseUriParameters;\r
-            std::map<ActionType , Action> m_actions;\r
+            std::map<std::string, UriParameterPtr> m_uriParameters;\r
+            std::map<std::string, UriParameterPtr > m_baseUriParameters;\r
+            std::map<ActionType , ActionPtr> m_actions;\r
             std::list<std::string> m_traits;\r
             std::string m_resourceType;\r
-            RamlResource *m_parentResource;\r
             std::string m_parentUri;\r
-            std::map<std::string, RamlResource> m_resources;\r
-            IncludeResolver *m_includeResolver;\r
+            std::map<std::string, std::shared_ptr<RamlResource> > m_resources;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
+\r
+    typedef std::shared_ptr<RamlResource> RamlResourcePtr;\r
 }\r
 #endif\r
index 366e026..e96226a 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -31,11 +31,11 @@ namespace RAML
     {\r
         m_type = type;\r
     }\r
-    Schema *RequestResponseBody::getSchema() const\r
+    SchemaPtr const &RequestResponseBody::getSchema() const\r
     {\r
         return m_schema;\r
     }\r
-    void RequestResponseBody::setSchema(Schema *schema)\r
+    void RequestResponseBody::setSchema(const SchemaPtr &schema)\r
     {\r
         m_schema = schema;\r
     }\r
@@ -47,22 +47,19 @@ namespace RAML
     {\r
         m_example = example;\r
     }\r
-    std::map<std::string, FormParameter > RequestResponseBody::getFormParameters() const\r
+    std::map<std::string, FormParameterPtr > const &RequestResponseBody::getFormParameters() const\r
     {\r
         return m_formParameters ;\r
     }\r
     void RequestResponseBody::setFormParameter(const std::string &paramName,\r
-            const FormParameter  &formParameter)\r
+            const FormParameterPtr  &formParameter)\r
     {\r
         m_formParameters[paramName] = formParameter;\r
     }\r
     void RequestResponseBody::readRequestResponseBody(const std::string &type,\r
-            const YAML::Node &yamlNode,\r
-            IncludeResolver *includeResolver)\r
+            const YAML::Node &yamlNode)\r
     {\r
         m_type = type;\r
-        m_schema = NULL;\r
-        m_includeResolver = includeResolver;\r
         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
         {\r
             std::string key = READ_NODE_AS_STRING(it->first);\r
@@ -72,12 +69,12 @@ namespace RAML
                 IncludeResolver::FileType fileType = m_includeResolver->getFileType(it->second);\r
                 if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE))\r
                 {\r
-                    setSchema(new Schema(m_includeResolver->readFromFile(it->second)));\r
+                    setSchema(std::make_shared<Schema>(m_includeResolver->readFromFile(it->second), m_includeResolver));\r
                 }\r
                 else\r
                 {\r
                     std::string value = READ_NODE_AS_STRING(it->second);\r
-                    setSchema(new Schema(value));\r
+                    setSchema(std::make_shared<Schema>(value, m_includeResolver));\r
                 }\r
             }\r
             else if (key == Keys::Example)\r
@@ -87,8 +84,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    FormParameter *formParameter = new FormParameter(tt->second);\r
-                    setFormParameter(READ_NODE_AS_STRING(tt->first), *formParameter);\r
+                    setFormParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<FormParameter>(tt->second));\r
                 }\r
             }\r
         }\r
index 6c3e6bb..7b2956e 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -35,27 +35,28 @@ namespace RAML
         public:\r
             virtual std::string getType() const;\r
             virtual void setType(const std::string &type);\r
-            virtual Schema *getSchema() const;\r
-            virtual void setSchema(Schema *schema);\r
+            virtual SchemaPtr const &getSchema() const;\r
+            virtual void setSchema(const SchemaPtr &schema);\r
             virtual std::string getExample() const;\r
             virtual void setExample(const std::string &example);\r
-            virtual std::map<std::string, FormParameter > getFormParameters() const;\r
-            virtual void setFormParameter(const std::string &paramName, const FormParameter  &formParameter);\r
-            RequestResponseBody(): m_schema(NULL) {}\r
-            RequestResponseBody(const std::string type) : m_type(type), m_schema(NULL) {}\r
+            virtual std::map<std::string, FormParameterPtr> const &getFormParameters() const;\r
+            virtual void setFormParameter(const std::string &paramName, const FormParameterPtr &formParameter);\r
+            RequestResponseBody(): m_schema(NULL), m_includeResolver(NULL) {}\r
+            RequestResponseBody(const std::string type) : m_type(type), m_schema(NULL),\r
+                m_includeResolver(NULL) {}\r
             RequestResponseBody(const std::string type, const YAML::Node &yamlNode,\r
-                                IncludeResolver *includeResolver) { readRequestResponseBody(type, yamlNode, includeResolver); }\r
+                                const IncludeResolverPtr &includeResolver): m_schema(NULL), m_includeResolver(includeResolver) { readRequestResponseBody(type, yamlNode); }\r
+\r
         private:\r
-            virtual void readRequestResponseBody(const std::string &type, const YAML::Node &yamlNode,\r
-                                                 IncludeResolver *includeResolver) ;\r
+            virtual void readRequestResponseBody(const std::string &type, const YAML::Node &yamlNode) ;\r
         private:\r
             std::string m_type;\r
-            Schema *m_schema;\r
+            SchemaPtr m_schema;\r
             std::string m_example;\r
-            std::map<std::string, FormParameter > m_formParameters;\r
-            IncludeResolver *m_includeResolver;\r
-\r
-\r
+            std::map<std::string, FormParameterPtr> m_formParameters;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
+\r
+    typedef std::shared_ptr<RequestResponseBody> RequestResponseBodyPtr;\r
 }\r
 #endif\r
diff --git a/service/simulator/ramlparser/raml/model/ResourceProperties.cpp b/service/simulator/ramlparser/raml/model/ResourceProperties.cpp
deleted file mode 100755 (executable)
index 9b6a122..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-#include "ResourceProperties.h"\r
-\r
-namespace RAML\r
-{\r
-\r
-    void ResourceProperties::readJson()\r
-    {\r
-        if (! m_cjson)\r
-            return;\r
-        cJSON *jsonrt = cJSON_GetObjectItem(m_cjson, "rt");\r
-        m_rt = jsonrt->valuestring;\r
-\r
-        cJSON *jsonif = cJSON_GetObjectItem(m_cjson, "if");\r
-        m_if = jsonif->valuestring;\r
-\r
-        cJSON *jsonProperties = cJSON_GetObjectItem(m_cjson, "properties");\r
-        cJSON *childProperties = jsonProperties->child;\r
-\r
-        while (childProperties)\r
-        {\r
-            std::string attName = childProperties->string;\r
-\r
-            std::string attType = cJSON_GetObjectItem(childProperties, "type")->valuestring;\r
-            if (attType == "string")\r
-            {\r
-                addAttribute(attName , std::string(cJSON_GetObjectItem(childProperties, "default")->valuestring));\r
-                cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "values");\r
-                if (allowedvalues)\r
-                {\r
-                    int size = cJSON_GetArraySize(allowedvalues);\r
-                    int idx = 0;\r
-                    std::vector<std::string> allwdValues;\r
-\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
-\r
-                    }\r
-                    while ( ++idx < size);\r
-\r
-                    setAllowedValues(attName, allwdValues);\r
-                }\r
-            }\r
-            else\r
-            {\r
-                addAttribute(attName , int(cJSON_GetObjectItem(childProperties, "default")->valueint));\r
-                cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "values");\r
-                if (allowedvalues)\r
-                {\r
-                    int size = cJSON_GetArraySize(allowedvalues);\r
-                    int idx = 0;\r
-                    std::vector<int> allwdValues;\r
-\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
-\r
-                    }\r
-                    while ( ++idx < size);\r
-\r
-                    setAllowedValues(attName, allwdValues);\r
-                }\r
-                cJSON *ranges = cJSON_GetObjectItem(childProperties, "range");\r
-                if (ranges)\r
-                {\r
-                    int sizeRange = cJSON_GetArraySize(ranges);\r
-                    if (sizeRange == 2)\r
-                    {\r
-                        setRange(attName , (cJSON_GetArrayItem(ranges, 0)->valueint) , (cJSON_GetArrayItem(ranges,\r
-                                 1)->valueint));\r
-                    }\r
-                }\r
-\r
-            }\r
-\r
-            setUpdateInterval(attName , cJSON_GetObjectItem(childProperties, "update_frequency")->valueint);\r
-            childProperties = childProperties->next;\r
-        }\r
-\r
-    }\r
-\r
-}\r
-\r
diff --git a/service/simulator/ramlparser/raml/model/ResourceProperties.h b/service/simulator/ramlparser/raml/model/ResourceProperties.h
deleted file mode 100755 (executable)
index 802bde9..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-#ifndef RESOURCE_PROPERTIES_H_\r
-#define RESOURCE_PROPERTIES_H_\r
-\r
-#include <string>\r
-#include <vector>\r
-#include <map>\r
-#include "cJSON.h"\r
-#include <boost/variant.hpp>\r
-#include <boost/lexical_cast.hpp>\r
-\r
-namespace RAML\r
-{\r
-\r
-    class ResourceProperties\r
-    {\r
-        public:\r
-            ResourceProperties() {}\r
-            ResourceProperties(cJSON *cjson) : m_cjson(cjson) { readJson();}\r
-\r
-            class Attribute\r
-            {\r
-                public:\r
-                    typedef boost::variant <\r
-                    int,\r
-                    double,\r
-                    std::string\r
-                    > ValueVariant;\r
-\r
-                    Attribute() = default;\r
-                    Attribute(const std::string &attrName) : m_name(attrName) {}\r
-\r
-                    inline std::string getName(void) const { return m_name; }\r
-                    inline void setName(const std::string &name) { m_name = name;}\r
-\r
-                    template <typename T>\r
-                    T getValue() const\r
-                    {\r
-                        T val = T();\r
-                        return boost::get<T>(m_value);\r
-                    }\r
-\r
-                    ValueVariant &getValue()\r
-                    {\r
-                        return m_value;\r
-                    }\r
-\r
-                    int getValueType() const\r
-                    {\r
-                        return m_value.which();\r
-                    }\r
-                    int getValueInt()\r
-                    {\r
-                        return boost::lexical_cast<int> (m_value);\r
-                    }\r
-                    std::string getValueString()\r
-                    {\r
-                        return boost::lexical_cast<std::string> (m_value);\r
-                    }\r
-\r
-                    template <typename T>\r
-                    void setValue(const T &value)\r
-                    {\r
-                        m_value = value;\r
-                    }\r
-\r
-                    inline void getRange(int &min, int &max) const\r
-                    {\r
-                        min = m_min;\r
-                        max = m_max;\r
-                    }\r
-\r
-                    inline void setRange(const int &min, const int &max)\r
-                    {\r
-                        m_min = min;\r
-                        m_max = max;\r
-                    }\r
-\r
-                    template <typename T>\r
-                    bool setAllowedValues(const std::vector<T> &values)\r
-                    {\r
-                        ValueVariant temp = values.at(0);\r
-                        if (temp.which() != m_value.which())\r
-                        {\r
-                            return false;\r
-                        }\r
-\r
-                        m_allowedValues.addValues(values);\r
-                        return true;\r
-                    }\r
-                    inline int getAllowedValuesSize() const\r
-                    {\r
-                        return m_allowedValues.size();\r
-                    }\r
-\r
-                    inline std::vector<ValueVariant> getAllowedValues()\r
-                    {\r
-                        return m_allowedValues.getValues();\r
-                    }\r
-\r
-                    int getUpdateFrequencyTime() {return m_updateInterval;}\r
-                    void setUpdateFrequencyTime(int interval) {m_updateInterval = interval;}\r
-\r
-                private:\r
-                    class AllowedValues\r
-                    {\r
-                        public:\r
-                            template <typename T>\r
-                            void addValue(const T &value)\r
-                            {\r
-                                ValueVariant temp = value;\r
-                                m_values.push_back(temp);\r
-                            }\r
-\r
-                            template <typename T>\r
-                            void addValues(const std::vector<T> &values)\r
-                            {\r
-                                for (auto value : values)\r
-                                {\r
-                                    ValueVariant vValue = value;\r
-                                    m_values.push_back(vValue);\r
-                                }\r
-                            }\r
-\r
-                            inline ValueVariant &at(int index)\r
-                            {\r
-                                return m_values.at(index);\r
-                            }\r
-                            inline int size() const\r
-                            {\r
-                                return m_values.size();\r
-                            }\r
-\r
-                            inline std::vector<ValueVariant> getValues()\r
-                            {\r
-                                return m_values;\r
-                            }\r
-\r
-                        private:\r
-                            std::vector<ValueVariant> m_values;\r
-                    };\r
-\r
-                    std::string m_name;\r
-                    ValueVariant m_value;\r
-                    int m_max;\r
-                    int m_min;\r
-                    AllowedValues m_allowedValues;\r
-                    int m_updateInterval;\r
-            };\r
-            int size() const { return m_attributes.size(); }\r
-            inline bool getAttribute(const std::string &attrName, Attribute &value)\r
-            {\r
-                if (m_attributes.end() != m_attributes.find(attrName))\r
-                {\r
-                    value = m_attributes[attrName];\r
-                    return true;\r
-                }\r
-\r
-                return false;\r
-            }\r
-\r
-            inline std::map<std::string, Attribute> getAttributes() const\r
-            {\r
-                return m_attributes;\r
-            }\r
-\r
-\r
-            template <typename T>\r
-            void addAttribute(const std::string &attrName, const T &attrValue)\r
-            {\r
-                if (m_attributes.end() == m_attributes.find(attrName))\r
-                {\r
-                    m_attributes[attrName] = Attribute(attrName);\r
-                    m_attributes[attrName].setValue(attrValue);\r
-                }\r
-            }\r
-\r
-        private:\r
-            inline void setRange(const std::string &attrName, const int min, const int max)\r
-            {\r
-                if (m_attributes.end() != m_attributes.find(attrName))\r
-                    m_attributes[attrName].setRange(min, max);\r
-            }\r
-\r
-\r
-            template <typename T>\r
-            void setAllowedValues(const std::string &attrName, const std::vector<T> &values)\r
-            {\r
-                if (m_attributes.end() != m_attributes.find(attrName))\r
-                    m_attributes[attrName].setAllowedValues(values);\r
-            }\r
-\r
-            inline void setUpdateInterval(const std::string &attrName, int interval)\r
-            {\r
-                if (m_attributes.end() != m_attributes.find(attrName))\r
-                    m_attributes[attrName].setUpdateFrequencyTime(interval);\r
-            }\r
-\r
-\r
-            inline void removeAttribute(const std::string &attrName)\r
-            {\r
-                m_attributes.erase(attrName);\r
-                return;\r
-            }\r
-            void readJson();\r
-\r
-        public:\r
-            std::string getResoureType() const {return m_rt; }\r
-            std::string getInterface() const {return m_if; }\r
-\r
-        private:\r
-            std::map<std::string, Attribute> m_attributes;\r
-            std::string m_rt;\r
-            std::string m_if;\r
-            cJSON *m_cjson;\r
-\r
-    };\r
-\r
-}\r
-#endif\r
index 8087d21..cbd1433 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
 namespace RAML\r
 {\r
 \r
-    std::map<std::string, HeaderResponse::getHeaders() const\r
+    std::map<std::string, HeaderPtr> const &Response::getHeaders() const\r
     {\r
         return m_headers;\r
     }\r
-    void Response::setHeader(const std::string &headerName, const Header &header)\r
+    void Response::setHeader(const std::string &headerName, const HeaderPtr &header)\r
     {\r
         m_headers[headerName] = header;\r
     }\r
@@ -41,24 +41,23 @@ namespace RAML
     }\r
     void Response::setResponseBody(const std::string &typeName)\r
     {\r
-        m_responseBody[typeName] = *(new RequestResponseBody(typeName));\r
+        m_responseBody[typeName] = std::make_shared<RequestResponseBody>(typeName);\r
     }\r
-    void Response::setResponseBody(const std::string &type, const RequestResponseBody &body)\r
+    void Response::setResponseBody(const std::string &type, const RequestResponseBodyPtr &body)\r
     {\r
         m_responseBody[type] = body;\r
     }\r
-    std::map<std::string, RequestResponseBodyResponse::getResponseBody() const\r
+    std::map<std::string, RequestResponseBodyPtr> const &Response::getResponseBody() const\r
     {\r
         return m_responseBody;\r
     }\r
-    RequestResponseBody &Response::getResponseBody(std::string bodyType)\r
+    RequestResponseBodyPtr Response::getResponseBody(const std::string &bodyType)\r
     {\r
         return m_responseBody[bodyType];\r
     }\r
 \r
-    void Response::readResponse(const YAML::Node &yamlNode, IncludeResolver *includeResolver)\r
+    void Response::readResponse(const YAML::Node &yamlNode)\r
     {\r
-        m_includeResolver = includeResolver;\r
         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
         {\r
             std::string key = READ_NODE_AS_STRING(it->first);\r
@@ -72,7 +71,7 @@ namespace RAML
                 for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
                 {\r
                     std::string type = READ_NODE_AS_STRING(tt->first);\r
-                    setResponseBody(type, *(new RequestResponseBody(type, tt->second, m_includeResolver)));\r
+                    setResponseBody(type, std::make_shared<RequestResponseBody>(type, tt->second, m_includeResolver));\r
                 }\r
             }\r
             else if (key == Keys::Headers)\r
@@ -80,8 +79,7 @@ namespace RAML
                 YAML::Node paramNode = it->second;\r
                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
                 {\r
-                    Header *header = new Header(tt->second);\r
-                    setHeader(READ_NODE_AS_STRING(tt->first), *header);\r
+                    setHeader(READ_NODE_AS_STRING(tt->first), std::make_shared<Header>(tt->second));\r
                 }\r
             }\r
         }\r
index cf720ec..92c09db 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -34,25 +34,27 @@ namespace RAML
     class Response\r
     {\r
         public:\r
-            virtual std::map<std::string, HeadergetHeaders() const;\r
-            virtual void setHeader(const std::string &headerName, const Header &header);\r
+            virtual std::map<std::string, HeaderPtr> const &getHeaders() const;\r
+            virtual void setHeader(const std::string &headerName, const HeaderPtr &header);\r
             virtual std::string getDescription() const;\r
             virtual void setDescription(const std::string &description);\r
             virtual void setResponseBody(const std::string &typeName);\r
-            virtual void setResponseBody(const std::string &type, const RequestResponseBody &body) ;\r
-            virtual std::map<std::string, RequestResponseBodygetResponseBody() const;\r
-            virtual RequestResponseBody &getResponseBody(const std::string bodyType);\r
+            virtual void setResponseBody(const std::string &type, const RequestResponseBodyPtr &body) ;\r
+            virtual std::map<std::string, RequestResponseBodyPtr> const &getResponseBody() const;\r
+            virtual RequestResponseBodyPtr getResponseBody(const std::string &bodyType);\r
 \r
 \r
-            Response() {}\r
-            Response(const YAML::Node &yamlNode, IncludeResolver *includeResolver) { readResponse(yamlNode, includeResolver);}\r
+            Response() : m_includeResolver(NULL) {}\r
+            Response(const YAML::Node &yamlNode,\r
+                     const IncludeResolverPtr &includeResolver): m_includeResolver(includeResolver)  { readResponse(yamlNode);}\r
         private:\r
-            void readResponse(const YAML::Node &yamlNode, IncludeResolver *includeResolver) ;\r
+            void readResponse(const YAML::Node &yamlNode) ;\r
         private:\r
             std::string m_description;\r
-            std::map<std::string, RequestResponseBody> m_responseBody;\r
-            std::map<std::string, Header> m_headers;\r
-            IncludeResolver *m_includeResolver;\r
+            std::map<std::string, RequestResponseBodyPtr> m_responseBody;\r
+            std::map<std::string, HeaderPtr> m_headers;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
+    typedef std::shared_ptr<Response> ResponsePtr;\r
 }\r
 #endif\r
index 39dece5..d03d638 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -37,8 +37,10 @@ namespace RAML
     void Schema::setSchema(const std::string &schema)\r
     {\r
         m_schema = schema;\r
+        m_cjson = cJSON_Parse(schema.c_str());\r
+        m_resProperties->setcJson(m_cjson);\r
     }\r
-    ResourceProperties *Schema::getProperties() const\r
+    JsonSchemaPtr const &Schema::getProperties() const\r
     {\r
         return m_resProperties;\r
     }\r
index e4e90ae..e38be93 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -25,7 +25,7 @@
 #include "cJSON.h"\r
 #include "IncludeResolver.h"\r
 \r
-#include "ResourceProperties.h"\r
+#include "JsonSchema.h"\r
 \r
 namespace RAML\r
 {\r
@@ -36,18 +36,22 @@ namespace RAML
             virtual void setJson(cJSON *cjson);\r
             virtual std::string getSchema() const;\r
             virtual void setSchema(const std::string &schema);\r
-            virtual ResourceProperties *getProperties() const;\r
+            virtual JsonSchemaPtr const &getProperties() const;\r
 \r
-            Schema(cJSON *cjson): m_cjson(cjson) {}\r
-            Schema(const std::string &schema): m_schema(schema) , m_cjson(cJSON_Parse(schema.c_str())),\r
-                m_resProperties(new ResourceProperties(m_cjson) ) {}\r
-            Schema() {}\r
+            Schema(const std::string &schema, const IncludeResolverPtr &includeResolver): m_schema(schema) ,\r
+                m_cjson(cJSON_Parse(schema.c_str())),\r
+                m_resProperties(std::make_shared<JsonSchema>(m_cjson, includeResolver) ) ,\r
+                m_includeResolver(includeResolver) {}\r
+            Schema(): m_cjson(NULL), m_includeResolver(NULL), m_resProperties(std::make_shared<JsonSchema>()) {}\r
+            ~Schema() { cJSON_Delete(m_cjson); }\r
 \r
         private:\r
             cJSON *m_cjson;\r
             std::string m_schema;\r
-            ResourceProperties *m_resProperties;\r
+            JsonSchemaPtr m_resProperties;\r
+            IncludeResolverPtr m_includeResolver;\r
     };\r
+    typedef std::shared_ptr<Schema> SchemaPtr;\r
 \r
 }\r
 #endif\r
index a96536e..5f8d61e 100755 (executable)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  *\r
- *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -31,6 +31,7 @@ namespace RAML
             UriParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
             UriParameter() {}\r
     };\r
+    typedef std::shared_ptr<UriParameter> UriParameterPtr;\r
 \r
 }\r
 #endif\r
old mode 100644 (file)
new mode 100755 (executable)
index 2364734..254444c
@@ -29,55 +29,47 @@ SimulatorResourceServerPtr SimulatorResourceCreator::createResource(const std::s
 {\r
     std::shared_ptr<SimulatorResourceServer> resource(new SimulatorResourceServer);\r
 \r
-    if (configPath.length() > 0)\r
-    {\r
-        std::size_t found = configPath.find_last_of("/\\");\r
-        if (found > configPath.length())\r
-        {\r
-            return resource;\r
-        }\r
-        std::string filePath = configPath.substr(0, found) + "/";\r
-        std::string fileName = configPath.substr(found + 1);\r
-\r
-        RamlPtr raml = (new RamlParser(filePath, fileName))->build();\r
+    RamlParser *ramlParser = new RamlParser(configPath);\r
+    RamlPtr raml = ramlParser->getRamlPtr();\r
         for (auto  resours : raml->getResources())\r
         {\r
             resource->setName(resours.first);\r
-            resource->setURI(resours.second.getResourceUri());\r
-            for (auto  action :  resours.second.getActions())\r
+        resource->setURI(resours.second->getResourceUri());\r
+        // TODO: Currently setting only baseline interface.\r
+        resource->setInterfaceType(OC::DEFAULT_INTERFACE);\r
+        // TODO: Need to modify based on the spec for observable property\r
+        resource->setObservable(true);\r
+        for (auto  action :  resours.second->getActions())\r
             {\r
-                for (auto  response :  action.second.getResponses())\r
+            for (auto  response :  action.second->getResponses())\r
                 {\r
-                    for (auto bdy :  response.second.getResponseBody())\r
+                for (auto bdy :  response.second->getResponseBody())\r
                     {\r
-                        auto resourceProperties = bdy.second.getSchema()->getProperties();\r
+                    auto resourceProperties = bdy.second->getSchema()->getProperties();\r
 \r
-                        resource->setResourceType(resourceProperties->getResoureType());\r
-                        resource->setInterfaceType(resourceProperties->getInterface());\r
-\r
-                        for ( auto property : resourceProperties->getAttributes() )\r
-                        {\r
-                            int type = property.second.getValueType();\r
+                    for ( auto property : resourceProperties->getProperties() )\r
+                    {\r
+                            int type = property.second->getValueType();\r
                             if (type)\r
                             {\r
-                                std::string attributeValue = property.second.getValueString();\r
-                                resource->addAttribute(property.second.getName(), std::string(attributeValue));\r
+                                std::string attributeValue = property.second->getValueString();\r
+                                resource->addAttribute(property.second->getName(), std::string(attributeValue));\r
                             }\r
                             else\r
                             {\r
-                                int attributeValue = property.second.getValueInt();\r
-                                resource->addAttribute(property.second.getName(), int(attributeValue));\r
+                                int attributeValue = property.second->getValueInt();\r
+                                resource->addAttribute(property.second->getName(), int(attributeValue));\r
                             }\r
 \r
-                            resource->setUpdateInterval(property.second.getName(), property.second.getUpdateFrequencyTime());\r
+                            resource->setUpdateInterval(property.second->getName(), property.second->getUpdateFrequencyTime());\r
 \r
-                            int min = 0, max = 0;\r
-                            property.second.getRange(min, max);\r
-                            resource->setRange(property.second.getName(), min, max);\r
+                            int min = 0, max = 0, multipleof = 0;\r
+                            property.second->getRange(min, max, multipleof);\r
+                            resource->setRange(property.second->getName(), min, max);\r
 \r
 \r
-                            if (property.second.getAllowedValuesSize() > 0)\r
-                                resource->setAllowedValues(property.second.getName(), property.second.getAllowedValues());\r
+                            if (property.second->getAllowedValuesSize() > 0)\r
+                                resource->setAllowedValues(property.second->getName(), property.second->getAllowedValues());\r
                         }\r
                         SIM_LOG(ILogger::INFO, "Created sample resource");\r
                         return resource;\r
@@ -86,8 +78,7 @@ SimulatorResourceServerPtr SimulatorResourceCreator::createResource(const std::s
 \r
             }\r
         }\r
-    }\r
-    SIM_LOG(ILogger::INFO, "Created sample resource");\r
+\r
     return resource;\r
 }\r
 \r