wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSContact.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 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  * @file        JSContact.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSContact class
23  */
24
25 #include <dpl/shared_ptr.h>
26 #include <CommonsJavaScript/Validator.h>
27 #include <JSTizenExceptionFactory.h>
28 #include <JSTizenException.h>
29 #include <SecurityExceptions.h>
30 #include "ContactFactory.h"
31 #include "plugin_config.h"
32 #include "ContactConverter.h"
33 #include "JSContact.h"
34 #include "Contact.h"
35 #include <ArgumentValidator.h>
36 #include <JSWebAPIError.h>
37 #include <TimeTracer.h>
38 #include <Logger.h>
39
40 #define FILTER_CLASS_NAME "Contact"
41
42 #define CONTACT_ATTR_ID             "id"
43 #define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
44 #define CONTACT_ATTR_PERSON_ID      "personId"
45 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
46 #define CONTACT_ATTR_IS_FAVORITE    "isFavorite"
47 #define CONTACT_ATTR_NAME           "name"
48 #define CONTACT_ATTR_ADDRESSES      "addresses"
49 #define CONTACT_ATTR_PHOTO_URI      "photoURI"
50 #define CONTACT_ATTR_PHONE_NUMBERS  "phoneNumbers"
51 #define CONTACT_ATTR_EMAILS         "emails"
52 #define CONTACT_ATTR_BIRTHDAY       "birthday"
53 #define CONTACT_ATTR_ANNIVERSARIES  "anniversaries"
54 #define CONTACT_ATTR_ORGANIZATIONS  "organizations"
55 #define CONTACT_ATTR_NOTES          "notes"
56 #define CONTACT_ATTR_URLS           "urls"
57 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
58 #define CONTACT_ATTR_RINGTONE_URI   "ringtoneURI"
59 #define CONTACT_ATTR_GROUP_IDS      "groupIds"
60 #define CONTACT_FUNC_CONVERT_TO_STRING          "convertToString"
61 #define CONTACT_FUNC_CLONE                                      "clone"
62
63 namespace DeviceAPI {
64 namespace Contact {
65
66 using namespace DeviceAPI::Common;
67 using namespace WrtDeviceApis::Commons;
68 using namespace WrtDeviceApis::CommonsJavaScript;
69
70 JSClassDefinition JSContact::m_classInfo =
71 {
72         0,
73         kJSClassAttributeNone,
74         FILTER_CLASS_NAME,
75         NULL,
76         m_property,
77         m_functions,
78         Initialize,
79         Finalize,
80         NULL, //hasProperty,
81         NULL, //GetProperty,
82         NULL, //SetProperty,
83         NULL, //DeleteProperty,
84         NULL, //getPropertyNames,
85         NULL, //CallAsFunction,
86         constructor, //CallAsConstructor,
87         hasInstance, //HasInstance,
88         NULL, //ConvertToType,
89 };
90
91 JSStaticValue JSContact::m_property[] = {
92         { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
93         { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
94         { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
95         { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
96         { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97         { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
98         { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
99         { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
100         { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
101         { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
102         { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
103         { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
104         { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
105         { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
106         { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
107         { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
108         { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
109         { 0, 0, 0, 0 }
110 };
111
112 JSStaticFunction JSContact::m_functions[] =
113 {
114         { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
115         { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
116         { 0, 0, 0 }
117 };
118
119 JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
120
121 JSClassRef JSContact::getClassRef() {
122         if (!m_classRef) {
123                 m_classRef = JSClassCreate(&m_classInfo);
124         }
125         return m_classRef;
126 }
127
128 bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
129 {
130         return JSValueIsObjectOfClass(context, value, getClassRef());
131 }
132
133 ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
134 {
135         if (!isObjectOfClass(context, value)) {
136                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
137         }
138         JSObjectRef object = JSValueToObject(context, value, NULL);
139         if (!object) {
140                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
141         }
142         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
143         if (!priv) {
144                 Throw(WrtDeviceApis::Commons::NullPointerException);
145         }
146         return priv->getObject();
147 }
148
149 void JSContact::Initialize(JSContextRef context, JSObjectRef object)
150 {
151         if (!JSObjectGetPrivate(object))
152         {
153                 ContactPtr contact = ContactFactory::getInstance().createContact();
154                 JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
155                 if (!JSObjectSetPrivate(object, priv)) {
156                         delete priv;
157                 }
158         }
159 }
160
161 void JSContact::Finalize(JSObjectRef object)
162 {
163         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
164
165         if (priv != NULL)
166                 delete (priv);
167 }
168
169 JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
170 {
171         JSContactPriv *priv = new JSContactPriv(context, contact);
172         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
173         if (NULL == jsObjectRef) {
174                 LoggerE("object creation error");
175                 return NULL;
176         }
177         return jsObjectRef;
178 }
179
180 ContactPtr JSContact::getPrivData(JSObjectRef object)
181 {
182         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
183         if (!priv) {
184                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
185         }
186         ContactPtr result = priv->getObject();
187         if (!result) {
188                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
189         }
190         return result;
191 }
192
193 JSObjectRef JSContact::constructor(JSContextRef context,
194                 JSObjectRef constructor,
195                 size_t argumentCount,
196                 const JSValueRef arguments[],
197                 JSValueRef* exception)
198 {
199         LoggerD("entered");
200
201         bool jsNoParam = false;
202         bool js1stParamIsObject = false;
203         bool js1stParamIsString = false;
204
205         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(constructor));
206         if (!priv) {
207                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
208         }
209         JSContextRef gContext = priv->getContext();
210
211         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
212         if (argumentCount == 0)
213         {
214                 jsNoParam = true;
215         }
216         else
217         {
218                 if (JSValueIsNull(gContext, arguments[0]) || JSValueIsUndefined(gContext, arguments[0]))
219                         jsNoParam = true;
220                 else if (JSValueIsObject(gContext, arguments[0]))
221                         js1stParamIsObject = true;
222                 else if (JSValueIsString(gContext, arguments[0]))
223                         js1stParamIsString = true;
224                 else
225                 {
226                         LoggerE("Argument type mismatch : 1nd argument must be ContactInit object or string");
227                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
228                         return NULL;
229                 }
230         }
231
232         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
233
234         ContactPtr contact(NULL);
235         if(js1stParamIsObject)
236         {
237                 Try {
238                         contact = converter->toContactFromInit(arguments[0]);
239
240                 } Catch(ConversionException) {
241                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
242                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
243                         return NULL;
244                 } Catch(Exception) {
245                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
246                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
247                         return NULL;
248                 }
249         }
250         else if(js1stParamIsString)
251         {
252                 Try {
253                         std::string stringRepresentation;       // vCard string
254
255                         stringRepresentation = converter->toString(arguments[0]);
256
257                         contact = ContactFactory::getInstance().createContact();
258                         contact->setContactFromString(stringRepresentation);
259
260                 } Catch(ConversionException) {
261                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
262                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
263                         return NULL;
264                 } Catch(InvalidArgumentException) {
265                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
266                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "1st argument must be vCard string");
267                         return NULL;
268                 } Catch(UnsupportedException) {
269                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
270                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
271                         return NULL;
272                 } Catch(Exception) {
273                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
274                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
275                         return NULL;
276                 }
277         }
278         else
279         {
280                 Try {
281                         contact = ContactFactory::getInstance().createContact();
282                 } Catch(Exception) {
283                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
284                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
285                         return NULL;
286                 }
287         }
288
289         JSObjectRef jsobject;
290
291         Try {
292                 jsobject = createJSObject(gContext, contact);
293         } Catch(Exception) {
294                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
295                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
296                 return NULL;
297         }
298
299         return jsobject;
300 }
301
302 bool JSContact::hasInstance(JSContextRef context,
303                 JSObjectRef constructor,
304                 JSValueRef possibleInstance,
305                 JSValueRef* exception)
306 {
307         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
308 }
309
310 JSValueRef JSContact::getId(JSContextRef context,
311                 JSObjectRef object,
312                 JSStringRef propertyName,
313                 JSValueRef* exception)
314 {
315         Try
316         {
317                 ContactConverterFactory::ConverterType converter =
318                                 ContactConverterFactory::getConverter(context);
319                 ContactPtr contact = getPrivData(object);
320                 if(!contact->getIdIsSet())
321                         return JSValueMakeNull(context);
322                 else
323                         return converter->toJSValueRef(contact->getId());
324         }
325         Catch(WrtDeviceApis::Commons::Exception)
326         {
327                 LoggerW("trying to get incorrect value");
328         }
329         return JSValueMakeUndefined(context);
330 }
331
332 JSValueRef JSContact::getAddressBookId(JSContextRef context,
333                 JSObjectRef object,
334                 JSStringRef propertyName,
335                 JSValueRef* exception)
336 {
337         Try
338         {
339                 ContactConverterFactory::ConverterType converter =
340                                 ContactConverterFactory::getConverter(context);
341                 ContactPtr contact = getPrivData(object);
342                 if(!contact->getAddressBookIdIsSet())
343                         return JSValueMakeNull(context);
344                 else
345                         return converter->toJSValueRef(contact->getAddressBookId());
346         }
347         Catch(WrtDeviceApis::Commons::Exception)
348         {
349                 LoggerW("trying to get incorrect value");
350         }
351         return JSValueMakeUndefined(context);
352 }
353
354 JSValueRef JSContact::getPersonId(JSContextRef context,
355                 JSObjectRef object,
356                 JSStringRef propertyName,
357                 JSValueRef* exception)
358 {
359         Try
360         {
361                 ContactConverterFactory::ConverterType converter =
362                                 ContactConverterFactory::getConverter(context);
363                 ContactPtr contact = getPrivData(object);
364                 if(!contact->getPersonIdIsSet())
365                         return JSValueMakeNull(context);
366                 else
367                         return converter->toJSValueRef(contact->getPersonId());
368         }
369         Catch(WrtDeviceApis::Commons::Exception)
370         {
371                 LoggerW("trying to get incorrect value");
372         }
373         return JSValueMakeUndefined(context);
374 }
375
376 JSValueRef JSContact::getLastUpdated(JSContextRef context,
377                 JSObjectRef object,
378                 JSStringRef propertyName,
379                 JSValueRef* exception)
380 {
381         Try
382         {
383                 ContactConverterFactory::ConverterType converter =
384                                 ContactConverterFactory::getConverter(context);
385                 ContactPtr contact = getPrivData(object);
386                 if(!contact->getLastUpdatedIsSet())
387                         return JSValueMakeNull(context);
388                 else
389                         return converter->toJSValueRef(contact->getLastUpdated());
390         }
391         Catch(WrtDeviceApis::Commons::Exception)
392         {
393                 LoggerW("trying to get incorrect value");
394         }
395
396         return JSValueMakeUndefined(context);
397 }
398
399 JSValueRef JSContact::getIsFavorite(JSContextRef context,
400                 JSObjectRef object,
401                 JSStringRef propertyName,
402                 JSValueRef* exception)
403 {
404         Try
405         {
406                 ContactConverterFactory::ConverterType converter =
407                                 ContactConverterFactory::getConverter(context);
408                 ContactPtr contact = getPrivData(object);
409                 return converter->toJSValueRef(contact->getIsFavorite());
410         }
411         Catch(WrtDeviceApis::Commons::Exception)
412         {
413                 LoggerW("trying to get incorrect value");
414         }
415
416         return JSValueMakeUndefined(context);
417 }
418
419 JSValueRef JSContact::getName(JSContextRef context,
420                 JSObjectRef object,
421                 JSStringRef propertyName,
422                 JSValueRef* exception)
423 {
424         Try
425         {
426                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
427                 if (!priv) {
428                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
429                 }
430                 JSContextRef gContext = priv->getContext();
431
432                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
433                 ContactPtr contact = getPrivData(object);
434                 ContactNamePtr contactName = contact->getName();
435                 if(contactName == NULL)
436                         return JSValueMakeNull(context);
437                 else
438                         return converter->toJSValueRef(contactName);
439         }
440         Catch(WrtDeviceApis::Commons::Exception)
441         {
442                 LoggerW("trying to get incorrect value");
443         }
444
445         return JSValueMakeUndefined(context);
446 }
447
448 bool JSContact::setName(JSContextRef context,
449                 JSObjectRef object,
450                 JSStringRef propertyName,
451                 JSValueRef value,
452                 JSValueRef* exception)
453 {
454         Try
455         {
456                 ContactPtr contact = getPrivData(object);
457                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
458                 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
459                 if(validator->isNullOrUndefined(value))
460                         contact->unsetName();
461                 else
462                         contact->setName(converter->toContactName(value));
463         }
464         Catch(WrtDeviceApis::Commons::Exception)
465         {
466                 LoggerW("trying to set incorrect value");
467                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
468         }
469
470         return true;
471 }
472
473 JSValueRef JSContact::getAddresses(JSContextRef context,
474                 JSObjectRef object,
475                 JSStringRef propertyName,
476                 JSValueRef* exception)
477 {
478         Try
479         {
480                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
481                 if (!priv) {
482                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
483                 }
484                 JSContextRef gContext = priv->getContext();
485                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
486                 ContactPtr contact = getPrivData(object);
487
488                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
489                 if(newContactT->addressesJSObjIsSet()){
490                         return newContactT->getAddressesJSObj();
491                 }else{
492                         JSValueRef tempJSValue = newContactT->getAddressesJSValue();
493                         tempJSValue = converter->toJSValueRef(newContactT->getAddresses());
494
495                         JSObjectRef convertedJSObject = newContactT->getAddressesJSObj();
496                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
497                         newContactT->setAddressesJSObj(true, convertedJSObject);
498
499                         JSValueProtect(gContext, convertedJSObject);
500                         newContactT->setContext(gContext);
501                         return tempJSValue;
502                 }
503         }
504         Catch(WrtDeviceApis::Commons::Exception)
505         {
506                 LoggerW("trying to get incorrect value");
507         }
508
509         return JSValueMakeUndefined(context);
510 }
511
512 bool JSContact::setAddresses(JSContextRef context,
513                 JSObjectRef object,
514                 JSStringRef propertyName,
515                 JSValueRef value,
516                 JSValueRef* exception)
517 {
518         Try
519         {
520                 ContactPtr contact = getPrivData(object);
521                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
522                 contact->setAddresses(converter->toContactAddressArray(value));
523                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
524                 newContactT->resetAddressesJSObj();
525         }
526         Catch(WrtDeviceApis::Commons::Exception)
527         {
528                 LoggerW("trying to set incorrect value");
529                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
530         }
531
532         return true;
533 }
534
535 JSValueRef JSContact::getPhotoURI(JSContextRef context,
536                 JSObjectRef object,
537                 JSStringRef propertyName,
538                 JSValueRef* exception)
539 {
540         Try
541         {
542                 ContactConverterFactory::ConverterType converter =
543                                 ContactConverterFactory::getConverter(context);
544                 ContactPtr contact = getPrivData(object);
545                 if(!contact->getPhotoURIIsSet())
546                         return JSValueMakeNull(context);
547                 else
548                         return converter->toJSValueRef(contact->getPhotoURI());
549         }
550         Catch(WrtDeviceApis::Commons::Exception)
551         {
552                 LoggerW("trying to get incorrect value");
553         }
554
555         return JSValueMakeUndefined(context);
556 }
557
558 bool JSContact::setPhotoURI(JSContextRef context,
559                 JSObjectRef object,
560                 JSStringRef propertyName,
561                 JSValueRef value,
562                 JSValueRef* exception)
563 {
564         Try
565         {
566                 ContactPtr contact = getPrivData(object);
567                 ContactConverterFactory::ConverterType converter =
568                                 ContactConverterFactory::getConverter(context);
569                 BasicValidator validator =
570                                 BasicValidatorFactory::getValidator(context, exception);
571                 if(validator->isNullOrUndefined(value))
572                         contact->unsetPhotoURI();
573                 else
574                         contact->setPhotoURI(converter->toString(value));
575         }
576         Catch(WrtDeviceApis::Commons::Exception)
577         {
578                 LoggerW("trying to set incorrect value");
579                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
580         }
581
582         return true;
583 }
584
585 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
586                 JSObjectRef object,
587                 JSStringRef propertyName,
588                 JSValueRef* exception)
589 {
590         Try
591         {
592                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
593                 if (!priv) {
594                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
595                 }
596                 JSContextRef gContext = priv->getContext();
597                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
598                 ContactPtr contact = getPrivData(object);
599
600                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
601                 if(newContactT->numbersJSObjIsSet()){
602                         return newContactT->getNumbersJSObj();
603                 }else{
604                         JSValueRef tempJSValue = newContactT->getNumbersJSValue();
605                         tempJSValue = converter->toJSValueRef(newContactT->getPhoneNumbers());
606
607                         JSObjectRef convertedJSObject = newContactT->getNumbersJSObj();
608                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
609                         newContactT->setNumbersJSObj(true, convertedJSObject);
610
611                         JSValueProtect(gContext, convertedJSObject);
612                         newContactT->setContext(gContext);
613                         return tempJSValue;
614                 }
615         }
616         Catch(WrtDeviceApis::Commons::Exception)
617         {
618                 LoggerW("trying to get incorrect value");
619         }
620
621         return JSValueMakeUndefined(context);
622 }
623
624 bool JSContact::setPhoneNumbers(JSContextRef context,
625                 JSObjectRef object,
626                 JSStringRef propertyName,
627                 JSValueRef value,
628                 JSValueRef* exception)
629 {
630         Try
631         {
632                 ContactPtr contact = getPrivData(object);
633                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
634                 contact->setPhoneNumbers(converter->toContactPhoneNumberArray(value));
635                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
636                 newContactT->resetNumbersJSObj();
637         }
638         Catch(WrtDeviceApis::Commons::Exception)
639         {
640                 LoggerW("trying to set incorrect value");
641                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
642         }
643
644         return true;
645 }
646
647 JSValueRef JSContact::getEmails(JSContextRef context,
648                 JSObjectRef object,
649                 JSStringRef propertyName,
650                 JSValueRef* exception)
651 {
652         Try
653         {
654                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
655                 if (!priv) {
656                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
657                 }
658                 JSContextRef gContext = priv->getContext();
659
660                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
661                 ContactPtr contact = getPrivData(object);
662
663                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
664                 if(newContactT->EmailsJSObjIsSet()){
665                         LoggerD("return init value");
666                         return newContactT->getEmailsJSObj();
667                 }else{
668                         LoggerD("new array");
669                         JSValueRef tempJSValue = newContactT->getEmailsJSValue();
670                         tempJSValue = converter->toJSValueRef(newContactT->getEmails());
671
672                         JSObjectRef convertedJSObject = newContactT->getEmailsJSObj();
673                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
674                         newContactT->setEmailsJSObj(true, convertedJSObject);
675
676                         JSValueProtect(gContext, convertedJSObject);
677                         newContactT->setContext(gContext);
678                         return tempJSValue;
679                 }
680         }
681         Catch(WrtDeviceApis::Commons::Exception)
682         {
683                 LoggerW("trying to get incorrect value");
684         }
685
686         return JSValueMakeUndefined(context);
687 }
688
689 bool JSContact::setEmails(JSContextRef context,
690                 JSObjectRef object,
691                 JSStringRef propertyName,
692                 JSValueRef value,
693                 JSValueRef* exception)
694 {
695         Try
696         {
697                 ContactPtr contact = getPrivData(object);
698                 ContactConverterFactory::ConverterType converter =
699                                 ContactConverterFactory::getConverter(context);
700                 contact->setEmails(converter->toContactEmailAddressArray(value));
701                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
702                 newContactT->resetEmailsJSObj();
703         }
704         Catch(WrtDeviceApis::Commons::Exception)
705         {
706                 LoggerW("trying to set incorrect value");
707                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
708         }
709
710         return true;
711 }
712
713 JSValueRef JSContact::getBirthday(JSContextRef context,
714                 JSObjectRef object,
715                 JSStringRef propertyName,
716                 JSValueRef* exception)
717 {
718         Try
719         {
720                 ContactConverterFactory::ConverterType converter =
721                                 ContactConverterFactory::getConverter(context);
722                 ContactPtr contact = getPrivData(object);
723                 if(!contact->getBirthdayIsSet())
724                         return JSValueMakeNull(context);
725                 else
726                         return converter->toJSValueRef(contact->getBirthday());
727         }
728         Catch(WrtDeviceApis::Commons::Exception)
729         {
730                 LoggerW("trying to get incorrect value");
731         }
732
733         return JSValueMakeUndefined(context);
734 }
735
736 bool JSContact::setBirthday(JSContextRef context,
737                 JSObjectRef object,
738                 JSStringRef propertyName,
739                 JSValueRef value,
740                 JSValueRef* exception)
741 {
742         Try
743         {
744                 ContactPtr contact = getPrivData(object);
745                 ContactConverterFactory::ConverterType converter =
746                                 ContactConverterFactory::getConverter(context);
747                 BasicValidator validator =
748                                 BasicValidatorFactory::getValidator(context, exception);
749                 if(validator->isNullOrUndefined(value))
750                         contact->unsetBirthday();
751                 else
752                         contact->setBirthday(converter->toDateTm(value));
753         }
754         Catch(WrtDeviceApis::Commons::Exception)
755         {
756                 LoggerW("trying to set incorrect value");
757                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
758         }
759
760         return true;
761 }
762
763 JSValueRef JSContact::getAnniversaries(JSContextRef context,
764                 JSObjectRef object,
765                 JSStringRef propertyName,
766                 JSValueRef* exception)
767 {
768         Try
769         {
770                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
771                 if (!priv) {
772                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
773                 }
774                 JSContextRef gContext = priv->getContext();
775
776                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
777                 ContactPtr contact = getPrivData(object);
778
779                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
780                 if(newContactT->anniversariesJSObjIsSet()){
781                         return newContactT->getAnniversariesJSObj();
782                 }else{
783                         JSValueRef tempJSValue = newContactT->getAnniversariesJSValue();
784                         tempJSValue = converter->toJSValueRef(newContactT->getAnniversaries());
785
786                         JSObjectRef convertedJSObject = newContactT->getAnniversariesJSObj();
787                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
788                         newContactT->setAnniversariesJSObj(true, convertedJSObject);
789
790                         JSValueProtect(gContext, convertedJSObject);
791                         newContactT->setContext(gContext);
792                         return tempJSValue;
793                 }
794         }
795         Catch(WrtDeviceApis::Commons::Exception)
796         {
797                 LoggerW("trying to get incorrect value");
798         }
799
800         return JSValueMakeUndefined(context);
801 }
802
803 bool JSContact::setAnniversaries(JSContextRef context,
804                 JSObjectRef object,
805                 JSStringRef propertyName,
806                 JSValueRef value,
807                 JSValueRef* exception)
808 {
809         Try
810         {
811                 ContactPtr contact = getPrivData(object);
812                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
813                 contact->setAnniversaries(converter->toContactAnniversaryArray(value));
814                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
815                 newContactT->resetAnniversariesJSObj();
816         }
817         Catch(WrtDeviceApis::Commons::Exception)
818         {
819                 LoggerW("trying to set incorrect value");
820                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
821         }
822
823         return true;
824 }
825
826 JSValueRef JSContact::getOrganizations(JSContextRef context,
827                 JSObjectRef object,
828                 JSStringRef propertyName,
829                 JSValueRef* exception)
830 {
831         Try
832         {
833                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
834                 if (!priv) {
835                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
836                 }
837                 JSContextRef gContext = priv->getContext();
838
839                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
840                 ContactPtr contact = getPrivData(object);
841
842                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
843                 if(newContactT->organizationsJSObjIsSet()){
844                         return newContactT->getOrganizationsJSObj();
845                 }else{
846                         JSValueRef tempJSValue = newContactT->getOrganizationsJSValue();
847                         tempJSValue = converter->toJSValueRef(newContactT->getOrganizations());
848
849                         JSObjectRef convertedJSObject = newContactT->getOrganizationsJSObj();
850                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
851                         newContactT->setOrganizationsJSObj(true, convertedJSObject);
852
853                         JSValueProtect(gContext, convertedJSObject);
854                         newContactT->setContext(gContext);
855                         return tempJSValue;
856                 }
857         }
858         Catch(WrtDeviceApis::Commons::Exception)
859         {
860                 LoggerW("trying to get incorrect value");
861         }
862
863         return JSValueMakeUndefined(context);
864 }
865
866 bool JSContact::setOrganizations(JSContextRef context,
867                 JSObjectRef object,
868                 JSStringRef propertyName,
869                 JSValueRef value,
870                 JSValueRef* exception)
871 {
872         Try
873         {
874                 ContactPtr contact = getPrivData(object);
875                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
876                 contact->setOrganizations(converter->toContactOrganizationArray(value));
877                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
878                 newContactT->resetOrganizationsJSObj();
879         }
880         Catch(WrtDeviceApis::Commons::Exception)
881         {
882                 LoggerW("trying to set incorrect value");
883                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
884         }
885
886         return true;
887 }
888
889 JSValueRef JSContact::getNotes(JSContextRef context,
890                 JSObjectRef object,
891                 JSStringRef propertyName,
892                 JSValueRef* exception)
893 {
894         Try
895         {
896                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
897                 if (!priv) {
898                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
899                 }
900                 JSContextRef gContext = priv->getContext();
901
902                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
903                 ContactPtr contact = getPrivData(object);
904
905                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
906                 if(newContactT->notesJSObjIsSet()){
907                         return newContactT->getNotesJSObj();
908                 }else{
909                         JSValueRef tempJSValue = newContactT->getNotesJSValue();
910                         tempJSValue = converter->toJSValueRef(newContactT->getNotes());
911
912                         JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
913                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
914                         newContactT->setNotesJSObj(true, convertedJSObject);
915
916                         JSValueProtect(gContext, convertedJSObject);
917                         newContactT->setContext(gContext);
918                         return tempJSValue;
919                 }
920         }
921         Catch(WrtDeviceApis::Commons::Exception)
922         {
923                 LoggerW("trying to get incorrect value");
924         }
925
926         return JSValueMakeUndefined(context);
927 }
928
929 bool JSContact::setNotes(JSContextRef context,
930                 JSObjectRef object,
931                 JSStringRef propertyName,
932                 JSValueRef value,
933                 JSValueRef* exception)
934 {
935         Try
936         {
937                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
938                 if (!priv) {
939                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
940                 }
941                 JSContextRef gContext = priv->getContext();
942                 ContactPtr contact = getPrivData(object);
943
944                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
945                 contact->setNotes(converter->toStringArray(value));
946                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
947                 newContactT->resetNotesJSObj();
948         }
949         Catch(WrtDeviceApis::Commons::Exception)
950         {
951                 LoggerW("trying to set incorrect value");
952                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
953         }
954
955         return true;
956 }
957
958 JSValueRef JSContact::getUrls(JSContextRef context,
959                 JSObjectRef object,
960                 JSStringRef propertyName,
961                 JSValueRef* exception)
962 {
963         Try
964         {
965                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
966                 if (!priv) {
967                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
968                 }
969                 JSContextRef gContext = priv->getContext();
970
971                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
972                 ContactPtr contact = getPrivData(object);
973
974                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
975                 if(newContactT->urlsJSObjIsSet()){
976                         return newContactT->getUrlsJSObj();
977                 }else{
978                         JSValueRef tempJSValue = newContactT->getUrlsJSValue();
979                         tempJSValue = converter->toJSValueRef(newContactT->getUrls());
980
981                         JSObjectRef convertedJSObject = newContactT->getUrlsJSObj();
982                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
983                         newContactT->setUrlsJSObj(true, convertedJSObject);
984
985                         JSValueProtect(gContext, convertedJSObject);
986                         newContactT->setContext(gContext);
987                         return tempJSValue;
988                 }
989         }
990         Catch(WrtDeviceApis::Commons::Exception)
991         {
992                 LoggerW("trying to get incorrect value");
993         }
994
995         return JSValueMakeUndefined(context);
996 }
997
998 bool JSContact::setUrls(JSContextRef context,
999                 JSObjectRef object,
1000                 JSStringRef propertyName,
1001                 JSValueRef value,
1002                 JSValueRef* exception)
1003 {
1004         Try
1005         {
1006                 ContactPtr contact = getPrivData(object);
1007                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1008                 contact->setUrls(converter->toContactWebSiteArray(value));
1009                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1010                 newContactT->resetUrlsJSObj();
1011         }
1012         Catch(WrtDeviceApis::Commons::Exception)
1013         {
1014                 LoggerW("trying to set incorrect value");
1015                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1016         }
1017
1018         return true;
1019 }
1020
1021 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
1022                 JSObjectRef object,
1023                 JSStringRef propertyName,
1024                 JSValueRef* exception)
1025 {
1026         Try
1027         {
1028                 ContactConverterFactory::ConverterType converter =
1029                                 ContactConverterFactory::getConverter(context);
1030                 ContactPtr contact = getPrivData(object);
1031                 if(!contact->getRingtoneURIIsSet())
1032                         return JSValueMakeNull(context);
1033                 else
1034                         return converter->toJSValueRef(contact->getRingtoneURI());
1035         }
1036         Catch(WrtDeviceApis::Commons::Exception)
1037         {
1038                 LoggerW("trying to get incorrect value");
1039         }
1040
1041         return JSValueMakeUndefined(context);
1042 }
1043
1044 bool JSContact::setRingtoneURI(JSContextRef context,
1045                 JSObjectRef object,
1046                 JSStringRef propertyName,
1047                 JSValueRef value,
1048                 JSValueRef* exception)
1049 {
1050         Try
1051         {
1052                 ContactPtr contact = getPrivData(object);
1053                 ContactConverterFactory::ConverterType converter =
1054                                 ContactConverterFactory::getConverter(context);
1055                 BasicValidator validator =
1056                                 BasicValidatorFactory::getValidator(context, exception);
1057                 if(validator->isNullOrUndefined(value))
1058                         contact->unsetRingtoneURI();
1059                 else
1060                         contact->setRingtoneURI(converter->toString(value));
1061         }
1062         Catch(WrtDeviceApis::Commons::Exception)
1063         {
1064                 LoggerW("trying to set incorrect value");
1065                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1066         }
1067
1068         return true;
1069 }
1070
1071 JSValueRef JSContact::getGroupIds(JSContextRef context,
1072                 JSObjectRef object,
1073                 JSStringRef propertyName,
1074                 JSValueRef* exception)
1075 {
1076         Try
1077         {
1078                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
1079                 if (!priv) {
1080                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1081                 }
1082                 JSContextRef gContext = priv->getContext();
1083
1084                 ContactConverterFactory::ConverterType converter =
1085                                 ContactConverterFactory::getConverter(gContext);
1086                 ContactPtr contact = getPrivData(object);
1087                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1088
1089                 if(newContactT->groupIdsJSObjIsSet()){
1090                         return newContactT->getGroupIdsJSObj();
1091                 }else{
1092                         JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
1093                         tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
1094
1095                         JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
1096                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
1097                         newContactT->setGroupIdsJSObj(true, convertedJSObject);
1098
1099                         JSValueProtect(gContext, convertedJSObject);
1100                         newContactT->setContext(gContext);
1101                         return tempJSValue;
1102                 }
1103         }
1104         Catch(WrtDeviceApis::Commons::Exception)
1105         {
1106                 LoggerW("trying to get incorrect value");
1107         }
1108
1109         return JSValueMakeUndefined(context);
1110 }
1111
1112 bool JSContact::setGroupIds(JSContextRef context,
1113                 JSObjectRef object,
1114                 JSStringRef propertyName,
1115                 JSValueRef value,
1116                 JSValueRef* exception)
1117 {
1118         Try
1119         {
1120                 ContactPtr contact = getPrivData(object);
1121                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1122                 contact->setGroupIds(converter->toStringArray(value));
1123                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1124                 newContactT->resetGroupIdsJSObj();
1125         }
1126         Catch(WrtDeviceApis::Commons::Exception)
1127         {
1128                 LoggerW("trying to set incorrect value");
1129                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1130         }
1131
1132         return true;
1133 }
1134
1135 JSValueRef JSContact::convertToString(JSContextRef context,
1136                 JSObjectRef object,
1137                 JSObjectRef thisObject,
1138                 size_t argumentCount,
1139                 const JSValueRef arguments[],
1140                 JSValueRef* exception)
1141 {
1142         LoggerD("entered");
1143         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1144         ContactPtr contact(NULL);
1145
1146         Try     {
1147                 contact = getPrivData(thisObject);
1148                 if (contact == NULL) {
1149                         ThrowMsg(InvalidArgumentException, "No private object.");
1150                 }
1151         } Catch(Exception) {
1152                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1153                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1154         }
1155
1156 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1157 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1158 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1159
1160         ArgumentValidator validator(context, argumentCount, arguments);
1161         std::string format;
1162         try     {
1163                 format = validator.toString(0, false);
1164         } catch (const TypeMismatchException& err ) {
1165                 return JSWebAPIError::throwException(context, exception, err);
1166         } catch(const BasePlatformException& err) {
1167                 return JSWebAPIError::throwException(context, exception, err);
1168         } catch(const ConversionException& err) {
1169                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1170         } catch(const NullPointerException& err) {
1171                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1172         }
1173
1174         std::string vCard;
1175         Try {
1176                 vCard = contact->convertToString(format);
1177         } Catch(ConversionException) {
1178                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1179                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1180         } Catch(UnsupportedException) {
1181                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1182                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1183         } Catch(Exception) {
1184                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1185                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1186         }
1187
1188         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1189         JSValueRef result;
1190         Try {
1191                 result = converter->toJSValueRef(vCard);
1192         } Catch(Exception) {
1193                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1194                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1195         }
1196         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1197         return result;
1198 }
1199
1200 JSValueRef JSContact::clone(JSContextRef context,
1201                 JSObjectRef object,
1202                 JSObjectRef thisObject,
1203                 size_t argumentCount,
1204                 const JSValueRef arguments[],
1205                 JSValueRef* exception)
1206 {
1207         LoggerD("entered");
1208         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1209         ContactPtr contact(NULL);
1210
1211         Try     {
1212                 contact = getPrivData(thisObject);
1213                 if (contact == NULL) {
1214                         ThrowMsg(InvalidArgumentException, "No private object.");
1215                 }
1216         } Catch(Exception) {
1217                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1218                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1219         }
1220
1221 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1222 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1223 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1224
1225         ContactPtr clonedContact(NULL);
1226         Try {
1227                 clonedContact = contact->clone();
1228         } Catch(Exception) {
1229                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1230                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1231         }
1232
1233         JSValueRef result;
1234         Try {
1235                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1236                 if (!priv) {
1237                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1238                 }
1239                 JSContextRef gContext = priv->getContext();
1240                 result = createJSObject(gContext, clonedContact);
1241         } Catch(Exception) {
1242                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1243                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1244         }
1245         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1246         return result;
1247 }
1248
1249 } // Contact
1250 } // DeviceAPI