KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > test > DummySyncSource


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.test;
20
21 import java.security.Principal JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import sync4j.syncclient.spds.engine.*;
25 import sync4j.syncclient.spds.SyncException;
26
27
28 /**
29  * This class implements a dummy <i>SyncSource</i> that just displays the calls
30  * to its methods
31  *
32  * @author Stefano Fornari
33  *
34  * @version $Id: DummySyncSource.java,v 1.3 2005/01/19 11:18:37 fabius Exp $
35  *
36  */

37 public class DummySyncSource implements SyncSource {
38
39     private String JavaDoc name = null;
40     private String JavaDoc type = null;
41     private String JavaDoc sourceURI = null;
42
43     private SyncItem[] allItems = null;
44     private SyncItem[] newItems = null;
45     private SyncItem[] deletedItems = null;
46     private SyncItem[] updatedItems = null;
47
48     // ------------------------------------------------------------ Constructors
49

50     /** Creates a new instance of AbstractSyncSource */
51     public DummySyncSource() {
52         newItems = new SyncItem[] {
53                            createItem("10", "This is a new item", SyncItemState.NEW)
54                        };
55         deletedItems = new SyncItem[] {
56                            createItem("20", "This is a deleted item", SyncItemState.DELETED)
57                        };
58         updatedItems = new SyncItem[] {
59                            createItem("30", "This is an updated item", SyncItemState.UPDATED)
60                        };
61
62         allItems = new SyncItem[newItems.length + updatedItems.length + 1];
63
64         allItems[0] = createItem("40", "This is an unchanged item", SyncItemState.SYNCHRONIZED);
65         allItems[1] = newItems[0];
66         allItems[2] = updatedItems[0];
67     }
68
69
70     // ---------------------------------------------------------- Public methods
71

72     public String JavaDoc getName() {
73         return name;
74     }
75
76     public void setName(String JavaDoc name) {
77         System.out.println("setName(" + name + ")");
78         this.name = name;
79     }
80
81     public String JavaDoc getType() {
82         return this.type;
83     }
84
85     public void setType(String JavaDoc type) {
86         System.out.println("setType(" + type + ")");
87         this.type = type;
88     }
89
90     /** Getter for property uri.
91      * @return Value of property uri.
92      */

93     public String JavaDoc getSourceURI() {
94         return sourceURI;
95     }
96
97     /** Setter for property uri.
98      * @param sourceURI New value of property uri.
99      */

100     public void setSourceURI(String JavaDoc sourceURI) {
101         System.out.println("setSourceURI(" + sourceURI + ")");
102         this.sourceURI = sourceURI;
103     }
104
105     /**
106      * Some other initialization parameter
107      */

108     public void setParam1(String JavaDoc value) {
109         System.out.println("setParam1(" + value + ")");
110     }
111
112     /**
113      * Returns a string representation of this object.
114      *
115      * @return a string representation of this object.
116      */

117     public String JavaDoc toString() {
118         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(super.toString());
119
120         sb.append(" - {name: ").append(getName() );
121         sb.append(" type: " ).append(getType() );
122         sb.append(" uri: " ).append(getSourceURI());
123         sb.append("}" );
124
125         return sb.toString();
126     }
127
128
129     public void beginSync(int type) throws SyncException {
130         System.out.println("beginSync(" + type + ")");
131     }
132
133     public void endSync() throws SyncException {
134         System.out.println("endSync()");
135     }
136
137     public SyncItem[] getAllSyncItems(Principal JavaDoc principal) throws SyncException {
138         System.out.println("getAllSyncItems(" + principal + ")");
139         return allItems;
140     }
141
142
143     public SyncItem[] getDeletedSyncItems(Principal JavaDoc principal,
144                                           Date JavaDoc since ) throws SyncException {
145         System.out.println("getDeletedSyncItems(" + principal + " , " + since + ")");
146
147         return deletedItems;
148
149     }
150
151
152     public SyncItem[] getNewSyncItems(Principal JavaDoc principal,
153                                       Date JavaDoc since ) throws SyncException {
154         System.out.println("getNewSyncItems(" + principal + " , " + since + ")");
155
156         return newItems;
157
158     }
159
160     public SyncItem[] getUpdatedSyncItems(Principal JavaDoc principal,
161                                           Date JavaDoc since ) throws SyncException {
162         System.out.println("getUpadtedSyncItems(" + principal + " , " + since + ")");
163
164         return updatedItems;
165
166     }
167
168     public void removeSyncItem(Principal JavaDoc principal, SyncItem syncItem) throws SyncException {
169         System.out.println("removeSyncItem(" + principal + " , " + syncItem.getKey().getKeyAsString() + ")");
170     }
171
172     public SyncItem setSyncItem(Principal JavaDoc principal, SyncItem syncItem) throws SyncException {
173         System.out.println("setSyncItem(" + principal + " , " + syncItem.getKey().getKeyAsString() + ")");
174         return new SyncItemImpl(this, syncItem.getKey().getKeyAsString()+"-1");
175     }
176
177     public void beginSync() {
178     }
179
180     public void commitSync() {
181     }
182
183     // ------------------------------------------------------------ Private data
184

185     private SyncItem createItem(String JavaDoc id, String JavaDoc content, char state) {
186         SyncItem item = new SyncItemImpl(this, id, state);
187
188         item.setProperty(
189             new SyncItemProperty(SyncItem.PROPERTY_BINARY_CONTENT, content.getBytes())
190         );
191
192         return item;
193     }
194 }
Popular Tags