KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spds > engine > SyncSourceDefinition


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.spds.engine;
20
21 import java.io.*;
22 import java.util.Hashtable JavaDoc;
23
24 import java.security.Principal JavaDoc;
25
26 import sync4j.syncclient.common.StringTools;
27
28
29 /**
30  * This class groups the configuration information of a SyncSource.
31  *
32  * @author Fabio Maggi
33  *
34  * @version $Id: SyncSourceDefinition.java,v 1.2 2005/01/19 11:18:36 fabius Exp $
35  */

36 public class SyncSourceDefinition {
37
38     // --------------------------------------------------------------- Constants
39

40     public static final String JavaDoc CONFIG_NAME = "name" ;
41     public static final String JavaDoc CONFIG_CLASS = "sourceClass" ;
42     public static final String JavaDoc CONFIG_URI = "sourceURI" ;
43     public static final String JavaDoc CONFIG_TYPE = "type" ;
44     public static final String JavaDoc CONFIG_LAST = "last" ;
45     public static final String JavaDoc CONFIG_DEFAULT_SYNC = "sync" ;
46     public static final String JavaDoc CONFIG_SUPPORTED_SYNC_MODES = "syncModes" ;
47
48     // ------------------------------------------------------------ Private date
49

50     private Hashtable JavaDoc properties = null;
51
52     public String JavaDoc getName() {
53         return (String JavaDoc)properties.get(CONFIG_NAME);
54     }
55
56     public String JavaDoc getSourceClass() {
57         return (String JavaDoc)properties.get(CONFIG_CLASS);
58     }
59
60     public String JavaDoc getSourceUri() {
61         return (String JavaDoc)properties.get(CONFIG_URI);
62     }
63
64     public String JavaDoc getType() {
65         return (String JavaDoc)properties.get(CONFIG_TYPE);
66     }
67
68     public String JavaDoc getDefaultSync() {
69         return (String JavaDoc)properties.get(CONFIG_DEFAULT_SYNC);
70     }
71
72     public String JavaDoc[] getSupportedSyncModes() {
73         return StringTools.split((String JavaDoc)properties.get(CONFIG_SUPPORTED_SYNC_MODES));
74     }
75
76     public long getLastTimestamp() {
77         String JavaDoc last = (String JavaDoc)properties.get(CONFIG_LAST);
78
79         try {
80             return (last == null) ? 0 : Long.parseLong(last);
81         } catch (NumberFormatException JavaDoc e) {
82             return 0;
83         }
84     }
85
86     public Hashtable JavaDoc getProperties() {
87         return properties;
88     }
89
90     public SyncSourceDefinition (Hashtable JavaDoc properties) {
91         String JavaDoc sourceClass = (String JavaDoc)properties.get(CONFIG_CLASS );
92         String JavaDoc uri = (String JavaDoc)properties.get(CONFIG_URI );
93         String JavaDoc className = (String JavaDoc)properties.get(CONFIG_CLASS );
94         String JavaDoc name = (String JavaDoc)properties.get(CONFIG_NAME );
95         String JavaDoc type = (String JavaDoc)properties.get(CONFIG_TYPE );
96         String JavaDoc defaultSync = (String JavaDoc)properties.get(CONFIG_DEFAULT_SYNC );
97         String JavaDoc syncModes = (String JavaDoc)properties.get(CONFIG_SUPPORTED_SYNC_MODES);
98
99
100         if (sourceClass == null) {
101             throw new IllegalArgumentException JavaDoc("Missing 'sourceClass' in properties!");
102         }
103
104         if (uri == null) {
105             throw new IllegalArgumentException JavaDoc("Missing 'uri' in properties!");
106         }
107
108         if (name == null) {
109             throw new IllegalArgumentException JavaDoc("Missing 'name' in properties!");
110         }
111
112         if (type == null) {
113             throw new IllegalArgumentException JavaDoc("Missing 'type' in properties!");
114         }
115
116         if (defaultSync == null) {
117             properties.put(CONFIG_DEFAULT_SYNC, "two-way");
118         }
119
120         if (syncModes == null) {
121             properties.put(CONFIG_SUPPORTED_SYNC_MODES, "two-way");
122         }
123
124         this.properties = properties;
125     }
126 }
Popular Tags