KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > source > SyncSourceInfo


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 package sync4j.framework.engine.source;
19
20 import sync4j.framework.engine.source.ContentType;
21
22 /**
23  * This class wraps the following information about a <i>SyncSource</i>
24  * <table>
25  * <tr>
26  * <td>supportedTypes</td>
27  * <td>Types supported by a source</td>
28  * </tr>
29  * <tr>
30  * <td>preferredType</td>
31  * <td>The preferred source content type</td>
32  * </tr>
33  * </table>
34  *
35  * @author Stefano Fornari
36  * @version $Id: SyncSourceInfo.java,v 1.7 2005/03/02 20:57:37 harrie Exp $
37  */

38 public class SyncSourceInfo implements java.io.Serializable JavaDoc {
39     
40     // -------------------------------------------------------------- Properties
41

42     private ContentType[] supportedTypes = null;
43     
44     /** Getter for property supportedTypes.
45      * @return Value of property supportedTypes.
46      *
47      */

48     public ContentType[] getSupportedTypes() {
49         return this.supportedTypes;
50     }
51     
52     /** Setter for property supportedTypes.
53      * @param supportedTypes New value of property supportedTypes.
54      *
55      */

56     public void setSupportedTypes(ContentType[] supportedTypes) {
57         this.supportedTypes = supportedTypes;
58         this.preferred = 0;
59     }
60     
61     /**
62      * The preferred content type index
63      **/

64     private int preferred = 0;
65     
66     /** Getter for property preferred.
67      * @return Value of property preferred.
68      *
69      */

70     public int getPreferred() {
71         return preferred;
72     }
73     
74     /** Setter for property preferredType.
75      * @param preferred New value of property preferredType.
76      *
77      */

78     public void setPreferred(int preferred) {
79         this.preferred = preferred;
80     }
81     
82     /**
83      * Returns the preferred content type among the supported ones.
84      *
85      * @return the preferred content type among the supported ones.
86      *
87      */

88     public ContentType getPreferredType() {
89         assert ((supportedTypes != null) && (preferred >= 0) && (preferred < supportedTypes.length));
90         return supportedTypes[preferred];
91     }
92     
93     // ------------------------------------------------------------ Constructors
94
/**
95      * Creates a new instance of SyncSuurceInfo
96      *
97      * @param supportedTypes - NOT NULL or EMPTY
98      * @param preferred the position in the <i>supportedTypes</i> array of the
99      * preferred type
100      *
101      * @throws IllegalArgumentException if the passed in parameters are not correct
102      */

103     public SyncSourceInfo(ContentType[] supportedTypes, int preferred) {
104         if ((supportedTypes == null) || (supportedTypes.length == 0)) {
105             throw new IllegalArgumentException JavaDoc("supportedTypes cannot be null");
106         }
107         
108         if ((preferred<0) || (preferred >= supportedTypes.length)) {
109             throw new IllegalArgumentException JavaDoc( "preferred is "
110                                               + preferred
111                                               + " when the supported type are "
112                                               + supportedTypes.length);
113         }
114         
115         this.supportedTypes = supportedTypes;
116         this.preferred = preferred;
117     }
118     
119     public SyncSourceInfo() {
120     }
121 }
Popular Tags