2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file JSContactAnniversary.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
21 * @brief Implementation of the JSContactAnniversary class
24 #include <dpl/shared_ptr.h>
25 #include <CommonsJavaScript/Converter.h>
26 #include <Tizen/Common/JSTizenExceptionFactory.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include "ContactConverter.h"
29 #include "JSContactAnniversary.h"
31 #define FILTER_CLASS_NAME "Anniversary"
32 #define CONTACT_ATTR_DATE "date"
33 #define CONTACT_ATTR_LABEL "label"
39 using namespace TizenApis::Commons;
40 using namespace TizenApis::Api::Contact;
42 JSClassRef JSContactAnniversary::m_classRef = NULL;
44 JSClassDefinition JSContactAnniversary::m_classInfo =
47 kJSClassAttributeNone,
57 NULL, //DeleteProperty,
58 NULL, //getPropertyNames,
62 NULL, //ConvertToType,
65 JSStaticValue JSContactAnniversary::m_property[] = {
66 { CONTACT_ATTR_DATE, getDate, setDate, kJSPropertyAttributeNone },
67 //{ CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone },
71 JSStaticFunction JSContactAnniversary::m_functions[] =
76 JSClassRef JSContactAnniversary::getClassRef() {
78 m_classRef = JSClassCreate(&m_classInfo);
83 JSValueRef JSContactAnniversary::createJSObject(JSContextRef context,
85 const std::string& label)
87 ContactAnniversaryPtr privateData = ContactAnniversaryPtr(new ContactAnniversary());
88 privateData->setDate(date);
89 //privateData->setLabel(label);
90 JSContactAnniversaryPriv *priv = new JSContactAnniversaryPriv(context, privateData);
91 JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
92 if (NULL == jsValueRef) {
93 LogError("object creation error");
94 return JSValueMakeUndefined(context);
99 bool JSContactAnniversary::isObjectOfClass(JSContextRef context, JSValueRef value)
101 return JSValueIsObjectOfClass(context, value, getClassRef());
104 ContactAnniversaryPtr JSContactAnniversary::getContactAnniversary(JSContextRef context, JSValueRef value)
106 if (!isObjectOfClass(context, value)) {
107 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
109 JSObjectRef object = JSValueToObject(context, value, NULL);
111 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
113 JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(object));
115 Throw(WrtDeviceApis::Commons::NullPointerException);
117 return priv->getObject();
120 void JSContactAnniversary::Initialize(JSContextRef context, JSObjectRef object)
122 assert(NULL != JSObjectGetPrivate(object));
125 void JSContactAnniversary::Finalize(JSObjectRef object)
127 //delete (JSObjectGetPrivate(object));
130 ContactAnniversaryPtr JSContactAnniversary::getPrivData(JSObjectRef object)
132 //LogDebug("entered");
133 JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(object));
135 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
137 ContactAnniversaryPtr result = priv->getObject();
139 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
144 JSValueRef JSContactAnniversary::getDate(JSContextRef context,
146 JSStringRef propertyName,
147 JSValueRef* exception)
149 //LogDebug("entered");
152 ContactConverterFactory::ConverterType converter =
153 ContactConverterFactory::getConverter(context);
154 ContactAnniversaryPtr anniversary = getPrivData(object);
155 return converter->toJSValueRef(anniversary->getDate());
157 Catch(WrtDeviceApis::Commons::Exception)
159 LogWarning("trying to get incorrect value");
161 return JSValueMakeUndefined(context);
164 bool JSContactAnniversary::setDate(JSContextRef context,
166 JSStringRef propertyName,
168 JSValueRef* exception)
172 ContactAnniversaryPtr anniversary = getPrivData(object);
173 ContactConverterFactory::ConverterType converter =
174 ContactConverterFactory::getConverter(context);
175 anniversary->setDate(converter->toDateTm(value));
178 Catch(WrtDeviceApis::Commons::Exception)
180 LogWarning("trying to set incorrect value");
182 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
186 JSValueRef JSContactAnniversary::getLabel(JSContextRef context,
188 JSStringRef propertyName,
189 JSValueRef* exception)
191 //LogDebug("entered");
194 ContactConverterFactory::ConverterType converter =
195 ContactConverterFactory::getConverter(context);
196 ContactAnniversaryPtr anniversary = getPrivData(object);
197 return converter->toJSValueRef(anniversary->getLabel());
199 Catch(WrtDeviceApis::Commons::Exception)
201 LogWarning("trying to get incorrect value");
203 return JSValueMakeUndefined(context);
206 bool JSContactAnniversary::setLabel(JSContextRef context,
208 JSStringRef propertyName,
210 JSValueRef* exception)
214 ContactAnniversaryPtr anniversary = getPrivData(object);
215 ContactConverterFactory::ConverterType converter =
216 ContactConverterFactory::getConverter(context);
217 anniversary->setLabel(converter->toString(value));
220 Catch(WrtDeviceApis::Commons::Exception)
222 LogWarning("trying to set incorrect value");
224 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");