wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Calendar / JSCalendarItemProperties.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 #include <ctime>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <JSTizenException.h>
23 #include <JSTizenExceptionFactory.h>
24 #include <SecurityExceptions.h>
25 #include <TimeUtilConverter.h>
26 #include <JSTZDate.h>
27 #include <JSSimpleCoordinates.h>
28 #include "EventAlarm.h"
29 #include "EventId.h"
30 #include "ICalendar.h"
31 #include "CalendarFactory.h"
32 #include <DurationProperties.h>
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarAttendee.h"
38 #include "JSCalendarEvent.h"
39 #include "JSCalendarTask.h"
40 #include "plugin_config.h"
41 #include <GlobalContextManager.h>
42 #include <TimeTracer.h>
43 #include <Logger.h>
44
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace DeviceAPI::Common;
48 using namespace DeviceAPI::Time;
49
50 namespace DeviceAPI {
51 namespace Calendar {
52
53 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
54
55 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
56     0,
57     kJSClassAttributeNone,
58     TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
59     0,
60     m_property,
61     m_function,
62     initialize,
63     finalize,
64     NULL, //hasProperty,
65     NULL, //getProperty,
66     NULL, //setProperty,
67     NULL, //DeleteProperty,
68     NULL, //GetPropertyNames,
69     NULL, //CallAsFunction,
70     NULL, //CallAsConstructor,
71     NULL, //HasInstance,
72     NULL  //ConvertToType
73 };
74
75 JSStaticValue JSCalendarItemProperties::m_property[] = {
76     // Item Properties
77     { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
78     { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
79     { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
80     { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
81     { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
82     { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
83     { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
84     { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
85     { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
86     { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
87     { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
88     { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
89     { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
90     { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
91     { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
92     { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
93     { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
94     { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
95     { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
96     { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97         { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
98
99     { 0, 0, 0, 0 }
100 };
101
102 JSStaticFunction JSCalendarItemProperties::m_function[] = {
103     { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
104     { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
105
106     { 0, 0, 0 }
107 };
108
109 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
110
111 void JSCalendarItemProperties::initialize(JSContextRef context,
112         JSObjectRef object)
113 {
114     if (!JSObjectGetPrivate(object)) {
115         LoggerD("Create calendar item private object.");
116         CalendarEventPtr item( new CalendarEvent() );
117         CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
118         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
119             delete priv;
120         }
121     } else {
122         LoggerD("Private object already set.");
123     }
124 }
125
126 void JSCalendarItemProperties::finalize(JSObjectRef object)
127 {
128     CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
129     if (priv) {
130         delete priv;
131         JSObjectSetPrivate(object, NULL);
132     }
133 }
134
135 const JSClassRef JSCalendarItemProperties::getClassRef()
136 {
137     if (!m_jsClassRef) {
138         m_jsClassRef = JSClassCreate(&m_classInfo);
139     }
140     return m_jsClassRef;
141 }
142
143 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
144 {
145     return &m_classInfo;
146 }
147
148 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
149 {
150     CalendarItemPropertiesPrivObject *priv =
151         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
152     if (!priv) {
153         ThrowMsg(NullPointerException, "Private object is null");
154     }
155     CalendarEventPtr result = priv->getObject();
156     if (!result) {
157         ThrowMsg(NullPointerException, "Private object is null");
158     }
159     return result;
160 }
161
162 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
163         JSContextRef ctx,
164         const JSObjectRef object)
165 {
166     Try
167     {
168         CalendarItemPropertiesPrivObject *priv =
169             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
170         delete priv;
171         priv = new CalendarItemPropertiesPrivObject(ctx, event);
172         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
173             delete priv;
174         }
175     }
176     Catch(Exception)
177     {
178         LoggerE("Error during replacing event object");
179     }
180 }
181
182 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
183 {
184     CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
185     return JSObjectMake(context, getClassRef(), priv);
186 }
187
188 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
189         JSObjectRef object,
190         JSObjectRef thisObject,
191         size_t argumentCount,
192         const JSValueRef arguments[],
193         JSValueRef* exception)
194 {
195         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
196     CalendarItemPropertiesPrivObject *privateObject =
197         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
198
199     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
200
201     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
202
203     Try
204     {
205         if (!privateObject) {
206             ThrowMsg(ConversionException, "Object is null.");
207         }
208
209         CalendarEventPtr item = privateObject->getObject();
210         if (!item) {
211             ThrowMsg(ConversionException, "Parameter conversion failed.");
212         }
213
214         CalendarConverter converter(context);
215
216         CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
217         if (argumentCount>=1) {
218             format = converter.toVObjectFormat(converter.toString(arguments[0]));
219         } else {
220             ThrowMsg(ConversionException, "Wrong parameter type.");
221         }
222
223         ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
224         calendar->setType(item->getCalendarType());
225
226         IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
227         dplEvent->setEvent(item);
228         dplEvent->setFormat(format);
229         dplEvent->setForSynchronousCall();
230         calendar->exportEventToString(dplEvent);
231
232         if (dplEvent->getResult()) {
233                         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
234             return converter.toJSValueRef(dplEvent->getEventString());
235         } else {
236             ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
237         }
238     }
239     Catch(UnsupportedException)
240     {
241                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
242         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
243     }
244     Catch(InvalidArgumentException)
245     {
246                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
247         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
248     }
249     Catch(ConversionException)
250     {
251                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
252         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
253     }
254     Catch (NotFoundException)
255     {
256                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
257         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
258     }
259     Catch(Exception)
260     {
261                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
262         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
263     }
264 }
265
266 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
267         JSObjectRef object,
268         JSObjectRef thisObject,
269         size_t argumentCount,
270         const JSValueRef arguments[],
271         JSValueRef* exception)
272 {
273         TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
274         TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
275     CalendarItemPropertiesPrivObject *privateObject =
276         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
277
278     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
279
280     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
281
282     Try
283     {
284         if (!privateObject) {
285             ThrowMsg(ConversionException, "Object is null.");
286         }
287
288         CalendarEventPtr item = privateObject->getObject(); // item to copy
289         if (!item) {
290             ThrowMsg(ConversionException, "Parameter conversion failed.");
291         }
292         JSContextRef globalContext = privateObject->getContext();
293
294         // Call the copy constructor.
295         CalendarEventPtr clonedItem( new CalendarEvent(*item));
296
297         // Reset the id.
298         clonedItem->resetId();
299         clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
300
301                 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
302                         TIME_TRACER_ITEM_END("clone(TASK)", 0);
303                 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
304                 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
305                         TIME_TRACER_ITEM_END("clone(EVENT)", 0);
306             // Use global context for potential async api invocation.
307             return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
308                 } else {
309                         ThrowMsg(ConversionException, "Wrong object type.");
310                 }
311     }
312     Catch(UnsupportedException)
313     {
314                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
315         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
316     }
317     Catch(InvalidArgumentException)
318     {
319                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
320         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
321     }
322     Catch(ConversionException)
323     {
324                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
325         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
326     }
327     Catch (NotFoundException)
328     {
329                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
330         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
331     }
332     Catch(Exception)
333     {
334                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
335         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
336     }
337 }
338
339 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
340         JSObjectRef object,
341         JSStringRef propertyName,
342         JSValueRef* exception)
343 {
344     Try
345     {
346         Converter converter(context);
347         CalendarEventPtr event = getPrivateObject(object);
348         return converter.toJSValueRef(event->getDescription());
349     }
350     Catch(Exception)
351     {
352                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
353     }
354     return JSValueMakeUndefined(context);
355 }
356
357 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
358         JSObjectRef object,
359         JSStringRef propertyName,
360         JSValueRef value,
361         JSValueRef* exception)
362 {
363     Try
364     {
365         Converter converter(context);
366         CalendarEventPtr event = getPrivateObject(object);
367         std::string description = converter.toString(value);
368         event->setDescription(description);
369         return true;
370     }
371     Catch(Exception)
372     {
373                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
374     }
375
376     return true;
377 }
378
379 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
380         JSObjectRef object,
381         JSStringRef propertyName,
382         JSValueRef* exception)
383 {
384     Try
385     {
386         Converter converter(context);
387         CalendarEventPtr event = getPrivateObject(object);
388         return converter.toJSValueRef(event->getSubject());
389     }
390     Catch(Exception)
391     {
392                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
393     }
394     return JSValueMakeUndefined(context);
395 }
396
397 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
398         JSObjectRef object,
399         JSStringRef propertyName,
400         JSValueRef value,
401         JSValueRef* exception)
402 {
403     Try
404     {
405         Converter converter(context);
406         CalendarEventPtr event = getPrivateObject(object);
407         std::string subject = converter.toString(value);
408         event->setSubject(subject);
409         return true;
410     }
411     Catch(Exception)
412     {
413                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
414     }
415
416     return true;
417 }
418
419 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
420         JSObjectRef object,
421         JSStringRef propertyName,
422         JSValueRef* exception)
423 {
424     Try
425     {
426         CalendarItemPropertiesPrivObject *privateObject =
427             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
428         TimeUtilConverter timeConverter(context);
429         CalendarEventPtr event = privateObject->getObject();
430
431         LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
432         if (UNDEFINED_TIME==event->getStartTime()) {
433             return JSValueMakeUndefined(context);
434         } else {
435             return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
436         }
437     }
438     Catch(Exception)
439     {
440                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
441     }
442     return JSValueMakeUndefined(context);
443 }
444
445 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
446         JSObjectRef object,
447         JSStringRef propertyName,
448         JSValueRef value,
449         JSValueRef* exception)
450 {
451     Try
452     {
453         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
454             ThrowMsg(ConversionException, "Wrong parameter type.");
455         }
456
457         CalendarEventPtr event = getPrivateObject(object);
458         TimeUtilConverter converter(context);
459         std::time_t duration = event->getEndTime() - event->getStartTime();
460         if (duration<0) {
461             duration = 0;
462         }
463
464         long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
465         event->setStartTime(startTime);
466         event->setEndTime(startTime + duration);
467
468         std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
469         event->setTimeZone(timeZone);
470         return true;
471     }
472     Catch(Exception)
473     {
474                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
475     }
476
477     return true;
478 }
479
480 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
481         JSObjectRef object,
482         JSStringRef propertyName,
483         JSValueRef* exception)
484 {
485     Try
486     {
487         Converter converter(context);
488         CalendarEventPtr event = getPrivateObject(object);
489         return converter.toJSValueRef(event->getLocation());
490     }
491     Catch(Exception)
492     {
493                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
494     }
495     return JSValueMakeUndefined(context);
496 }
497
498 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
499         JSObjectRef object,
500         JSStringRef propertyName,
501         JSValueRef value,
502         JSValueRef* exception)
503 {
504     Try
505     {
506         Converter converter(context);
507         CalendarEventPtr event = getPrivateObject(object);
508         std::string location = converter.toString(value);
509         event->setLocation(location);
510         return true;
511     }
512     Catch(Exception)
513     {
514                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
515     }
516
517     return true;
518 }
519
520 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
521         JSObjectRef object,
522         JSStringRef propertyName,
523         JSValueRef* exception)
524 {
525     Try
526     {
527             CalendarEventPtr item = getPrivateObject(object);
528                 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
529
530         CalendarConverter converter(globalContext);
531
532                 if(item->getCategoriesJSRef()) {
533                         return item->getCategoriesJSRef();
534                 } else {
535                         LoggerD("Create a JS object for categories.");
536                 StringArrayPtr categories = item->getCategories();
537                         JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
538                         item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
539
540                         JSValueProtect(globalContext, jsCategories);
541                         item->setContext(globalContext);
542             return jsCategories;
543                 }
544     }
545     Catch(Exception)
546     {
547                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
548     }
549     return JSValueMakeUndefined(context);
550 }
551
552 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
553         JSObjectRef object,
554         JSStringRef propertyName,
555         JSValueRef value,
556         JSValueRef* exception)
557 {
558     Try
559     {
560         CalendarEventPtr event = getPrivateObject(object);
561         CalendarConverter converter(context);
562                 event->setCategories(converter.toStringArray(value));
563         return true;
564     }
565     Catch(Exception)
566     {
567                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
568     }
569
570     return true;
571 }
572
573 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
574         JSObjectRef object,
575         JSStringRef propertyName,
576         JSValueRef* exception)
577 {
578     Try
579     {
580         CalendarConverter converter(context);
581         CalendarEventPtr event = getPrivateObject(object);
582         std::string status = converter.toTizenValue(event->getStatus());
583         return converter.toJSValueRef(status);
584     }
585     Catch(Exception)
586     {
587                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
588     }
589     return JSValueMakeUndefined(context);
590 }
591
592 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
593         JSObjectRef object,
594         JSStringRef propertyName,
595         JSValueRef value,
596         JSValueRef* exception)
597 {
598     CalendarEventPtr event(NULL);
599     Try
600     {
601         event = getPrivateObject(object);
602         CalendarConverter converter(context);
603         CalendarEvent::EventStatus status =
604             converter.toEventStatus(converter.toString(value));
605         event->setStatus(status);
606         return true;
607     }
608     Catch(Exception)
609     {
610                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
611     }
612
613     return true;
614 }
615
616 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
617         JSObjectRef object,
618         JSStringRef propertyName,
619         JSValueRef* exception)
620 {
621     Try
622     {
623         CalendarEventPtr event = getPrivateObject(object);
624
625         JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
626         if (NULL == jsResult) {
627             ThrowMsg(NullPointerException, "Can not create array object.");
628         }
629         for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
630             if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
631                ThrowMsg(UnknownException, "Can not insert value into array.");
632             }
633         }
634         return jsResult;
635     }
636     Catch(Exception)
637     {
638                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
639     }
640     return JSValueMakeUndefined(context);
641 }
642
643 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
644         JSObjectRef object,
645         JSStringRef propertyName,
646         JSValueRef value,
647         JSValueRef* exception)
648 {
649     CalendarEventPtr event(NULL);
650     Try
651     {
652         event = getPrivateObject(object);
653         CalendarConverter converter(context);
654
655         EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
656
657         event->setAlarms(alarms);
658         return true;
659     }
660     Catch(Exception)
661     {
662                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
663     }
664
665     return true;
666 }
667
668 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
669         JSObjectRef object,
670         JSStringRef propertyName,
671         JSValueRef* exception)
672 {
673     Try
674     {
675         Converter converter(context);
676         CalendarEventPtr event = getPrivateObject(object);
677         return converter.toJSValueRef(event->getOrganizer());
678     }
679     Catch(Exception)
680     {
681                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
682     }
683     return JSValueMakeUndefined(context);
684 }
685
686 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
687         JSObjectRef object,
688         JSStringRef propertyName,
689         JSValueRef value,
690         JSValueRef* exception)
691 {
692     Try
693     {
694         Converter converter(context);
695         CalendarEventPtr event = getPrivateObject(object);
696         std::string organizer = converter.toString(value);
697         event->setOrganizer(organizer);
698         return true;
699     }
700     Catch(Exception)
701     {
702                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
703     }
704
705     return true;
706 }
707
708 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
709         JSObjectRef object,
710         JSStringRef propertyName,
711         JSValueRef* exception)
712 {
713     Try
714     {
715         CalendarConverter converter(context);
716         CalendarEventPtr event = getPrivateObject(object);
717         std::string visibility = converter.toTizenValue(event->getVisibility());
718         return converter.toJSValueRef(visibility);
719     }
720     Catch(Exception)
721     {
722                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
723     }
724     return JSValueMakeUndefined(context);
725 }
726
727 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
728         JSObjectRef object,
729         JSStringRef propertyName,
730         JSValueRef value,
731         JSValueRef* exception)
732 {
733     CalendarEventPtr event(NULL);
734     Try
735     {
736         event = getPrivateObject(object);
737         CalendarConverter converter(context);
738         CalendarEvent::EventVisibility visibility =
739             converter.toEventVisibility(converter.toString(value));
740         event->setVisibility(visibility);
741         return true;
742     }
743     Catch(Exception)
744     {
745                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
746     }
747
748     return true;
749 }
750
751 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
752         JSObjectRef object,
753         JSStringRef propertyName,
754         JSValueRef* exception)
755 {
756     Try
757     {
758         CalendarEventPtr item = getPrivateObject(object);
759         if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
760                         return JSValueMakeUndefined(context);
761                 } else {
762                         return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
763                 }
764     }
765     Catch(Exception)
766     {
767                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
768     }
769
770     return JSValueMakeUndefined(context);
771 }
772
773 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
774         JSObjectRef object,
775         JSStringRef propertyName,
776         JSValueRef value,
777         JSValueRef* exception)
778 {
779     Try
780     {
781         CalendarEventPtr item = getPrivateObject(object);
782
783                 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
784                 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
785                 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
786                 } else {
787                 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
788
789                 item->setGeolocation(geoLocation);
790                 }
791         return true;
792     }
793     Catch(Exception)
794     {
795                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
796     }
797
798     return true;
799 }
800
801 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
802         JSObjectRef object,
803         JSStringRef propertyName,
804         JSValueRef* exception)
805 {
806     Try
807     {
808         CalendarEventPtr item = getPrivateObject(object);
809
810                 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
811                         LoggerD("Start or end time is not defined.");
812                     return JSValueMakeUndefined(context);
813                 }
814
815         TimeUtilConverter converter(context);
816         long long length = item->getEndTime() - item->getStartTime(); // in seconds only
817         LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
818         return converter.makeMillisecondDurationObject( length*1000 );
819     }
820     Catch(Exception)
821     {
822                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
823     }
824     return JSValueMakeUndefined(context);
825 }
826
827 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
828         JSObjectRef object,
829         JSStringRef propertyName,
830         JSValueRef value,
831         JSValueRef* exception)
832 {
833     Try
834     {
835         CalendarEventPtr event = getPrivateObject(object);
836         TimeUtilConverter converter(context);
837         long length = converter.getDurationLength(value);
838         int unit = converter.getDurationUnit(value);
839         if (length < 0) {
840             DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
841             return false;
842         }
843         if( SECONDS_UNIT==unit ) {
844             event->setEndTime(event->getStartTime() + length);
845         } else if ( MINUTES_UNIT==unit ) {
846             event->setEndTime(event->getStartTime() + length*60);
847         } else if ( HOURS_UNIT==unit ) {
848             event->setEndTime(event->getStartTime() + length*60*60);
849         } else if ( DAYS_UNIT==unit ) {
850             event->setEndTime(event->getStartTime() + length*24*60*60);
851         } else if ( MSECS_UNIT==unit ) {
852             event->setEndTime(event->getStartTime() + length/1000);
853         } else {
854             DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
855             return false;
856         }
857
858         return true;
859     }
860     Catch(Exception)
861     {
862                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
863     }
864
865     return true;
866 }
867
868 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
869         JSObjectRef object,
870         JSStringRef propertyName,
871         JSValueRef* exception)
872 {
873     Try
874     {
875         CalendarConverter converter(context);
876         CalendarEventPtr event = getPrivateObject(object);
877         return converter.toJSValueRef(event->getIsAllDay());
878     }
879     Catch(Exception)
880     {
881                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
882     }
883     return JSValueMakeUndefined(context);
884 }
885
886 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
887         JSObjectRef object,
888         JSStringRef propertyName,
889         JSValueRef value,
890         JSValueRef* exception)
891 {
892     Try
893     {
894         CalendarEventPtr event = getPrivateObject(object);
895         Converter converter(context);
896         event->setIsAllDay(converter.toBool(value));
897         return true;
898     }
899     Catch(Exception)
900     {
901                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
902     }
903
904     return true;
905 }
906
907 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
908         JSObjectRef object,
909         JSStringRef propertyName,
910         JSValueRef* exception)
911 {
912     Try
913     {
914         CalendarConverter converter(context);
915         CalendarEventPtr event = getPrivateObject(object);
916         std::string availability = converter.toTizenValue(event->getAvailability());
917         return converter.toJSValueRef(availability);
918     }
919     Catch(Exception)
920     {
921                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
922     }
923     return JSValueMakeUndefined(context);
924 }
925
926 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
927         JSObjectRef object,
928         JSStringRef propertyName,
929         JSValueRef value,
930         JSValueRef* exception)
931 {
932     CalendarEventPtr event(NULL);
933     Try
934     {
935         event = getPrivateObject(object);
936         CalendarConverter converter(context);
937         CalendarEvent::EventAvailability availability =
938             converter.toEventAvailability(converter.toString(value));
939         event->setAvailability(availability);
940         return true;
941     }
942     Catch(Exception)
943     {
944                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
945     }
946
947     return true;
948 }
949
950 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
951         JSObjectRef object,
952         JSStringRef propertyName,
953         JSValueRef* exception)
954 {
955     Try
956     {
957         CalendarEventPtr event = getPrivateObject(object);
958         EventAttendeeListPtr attendees = event->getAttendees();
959         if (attendees) {
960             JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
961             if (NULL == jsResult) {
962                 ThrowMsg(NullPointerException, "Can not create array object.");
963             }
964             for(unsigned int i=0; i<attendees->size(); i++) {
965                 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
966                    ThrowMsg(UnknownException, "Can not insert value into array.");
967                 }
968             }
969             return jsResult;
970         }
971     }
972     Catch(Exception)
973     {
974                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
975     }
976     return JSValueMakeUndefined(context);
977 }
978
979 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
980         JSObjectRef object,
981         JSStringRef propertyName,
982         JSValueRef value,
983         JSValueRef* exception)
984 {
985     Try
986     {
987         CalendarEventPtr event = getPrivateObject(object);
988         CalendarConverter converter(context);
989         event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
990         return true;
991     }
992     Catch(Exception)
993     {
994                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
995     }
996
997     return true;
998 }
999
1000 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1001         JSObjectRef object,
1002         JSStringRef propertyName,
1003         JSValueRef* exception)
1004 {
1005     Try
1006         {
1007         CalendarItemPropertiesPrivObject *privateObject =
1008             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1009         CalendarEventPtr task = privateObject->getObject();
1010         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1011             return JSValueMakeUndefined(context);
1012         }
1013         if (!task) {
1014             ThrowMsg(NullPointerException, "Task object is NULL.");
1015         }
1016
1017         if (UNDEFINED_TIME==task->getEndTime()) {
1018             return JSValueMakeUndefined(context);
1019         } else {
1020             TimeUtilConverter timeConverter(context);
1021             return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1022         }
1023     }
1024     Catch(Exception)
1025     {
1026                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1027     }
1028     return JSValueMakeUndefined(context);
1029 }
1030
1031 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1032         JSObjectRef object,
1033         JSStringRef propertyName,
1034         JSValueRef value,
1035         JSValueRef* exception)
1036 {
1037     Try
1038     {
1039         CalendarEventPtr task = getPrivateObject(object);
1040         if (!task) {
1041             ThrowMsg(NullPointerException, "Task object is NULL.");
1042         }
1043         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1044             ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1045         }
1046         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1047             ThrowMsg(ConversionException, "Wrong parameter type.");
1048         }
1049
1050         TimeUtilConverter converter(context);
1051         long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1052
1053         task->setEndTime(dueDate);
1054
1055         if( task->getTimeZone().empty() ) {
1056             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1057             task->setTimeZone(timeZone);
1058         }
1059         return true;
1060     }
1061     Catch(Exception)
1062     {
1063                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1064     }
1065
1066     return true;
1067 }
1068
1069 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1070         JSObjectRef object,
1071         JSStringRef propertyName,
1072         JSValueRef* exception)
1073 {
1074     Try
1075     {
1076         CalendarItemPropertiesPrivObject *privateObject =
1077             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1078         CalendarEventPtr task = privateObject->getObject();
1079         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1080             return JSValueMakeUndefined(context);
1081         }
1082         if (!task) {
1083             ThrowMsg(NullPointerException, "Task object is NULL.");
1084         }
1085
1086         if (UNDEFINED_TIME==task->getCompletedDate()) {
1087             return JSValueMakeUndefined(context);
1088         } else {
1089             TimeUtilConverter timeConverter(context);
1090             return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1091         }
1092     }
1093     Catch(Exception)
1094     {
1095                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1096     }
1097     return JSValueMakeUndefined(context);
1098 }
1099
1100 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1101         JSObjectRef object,
1102         JSStringRef propertyName,
1103         JSValueRef value,
1104         JSValueRef* exception)
1105 {
1106     Try
1107     {
1108         CalendarEventPtr task = getPrivateObject(object);
1109         if (!task) {
1110             ThrowMsg(NullPointerException, "Task object is NULL.");
1111         }
1112         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1113             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1114         }
1115         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1116             ThrowMsg(ConversionException, "Wrong parameter type.");
1117         }
1118
1119         TimeUtilConverter converter(context);
1120         long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1121
1122         task->setCompletedDate(completedDate);
1123
1124         if( task->getTimeZone().empty() ) {
1125             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1126             task->setTimeZone(timeZone);
1127         }
1128         return true;
1129     }
1130     Catch(Exception)
1131     {
1132                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1133     }
1134
1135     return true;
1136 }
1137
1138 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1139         JSObjectRef object,
1140         JSStringRef propertyName,
1141         JSValueRef* exception)
1142 {
1143     Try
1144     {
1145         CalendarEventPtr task = getPrivateObject(object);
1146         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1147             return JSValueMakeUndefined(context);
1148         }
1149
1150         Converter converter(context);
1151         return converter.toJSValueRef(task->getProgress());
1152     }
1153     Catch(Exception)
1154     {
1155                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1156     }
1157     return JSValueMakeUndefined(context);
1158 }
1159
1160 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1161         JSObjectRef object,
1162         JSStringRef propertyName,
1163         JSValueRef value,
1164         JSValueRef* exception)
1165 {
1166     Try
1167     {
1168         CalendarEventPtr task = getPrivateObject(object);
1169         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1170             return JSValueMakeUndefined(context);
1171         }
1172
1173         Converter converter(context);
1174         int progress = converter.toInt(value);
1175         task->setProgress(progress);
1176         return true;
1177     }
1178     Catch(Exception)
1179     {
1180                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1181     }
1182
1183     return true;
1184 }
1185
1186 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1187         JSObjectRef object,
1188         JSStringRef propertyName,
1189         JSValueRef* exception)
1190 {
1191     Try
1192     {
1193         CalendarConverter converter(context);
1194         CalendarEventPtr item = getPrivateObject(object);
1195         if (!item) {
1196             ThrowMsg(NullPointerException, "Item object is NULL.");
1197         }
1198
1199         std::string priority = converter.toTizenValue(item->getPriority());
1200         return converter.toJSValueRef(priority);
1201     }
1202     Catch(Exception)
1203     {
1204                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1205     }
1206     return JSValueMakeUndefined(context);
1207 }
1208
1209 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1210         JSObjectRef object,
1211         JSStringRef propertyName,
1212         JSValueRef value,
1213         JSValueRef* exception)
1214 {
1215     CalendarEventPtr item = getPrivateObject(object);
1216     Try
1217     {
1218         CalendarConverter converter(context);
1219         CalendarEvent::TaskPriority priority =
1220             converter.toTaskPriority(converter.toString(value));
1221         item->setPriority(priority);
1222         return true;
1223     }
1224     Catch(Exception)
1225     {
1226                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1227     }
1228
1229     return true;
1230 }
1231
1232 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1233         JSObjectRef object,
1234         JSStringRef propertyName,
1235         JSValueRef* exception)
1236 {
1237     Try
1238     {
1239         CalendarItemPropertiesPrivObject *privateObject =
1240             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1241         CalendarEventPtr event = privateObject->getObject();
1242         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1243             return JSValueMakeUndefined(context);
1244         }
1245         if (!event) {
1246             ThrowMsg(NullPointerException, "Event object is NULL.");
1247         }
1248
1249         if (UNDEFINED_TIME==event->getEndTime()) {
1250             return JSValueMakeUndefined(context);
1251         } else {
1252             TimeUtilConverter timeConverter(context);
1253             return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1254         }
1255     }
1256     Catch(Exception)
1257     {
1258                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1259     }
1260     return JSValueMakeUndefined(context);
1261 }
1262
1263 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1264         JSObjectRef object,
1265         JSStringRef propertyName,
1266         JSValueRef value,
1267         JSValueRef* exception)
1268 {
1269     Try
1270     {
1271         CalendarEventPtr event = getPrivateObject(object);
1272         if (!event) {
1273             ThrowMsg(NullPointerException, "Event object is NULL.");
1274         }
1275         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1276             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1277         }
1278         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1279             ThrowMsg(ConversionException, "Wrong parameter type.");
1280         }
1281
1282         TimeUtilConverter converter(context);
1283         long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1284
1285         event->setEndTime(endDate);
1286
1287         if( event->getTimeZone().empty() ) {
1288             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1289             event->setTimeZone(timeZone);
1290         }
1291         return true;
1292     }
1293     Catch(Exception)
1294     {
1295                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1296     }
1297
1298     return true;
1299 }
1300
1301 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1302         JSObjectRef object,
1303         JSStringRef propertyName,
1304         JSValueRef* exception)
1305 {
1306     Try
1307     {
1308         CalendarEventPtr item = getPrivateObject(object);
1309         if (!item) {
1310             ThrowMsg(NullPointerException, "Item object is NULL.");
1311         }
1312
1313         if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1314             return JSValueMakeNull(context);
1315         } else {
1316             TimeUtilConverter timeConverter(context);
1317             return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1318         }
1319     }
1320     Catch(Exception)
1321     {
1322                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1323     }
1324     return JSValueMakeUndefined(context);
1325 }
1326
1327 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1328         JSObjectRef object,
1329         JSStringRef propertyName,
1330         JSValueRef* exception)
1331 {
1332     Try
1333     {
1334         CalendarEventPtr item = getPrivateObject(object);
1335
1336             if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1337             return JSValueMakeNull(context);
1338             } else {
1339                 CalendarConverter converter(context);
1340                         std::stringstream ss;
1341                         ss<<item->getCalendarId();
1342                         return converter.toJSValueRef(ss.str());
1343             }
1344
1345     }
1346     Catch(Exception)
1347     {
1348                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1349     }
1350     return JSValueMakeUndefined(context);
1351 }
1352
1353 }
1354 }