Merge "Fixed exception handling codes" into tizen_2.1
[framework/osp/social.git] / src / FSclAddress.cpp
1 //
2 // Open Service Platform
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  * @file                FSclAddress.cpp
19  * @brief               This is the implementation for Address class.
20  *
21  * This file contains definitions of @e Address class.
22  */
23
24 #include <FBaseString.h>
25 #include <FSclAddress.h>
26 #include <FApp_AppInfo.h>
27 #include <FBaseSysLog.h>
28 #include "FScl_AddressImpl.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Social
34 {
35
36 static const int _MAX_ADDR_COUNTRY_LENGTH_2_0 = 100;
37
38 Address::Address(void)
39 {
40         __pAddressImpl = new (std::nothrow) _AddressImpl();
41         SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
42 }
43
44 Address::Address(const Address& rhs)
45 {
46         __pAddressImpl = new (std::nothrow) _AddressImpl(*rhs.__pAddressImpl);
47         SysTryReturnVoidResult(NID_SCL, __pAddressImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
48
49 }
50
51 Address::~Address(void)
52 {
53         delete __pAddressImpl;
54 }
55
56 Address&
57 Address::operator =(const Address& rhs)
58 {
59         if (this == &rhs)
60         {
61                 return *this;
62         }
63
64         *__pAddressImpl = *rhs.__pAddressImpl;
65
66         return *this;
67 }
68
69 bool
70 Address::operator ==(const Address& rhs) const
71 {
72         return *__pAddressImpl == *rhs.__pAddressImpl;
73 }
74
75 bool
76 Address::operator !=(const Address& rhs) const
77 {
78         return !(*this == rhs);
79 }
80
81 bool
82 Address::Equals(const Object& rhs) const
83 {
84         const Address* pAddress = dynamic_cast<const Address*>(&rhs);
85
86         if (pAddress == null)
87         {
88                 return false;
89         }
90
91         return __pAddressImpl->Equals(*pAddress->__pAddressImpl);
92 }
93
94 int
95 Address::GetHashCode(void) const
96 {
97         return __pAddressImpl->GetHashCode();
98 }
99
100 AddressType
101 Address::GetType(void) const
102 {
103         AddressType type =  __pAddressImpl->GetType();
104
105         if (type == ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
106         {
107                 type =  ADDRESS_TYPE_OTHER;
108         }
109
110         return type;
111 }
112
113 String
114 Address::GetExtended(void) const
115 {
116         String extended =  __pAddressImpl->GetExtended();
117
118         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
119         {
120                 if (extended.GetLength() > MAX_ADDR_EXTENDED_LENGTH)
121                 {
122                         extended.SetLength(MAX_ADDR_EXTENDED_LENGTH);
123                 }
124         }
125
126         return extended;
127 }
128
129 String
130 Address::GetStreet(void) const
131 {
132         String street =  __pAddressImpl->GetStreet();
133
134         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
135         {
136                 if (street.GetLength() > MAX_ADDR_STREET_LENGTH)
137                 {
138                         street.SetLength(MAX_ADDR_STREET_LENGTH);
139                 }
140         }
141
142         return street;
143 }
144
145 String
146 Address::GetCity(void) const
147 {
148         String city =  __pAddressImpl->GetCity();
149
150         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
151         {
152                 if (city.GetLength() > MAX_ADDR_CITY_LENGTH)
153                 {
154                         city.SetLength(MAX_ADDR_CITY_LENGTH);
155                 }
156         }
157
158         return city;
159 }
160
161 String
162 Address::GetState(void) const
163 {
164         String state =  __pAddressImpl->GetState();
165
166         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
167         {
168                 if (state.GetLength() > MAX_ADDR_STATE_LENGTH)
169                 {
170                         state.SetLength(MAX_ADDR_STATE_LENGTH);
171                 }
172         }
173
174         return state;
175 }
176
177 String
178 Address::GetPostalCode(void) const
179 {
180         String postalCode =  __pAddressImpl->GetPostalCode();
181
182         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
183         {
184                 if (postalCode.GetLength() > MAX_ADDR_POSTAL_CODE_LENGTH)
185                 {
186                         postalCode.SetLength(MAX_ADDR_POSTAL_CODE_LENGTH);
187                 }
188         }
189
190         return postalCode;
191 }
192
193 String
194 Address::GetCountry(void) const
195 {
196         String country =  __pAddressImpl->GetCountry();
197
198         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
199         {
200                 if (country.GetLength() > _MAX_ADDR_COUNTRY_LENGTH_2_0)
201                 {
202                         country.SetLength(_MAX_ADDR_COUNTRY_LENGTH_2_0);
203                 }
204         }
205
206         return country;
207 }
208
209 String
210 Address::GetPostOfficeBoxNumber(void) const
211 {
212         String postOfficeBoxNumber = __pAddressImpl->GetPostOfficeBoxNumber();
213
214         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
215         {
216                 if (postOfficeBoxNumber.GetLength() > MAX_ADDR_POBOXNUM_LENGTH)
217                 {
218                         postOfficeBoxNumber.SetLength(MAX_ADDR_POBOXNUM_LENGTH);
219                 }
220         }
221
222         return postOfficeBoxNumber;
223 }
224
225 void
226 Address::SetType(AddressType type)
227 {
228         return __pAddressImpl->SetType(type);
229 }
230
231 result
232 Address::SetExtended(const String& extended)
233 {
234         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
235         {
236                 SysTryReturn(NID_SCL, extended.GetLength() <= MAX_ADDR_EXTENDED_LENGTH,
237                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_EXTENDED_LENGTH.", GetErrorMessage(E_INVALID_ARG));
238         }
239
240         __pAddressImpl->SetExtended(extended);
241
242         return E_SUCCESS;
243 }
244
245 result
246 Address::SetStreet(const String& street)
247 {
248         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
249         {
250                 SysTryReturn(NID_SCL, street.GetLength() <= MAX_ADDR_STREET_LENGTH,
251                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_STREET_LENGTH.", GetErrorMessage(E_INVALID_ARG));
252         }
253
254         __pAddressImpl->SetStreet(street);
255
256         return E_SUCCESS;
257 }
258
259 result
260 Address::SetCity(const String& city)
261 {
262         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
263         {
264                 SysTryReturn(NID_SCL, city.GetLength() <= MAX_ADDR_CITY_LENGTH,
265                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_CITY_LENGTH.", GetErrorMessage(E_INVALID_ARG));
266         }
267
268         __pAddressImpl->SetCity(city);
269
270         return E_SUCCESS;
271 }
272
273 result
274 Address::SetState(const String& state)
275 {
276         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
277         {
278                 SysTryReturn(NID_SCL, state.GetLength() <= MAX_ADDR_STATE_LENGTH,
279                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_STATE_LENGTH.", GetErrorMessage(E_INVALID_ARG));
280         }
281
282         __pAddressImpl->SetState(state);
283
284         return E_SUCCESS;
285 }
286
287 result
288 Address::SetPostalCode(const String& postalCode)
289 {
290         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
291         {
292                 SysTryReturn(NID_SCL, postalCode.GetLength() <= MAX_ADDR_POSTAL_CODE_LENGTH,
293                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_POSTAL_CODE_LENGTH.", GetErrorMessage(E_INVALID_ARG));
294         }
295
296         __pAddressImpl->SetPostalCode(postalCode);
297
298         return E_SUCCESS;
299 }
300
301 result
302 Address::SetCountry(const String& country)
303 {
304         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
305         {
306                 SysTryReturn(NID_SCL, country.GetLength() <= _MAX_ADDR_COUNTRY_LENGTH_2_0,
307                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of country exceeds the maximum length.", GetErrorMessage(E_INVALID_ARG));
308         }
309
310         __pAddressImpl->SetCountry(country);
311
312         return E_SUCCESS;
313 }
314
315 result
316 Address::SetPostOfficeBoxNumber(const String& postOfficeBoxNumber)
317 {
318         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
319         {
320                 SysTryReturn(NID_SCL, postOfficeBoxNumber.GetLength() <= MAX_ADDR_POBOXNUM_LENGTH,
321                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value exceeds MAX_ADDR_POBOXNUM_LENGTH.", GetErrorMessage(E_INVALID_ARG));
322         }
323
324         __pAddressImpl->SetPostOfficeBoxNumber(postOfficeBoxNumber);
325
326         return E_SUCCESS;
327 }
328
329 String
330 Address::GetLabel(void) const
331 {
332         return __pAddressImpl->GetLabel();
333 }
334
335 void
336 Address::SetLabel(const String& label)
337 {
338         __pAddressImpl->SetLabel(label);
339 }
340
341
342 }} //Tizen::Social