Update change log and spec for wrt-plugins-tizen_0.4.49
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSContactAddress.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        JSContactAddress.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSContactAddress class
23  */
24
25 #include <dpl/shared_ptr.h>
26 #include <CommonsJavaScript/Validator.h>
27 #include <JSWebAPIErrorFactory.h>
28 #include "ContactConverter.h"
29 #include "JSContactAddress.h"
30 #include <Logger.h>
31 #include <Export.h>
32
33 #define CONTACT_CLASS_NAME "ContactAddress"
34
35 #define CONTACT_ATTR_COUNTRY "country"
36 #define CONTACT_ATTR_REGION "region"
37 #define CONTACT_ATTR_CITY "city"
38 #define CONTACT_ATTR_STREET_ADDRESS "streetAddress"
39 #define CONTACT_ATTR_ADDITIONAL_INFORMATION "additionalInformation"
40 #define CONTACT_ATTR_POSTAL_CODE "postalCode"
41 #define CONTACT_ATTR_IS_DEFAULT "isDefault"
42 #define CONTACT_ATTR_TYPES "types"
43 #define CONTACT_ATTR_LABEL "label"
44
45 namespace DeviceAPI {
46 namespace Contact {
47
48 using namespace DeviceAPI::Common;
49 using namespace WrtDeviceApis::Commons;
50 using namespace WrtDeviceApis::CommonsJavaScript;
51
52 JSClassDefinition JSContactAddress::m_classInfo =
53 {
54         0,
55         kJSClassAttributeNone,
56         CONTACT_CLASS_NAME,
57         NULL,
58         m_property,
59         m_functions,
60         Initialize,
61         Finalize,
62         NULL, //hasProperty,
63         NULL, //GetProperty,
64         NULL, //SetProperty,
65         NULL, //DeleteProperty,
66         NULL, //getPropertyNames,
67         NULL, //CallAsFunction,
68         constructor, //CallAsConstructor,
69         hasInstance, //HasInstance,
70         NULL, //ConvertToType,
71 };
72
73 JSStaticValue JSContactAddress::m_property[] = {
74         { CONTACT_ATTR_COUNTRY, getCountry, setCountry, kJSPropertyAttributeNone },
75         { CONTACT_ATTR_REGION, getRegion, setRegion, kJSPropertyAttributeNone },
76         { CONTACT_ATTR_CITY, getCity, setCity, kJSPropertyAttributeNone },
77         { CONTACT_ATTR_STREET_ADDRESS, getStreetAddress, setStreetAddress, kJSPropertyAttributeNone },
78         { CONTACT_ATTR_ADDITIONAL_INFORMATION, getAdditionalInformation, setAdditionalInformation, kJSPropertyAttributeNone },
79         { CONTACT_ATTR_POSTAL_CODE, getPostalCode, setPostalCode, kJSPropertyAttributeNone },
80         { CONTACT_ATTR_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeNone },
81         { CONTACT_ATTR_TYPES, getTypes, setTypes, kJSPropertyAttributeNone },
82         { CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone },
83         { 0, 0, 0, 0 }
84 };
85
86 JSStaticFunction JSContactAddress::m_functions[] =
87 {
88         { 0, 0, 0 }
89 };
90
91 JSClassRef JSContactAddress::m_classRef = JSClassCreate(&m_classInfo);
92
93 JSClassRef DLL_EXPORT JSContactAddress::getClassRef() {
94         if (!m_classRef) {
95                 m_classRef = JSClassCreate(&m_classInfo);
96         }
97         return m_classRef;
98 }
99
100 bool JSContactAddress::isObjectOfClass(JSContextRef context, JSValueRef value)
101 {
102         return JSValueIsObjectOfClass(context, value, getClassRef());
103 }
104
105 ContactAddressPtr JSContactAddress::getContactAddress(JSContextRef context, JSValueRef value)
106 {
107         if (!isObjectOfClass(context, value)) {
108                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
109         }
110         JSObjectRef object = JSValueToObject(context, value, NULL);
111         if (!object) {
112                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
113         }
114         JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
115         if (!priv) {
116                 Throw(WrtDeviceApis::Commons::NullPointerException);
117         }
118         return priv->getObject();
119 }
120
121 void JSContactAddress::Initialize(JSContextRef context, JSObjectRef object)
122 {
123         if (!JSObjectGetPrivate(object))
124         {
125                 ContactAddressPtr address(new ContactAddress());
126                 JSContactAddressPriv *priv = new JSContactAddressPriv(context, ContactAddressPtr(address));
127                 if (!JSObjectSetPrivate(object, priv)) {
128                         delete priv;
129                 }
130         }
131 }
132
133 void JSContactAddress::Finalize(JSObjectRef object)
134 {
135         JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
136
137         if (priv != NULL)
138                 delete (priv);
139 }
140
141 JSObjectRef JSContactAddress::createJSObject(JSContextRef context, const ContactAddressPtr contactAddress)
142 {
143         JSContactAddressPriv *priv = new JSContactAddressPriv(context, contactAddress);
144         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
145         if (NULL == jsObjectRef) {
146                 LoggerE("object creation error");
147                 return NULL;
148         }
149         return jsObjectRef;
150 }
151
152 ContactAddressPtr JSContactAddress::getPrivData(JSObjectRef object)
153 {
154         JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
155         if (!priv) {
156                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
157         }
158         ContactAddressPtr result = priv->getObject();
159         if (!result) {
160                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
161         }
162         return result;
163 }
164
165 JSObjectRef JSContactAddress::constructor(JSContextRef context,
166                 JSObjectRef constructor,
167                 size_t argumentCount,
168                 const JSValueRef arguments[],
169                 JSValueRef* exception)
170 {
171         bool js1stParamIsObject = false;
172
173         JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(constructor));
174         if (!priv) {
175                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
176         }
177         JSContextRef gContext = priv->getContext();
178
179         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
180         Try {
181                 if (argumentCount >= 1)
182                 {
183                         if (JSValueIsObject(gContext, arguments[0]))
184                                 js1stParamIsObject = true;
185
186                         if (!js1stParamIsObject &&
187                                         !JSValueIsNull(gContext, arguments[0]) &&
188                                         !JSValueIsUndefined(gContext, arguments[0]))
189                                 ThrowMsg(InvalidArgumentException, "1st argument must be a 'ContactAddressInit object'");
190                 }
191
192         } Catch(Exception ) {
193                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
194                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
195                 return NULL;
196         }
197
198         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
199
200         ContactAddressPtr contactAddress(NULL);
201
202         Try {
203                 if(js1stParamIsObject)
204                         contactAddress = converter->toContactAddressFromInit(arguments[0]);
205                 else
206                         contactAddress = ContactAddressPtr(new ContactAddress());
207
208         } Catch(Exception) {
209                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
210                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
211                 return NULL;
212         }
213
214         JSObjectRef jsobject;
215
216         Try {
217                 jsobject = createJSObject(gContext, contactAddress);
218         } Catch(Exception) {
219                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
220                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
221                 return NULL;
222         }
223
224         return jsobject;
225 }
226
227 bool JSContactAddress::hasInstance(JSContextRef context,
228                 JSObjectRef constructor,
229                 JSValueRef possibleInstance,
230                 JSValueRef* exception)
231 {
232         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
233 }
234
235 JSValueRef JSContactAddress::getCountry(JSContextRef context,
236                 JSObjectRef object,
237                 JSStringRef propertyName,
238                 JSValueRef* exception)
239 {
240         Try
241         {
242                 ContactConverterFactory::ConverterType converter =
243                                 ContactConverterFactory::getConverter(context);
244                 ContactAddressPtr contactAddress = getPrivData(object);
245                 if(!contactAddress->getCountryIsSet())
246                         return JSValueMakeNull(context);
247                 else
248                         return converter->toJSValueRef(contactAddress->getCountry());
249         }
250         Catch(WrtDeviceApis::Commons::Exception)
251         {
252                 LoggerW("trying to get incorrect value");
253         }
254         return JSValueMakeUndefined(context);
255 }
256
257 bool JSContactAddress::setCountry(JSContextRef context,
258                 JSObjectRef object,
259                 JSStringRef propertyName,
260                 JSValueRef value,
261                 JSValueRef* exception)
262 {
263         Try
264         {
265                 ContactAddressPtr contactAddress = getPrivData(object);
266                 ContactConverterFactory::ConverterType converter =
267                                 ContactConverterFactory::getConverter(context);
268                 BasicValidator validator =
269                                 BasicValidatorFactory::getValidator(context, exception);
270                 if(validator->isNullOrUndefined(value))
271                         contactAddress->unsetCountry();
272                 else
273                         contactAddress->setCountry(converter->toString(value));
274         }
275         Catch(WrtDeviceApis::Commons::Exception)
276         {
277                 LoggerW("trying to set incorrect value");
278                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
279         }
280         return true;
281 }
282
283
284 JSValueRef JSContactAddress::getRegion(JSContextRef context,
285                 JSObjectRef object,
286                 JSStringRef propertyName,
287                 JSValueRef* exception)
288 {
289         Try
290         {
291                 ContactConverterFactory::ConverterType converter =
292                                 ContactConverterFactory::getConverter(context);
293                 ContactAddressPtr contactAddress = getPrivData(object);
294                 if(!contactAddress->getRegionIsSet())
295                         return JSValueMakeNull(context);
296                 else
297                         return converter->toJSValueRef(contactAddress->getRegion());
298         }
299         Catch(WrtDeviceApis::Commons::Exception)
300         {
301                 LoggerW("trying to get incorrect value");
302         }
303         return JSValueMakeUndefined(context);
304 }
305
306 bool JSContactAddress::setRegion(JSContextRef context,
307                 JSObjectRef object,
308                 JSStringRef propertyName,
309                 JSValueRef value,
310                 JSValueRef* exception)
311 {
312         Try
313         {
314                 ContactAddressPtr contactAddress = getPrivData(object);
315                 ContactConverterFactory::ConverterType converter =
316                                 ContactConverterFactory::getConverter(context);
317                 BasicValidator validator =
318                                 BasicValidatorFactory::getValidator(context, exception);
319                 if(validator->isNullOrUndefined(value))
320                         contactAddress->unsetRegion();
321                 else
322                         contactAddress->setRegion(converter->toString(value));
323         }
324         Catch(WrtDeviceApis::Commons::Exception)
325         {
326                 LoggerW("trying to set incorrect value");
327                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
328         }
329         return true;
330 }
331
332 JSValueRef JSContactAddress::getCity(JSContextRef context,
333                 JSObjectRef object,
334                 JSStringRef propertyName,
335                 JSValueRef* exception)
336 {
337         Try
338         {
339                 ContactConverterFactory::ConverterType converter =
340                                 ContactConverterFactory::getConverter(context);
341                 ContactAddressPtr contactAddress = getPrivData(object);
342                 if(!contactAddress->getCityIsSet())
343                         return JSValueMakeNull(context);
344                 else
345                         return converter->toJSValueRef(contactAddress->getCity());
346         }
347         Catch(WrtDeviceApis::Commons::Exception)
348         {
349                 LoggerW("trying to get incorrect value");
350         }
351         return JSValueMakeUndefined(context);
352 }
353
354 bool JSContactAddress::setCity(JSContextRef context,
355                 JSObjectRef object,
356                 JSStringRef propertyName,
357                 JSValueRef value,
358                 JSValueRef* exception)
359 {
360         Try
361         {
362                 ContactAddressPtr contactAddress = getPrivData(object);
363                 ContactConverterFactory::ConverterType converter =
364                                 ContactConverterFactory::getConverter(context);
365                 BasicValidator validator =
366                                 BasicValidatorFactory::getValidator(context, exception);
367                 if(validator->isNullOrUndefined(value))
368                         contactAddress->unsetCity();
369                 else
370                         contactAddress->setCity(converter->toString(value));
371         }
372         Catch(WrtDeviceApis::Commons::Exception)
373         {
374                 LoggerW("trying to set incorrect value");
375                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
376         }
377         return true;
378 }
379
380
381 JSValueRef JSContactAddress::getStreetAddress(JSContextRef context,
382                 JSObjectRef object,
383                 JSStringRef propertyName,
384                 JSValueRef* exception)
385 {
386         Try
387         {
388                 ContactConverterFactory::ConverterType converter =
389                                 ContactConverterFactory::getConverter(context);
390                 ContactAddressPtr contactAddress = getPrivData(object);
391                 if(!contactAddress->getStreetAddressIsSet())
392                         return JSValueMakeNull(context);
393                 else
394                         return converter->toJSValueRef(contactAddress->getStreetAddress());
395         }
396         Catch(WrtDeviceApis::Commons::Exception)
397         {
398                 LoggerW("trying to get incorrect value");
399         }
400         return JSValueMakeUndefined(context);
401 }
402
403 bool JSContactAddress::setStreetAddress(JSContextRef context,
404                 JSObjectRef object,
405                 JSStringRef propertyName,
406                 JSValueRef value,
407                 JSValueRef* exception)
408 {
409         Try
410         {
411                 ContactAddressPtr contactAddress = getPrivData(object);
412                 ContactConverterFactory::ConverterType converter =
413                                 ContactConverterFactory::getConverter(context);
414                 BasicValidator validator =
415                                 BasicValidatorFactory::getValidator(context, exception);
416                 if(validator->isNullOrUndefined(value))
417                         contactAddress->unsetStreetAddress();
418                 else
419                         contactAddress->setStreetAddress(converter->toString(value));
420         }
421         Catch(WrtDeviceApis::Commons::Exception)
422         {
423                 LoggerW("trying to set incorrect value");
424                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
425         }
426         return true;
427 }
428
429
430 JSValueRef JSContactAddress::getAdditionalInformation(JSContextRef context,
431                 JSObjectRef object,
432                 JSStringRef propertyName,
433                 JSValueRef* exception)
434 {
435         Try
436         {
437                 ContactConverterFactory::ConverterType converter =
438                                 ContactConverterFactory::getConverter(context);
439                 ContactAddressPtr contactAddress = getPrivData(object);
440                 if(!contactAddress->getAdditionalInformationIsSet())
441                         return JSValueMakeNull(context);
442                 else
443                         return converter->toJSValueRef(contactAddress->getAdditionalInformation());
444         }
445         Catch(WrtDeviceApis::Commons::Exception)
446         {
447                 LoggerW("trying to get incorrect value");
448         }
449         return JSValueMakeUndefined(context);
450 }
451
452 bool JSContactAddress::setAdditionalInformation(JSContextRef context,
453                 JSObjectRef object,
454                 JSStringRef propertyName,
455                 JSValueRef value,
456                 JSValueRef* exception)
457 {
458         Try
459         {
460                 ContactAddressPtr contactAddress = getPrivData(object);
461                 ContactConverterFactory::ConverterType converter =
462                                 ContactConverterFactory::getConverter(context);
463                 BasicValidator validator =
464                                 BasicValidatorFactory::getValidator(context, exception);
465                 if(validator->isNullOrUndefined(value))
466                         contactAddress->unsetAdditionalInformation();
467                 else
468                         contactAddress->setAdditionalInformation(converter->toString(value));
469         }
470         Catch(WrtDeviceApis::Commons::Exception)
471         {
472                 LoggerW("trying to set incorrect value");
473                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
474         }
475         return true;
476 }
477
478
479 JSValueRef JSContactAddress::getPostalCode(JSContextRef context,
480                 JSObjectRef object,
481                 JSStringRef propertyName,
482                 JSValueRef* exception)
483 {
484         Try
485         {
486                 ContactConverterFactory::ConverterType converter =
487                                 ContactConverterFactory::getConverter(context);
488                 ContactAddressPtr contactAddress = getPrivData(object);
489                 if(!contactAddress->getPostalCodeIsSet())
490                         return JSValueMakeNull(context);
491                 else
492                         return converter->toJSValueRef(contactAddress->getPostalCode());
493         }
494         Catch(WrtDeviceApis::Commons::Exception)
495         {
496                 LoggerW("trying to get incorrect value");
497         }
498         return JSValueMakeUndefined(context);
499 }
500
501 bool JSContactAddress::setPostalCode(JSContextRef context,
502                 JSObjectRef object,
503                 JSStringRef propertyName,
504                 JSValueRef value,
505                 JSValueRef* exception)
506 {
507         Try
508         {
509                 ContactAddressPtr contactAddress = getPrivData(object);
510                 ContactConverterFactory::ConverterType converter =
511                                 ContactConverterFactory::getConverter(context);
512                 BasicValidator validator =
513                                 BasicValidatorFactory::getValidator(context, exception);
514                 if(validator->isNullOrUndefined(value))
515                         contactAddress->unsetPostalCode();
516                 else
517                         contactAddress->setPostalCode(converter->toString(value));
518         }
519         Catch(WrtDeviceApis::Commons::Exception)
520         {
521                 LoggerW("trying to set incorrect value");
522                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
523         }
524         return true;
525 }
526
527
528 JSValueRef JSContactAddress::getIsDefault(JSContextRef context,
529                 JSObjectRef object,
530                 JSStringRef propertyName,
531                 JSValueRef* exception)
532 {
533         Try
534         {
535                 ContactConverterFactory::ConverterType converter =
536                                 ContactConverterFactory::getConverter(context);
537                 ContactAddressPtr contactAddress = getPrivData(object);
538                 return converter->toJSValueRef(contactAddress->getIsDefault());
539         }
540         Catch(WrtDeviceApis::Commons::Exception)
541         {
542                 LoggerW("trying to get incorrect value");
543         }
544         return JSValueMakeUndefined(context);
545 }
546
547 bool JSContactAddress::setIsDefault(JSContextRef context,
548                 JSObjectRef object,
549                 JSStringRef propertyName,
550                 JSValueRef value,
551                 JSValueRef* exception)
552 {
553         Try
554         {
555                 ContactAddressPtr contactAddress = getPrivData(object);
556                 ContactConverterFactory::ConverterType converter =
557                                 ContactConverterFactory::getConverter(context);
558                 BasicValidator validator =
559                                 BasicValidatorFactory::getValidator(context, exception);
560                 contactAddress->setIsDefault(converter->toBool(value));
561         }
562         Catch(WrtDeviceApis::Commons::Exception)
563         {
564                 LoggerW("trying to set incorrect value");
565                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
566         }
567         return true;
568 }
569
570
571 JSValueRef JSContactAddress::getTypes(JSContextRef context,
572                 JSObjectRef object,
573                 JSStringRef propertyName,
574                 JSValueRef* exception)
575 {
576         Try
577         {
578                 JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
579                 if (!priv) {
580                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
581                 }
582                 JSContextRef gContext = priv->getContext();
583                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
584                 ContactAddressPtr contactAddress = getPrivData(object);
585
586                 if(contactAddress->IsTypesSetJSArray()){
587                         return contactAddress->getTypesJSObj();
588                 }else{
589                         JSValueRef tempJSValue = contactAddress->getTypesJSArray();
590                         tempJSValue = converter->toJSValueRef(contactAddress->getTypes());
591
592                         JSObjectRef convertedJSObject = contactAddress->getTypesJSObj();
593                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
594                         contactAddress->setTypesJSArray(true, convertedJSObject);
595
596                         JSValueProtect(gContext, convertedJSObject);
597                         contactAddress->setContext(gContext);
598                         return tempJSValue;
599                 }
600         }
601         Catch(WrtDeviceApis::Commons::Exception)
602         {
603                 LoggerW("trying to get incorrect value");
604         }
605         return JSValueMakeUndefined(context);
606 }
607
608 bool JSContactAddress::setTypes(JSContextRef context,
609                 JSObjectRef object,
610                 JSStringRef propertyName,
611                 JSValueRef value,
612                 JSValueRef* exception)
613 {
614         Try
615         {
616                 ContactAddressPtr contactAddress = getPrivData(object);
617                 ContactConverterFactory::ConverterType converter =
618                                 ContactConverterFactory::getConverter(context);
619
620                 contactAddress->setTypes(converter->toContactAddressTypeArray(value));
621                 contactAddress->resetTypesJSObj();
622         }
623         Catch(WrtDeviceApis::Commons::Exception)
624         {
625                 LoggerW("trying to set incorrect value");
626                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
627         }
628         return true;
629 }
630
631 JSValueRef JSContactAddress::getLabel(JSContextRef context,
632                 JSObjectRef object,
633                 JSStringRef propertyName,
634                 JSValueRef* exception)
635 {
636         Try
637         {
638                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
639                 ContactAddressPtr contactAddress = getPrivData(object);
640                 if(!contactAddress->getLabelIsSet())
641                         return JSValueMakeNull(context);
642                 else
643                         return converter->toJSValueRef(contactAddress->getLabel());
644         }
645         Catch(WrtDeviceApis::Commons::Exception)
646         {
647                 LoggerW("trying to get incorrect value");
648         }
649         return JSValueMakeUndefined(context);
650 }
651
652 bool JSContactAddress::setLabel(JSContextRef context,
653                 JSObjectRef object,
654                 JSStringRef propertyName,
655                 JSValueRef value,
656                 JSValueRef* exception)
657 {
658         Try
659         {
660                 ContactAddressPtr contactAddress = getPrivData(object);
661                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
662                 BasicValidator validator =
663                                 BasicValidatorFactory::getValidator(context, exception);
664                 contactAddress->setLabel(converter->toString(value));
665         }
666         Catch(WrtDeviceApis::Commons::Exception)
667         {
668                 LoggerW("trying to set incorrect value");
669                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
670         }
671         return true;
672 }
673
674 } // Contact
675 } // DeviceAPI