2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 * Created on: 2012. 1. 30.
25 #include "JSAccountServiceType.h"
27 #include <CommonsJavaScript/Converter.h>
28 #include "AccountConverter.h"
30 using namespace TizenApis::Api::Account;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 //using namespace TizenApis::Commons;
40 #define ACCOUNT_SERVICE_TYPE "AccountServiceType"
41 #define ACCOUNT_SERVICE_TYPE_ID "id"
42 #define ACCOUNT_SERVICE_TYPE_DISPLAY_NAME "displayName"
43 #define ACCOUNT_SERVICE_TYPE_ICON_PATH "icon"
44 #define ACCOUNT_SERVICE_TYPE_TAGS "tags"
47 JSClassDefinition JSAccountServiceType::m_classInfo = {
49 kJSClassAttributeNone,
59 NULL, //deleteProperty,
60 NULL, //getPropertyNames,
61 NULL, //callAsFunction,
62 NULL, //callAsConstructor,
64 NULL, //convertToType,
67 JSStaticValue JSAccountServiceType::m_property[] = {
68 { ACCOUNT_SERVICE_TYPE_ID, getProperty, NULL, kJSPropertyAttributeNone },
69 { ACCOUNT_SERVICE_TYPE_DISPLAY_NAME, getProperty, NULL, kJSPropertyAttributeNone },
70 { ACCOUNT_SERVICE_TYPE_ICON_PATH, getProperty, NULL, kJSPropertyAttributeNone },
71 { ACCOUNT_SERVICE_TYPE_TAGS, getProperty, NULL, kJSPropertyAttributeNone },
76 JSClassRef JSAccountServiceType::m_jsClassRef = JSClassCreate(
77 JSAccountServiceType::getClassInfo());
79 const JSClassDefinition* JSAccountServiceType::getClassInfo(){
80 return &(m_classInfo);
83 JSClassRef JSAccountServiceType::getClassRef() {
85 m_jsClassRef = JSClassCreate(&m_classInfo);
90 JSObjectRef JSAccountServiceType::createJSObject(JSContextRef context, AccountServiceTypePropertyPtr account){
93 AccountServiceTypePrivateObject *priv = new AccountServiceTypePrivateObject(context, account);
95 JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
100 void JSAccountServiceType::initialize(JSContextRef context, JSObjectRef object) {
102 AccountServiceTypePrivateObject *privateObject = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
103 if (NULL == privateObject) {
104 LogDebug("privateObject is NULL");
108 void JSAccountServiceType::finalize(JSObjectRef object) {
110 AccountServiceTypePrivateObject* priv = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
112 JSObjectSetPrivate(object, NULL);
115 JSValueRef JSAccountServiceType::getProperty(JSContextRef context,
116 JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
118 AccountConverterFactory::ConverterType converter = AccountConverterFactory::getConverter(context);
120 AccountServiceTypePrivateObject* priv = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
122 Throw(NullPointerException);
124 AccountServiceTypePropertyPtr accountServiceTypeProperty = priv->getObject();
126 if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_ID)) {
127 return converter->toJSValueRef(accountServiceTypeProperty->getId());
128 } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_DISPLAY_NAME)) {
129 return converter->toJSValueRef(accountServiceTypeProperty->getDisplayName());
130 } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_ICON_PATH)) {
131 return converter->toJSValueRef(accountServiceTypeProperty->getIconPath());
132 } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_TAGS)) {
133 return converter->toJSValueRef(accountServiceTypeProperty->getTags());
136 LogError("invalid property");
139 return JSValueMakeUndefined(context);
142 JSAccountServiceType::~JSAccountServiceType() {
143 // TODO Auto-generated destructor stub
146 } //namespace Account
147 } //namespace Tizen1_0
148 } //namespace TizenApis