2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <CommonsJavaScript/Converter.h>
24 //#include <Commons/Exception.h>
25 #include <JSWebAPIErrorFactory.h>
27 #include "ApplicationMetaData.h"
28 #include "JSApplicationMetaData.h"
33 namespace Application {
35 using namespace WrtDeviceApis;
36 using namespace DeviceAPI::Common;
39 JSClassRef JSApplicationMetaData::m_classRef = NULL;
41 JSClassDefinition JSApplicationMetaData::m_classInfo = {
43 kJSClassAttributeNone,
44 TIZEN_INTERFACE_APPLICATION_META_DATA,
53 NULL, //DeleteProperty,
54 NULL, //GetPropertyNames,
55 NULL, //CallAsFunction,
56 NULL, //CallAsConstructor,
61 JSStaticValue JSApplicationMetaData::m_property[] = {
62 { TIZEN_APPLICATION_META_DATA_KEY, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 { TIZEN_APPLICATION_META_DATA_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 JSClassRef DLL_EXPORT JSApplicationMetaData::getClassRef() {
69 m_classRef = JSClassCreate(&m_classInfo);
75 void JSApplicationMetaData::initialize(JSContextRef context, JSObjectRef object)
79 void JSApplicationMetaData::finalize(JSObjectRef object)
81 JSApplicationMetaDataPriv* priv = static_cast<JSApplicationMetaDataPriv*>(JSObjectGetPrivate(object));
82 JSObjectSetPrivate(object, NULL);
86 bool JSApplicationMetaData::isObjectOfClass(JSContextRef context, JSValueRef value)
88 return JSValueIsObjectOfClass(context, value, getClassRef());
91 ApplicationMetaDataPtr JSApplicationMetaData::getPrivData(JSObjectRef object)
93 JSApplicationMetaDataPriv *priv = static_cast<JSApplicationMetaDataPriv*>(JSObjectGetPrivate(object));
95 throw TypeMismatchException("Private object is null");
97 ApplicationMetaDataPtr result = priv->getObject();
99 throw TypeMismatchException("Private object is null");
105 JSValueRef JSApplicationMetaData::getProperty(JSContextRef context,
107 JSStringRef propertyName,
108 JSValueRef* exception)
111 CommonsJavaScript::Converter converter(context);
112 ApplicationMetaDataPtr privateData = getPrivData(object);
114 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_META_DATA_KEY)) {
115 return converter.toJSValueRef(privateData->getKey());
116 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_META_DATA_VALUE)) {
117 std::string value = privateData->getValue();
119 // if key is not exist, return NULL
121 return JSValueMakeNull(context);
124 // if key does not have value, return empty string.
125 if (value.compare("(null)") == 0) {
129 return converter.toJSValueRef(value);
131 } catch (const BasePlatformException &err) {
132 return JSWebAPIErrorFactory::postException(context, exception, err);
134 DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
135 return JSWebAPIErrorFactory::postException(context, exception, err);
138 return JSValueMakeUndefined(context);