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.
18 * @file JSContactOrganization.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
21 * @brief Implementation of the JSContactOrganization class
24 #include "JSContactOrganization.h"
25 #include <dpl/shared_ptr.h>
26 #include <Tizen/Common/JSTizenExceptionFactory.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include <CommonsJavaScript/Converter.h>
29 #include "ContactConverter.h"
31 #define ORGANIZATION_CLASS_NAME "ContactOrganization"
33 #define CONTACT_ATTR_NAME "name"
34 #define CONTACT_ATTR_DEPARTMENT "department"
35 #define CONTACT_ATTR_OFFICE "office"
36 #define CONTACT_ATTR_TITLE "title"
37 #define CONTACT_ATTR_ROLE "role"
38 #define CONTACT_ATTR_LOGO_URI "logoURI"
44 using namespace TizenApis::Commons;
45 using namespace TizenApis::Api::Contact;
47 JSClassRef JSContactOrganization::m_classRef = NULL;
49 JSClassDefinition JSContactOrganization::m_classInfo =
52 kJSClassAttributeNone,
53 ORGANIZATION_CLASS_NAME,
62 NULL, //DeleteProperty,
63 NULL, //getPropertyNames,
67 NULL, //ConvertToType,
70 JSStaticValue JSContactOrganization::m_property[] = {
71 { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
72 { CONTACT_ATTR_DEPARTMENT, getDepartment, setDepartment, kJSPropertyAttributeNone },
73 { CONTACT_ATTR_OFFICE, getOffice, setOffice, kJSPropertyAttributeNone },
74 { CONTACT_ATTR_TITLE, getTitle, setTitle, kJSPropertyAttributeNone },
75 { CONTACT_ATTR_ROLE, getRole, setRole, kJSPropertyAttributeNone },
76 { CONTACT_ATTR_LOGO_URI, getLogoURI, setLogoURI, kJSPropertyAttributeNone },
80 JSStaticFunction JSContactOrganization::m_functions[] =
85 JSClassRef JSContactOrganization::getClassRef() {
87 m_classRef = JSClassCreate(&m_classInfo);
92 JSValueRef JSContactOrganization::createJSObject(JSContextRef context,
93 const std::string& name,
94 const std::string& department,
95 const std::string& office,
96 const std::string& title,
97 const std::string& role,
98 const std::string& logoURI)
100 ContactOrganizationPtr privateData = ContactOrganizationPtr(new ContactOrganization());
101 privateData->setName(name);
102 privateData->setDepartment(department);
103 privateData->setOffice(office);
104 privateData->setTitle(title);
105 privateData->setRole(role);
106 privateData->setLogoURI(logoURI);
107 JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, privateData);
108 JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
109 if (NULL == jsValueRef) {
110 LogError("object creation error");
111 return JSValueMakeUndefined(context);
116 bool JSContactOrganization::isObjectOfClass(JSContextRef context, JSValueRef value)
118 return JSValueIsObjectOfClass(context, value, getClassRef());
121 ContactOrganizationPtr JSContactOrganization::getContactOrganization(JSContextRef context, JSValueRef value)
123 if (!isObjectOfClass(context, value)) {
124 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
126 JSObjectRef object = JSValueToObject(context, value, NULL);
128 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
130 JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
132 Throw(WrtDeviceApis::Commons::NullPointerException);
134 return priv->getObject();
137 void JSContactOrganization::Initialize(JSContextRef context, JSObjectRef object)
139 assert(NULL != JSObjectGetPrivate(object));
142 void JSContactOrganization::Finalize(JSObjectRef object)
144 //delete (JSObjectGetPrivate(object));
147 ContactOrganizationPtr JSContactOrganization::getPrivData(JSObjectRef object)
149 //LogDebug("entered");
150 JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
152 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
154 ContactOrganizationPtr result = priv->getObject();
156 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
161 JSValueRef JSContactOrganization::getName(JSContextRef context,
163 JSStringRef propertyName,
164 JSValueRef* exception)
166 //LogDebug("entered");
169 ContactConverterFactory::ConverterType converter =
170 ContactConverterFactory::getConverter(context);
171 ContactOrganizationPtr organization = getPrivData(object);
172 return converter->toJSValueRef(organization->getName());
174 Catch(WrtDeviceApis::Commons::Exception)
176 LogWarning("trying to get incorrect value");
178 return JSValueMakeUndefined(context);
181 bool JSContactOrganization::setName(JSContextRef context,
183 JSStringRef propertyName,
185 JSValueRef* exception)
189 ContactOrganizationPtr organization = getPrivData(object);
190 ContactConverterFactory::ConverterType converter =
191 ContactConverterFactory::getConverter(context);
192 organization->setName(converter->toString(value));
195 Catch(WrtDeviceApis::Commons::Exception)
197 LogWarning("trying to set incorrect value");
199 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
204 JSValueRef JSContactOrganization::getDepartment(JSContextRef context,
206 JSStringRef propertyName,
207 JSValueRef* exception)
209 //LogDebug("entered");
212 ContactConverterFactory::ConverterType converter =
213 ContactConverterFactory::getConverter(context);
214 ContactOrganizationPtr organization = getPrivData(object);
215 return converter->toJSValueRef(organization->getDepartment());
217 Catch(WrtDeviceApis::Commons::Exception)
219 LogWarning("trying to get incorrect value");
221 return JSValueMakeUndefined(context);
224 bool JSContactOrganization::setDepartment(JSContextRef context,
226 JSStringRef propertyName,
228 JSValueRef* exception)
232 ContactOrganizationPtr organization = getPrivData(object);
233 ContactConverterFactory::ConverterType converter =
234 ContactConverterFactory::getConverter(context);
235 organization->setDepartment(converter->toString(value));
238 Catch(WrtDeviceApis::Commons::Exception)
240 LogWarning("trying to set incorrect value");
242 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
246 JSValueRef JSContactOrganization::getOffice(JSContextRef context,
248 JSStringRef propertyName,
249 JSValueRef* exception)
251 //LogDebug("entered");
254 ContactConverterFactory::ConverterType converter =
255 ContactConverterFactory::getConverter(context);
256 ContactOrganizationPtr organization = getPrivData(object);
257 return converter->toJSValueRef(organization->getOffice());
259 Catch(WrtDeviceApis::Commons::Exception)
261 LogWarning("trying to get incorrect value");
263 return JSValueMakeUndefined(context);
266 bool JSContactOrganization::setOffice(JSContextRef context,
268 JSStringRef propertyName,
270 JSValueRef* exception)
274 ContactOrganizationPtr organization = getPrivData(object);
275 ContactConverterFactory::ConverterType converter =
276 ContactConverterFactory::getConverter(context);
277 organization->setOffice(converter->toString(value));
280 Catch(WrtDeviceApis::Commons::Exception)
282 LogWarning("trying to set incorrect value");
284 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
288 JSValueRef JSContactOrganization::getTitle(JSContextRef context,
290 JSStringRef propertyName,
291 JSValueRef* exception)
293 //LogDebug("entered");
296 ContactConverterFactory::ConverterType converter =
297 ContactConverterFactory::getConverter(context);
298 ContactOrganizationPtr organization = getPrivData(object);
299 return converter->toJSValueRef(organization->getTitle());
301 Catch(WrtDeviceApis::Commons::Exception)
303 LogWarning("trying to get incorrect value");
305 return JSValueMakeUndefined(context);
308 bool JSContactOrganization::setTitle(JSContextRef context,
310 JSStringRef propertyName,
312 JSValueRef* exception)
316 ContactOrganizationPtr organization = getPrivData(object);
317 ContactConverterFactory::ConverterType converter =
318 ContactConverterFactory::getConverter(context);
319 organization->setTitle(converter->toString(value));
322 Catch(WrtDeviceApis::Commons::Exception)
324 LogWarning("trying to set incorrect value");
326 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
330 JSValueRef JSContactOrganization::getRole(JSContextRef context,
332 JSStringRef propertyName,
333 JSValueRef* exception)
335 //LogDebug("entered");
338 ContactConverterFactory::ConverterType converter =
339 ContactConverterFactory::getConverter(context);
340 ContactOrganizationPtr organization = getPrivData(object);
341 return converter->toJSValueRef(organization->getRole());
343 Catch(WrtDeviceApis::Commons::Exception)
345 LogWarning("trying to get incorrect value");
347 return JSValueMakeUndefined(context);
350 bool JSContactOrganization::setRole(JSContextRef context,
352 JSStringRef propertyName,
354 JSValueRef* exception)
358 ContactOrganizationPtr organization = getPrivData(object);
359 ContactConverterFactory::ConverterType converter =
360 ContactConverterFactory::getConverter(context);
361 organization->setRole(converter->toString(value));
364 Catch(WrtDeviceApis::Commons::Exception)
366 LogWarning("trying to set incorrect value");
368 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
372 JSValueRef JSContactOrganization::getLogoURI(JSContextRef context,
374 JSStringRef propertyName,
375 JSValueRef* exception)
377 //LogDebug("entered");
380 ContactConverterFactory::ConverterType converter =
381 ContactConverterFactory::getConverter(context);
382 ContactOrganizationPtr organization = getPrivData(object);
383 return converter->toJSValueRef(organization->getLogoURI());
385 Catch(WrtDeviceApis::Commons::Exception)
387 LogWarning("trying to get incorrect value");
389 return JSValueMakeUndefined(context);
392 bool JSContactOrganization::setLogoURI(JSContextRef context,
394 JSStringRef propertyName,
396 JSValueRef* exception)
400 ContactOrganizationPtr organization = getPrivData(object);
401 ContactConverterFactory::ConverterType converter =
402 ContactConverterFactory::getConverter(context);
403 organization->setLogoURI(converter->toString(value));
406 Catch(WrtDeviceApis::Commons::Exception)
408 LogWarning("trying to set incorrect value");
410 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");