13b346c87a0e82cc541aa55290f06979bd77b894
[framework/web/wrt-plugins-tizen.git] / src / Calendar / JSCalendar.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 #include <dpl/log/log.h>
20 #include "ICalendar.h"
21 #include "EventId.h"
22 #include "CalendarFactory.h"
23
24 #include <CommonsJavaScript/PrivateObject.h>
25 #include <CommonsJavaScript/Converter.h>
26 #include <CommonsJavaScript/JSUtils.h>
27 #include <CommonsJavaScript/Utils.h>
28 #include <CommonsJavaScript/Validator.h>
29 #include <CommonsJavaScript/ScopedJSStringRef.h>
30 #include <JSTizenException.h>
31 #include <JSTizenExceptionFactory.h>
32 #include <SecurityExceptions.h>
33 #include <FilterConverter.h>
34 #include <TimeUtilConverter.h>
35
36 #include "JSCalendarManager.h"
37 #include "CalendarConverter.h"
38 #include "JSCalendar.h"
39 #include "JSCalendarEvent.h"
40 #include "JSCalendarTask.h"
41 #include "JSCalendarItemProperties.h"
42 #include "JSCalendarEventId.h"
43 #include "plugin_config.h"
44 #include "CalendarResponseDispatcher.h"
45 #include "CalendarMultiCallback.h"
46
47 #include "CalendarAsyncCallbackManager.h"
48 #include "CalendarListenerManager.h"
49
50
51 using namespace WrtDeviceApis::Commons;
52 using namespace WrtDeviceApis::CommonsJavaScript;
53 using namespace DeviceAPI::Common;
54
55 #define TIZEN_CALENDAR_ATTRIBUTENAME "Calendar"
56
57 namespace DeviceAPI {
58 namespace Calendar {
59
60 JSClassDefinition JSCalendar::m_classInfo = {
61     0,
62     kJSClassAttributeNone,
63     TIZEN_CALENDAR_ATTRIBUTENAME,
64     NULL,
65     m_property,
66     m_function,
67     initialize,
68     finalize,
69     NULL, //HasProperty,
70     NULL, //GetProperty,
71     NULL, //SetProperty,
72     NULL, //DeleteProperty,
73     NULL, //GetPropertyNames,
74     NULL, //CallAsFunction,
75     NULL, //CallAsConstructor,
76     NULL, //HasInstance,
77     NULL //ConvertToType
78 };
79
80 JSStaticValue JSCalendar::m_property[] = {
81     { TIZEN_CALENDAR_PROPERTY_NAME, JSCalendar::getPropertyName,
82       NULL, kJSPropertyAttributeReadOnly },
83     /*{ TIZEN_CALENDAR_PROPERTY_ACCOUNT_SERVICE_ID, JSCalendar::getPropertyAccountServiceId,
84       NULL, kJSPropertyAttributeReadOnly },*/
85     { TIZEN_CALENDAR_PROPERTY_ID, JSCalendar::getPropertyId,
86       NULL, kJSPropertyAttributeReadOnly },
87     { 0, 0, 0, 0 }
88 };
89
90 JSStaticFunction JSCalendar::m_function[] = {
91     { CALENDAR_FUNCTION_API_ADD, add, kJSPropertyAttributeNone },
92     { CALENDAR_FUNCTION_API_ADD_BATCH, addBatch, kJSPropertyAttributeNone },
93     { CALENDAR_FUNCTION_API_UPDATE, update, kJSPropertyAttributeNone },
94     { CALENDAR_FUNCTION_API_UPDATE_BATCH, updateBatch, kJSPropertyAttributeNone },
95     { CALENDAR_FUNCTION_API_REMOVE, remove, kJSPropertyAttributeNone },
96     { CALENDAR_FUNCTION_API_REMOVE_BATCH, removeBatch, kJSPropertyAttributeNone },
97     { CALENDAR_FUNCTION_API_FIND, find, kJSPropertyAttributeNone },
98     { CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER, addChangeListener, kJSPropertyAttributeNone },
99     { CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER, removeChangeListener, kJSPropertyAttributeNone },
100     { CALENDAR_FUNCTION_API_GET, get, kJSPropertyAttributeNone },
101
102     { 0, 0, 0 }
103 };
104
105 JSClassRef JSCalendar::m_jsClassRef = JSClassCreate(JSCalendar::getClassInfo());
106
107 void JSCalendar::initialize(JSContextRef context, JSObjectRef object)
108 {
109     if (!JSObjectGetPrivate(object)) {
110         LogDebug("Create calendar private object.");
111         ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
112         CalendarPrivObject *priv = new CalendarPrivObject(context, calendar);
113         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
114             delete priv;
115         }
116     } else {
117         LogDebug("Private object already set.");
118     }
119 }
120
121 void JSCalendar::finalize(JSObjectRef object)
122 {
123     CalendarPrivObject *priv = static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
124     if (priv) {
125         delete priv;
126         JSObjectSetPrivate(object, NULL);
127     }
128 }
129
130 const JSClassRef JSCalendar::getClassRef()
131 {
132     if (!m_jsClassRef) {
133         m_jsClassRef = JSClassCreate(&m_classInfo);
134     }
135     return m_jsClassRef;
136 }
137
138 const JSClassDefinition* JSCalendar::getClassInfo()
139 {
140     return &m_classInfo;
141 }
142
143 JSValueRef JSCalendar::add(JSContextRef context,
144         JSObjectRef object,
145         JSObjectRef thisObject,
146         size_t argumentCount,
147         const JSValueRef arguments[],
148         JSValueRef* exception)
149 {
150     CalendarPrivObject *privateObject =
151         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
152
153     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD);
154
155     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
156
157     Try
158     {
159         if (!privateObject) {
160             ThrowMsg(ConversionException, "Object is null.");
161         }
162
163         ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
164
165         if (argumentCount<1) {
166             ThrowMsg(ConversionException, "Wrong parameter type.");
167         }
168
169         if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
170             if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef())) {
171                 ThrowMsg(ConversionException, "Wrong first parameter type.");
172             }
173         } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
174             if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
175                 ThrowMsg(ConversionException, "Wrong first parameter type.");
176             }
177         } else {
178             ThrowMsg(ConversionException, "Wrong calendar type.");
179         }
180
181         JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
182         CalendarEventPtr event = JSCalendarEvent::getPrivateObject(arg);
183         if (!event) {
184             ThrowMsg(ConversionException, "Parameter conversion failed.");
185         }
186
187         IEventAddEventPtr dplEvent(new IEventAddEvent());
188         dplEvent->setEvent(event);
189         dplEvent->setForSynchronousCall();
190         calendar->addEvent(dplEvent);
191
192         if (dplEvent->getResult()) {
193             LogDebug("Add result successful.");
194             return JSValueMakeUndefined(context);
195         } else {
196             ThrowMsg(UnknownException, "Adding failed by unknown reason.");
197         }
198     }
199     Catch(UnsupportedException)
200     {
201                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
202         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
203     }
204     Catch(InvalidArgumentException)
205     {
206                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
207         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
208     }
209     Catch(ConversionException)
210     {
211                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
212         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
213     }
214     Catch(Exception)
215     {
216                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
217         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
218     }
219 }
220
221 JSValueRef JSCalendar::addBatch(JSContextRef context,
222         JSObjectRef object,
223         JSObjectRef thisObject,
224         size_t argumentCount,
225         const JSValueRef arguments[],
226         JSValueRef* exception)
227 {
228     CalendarPrivObject *privateObject =
229         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
230
231     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD_BATCH);
232
233     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
234
235     Try
236     {
237         if (!privateObject) {
238             ThrowMsg(ConversionException, "Object is null.");
239         }
240
241         ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
242
243         JSContextRef globalContext = privateObject->getContext();
244         CalendarConverter converter(context);
245
246         if (argumentCount<1) {
247             ThrowMsg(ConversionException, "Wrong parameter type.");
248         }
249
250         CalendarEventListPtr events;
251         if (!JSIsArrayValue(context, arguments[0])) {
252             ThrowMsg(ConversionException, "Wrong first parameter type.");
253         }
254         events = converter.toVectorOfEvents(arguments[0]);
255         if (!events) {
256             ThrowMsg(ConversionException, "First parameter conversion failed.");
257         }
258
259         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
260         if (argumentCount>=2) {
261             cbm->setOnSuccess(converter.toFunctionOrNull(arguments[1]));
262         }
263         if (argumentCount>=3) {
264             cbm->setOnError(converter.toFunctionOrNull(arguments[2]));
265         }
266
267                 cbm->setObject(thisObject);
268
269         LogDebug("Proceed the event to the platform.");
270
271         IEventAddEventsPtr dplEvent(new IEventAddEvents());
272         dplEvent->setCalendarType(calendar->getType());
273         dplEvent->setEvents(events);
274         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
275         dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
276         calendar->addEvents(dplEvent);
277
278                 CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
279
280         return JSValueMakeUndefined(context);
281     }
282     Catch(UnsupportedException)
283     {
284                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
285         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
286     }
287     Catch(InvalidArgumentException)
288     {
289                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
290         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
291     }
292     Catch(ConversionException)
293     {
294                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
295         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
296     }
297     Catch(Exception)
298     {
299                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
300         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
301     }
302 }
303
304 JSValueRef JSCalendar::update(JSContextRef context,
305         JSObjectRef object,
306         JSObjectRef thisObject,
307         size_t argumentCount,
308         const JSValueRef arguments[],
309         JSValueRef* exception)
310 {
311     CalendarPrivObject *privateObject =
312         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
313
314     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_UPDATE);
315
316     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
317
318     Try
319     {
320         if (!privateObject) {
321             ThrowMsg(ConversionException, "Object is null.");
322         }
323
324         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
325
326         if (argumentCount<1) {
327             ThrowMsg(ConversionException, "Wrong parameter type.");
328         }
329
330         if (argumentCount>=1) {
331             if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef()) &&
332             !JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
333                 ThrowMsg(ConversionException, "Wrong first parameter type.");
334             }
335         } else {
336             ThrowMsg(ConversionException, "Wrong first parameter type.");
337         }
338
339         CalendarConverter converter(context);
340
341         JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
342         CalendarEventPtr item = JSCalendarEvent::getPrivateObject(arg);
343         if (!item) {
344             ThrowMsg(ConversionException, "Parameter conversion failed.");
345         }
346
347         bool updateAllInstances = true; // Set the default value.
348         if (argumentCount>=2) {
349             updateAllInstances = converter.toBool(arguments[1]);
350         }
351
352         IEventUpdateEventPtr dplEvent(new IEventUpdateEvent());
353         dplEvent->setEvent(item);
354         dplEvent->setUpdateAllInstances(updateAllInstances);
355         dplEvent->setForSynchronousCall();
356         calendar->updateEvent(dplEvent);
357
358         if (dplEvent->getResult()) {
359             return JSValueMakeUndefined(context);
360         } else {
361             ThrowMsg(UnknownException, "Updating failed by unknown reason.");
362         }
363     }
364     Catch(UnsupportedException)
365     {
366                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
367         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
368     }
369     Catch(InvalidArgumentException)
370     {
371                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
372         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
373     }
374     Catch(ConversionException)
375     {
376                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
377         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
378     }
379     Catch (NotFoundException)
380     {
381                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
382         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
383     }
384     Catch(Exception)
385     {
386                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
387         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
388     }
389 }
390
391 JSValueRef JSCalendar::updateBatch(JSContextRef context,
392         JSObjectRef object,
393         JSObjectRef thisObject,
394         size_t argumentCount,
395         const JSValueRef arguments[],
396         JSValueRef* exception)
397 {
398     CalendarPrivObject *privateObject =
399         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
400
401     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_UPDATE_BATCH);
402
403     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
404
405     Try
406     {
407         if (!privateObject) {
408             ThrowMsg(ConversionException, "Object is null.");
409         }
410
411         JSContextRef globalContext = privateObject->getContext();
412
413         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
414
415         CalendarConverter converter(context);
416
417         if (argumentCount>=1) {
418             if (!JSIsArrayValue(context, arguments[0])) {
419                 ThrowMsg(ConversionException, "Wrong first parameter type.");
420             }
421         } else {
422             ThrowMsg(ConversionException, "Wrong parameter type.");
423         }
424         CalendarEventListPtr events;
425         events = converter.toVectorOfEvents(arguments[0]);
426         if (!events) {
427             ThrowMsg(ConversionException, "Third parameter conversion failed.");
428         }
429
430         JSValueRef onSuccess = NULL;
431         if (argumentCount>=2) {
432             onSuccess = converter.toFunctionOrNull(arguments[1]);
433         }
434         JSValueRef onError = NULL;
435         if (argumentCount>=3) {
436             onError = converter.toFunctionOrNull(arguments[2]);
437         }
438         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
439
440         bool updateAllInstances = true; // Set the default value.
441         if( argumentCount>=4 ) {
442             updateAllInstances = converter.toBool(arguments[3]);
443         }
444
445                 cbm->setObject(thisObject);
446
447         LogDebug("Proceed the event to the platform.");
448
449         IEventUpdateEventsPtr dplEvent(new IEventUpdateEvents());
450         dplEvent->setEvents(events);
451         dplEvent->setUpdateAllInstances(updateAllInstances);
452         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
453         dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
454         calendar->updateEvents(dplEvent);
455
456                 CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
457
458         return JSValueMakeUndefined(context);
459     }
460     Catch(UnsupportedException)
461     {
462                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
463         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
464     }
465     Catch(InvalidArgumentException)
466     {
467                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
468         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
469     }
470     Catch(ConversionException)
471     {
472                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
473         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
474     }
475     Catch (NotFoundException)
476     {
477                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
478         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
479     }
480     Catch(Exception)
481     {
482                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
483         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
484     }
485 }
486
487 JSValueRef JSCalendar::remove(JSContextRef context,
488         JSObjectRef object,
489         JSObjectRef thisObject,
490         size_t argumentCount,
491         const JSValueRef arguments[],
492         JSValueRef* exception)
493 {
494     CalendarPrivObject *privateObject =
495         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
496
497     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE);
498
499     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
500
501     Try
502     {
503         if (!privateObject) {
504             ThrowMsg(ConversionException, "Object is null.");
505         }
506
507         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
508
509         EventIdPtr itemId;
510         CalendarConverter converter(context);
511
512         if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
513             if (argumentCount<1) {
514                 ThrowMsg(ConversionException, "Wrong parameter type.");
515             }
516
517             if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
518                 ThrowMsg(ConversionException, "Wrong parameter type.");
519             }
520             itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
521             if (!itemId) {
522                 ThrowMsg(ConversionException, "Parameter conversion failed.");
523             }
524             itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
525         } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
526             EventIdPtr result( new EventId() );
527             if (argumentCount>=1) {
528                 result->setUId(converter.toString(arguments[0]));
529             }
530             itemId = result;
531             itemId->setCalendarType(CalendarEvent::TASK_TYPE);
532         } else {
533             ThrowMsg(ConversionException, "Parameter conversion failed.");
534         }
535
536         IEventDeleteEventPtr dplEvent(new IEventDeleteEvent());
537         dplEvent->setEventId(itemId);
538         dplEvent->setForSynchronousCall();
539         calendar->deleteEvent(dplEvent);
540
541         if (dplEvent->getResult()) {
542             LogInfo("Successfully deleted.");
543             return JSValueMakeUndefined(context);
544         } else {
545             if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) {
546                 ThrowMsg(NotFoundException, "Item not found.");
547             } else {
548                 ThrowMsg(UnknownException, "Removing failed by unnkown reason.");
549             }
550         }
551     }
552     Catch(UnsupportedException)
553     {
554                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
555         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
556     }
557     Catch(InvalidArgumentException)
558     {
559                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
560         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
561     }
562     Catch(ConversionException)
563     {
564                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
565         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
566     }
567     Catch (NotFoundException)
568     {
569                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
570         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
571     }
572     Catch(Exception)
573     {
574                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
575         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
576     }
577 }
578
579 JSValueRef JSCalendar::removeBatch(JSContextRef context,
580         JSObjectRef object,
581         JSObjectRef thisObject,
582         size_t argumentCount,
583         const JSValueRef arguments[],
584         JSValueRef* exception)
585 {
586     CalendarPrivObject *privateObject =
587         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
588
589     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE_BATCH);
590
591     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
592
593     Try
594     {
595         if (!privateObject) {
596             ThrowMsg(ConversionException, "Object is null.");
597         }
598
599         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
600         JSContextRef globalContext = privateObject->getContext();
601
602         CalendarConverter converter(context);
603
604         if (argumentCount>=1) {
605             if (!JSIsArrayValue(context, arguments[0])) {
606                 ThrowMsg(ConversionException, "Wrong first parameter type.");
607             }
608         } else {
609                         ThrowMsg(ConversionException, "Wrong parameter type.");
610         }
611
612         // Pick one array element to determine its type.
613         JSObjectRef objArg = converter.toJSObjectRef(arguments[0]);
614         JSValueRef element;
615         if (JSGetArrayLength(context, objArg)>0) {
616             element = JSGetArrayElement(context, objArg, 0);
617         } else {
618             ThrowMsg(ConversionException, "Wrong first parameter type.");
619         }
620
621         EventIdListPtr itemIds;
622         if (JSValueIsObjectOfClass(context, element, JSCalendarEventId::getClassRef())) {
623             itemIds = converter.toVectorOfEventIds(arguments[0]);
624             if (!itemIds) {
625                 ThrowMsg(ConversionException, "Parameter conversion failed.");
626             }
627         } else if (JSValueIsString(context, element)) {
628             std::vector<std::string> idStrings = converter.toVectorOfStrings(arguments[0]);
629             EventIdListPtr result(new EventIdList());
630             for (unsigned int i=0; i<idStrings.size(); i++) {
631                 EventIdPtr idPtr( new EventId() );
632                 idPtr->setUId(idStrings[i]);
633                 idPtr->setCalendarType(CalendarEvent::TASK_TYPE);
634                 result->push_back(idPtr);
635             }
636             itemIds = result;
637         } else {
638             ThrowMsg(ConversionException, "Wrong parameter type.");
639         }
640
641         JSValueRef onSuccess = NULL;
642         if (argumentCount>=2) {
643             onSuccess = converter.toFunctionOrNull(arguments[1]);
644         }
645         JSValueRef onError = NULL;
646         if (argumentCount>=3) {
647             onError = converter.toFunctionOrNull(arguments[2]);
648         }
649         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
650
651                 cbm->setObject(thisObject);
652
653         LogDebug("Proceed the event to the platform.");
654
655         IEventDeleteEventsPtr dplEvent(new IEventDeleteEvents());
656         dplEvent->setEventIds(itemIds);
657         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
658         dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
659         calendar->deleteEvents(dplEvent);
660
661                 CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
662
663         return JSValueMakeUndefined(context);
664     }
665     Catch(UnsupportedException)
666     {
667                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
668         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
669     }
670     Catch(InvalidArgumentException)
671     {
672                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
673         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
674     }
675     Catch(ConversionException)
676     {
677                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
678         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
679     }
680     Catch (NotFoundException)
681     {
682                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
683         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
684     }
685     Catch(Exception)
686     {
687                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
688         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
689     }
690 }
691
692 JSValueRef JSCalendar::find(JSContextRef context,
693         JSObjectRef object,
694         JSObjectRef thisObject,
695         size_t argumentCount,
696         const JSValueRef arguments[],
697         JSValueRef* exception)
698 {
699     CalendarPrivObject *privateObject =
700         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
701
702     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_FIND);
703
704     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
705
706     Try
707     {
708         if (!privateObject) {
709             ThrowMsg(ConversionException, "Object is null.");
710         }
711
712         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
713
714         JSContextRef globalContext = privateObject->getContext();
715
716         Validator validator(context, exception);
717         CalendarConverter converter(context);
718         DeviceAPI::Tizen::FilterConverterFactory::ConverterType filterConverter = DeviceAPI::Tizen::FilterConverterFactory::getConverter(context);
719
720         if (argumentCount<1) {
721             ThrowMsg(ConversionException, "Wrong parameter type.");
722         }
723
724         JSValueRef onSuccess = NULL;
725         if (argumentCount>=1) {
726             onSuccess = converter.toFunction(arguments[0]);
727         }
728         JSValueRef onError = NULL;
729         if (argumentCount>=2) {
730             onError = converter.toFunctionOrNull(arguments[1]);
731         }
732         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
733
734                 cbm->setObject(thisObject);
735
736         LogDebug("Proceed the find event to the platform.");
737
738         IEventFindEventsPtr dplEvent(new IEventFindEvents());
739         dplEvent->setCalendarType(calendar->getType());
740         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
741         dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
742
743         if (argumentCount>=3) {
744             if (JSValueIsObject(context, arguments[2])) {
745                 dplEvent->setGenericFilter(filterConverter->toFilter(arguments[2]));
746             } else if (JSValueIsNull(context, arguments[2]) || JSValueIsUndefined(context, arguments[2])) {
747                                 LogDebug("Use default filter.");
748             } else {
749                 ThrowMsg(ConversionException, "Wrong third parameter type.");
750             }
751         }
752         if (argumentCount>=4) {
753             if (JSValueIsObject(context, arguments[3])) {
754                 // Though the sortMode is a single type, we save it in an array internally.
755                 DeviceAPI::Tizen::SortModeArrayPtr sortModes(new DeviceAPI::Tizen::SortModeArray());
756                 sortModes->push_back(filterConverter->toSortMode(arguments[3]));
757                 dplEvent->setSortModes(sortModes);
758                         } else if (JSValueIsNull(context, arguments[3]) || JSValueIsUndefined(context, arguments[3])) {
759                                 LogDebug("Use default sort mode.");
760             } else {
761                 ThrowMsg(ConversionException, "Wrong fourth parameter type.");
762             }
763         }
764
765         calendar->findEvents(dplEvent);
766
767                 CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
768
769                 return JSValueMakeUndefined(context);
770     }
771     Catch(UnsupportedException)
772     {
773                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
774         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
775     }
776     Catch(InvalidArgumentException)
777     {
778                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
779         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
780     }
781     Catch(ConversionException)
782     {
783                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
784         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
785     }
786     Catch (NotFoundException)
787     {
788                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
789         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
790     }
791     Catch(Exception)
792     {
793                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
794         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
795     }
796 }
797
798 JSValueRef JSCalendar::get(JSContextRef context,
799         JSObjectRef object,
800         JSObjectRef thisObject,
801         size_t argumentCount,
802         const JSValueRef arguments[],
803         JSValueRef* exception)
804 {
805     CalendarPrivObject *privateObject =
806         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
807
808     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_GET);
809
810     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
811
812     Try
813     {
814         if (!privateObject) {
815             ThrowMsg(ConversionException, "Object is null.");
816         }
817
818         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
819         JSContextRef globalContext = privateObject->getContext();
820
821         EventIdPtr itemId;
822         CalendarConverter converter(context);
823         if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
824             if (argumentCount<1) {
825                 ThrowMsg(ConversionException, "Wrong parameter type.");
826             }
827
828             if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
829                 itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
830                 if (!itemId) {
831                     ThrowMsg(ConversionException, "Parameter conversion failed.");
832                 }
833                 itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
834             } else {
835                 ThrowMsg(ConversionException, "Wrong parameter type.");
836             }
837         } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
838             EventIdPtr result( new EventId() );
839             itemId = result;
840             if (argumentCount>=1) {
841                 itemId->setUId(converter.toString(arguments[0]));
842             }
843             itemId->setCalendarType(CalendarEvent::TASK_TYPE);
844         } else {
845             ThrowMsg(ConversionException, "Wrong calendar type.");
846         }
847
848         IEventGetPtr dplEvent(new IEventGet());
849         dplEvent->setForSynchronousCall();
850         dplEvent->setItemId(itemId);
851         calendar->get(dplEvent);
852
853         // Process the found item.
854         if (dplEvent->getResult()) {
855                         LogDebug("Successfully got an item.");
856                         if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
857                 // Use global context for the expandRecurrence api in event.
858                     return JSCalendarEvent::createJSCalendarEvent(globalContext, dplEvent->getItem());
859                         } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
860                     return JSCalendarTask::createJSCalendarTask(context, dplEvent->getItem());
861                         } else {
862                     ThrowMsg(UnknownException, "Wrong calendar type.");
863                         }
864         } else {
865             if(ExceptionCodes::NotFoundException==dplEvent->getExceptionCode()) {
866                 ThrowMsg(NotFoundException, "Item not found.");
867             } else {
868                 ThrowMsg(UnknownException, "Getting an item failed by unknown reason.");
869             }
870         }
871     }
872     Catch(UnsupportedException)
873     {
874                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
875         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
876     }
877     Catch(InvalidArgumentException)
878     {
879                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
880         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
881     }
882     Catch(ConversionException)
883     {
884                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
885         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
886     }
887     Catch (NotFoundException)
888     {
889                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
890         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
891     }
892     Catch(Exception)
893     {
894                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
895         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
896     }
897 }
898
899 JSValueRef JSCalendar::addChangeListener(JSContextRef context,
900         JSObjectRef object,
901         JSObjectRef thisObject,
902         size_t argumentCount,
903         const JSValueRef arguments[],
904         JSValueRef* exception)
905 {
906     CalendarPrivObject *privateObject =
907         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
908
909     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER);
910
911     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
912
913     Try
914     {
915         if (!privateObject) {
916             ThrowMsg(ConversionException, "Object is null.");
917         }
918
919         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
920         JSContextRef globalContext = privateObject->getContext();
921
922         CalendarConverter converter(context);
923
924         if (argumentCount>=1) {
925             if (!JSValueIsObject(context, arguments[0])) {
926                 ThrowMsg(ConversionException, "Wrong first parameter type.");
927             }
928         } else {
929             ThrowMsg(ConversionException, "Wrong first parameter type.");
930         }
931
932         JSObjectRef objectCallbacks = converter.toJSObjectRef(arguments[0]);
933         CalendarChangeCallback result;
934         Validator validator(context);
935
936         result.onAdded = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsadded");
937         if (validator.isNullOrUndefined(result.onAdded)) {
938             result.onAdded = NULL;
939         } else if(!validator.isCallback(result.onAdded)) {
940             ThrowMsg(ConversionException, "Wrong first parameter type.");
941         }
942
943         result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsupdated");
944         if (validator.isNullOrUndefined(result.onUpdated)) {
945             result.onUpdated = NULL;
946         } else if(!validator.isCallback(result.onUpdated)) {
947             ThrowMsg(ConversionException, "Wrong first parameter type.");
948         }
949
950         result.onDeleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsremoved");
951         if (validator.isNullOrUndefined(result.onDeleted)) {
952             result.onDeleted = NULL;
953         } else if(!validator.isCallback(result.onDeleted)) {
954             ThrowMsg(ConversionException, "Wrong first parameter type.");
955         }
956
957         if (!result.onAdded && !result.onUpdated && !result.onDeleted) {
958             ThrowMsg(ConversionException, "Wrong second parameter type.");
959         }
960
961         JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(globalContext, result.onAdded, NULL);
962         JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(globalContext, result.onUpdated, NULL);
963         JSCallbackManagerPtr onDeletedCbm = JSCallbackManager::createObject(globalContext, result.onDeleted, NULL);
964
965         LogDebug("Make change emitter and process sync operation.");
966
967         CalendarChangeCallbackPrivateDataPtr privData(new CalendarChangeCallbackPrivateData(
968             onAddedCbm, onUpdatedCbm, onDeletedCbm));
969         OnEventsChangedEmitterPtr emitter(new OnEventsChangedEmitter());
970         emitter->setListener(&CalendarResponseDispatcher::getInstance());
971         emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
972
973         IEventWatchChangesPtr dplEvent(new IEventWatchChanges());
974         dplEvent->setEmitter(emitter);
975         dplEvent->setForSynchronousCall();
976         calendar->watchChanges(dplEvent);
977
978         long watchId;
979         if (dplEvent->getResult()) {
980             watchId = dplEvent->getWatchId();
981
982                         CalendarListenerCancellerPtr canceller = CalendarListenerCancellerPtr(new CalendarListenerCanceller(globalContext, thisObject, watchId));
983                         DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
984                         CalendarListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
985
986             LogDebug("Returning the watchId "<<watchId);
987             return converter.toJSValueRefLong(watchId);
988         } else {
989             ThrowMsg(UnknownException, "Adding change listener failed by unknown reason.");
990         }
991     }
992     Catch(UnsupportedException)
993     {
994                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
995         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
996     }
997     Catch(InvalidArgumentException)
998     {
999                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1000         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1001     }
1002     Catch(ConversionException)
1003     {
1004                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1005         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1006     }
1007     Catch(Exception)
1008     {
1009                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1010         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1011     }
1012 }
1013
1014 JSValueRef JSCalendar::removeChangeListener(JSContextRef context,
1015         JSObjectRef object,
1016         JSObjectRef thisObject,
1017         size_t argumentCount,
1018         const JSValueRef arguments[],
1019         JSValueRef* exception)
1020 {
1021     CalendarPrivObject *privateObject =
1022         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1023
1024     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER);
1025
1026     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1027
1028     Try
1029     {
1030         if (!privateObject) {
1031             ThrowMsg(ConversionException, "Object is null.");
1032         }
1033
1034         ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1035
1036         JSContextRef globalContext = privateObject->getContext();
1037
1038         long watchId = -1;
1039         CalendarConverter converter(context);
1040         if (argumentCount>=1) {
1041             watchId = converter.toLong(arguments[0]);
1042         } else {
1043             ThrowMsg(ConversionException, "Wrong parameter type.");
1044         }
1045
1046         LogDebug("Make sync operation with watchId: "<<watchId);
1047
1048         IEventClearWatchPtr dplEvent(new IEventClearWatch());
1049         dplEvent->setWatchId(watchId);
1050         dplEvent->setForSynchronousCall();
1051         calendar->clearWatch(dplEvent);
1052
1053                 CalendarListenerCancellerPtr canceller = CalendarListenerCancellerPtr(new CalendarListenerCanceller(globalContext, thisObject, watchId));
1054                 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1055                 CalendarListenerManagerSingleton::Instance().unregisterListener(listenerItem);
1056
1057         return JSValueMakeUndefined(context);
1058     }
1059     Catch(UnsupportedException)
1060     {
1061                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1062         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1063     }
1064     Catch(InvalidArgumentException)
1065     {
1066                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1067         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1068     }
1069     Catch(ConversionException)
1070     {
1071                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1072         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1073     }
1074     Catch (NotFoundException)
1075     {
1076                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1077         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
1078     }
1079     Catch(Exception)
1080     {
1081                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1082         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1083     }
1084 }
1085
1086 JSValueRef JSCalendar::getPropertyName(JSContextRef context,
1087         JSObjectRef object,
1088         JSStringRef propertyName,
1089         JSValueRef* exception)
1090 {
1091     Try
1092     {
1093         ICalendarPtr calendar = getCalendar(context, object, exception);
1094         Converter converter(context);
1095                 if(calendar->getIsUnified()) {
1096                         return JSValueMakeNull(context);
1097                 } else {
1098                 return converter.toJSValueRef(calendar->getName());
1099                 }
1100         }
1101     Catch(Exception)
1102     {
1103                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1104     }
1105     return JSValueMakeUndefined(context);
1106 }
1107
1108 JSValueRef JSCalendar::getPropertyAccountServiceId(JSContextRef context,
1109         JSObjectRef object,
1110         JSStringRef propertyName,
1111         JSValueRef* exception)
1112 {
1113     Try
1114     {
1115         ICalendarPtr calendar = getCalendar(context, object, exception);
1116         Converter converter(context);
1117                 if(calendar->getIsUnified()) {
1118                         return JSValueMakeNull(context);
1119                 } else {
1120                 return converter.toJSValueRefLong(calendar->getAccountId());
1121                 }
1122     }
1123     Catch(Exception)
1124     {
1125                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1126     }
1127     return JSValueMakeUndefined(context);
1128 }
1129
1130 JSValueRef JSCalendar::getPropertyId(JSContextRef context,
1131         JSObjectRef object,
1132         JSStringRef propertyName,
1133         JSValueRef* exception)
1134 {
1135     Try
1136     {
1137         ICalendarPtr calendar = getCalendar(context, object, exception);
1138         Converter converter(context);
1139                 if(calendar->getIsUnified()) {
1140                         return JSValueMakeNull(context);
1141                 } else {
1142                 return converter.toJSValueRef(calendar->getId());
1143                 }
1144     }
1145     Catch(Exception)
1146     {
1147                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1148     }
1149     return JSValueMakeUndefined(context);
1150 }
1151
1152 ICalendarPtr JSCalendar::getCalendar(JSContextRef ctx,
1153         const JSObjectRef object,
1154         JSValueRef* exception)
1155 {
1156     CalendarPrivObject *priv =
1157         static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
1158     if (priv) {
1159         return priv->getObject();
1160     }
1161     ThrowMsg(NullPointerException, "Private object is NULL.");
1162 }
1163
1164 }
1165 }