Update change log and spec for wrt-plugins-tizen_0.4.49
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSContactOrganization.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        JSContactOrganization.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSContactOrganization class
23  */
24
25 #include "JSContactOrganization.h"
26 #include <dpl/shared_ptr.h>
27 #include <CommonsJavaScript/Validator.h>
28 #include <JSWebAPIErrorFactory.h>
29 #include "ContactConverter.h"
30 #include <Logger.h>
31 #include <Export.h>
32
33 #define ORGANIZATION_CLASS_NAME "ContactOrganization"
34
35 #define CONTACT_ATTR_NAME "name"
36 #define CONTACT_ATTR_DEPARTMENT "department"
37 #define CONTACT_ATTR_TITLE "title"
38 #define CONTACT_ATTR_ROLE "role"
39 #define CONTACT_ATTR_LOGO_URI "logoURI"
40
41 #define CONTACT_ATTR_ASSISTANT_NAME "assistant"
42 #define CONTACT_ATTR_LOCATION "location"
43 #define CONTACT_ATTR_DESCRIPTION "description"
44 #define CONTACT_ATTR_PHONETIC_NAME "phoneticName"
45 #define CONTACT_ATTR_TYPE "type"
46 #define CONTACT_ATTR_LABEL "label"
47
48 namespace DeviceAPI {
49 namespace Contact {
50
51 using namespace DeviceAPI::Common;
52 using namespace WrtDeviceApis::Commons;
53 using namespace WrtDeviceApis::CommonsJavaScript;
54
55 JSClassDefinition JSContactOrganization::m_classInfo =
56 {
57         0,
58         kJSClassAttributeNone,
59         ORGANIZATION_CLASS_NAME,
60         NULL,
61         m_property,
62         m_functions,
63         Initialize,
64         Finalize,
65         NULL, //hasProperty,
66         NULL, //GetProperty,
67         NULL, //SetProperty,
68         NULL, //DeleteProperty,
69         NULL, //getPropertyNames,
70         NULL, //CallAsFunction,
71         constructor, //CallAsConstructor,
72         hasInstance, //HasInstance,
73         NULL, //ConvertToType,
74 };
75
76 JSStaticValue JSContactOrganization::m_property[] = {
77         { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
78         { CONTACT_ATTR_DEPARTMENT, getDepartment, setDepartment, kJSPropertyAttributeNone },
79         { CONTACT_ATTR_TITLE, getTitle, setTitle, kJSPropertyAttributeNone },
80         { CONTACT_ATTR_ROLE, getRole, setRole, kJSPropertyAttributeNone },
81         { CONTACT_ATTR_LOGO_URI, getLogoURI, setLogoURI, kJSPropertyAttributeNone },
82         { CONTACT_ATTR_ASSISTANT_NAME, getAssistant, setAssistant, kJSPropertyAttributeNone },
83         { CONTACT_ATTR_LOCATION, getLocation, setLocation, kJSPropertyAttributeNone },
84         { CONTACT_ATTR_DESCRIPTION, getDescription, setDescription, kJSPropertyAttributeNone },
85         { CONTACT_ATTR_PHONETIC_NAME, getPhoneticName, setPhoneticName, kJSPropertyAttributeNone },
86         { CONTACT_ATTR_TYPE, getType, setType, kJSPropertyAttributeNone },
87         { CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone },
88         { 0, 0, 0, 0 }
89 };
90
91 JSStaticFunction JSContactOrganization::m_functions[] =
92 {
93         { 0, 0, 0 }
94 };
95
96 JSClassRef JSContactOrganization::m_classRef = JSClassCreate(&m_classInfo);
97
98 JSClassRef DLL_EXPORT JSContactOrganization::getClassRef() {
99         if (!m_classRef) {
100                 m_classRef = JSClassCreate(&m_classInfo);
101         }
102         return m_classRef;
103 }
104
105 bool JSContactOrganization::isObjectOfClass(JSContextRef context, JSValueRef value)
106 {
107         return JSValueIsObjectOfClass(context, value, getClassRef());
108 }
109
110 ContactOrganizationPtr JSContactOrganization::getContactOrganization(JSContextRef context, JSValueRef value)
111 {
112         if (!isObjectOfClass(context, value)) {
113                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
114         }
115         JSObjectRef object = JSValueToObject(context, value, NULL);
116         if (!object) {
117                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
118         }
119         JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
120         if (!priv) {
121                 Throw(WrtDeviceApis::Commons::NullPointerException);
122         }
123         return priv->getObject();
124 }
125
126 void JSContactOrganization::Initialize(JSContextRef context, JSObjectRef object)
127 {
128         if (!JSObjectGetPrivate(object))
129         {
130                 ContactOrganizationPtr organization(new ContactOrganization());
131                 JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, ContactOrganizationPtr(organization));
132                 if (!JSObjectSetPrivate(object, priv)) {
133                         delete priv;
134                 }
135         }
136 }
137
138 void JSContactOrganization::Finalize(JSObjectRef object)
139 {
140         JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
141
142         if (priv != NULL)
143                 delete (priv);
144 }
145
146 JSObjectRef JSContactOrganization::createJSObject(JSContextRef context, ContactOrganizationPtr contactOrganization)
147 {
148         JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, contactOrganization);
149         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
150         if (NULL == jsObjectRef) {
151                 LoggerE("object creation error");
152                 return NULL;
153         }
154         return jsObjectRef;
155 }
156
157 ContactOrganizationPtr JSContactOrganization::getPrivData(JSObjectRef object)
158 {
159         JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
160         if (!priv) {
161                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
162         }
163         ContactOrganizationPtr result = priv->getObject();
164         if (!result) {
165                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
166         }
167         return result;
168 }
169
170 JSObjectRef JSContactOrganization::constructor(JSContextRef context,
171                 JSObjectRef constructor,
172                 size_t argumentCount,
173                 const JSValueRef arguments[],
174                 JSValueRef* exception)
175 {
176         bool js1stParamIsObject = false;
177
178         JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(constructor));
179         if (!priv) {
180                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
181         }
182         JSContextRef gContext = priv->getContext();
183
184         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
185         Try {
186                 if (argumentCount >= 1)
187                 {
188                         if (JSValueIsObject(gContext, arguments[0]))
189                                 js1stParamIsObject = true;
190
191                         if (!js1stParamIsObject &&
192                                         !JSValueIsNull(gContext, arguments[0]) &&
193                                         !JSValueIsUndefined(gContext, arguments[0]))
194                                 ThrowMsg(InvalidArgumentException, "1st argument must be a 'object'");
195                 }
196
197         } Catch(Exception ) {
198                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
199                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'object'");
200                 return NULL;
201         }
202
203         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
204
205         ContactOrganizationPtr contactOrganization(NULL);
206         Try {
207                 if(js1stParamIsObject)
208                         contactOrganization = converter->toContactOrganizationFromInit(arguments[0]);
209                 else
210                         contactOrganization = ContactOrganizationPtr(new ContactOrganization());
211
212         } Catch(Exception) {
213                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
214                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
215                 return NULL;
216         }
217
218         JSObjectRef jsobject;
219
220         Try {
221                 jsobject = createJSObject(gContext, contactOrganization);
222         } Catch(Exception) {
223                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
224                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
225                 return NULL;
226         }
227
228         return jsobject;
229 }
230
231 bool JSContactOrganization::hasInstance(JSContextRef context,
232                 JSObjectRef constructor,
233                 JSValueRef possibleInstance,
234                 JSValueRef* exception)
235 {
236         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
237 }
238
239 JSValueRef JSContactOrganization::getName(JSContextRef context,
240                 JSObjectRef object,
241                 JSStringRef propertyName,
242                 JSValueRef* exception)
243 {
244         Try
245         {
246                 ContactConverterFactory::ConverterType converter =
247                                 ContactConverterFactory::getConverter(context);
248                 ContactOrganizationPtr organization = getPrivData(object);
249                 if(!organization->getNameIsSet())
250                         return JSValueMakeNull(context);
251                 else
252                         return converter->toJSValueRef(organization->getName());
253         }
254         Catch(WrtDeviceApis::Commons::Exception)
255         {
256                 LoggerW("trying to get incorrect value");
257         }
258         return JSValueMakeUndefined(context);
259 }
260
261 bool JSContactOrganization::setName(JSContextRef context,
262                 JSObjectRef object,
263                 JSStringRef propertyName,
264                 JSValueRef value,
265                 JSValueRef* exception)
266 {
267         Try
268         {
269                 ContactOrganizationPtr organization = getPrivData(object);
270                 ContactConverterFactory::ConverterType converter =
271                                 ContactConverterFactory::getConverter(context);
272                 BasicValidator validator =
273                                 BasicValidatorFactory::getValidator(context, exception);
274                 if(validator->isNullOrUndefined(value))
275                         organization->unsetName();
276                 else
277                         organization->setName(converter->toString(value));
278         }
279         Catch(WrtDeviceApis::Commons::Exception)
280         {
281                 LoggerW("trying to set incorrect value");
282                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
283         }
284         return true;
285 }
286
287
288 JSValueRef JSContactOrganization::getDepartment(JSContextRef context,
289                 JSObjectRef object,
290                 JSStringRef propertyName,
291                 JSValueRef* exception)
292 {
293         Try
294         {
295                 ContactConverterFactory::ConverterType converter =
296                                 ContactConverterFactory::getConverter(context);
297                 ContactOrganizationPtr organization = getPrivData(object);
298                 if(!organization->getDepartmentIsSet())
299                         return JSValueMakeNull(context);
300                 else
301                         return converter->toJSValueRef(organization->getDepartment());
302         }
303         Catch(WrtDeviceApis::Commons::Exception)
304         {
305                 LoggerW("trying to get incorrect value");
306         }
307         return JSValueMakeUndefined(context);
308 }
309
310 bool JSContactOrganization::setDepartment(JSContextRef context,
311                 JSObjectRef object,
312                 JSStringRef propertyName,
313                 JSValueRef value,
314                 JSValueRef* exception)
315 {
316         Try
317         {
318                 ContactOrganizationPtr organization = getPrivData(object);
319                 ContactConverterFactory::ConverterType converter =
320                                 ContactConverterFactory::getConverter(context);
321                 BasicValidator validator =
322                                 BasicValidatorFactory::getValidator(context, exception);
323                 if(validator->isNullOrUndefined(value))
324                         organization->unsetDepartment();
325                 else
326                         organization->setDepartment(converter->toString(value));
327         }
328         Catch(WrtDeviceApis::Commons::Exception)
329         {
330                 LoggerW("trying to set incorrect value");
331                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
332         }
333         return true;
334 }
335
336 JSValueRef JSContactOrganization::getTitle(JSContextRef context,
337                 JSObjectRef object,
338                 JSStringRef propertyName,
339                 JSValueRef* exception)
340 {
341         Try
342         {
343                 ContactConverterFactory::ConverterType converter =
344                                 ContactConverterFactory::getConverter(context);
345                 ContactOrganizationPtr organization = getPrivData(object);
346                 if(!organization->getTitleIsSet())
347                         return JSValueMakeNull(context);
348                 else
349                         return converter->toJSValueRef(organization->getTitle());
350         }
351         Catch(WrtDeviceApis::Commons::Exception)
352         {
353                 LoggerW("trying to get incorrect value");
354         }
355         return JSValueMakeUndefined(context);
356 }
357
358 bool JSContactOrganization::setTitle(JSContextRef context,
359                 JSObjectRef object,
360                 JSStringRef propertyName,
361                 JSValueRef value,
362                 JSValueRef* exception)
363 {
364         Try
365         {
366                 ContactOrganizationPtr organization = getPrivData(object);
367                 ContactConverterFactory::ConverterType converter =
368                                 ContactConverterFactory::getConverter(context);
369                 BasicValidator validator =
370                                 BasicValidatorFactory::getValidator(context, exception);
371                 if(validator->isNullOrUndefined(value))
372                         organization->unsetTitle();
373                 else
374                         organization->setTitle(converter->toString(value));
375         }
376         Catch(WrtDeviceApis::Commons::Exception)
377         {
378                 LoggerW("trying to set incorrect value");
379                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
380         }
381         return true;
382 }
383
384 JSValueRef JSContactOrganization::getRole(JSContextRef context,
385                 JSObjectRef object,
386                 JSStringRef propertyName,
387                 JSValueRef* exception)
388 {
389         Try
390         {
391                 ContactConverterFactory::ConverterType converter =
392                                 ContactConverterFactory::getConverter(context);
393                 ContactOrganizationPtr organization = getPrivData(object);
394                 if(!organization->getRoleIsSet())
395                         return JSValueMakeNull(context);
396                 else
397                         return converter->toJSValueRef(organization->getRole());
398         }
399         Catch(WrtDeviceApis::Commons::Exception)
400         {
401                 LoggerW("trying to get incorrect value");
402         }
403         return JSValueMakeUndefined(context);
404 }
405
406 bool JSContactOrganization::setRole(JSContextRef context,
407                 JSObjectRef object,
408                 JSStringRef propertyName,
409                 JSValueRef value,
410                 JSValueRef* exception)
411 {
412         Try
413         {
414                 ContactOrganizationPtr organization = getPrivData(object);
415                 ContactConverterFactory::ConverterType converter =
416                                 ContactConverterFactory::getConverter(context);
417                 BasicValidator validator =
418                                 BasicValidatorFactory::getValidator(context, exception);
419                 if(validator->isNullOrUndefined(value))
420                         organization->unsetRole();
421                 else
422                         organization->setRole(converter->toString(value));
423         }
424         Catch(WrtDeviceApis::Commons::Exception)
425         {
426                 LoggerW("trying to set incorrect value");
427                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
428         }
429         return true;
430 }
431
432 JSValueRef JSContactOrganization::getLogoURI(JSContextRef context,
433                 JSObjectRef object,
434                 JSStringRef propertyName,
435                 JSValueRef* exception)
436 {
437         Try
438         {
439                 ContactConverterFactory::ConverterType converter =
440                                 ContactConverterFactory::getConverter(context);
441                 ContactOrganizationPtr organization = getPrivData(object);
442                 if(!organization->getLogoURIIsSet())
443                         return JSValueMakeNull(context);
444                 else
445                         return converter->toJSValueRef(organization->getLogoURI());
446         }
447         Catch(WrtDeviceApis::Commons::Exception)
448         {
449                 LoggerW("trying to get incorrect value");
450         }
451         return JSValueMakeUndefined(context);
452 }
453
454 bool JSContactOrganization::setLogoURI(JSContextRef context,
455                 JSObjectRef object,
456                 JSStringRef propertyName,
457                 JSValueRef value,
458                 JSValueRef* exception)
459 {
460         Try
461         {
462                 ContactOrganizationPtr organization = getPrivData(object);
463                 ContactConverterFactory::ConverterType converter =
464                                 ContactConverterFactory::getConverter(context);
465                 BasicValidator validator =
466                                 BasicValidatorFactory::getValidator(context, exception);
467                 if(validator->isNullOrUndefined(value))
468                         organization->unsetLogoURI();
469                 else
470                         organization->setLogoURI(converter->toString(value));
471         }
472         Catch(WrtDeviceApis::Commons::Exception)
473         {
474                 LoggerW("trying to set incorrect value");
475                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
476         }
477         return true;
478 }
479
480 JSValueRef JSContactOrganization::getAssistant(JSContextRef context,
481                 JSObjectRef object,
482                 JSStringRef propertyName,
483                 JSValueRef* exception)
484 {
485         Try
486         {
487                 ContactConverterFactory::ConverterType converter =
488                                 ContactConverterFactory::getConverter(context);
489                 ContactOrganizationPtr organization = getPrivData(object);
490                 if(!organization->getAssistantIsSet())
491                         return JSValueMakeNull(context);
492                 else
493                         return converter->toJSValueRef(organization->getAssistant());
494         }
495         Catch(WrtDeviceApis::Commons::Exception)
496         {
497                 LoggerW("trying to get incorrect value");
498         }
499         return JSValueMakeUndefined(context);
500 }
501
502 bool JSContactOrganization::setAssistant(JSContextRef context,
503                 JSObjectRef object,
504                 JSStringRef propertyName,
505                 JSValueRef value,
506                 JSValueRef* exception)
507 {
508         Try
509         {
510                 ContactOrganizationPtr organization = getPrivData(object);
511                 ContactConverterFactory::ConverterType converter =
512                                 ContactConverterFactory::getConverter(context);
513                 BasicValidator validator =
514                                 BasicValidatorFactory::getValidator(context, exception);
515                 if(validator->isNullOrUndefined(value))
516                         organization->unsetAssistant();
517                 else
518                         organization->setAssistant(converter->toString(value));
519         }
520         Catch(WrtDeviceApis::Commons::Exception)
521         {
522                 LoggerW("trying to set incorrect value");
523                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
524         }
525         return true;
526 }
527
528 JSValueRef JSContactOrganization::getLocation(JSContextRef context,
529                 JSObjectRef object,
530                 JSStringRef propertyName,
531                 JSValueRef* exception)
532 {
533         Try
534         {
535                 ContactConverterFactory::ConverterType converter =
536                                 ContactConverterFactory::getConverter(context);
537                 ContactOrganizationPtr organization = getPrivData(object);
538                 return converter->toJSValueRef(organization->getLocation());
539         }
540         Catch(WrtDeviceApis::Commons::Exception)
541         {
542                 LoggerW("trying to get incorrect value");
543         }
544         return JSValueMakeUndefined(context);
545 }
546
547 bool JSContactOrganization::setLocation(JSContextRef context,
548                 JSObjectRef object,
549                 JSStringRef propertyName,
550                 JSValueRef value,
551                 JSValueRef* exception)
552 {
553         Try
554         {
555                 ContactOrganizationPtr organization = getPrivData(object);
556                 ContactConverterFactory::ConverterType converter =
557                                 ContactConverterFactory::getConverter(context);
558                 BasicValidator validator =
559                                 BasicValidatorFactory::getValidator(context, exception);
560                 if(validator->isNullOrUndefined(value))
561                         organization->unsetLocation();
562                 else
563                         organization->setLocation(converter->toString(value));
564         }
565         Catch(WrtDeviceApis::Commons::Exception)
566         {
567                 LoggerW("trying to set incorrect value");
568                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
569         }
570         return true;
571 }
572
573 JSValueRef JSContactOrganization::getDescription(JSContextRef context,
574                 JSObjectRef object,
575                 JSStringRef propertyName,
576                 JSValueRef* exception)
577 {
578         Try
579         {
580                 ContactConverterFactory::ConverterType converter =
581                                 ContactConverterFactory::getConverter(context);
582                 ContactOrganizationPtr organization = getPrivData(object);
583                 if(!organization->getDescriptionIsSet())
584                         return JSValueMakeNull(context);
585                 else
586                         return converter->toJSValueRef(organization->getDescription());
587         }
588         Catch(WrtDeviceApis::Commons::Exception)
589         {
590                 LoggerW("trying to get incorrect value");
591         }
592         return JSValueMakeUndefined(context);
593 }
594
595 bool JSContactOrganization::setDescription(JSContextRef context,
596                 JSObjectRef object,
597                 JSStringRef propertyName,
598                 JSValueRef value,
599                 JSValueRef* exception)
600 {
601         Try
602         {
603                 ContactOrganizationPtr organization = getPrivData(object);
604                 ContactConverterFactory::ConverterType converter =
605                                 ContactConverterFactory::getConverter(context);
606                 BasicValidator validator =
607                                 BasicValidatorFactory::getValidator(context, exception);
608                 if(validator->isNullOrUndefined(value))
609                         organization->unsetDescription();
610                 else
611                         organization->setDescription(converter->toString(value));
612         }
613         Catch(WrtDeviceApis::Commons::Exception)
614         {
615                 LoggerW("trying to set incorrect value");
616                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
617         }
618         return true;
619 }
620
621 JSValueRef JSContactOrganization::getPhoneticName(JSContextRef context,
622                 JSObjectRef object,
623                 JSStringRef propertyName,
624                 JSValueRef* exception)
625 {
626         Try
627         {
628                 ContactConverterFactory::ConverterType converter =
629                                 ContactConverterFactory::getConverter(context);
630                 ContactOrganizationPtr organization = getPrivData(object);
631                 if(!organization->getPhoneticNameIsSet())
632                         return JSValueMakeNull(context);
633                 else
634                         return converter->toJSValueRef(organization->getPhoneticName());
635         }
636         Catch(WrtDeviceApis::Commons::Exception)
637         {
638                 LoggerW("trying to get incorrect value");
639         }
640         return JSValueMakeUndefined(context);
641 }
642
643 bool JSContactOrganization::setPhoneticName(JSContextRef context,
644                 JSObjectRef object,
645                 JSStringRef propertyName,
646                 JSValueRef value,
647                 JSValueRef* exception)
648 {
649         Try
650         {
651                 ContactOrganizationPtr organization = getPrivData(object);
652                 ContactConverterFactory::ConverterType converter =
653                                 ContactConverterFactory::getConverter(context);
654                 BasicValidator validator =
655                                 BasicValidatorFactory::getValidator(context, exception);
656                 if(validator->isNullOrUndefined(value))
657                         organization->unsetPhoneticName();
658                 else
659                         organization->setPhoneticName(converter->toString(value));
660         }
661         Catch(WrtDeviceApis::Commons::Exception)
662         {
663                 LoggerW("trying to set incorrect value");
664                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
665         }
666         return true;
667 }
668
669 JSValueRef JSContactOrganization::getType(JSContextRef context,
670                 JSObjectRef object,
671                 JSStringRef propertyName,
672                 JSValueRef* exception)
673 {
674         Try
675         {
676                 ContactConverterFactory::ConverterType converter =
677                                 ContactConverterFactory::getConverter(context);
678                 ContactOrganizationPtr organization = getPrivData(object);
679                 if(!organization->getTypeIsSet())
680                         return JSValueMakeNull(context);
681                 else
682                         return converter->toJSValueRef(organization->getType());
683         }
684         Catch(WrtDeviceApis::Commons::Exception)
685         {
686                 LoggerW("trying to get incorrect value");
687         }
688         return JSValueMakeUndefined(context);
689 }
690
691 bool JSContactOrganization::setType(JSContextRef context,
692                 JSObjectRef object,
693                 JSStringRef propertyName,
694                 JSValueRef value,
695                 JSValueRef* exception)
696 {
697         Try
698         {
699                 ContactOrganizationPtr organization = getPrivData(object);
700                 ContactConverterFactory::ConverterType converter =
701                                 ContactConverterFactory::getConverter(context);
702                 BasicValidator validator =
703                                 BasicValidatorFactory::getValidator(context, exception);
704                 if(validator->isNullOrUndefined(value))
705                         organization->unsetType();
706                 else
707                         organization->setType(converter->toContactOrganizationType(value));
708         }
709         Catch(WrtDeviceApis::Commons::Exception)
710         {
711                 LoggerW("trying to set incorrect value");
712                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
713         }
714         return true;
715 }
716
717 JSValueRef JSContactOrganization::getLabel(JSContextRef context,
718                 JSObjectRef object,
719                 JSStringRef propertyName,
720                 JSValueRef* exception)
721 {
722         Try
723         {
724                 ContactConverterFactory::ConverterType converter =
725                                 ContactConverterFactory::getConverter(context);
726                 ContactOrganizationPtr organization = getPrivData(object);
727                 return converter->toJSValueRef(organization->getLabel());
728         }
729         Catch(WrtDeviceApis::Commons::Exception)
730         {
731                 LoggerW("trying to get incorrect value");
732         }
733         return JSValueMakeUndefined(context);
734 }
735
736 bool JSContactOrganization::setLabel(JSContextRef context,
737                 JSObjectRef object,
738                 JSStringRef propertyName,
739                 JSValueRef value,
740                 JSValueRef* exception)
741 {
742         Try
743         {
744                 ContactOrganizationPtr organization = getPrivData(object);
745                 ContactConverterFactory::ConverterType converter =
746                                 ContactConverterFactory::getConverter(context);
747                 BasicValidator validator =
748                                 BasicValidatorFactory::getValidator(context, exception);
749                 if(validator->isNullOrUndefined(value))
750                         organization->unsetLabel();
751                 else
752                         organization->setLabel(converter->toString(value));
753         }
754         Catch(WrtDeviceApis::Commons::Exception)
755         {
756                 LoggerW("trying to set incorrect value");
757                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
758         }
759         return true;
760 }
761
762 } // Contact
763 } // DeviceAPI