Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / client-api / src / c++ / common / syncml / core / Item.cpp
1 /*
2  * Funambol is a mobile platform developed by Funambol, Inc. 
3  * Copyright (C) 2003 - 2007 Funambol, Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by
7  * the Free Software Foundation with the addition of the following permission 
8  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
10  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License 
18  * along with this program; if not, see http://www.gnu.org/licenses or write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301 USA.
21  * 
22  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
23  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License
30  * version 3, these Appropriate Legal Notices must retain the display of the
31  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
32  * feasible for technical reasons, the Appropriate Legal Notices must display
33  * the words "Powered by Funambol".
34  */
35
36
37 #include "syncml/core/Item.h"
38 #include "base/globalsdef.h"
39
40 USE_NAMESPACE
41
42
43 Item::Item() {
44    initialize();
45 }
46
47 Item::~Item() {
48     if (target) { delete target; target = NULL; }
49     if (source) { delete source; source = NULL; }
50     if (meta  ) { delete meta  ; meta   = NULL; }
51     if (data  ) { delete data  ; data   = NULL; }
52     if (targetParent) { delete [] targetParent; targetParent = NULL; }
53     if (sourceParent) { delete [] sourceParent; sourceParent = NULL; }
54     moreData = false;
55
56 }
57
58
59 void Item::initialize() {
60     target       = NULL;
61     source       = NULL;
62     targetParent = NULL;
63     sourceParent = NULL;
64     meta         = NULL;
65     data         = NULL;
66     moreData     = false;
67 }
68
69 /**
70  * Creates a new Item object.
71  *
72  * @param target item target - NULL ALLOWED
73  * @param source item source - NULL ALLOWED
74  * @param targetParent item target parent - NULL ALLOWED (DEFAULT)
75  * @param sourceParent item source parent - NULL ALLOWED (DEFAULT)
76  * @param meta item meta data - NULL ALLOWED
77  * @param data item data - NULL ALLOWED
78  *
79  */
80 Item::Item( Target* target,
81             Source* source,
82             char* tParent,
83             char* sParent,
84             Meta*   meta  ,
85             ComplexData* data,
86             bool moreData) {
87     initialize();
88
89     setTarget(target);
90     setSource(source);
91     setTargetParent(tParent);
92     setSourceParent(sParent);
93     setMeta(meta);
94     setData(data);
95     setMoreData(moreData);
96
97 }
98
99
100
101
102 /**
103 * Creates a new Item object.
104 *
105 * @param target item target - NULL ALLOWED
106 * @param source item source - NULL ALLOWED
107 * @param meta item meta data - NULL ALLOWED
108 * @param data item data - NULL ALLOWED
109 *
110 */
111 Item::Item( Target* target,
112             Source* source,
113             Meta*   meta  ,
114             ComplexData* data,
115             bool moreData) {
116     initialize();
117     setTarget(target);
118     setSource(source);
119     setTargetParent(NULL);
120     setSourceParent(NULL);
121     setMeta(meta);
122     setData(data);
123     setMoreData(moreData);
124
125 }
126
127 /**
128 * Returns the item target
129 *
130 * @return the item target
131 */
132 Target* Item::getTarget() {
133     return target;
134 }
135
136 /**
137 * Sets the item target
138 *
139 * @param target the target
140 *
141 */
142 void Item::setTarget(Target* target) {
143     if (this->target) {
144                 delete this->target; this->target = NULL;
145     }
146     if (target) {
147             this->target = target->clone();
148     }
149 }
150
151 /**
152 * Returns the item source
153 *
154 * @return the item source
155 */
156 Source* Item::getSource() {
157     return source;
158 }
159
160 /**
161 * Sets the item source
162 *
163 * @param source the source
164 *
165 */
166 void Item::setSource(Source* source) {
167     if (this->source) {
168                 delete this->source; this->source = NULL;
169     }
170     if (source) {
171             this->source = source->clone();
172     }
173 }
174
175 /**
176 * Returns the item meta element
177 *
178 * @return the item meta element
179 */
180 Meta* Item::getMeta() {
181     return meta;
182 }
183
184 /**
185 * Sets the meta item
186 *
187 * @param meta the item meta element
188 *
189 */
190 void Item::setMeta(Meta* meta) {
191     if (this->meta) {
192                 delete this->meta; this->meta = NULL;
193     }
194     if (meta) {
195             this->meta = meta->clone();
196     }
197 }
198
199 /**
200 * Returns the item data
201 *
202 * @return the item data
203 *
204 */
205 ComplexData* Item::getData() {
206     return data;
207 }
208
209 /**
210 * Sets the item data
211 *
212 * @param data the item data
213 *
214 */
215 void Item::setData(ComplexData* data) {
216     if (this->data) {
217                 delete this->data; this->data = NULL;
218     }
219     if (data) {
220             this->data = data->clone();
221     }
222 }
223
224 /**
225 * Gets moreData property
226 *
227 * @return true if the data item is incomplete and has further chunks
228 *         to come, false otherwise
229 */
230 bool Item::isMoreData() {
231     return (moreData != NULL);
232 }
233
234 /**
235 * Gets the Boolean value of moreData
236 *
237 * @return true if the data item is incomplete and has further chunks
238 *         to come, false otherwise
239 */
240 bool Item::getMoreData() {
241     return moreData;
242 }
243
244 /**
245 * Sets the moreData property
246 *
247 * @param moreData the moreData property
248 */
249 void Item::setMoreData(bool moreData) {
250     this->moreData = moreData;
251 }
252
253 /**
254  * Gets the taregtParent property
255  *
256  * @return the taregtParent property value
257  */
258 const char* Item::getTargetParent() {
259     return targetParent;
260 }
261
262 /**
263  * Sets the taregtParent property
264  *
265  * @param parent the taregtParent property
266  */
267 void Item::setTargetParent(const char*parent) {
268     if (targetParent) {
269         delete [] targetParent; targetParent = NULL;
270     }
271     targetParent = stringdup(parent);
272 }
273
274 /**
275  * Gets the sourceParent property
276  *
277  * @return the sourceParent property value
278  */
279 const char* Item::getSourceParent() {
280     return sourceParent;
281 }
282
283 /**
284  * Sets the sourceParent property
285  *
286  * @param parent the sourceParent property
287  */
288 void Item::setSourceParent(const char*parent) {
289     if (sourceParent) {
290         delete [] sourceParent; sourceParent = NULL;
291     }
292     sourceParent = stringdup(parent);
293 }
294
295 /**
296  * Item can be an element of an Array object
297  */
298 ArrayElement* Item::clone() {
299     //Item* ret = new Item(target, source, targetParent, sourceParent, meta, data, moreData);
300     Item* ret = new Item(target, source, meta, data, moreData);
301     return ret;
302 }