252d6f12f11b17eece12f25d2804bc135250741f
[framework/web/wrt-plugins-tizen.git] / src / Common / PlatformException.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 #include "PlatformException.h"
20 #include "JSUtil.h"
21 #include "JSWebAPIError.h"
22 #include <CommonsJavaScript/Converter.h>
23
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
26
27
28
29 namespace DeviceAPI {
30 namespace Common{
31
32 BasePlatformException::BasePlatformException(int code, const char* name, const char* message):mCode(code),mName(name),mMessage(message){
33 }
34
35 BasePlatformException::BasePlatformException(JSContextRef context, JSValueRef value){
36     JSObjectRef object = JSValueToObject(context, value, NULL);
37     if( object == NULL )
38         return;
39
40     JSValueRef message = JSUtil::getProperty(context, object, "message");
41     JSValueRef code = JSUtil::getProperty(context, object, "code");    
42     JSValueRef name = JSUtil::getProperty(context, object, "name");
43
44     try{
45         Converter convert(context);
46         if( !JSValueIsUndefined(context, message ))
47             mMessage = convert.toString(message);
48         if( !JSValueIsUndefined(context, name ))
49             mName = convert.toString(name);
50         if( !JSValueIsUndefined(context, code ))
51             mCode = convert.toInt(code);
52     }catch( const ConversionException& err){
53     }
54 }
55
56 int BasePlatformException::getCode() const{
57     return mCode;    
58 }
59
60 std::string BasePlatformException::getName() const{
61     return mName;
62 }
63
64 std::string BasePlatformException::getMessage() const{
65     return mMessage;
66 }
67
68
69 TypeMismatchException::TypeMismatchException(const char* message):BasePlatformException(JSWebAPIError::TYPE_MISMATCH_ERR,"TypeMismatchError", message){
70 }
71 TypeMismatchException::TypeMismatchException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
72     mCode = JSWebAPIError::TYPE_MISMATCH_ERR;
73     mName = "TypeMismatchError";
74 }
75
76 InvalidValuesException::InvalidValuesException(const char* message):BasePlatformException(0,"InvalidValuesError", message){
77 }
78 InvalidValuesException::InvalidValuesException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
79     mCode = 0;
80     mName = "InvalidValuesError";
81 }
82
83 IOException::IOException(const char* message):BasePlatformException(0,"IOError", message){
84 }
85 IOException::IOException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
86     mCode = 0;
87     mName = "IOError";
88 }
89
90
91 UnknownException::UnknownException(const char* message):BasePlatformException(0,"UnknownError", message){
92 }
93 UnknownException::UnknownException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
94     mCode = 0;
95     mName = "UnknownError";
96 }
97
98 ServiceNotAvailableException::ServiceNotAvailableException(const char* message):BasePlatformException(0,"ServiceNotAvailableError", message){
99 }
100 ServiceNotAvailableException::ServiceNotAvailableException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
101     mCode = 0;
102     mName = "ServiceNotAvailableError";
103 }
104
105 SecurityException::SecurityException(const char* message):BasePlatformException(JSWebAPIError::SECURITY_ERR,"SecurityError", message){
106 }
107 SecurityException::SecurityException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
108     mCode = JSWebAPIError::SECURITY_ERR;
109     mName = "SecurityError";
110 }
111
112 NotSupportedException::NotSupportedException(const char* message):BasePlatformException(JSWebAPIError::NOT_SUPPORTED_ERR,"NotSupportedError", message){
113 }
114 NotSupportedException::NotSupportedException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
115     mCode = JSWebAPIError::NOT_SUPPORTED_ERR;
116     mName = "NotSupportedError";
117 }
118
119 NotFoundException::NotFoundException(const char* message):BasePlatformException(JSWebAPIError::NOT_FOUND_ERR,"NotFoundError", message){
120 }
121 NotFoundException::NotFoundException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
122     mCode = JSWebAPIError::NOT_FOUND_ERR;
123     mName = "NotFoundError";
124 }
125
126
127
128
129 }
130 }