KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > Search


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
20 package sync4j.framework.core;
21
22 import java.util.*;
23
24 /**
25  *
26  * This class represents the <Search> tag as defined by the SyncML
27  * representation specifications.
28  *
29  * @author Stefano Fornari @ Funambol
30  *
31  * @version $Id: Search.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
32  *
33  */

34 public final class Search
35 extends AbstractCommand
36 implements java.io.Serializable JavaDoc {
37     
38     // --------------------------------------------------------------- Constants
39

40     public static String JavaDoc COMMAND_NAME = "Search";
41     
42     // ------------------------------------------------------------ Private data
43

44     private Boolean JavaDoc noResults;
45     private Target target ;
46     private ArrayList sources = new ArrayList();
47     private String JavaDoc lang ;
48     private Data data ;
49     
50     // ------------------------------------------------------------ Constructors
51

52     /**
53      * For serialization purposes
54      */

55     protected Search() {}
56     
57     /**
58      * Creates a new Search object.
59      *
60      * @param cmdID command identifier - NOT NULL
61      * @param noResp is <NoResponse/> required?
62      * @param noResults is <NoResults/> required?
63      * @param cred authentication credentials
64      * @param target target
65      * @param sources sources - NOT NULL
66      * @param lang preferred language
67      * @param meta meta data - NOT NULL
68      * @param data contains the search grammar - NOT NULL
69      *
70      * @throws java.lang.IllegalArgumentException if any NOT NULL parameter is null
71      *
72      */

73     public Search(
74                final CmdID cmdID ,
75                final boolean noResp ,
76                final boolean noResults,
77                final Cred cred ,
78                final Target target ,
79                final Source[] sources ,
80                final String JavaDoc lang ,
81                final Meta meta ,
82                final Data data ) {
83         super(cmdID, noResp);
84
85         setCred(cred);
86         setMeta(meta);
87         setSources(sources);
88         setData(data);
89         
90         this.noResults = (noResults) ? new Boolean JavaDoc(noResults) : null;
91         this.target = target;
92         this.lang = lang ;
93     }
94     
95     // ---------------------------------------------------------- Public methods
96

97     /**
98      * Returns noResults
99      *
100      * @return noResults
101      *
102      */

103     public boolean isNoResults() {
104         return (noResults != null);
105     }
106     
107     /**
108      * Sets noResults
109      *
110      * @param noResults the noResults value
111      */

112     public void setNoResults(Boolean JavaDoc noResults) {
113         this.noResults = (noResults.booleanValue()) ? noResults : null;
114     }
115     
116     /**
117      * Gets the Boolean value of noResults property
118      *
119      * @return noResults if boolean value is true, otherwise null
120      */

121     public Boolean JavaDoc getNoResults() {
122         if (!noResults.booleanValue()) {
123             return null;
124         }
125         return noResults;
126     }
127     
128     /**
129      * Returns target property
130      * @return target the Target property
131      */

132     public Target getTarget() {
133         return target;
134     }
135     
136     /**
137      * Sets target property
138      *
139      * @param target the target property
140      */

141     public void setTarget(Target target) {
142         this.target = target;
143     }
144     
145     /**
146      * Returns command sources
147      * @return command sources
148      */

149     public ArrayList getSources() {
150         return sources;
151     }
152     
153     /**
154      * Sets command sources
155      *
156      * @param sources the command sources - NOT NULL
157      *
158      * @throws IllegalArgumentException if sources is null
159      */

160     public void setSources(Source[] sources) {
161         if (sources == null) {
162             throw new IllegalArgumentException JavaDoc("sources cannot be null");
163         }
164         this.sources.clear();
165         this.sources.addAll(Arrays.asList(sources));
166     }
167     
168     /**
169      * Returns the preferred language
170      *
171      * @return the preferred language
172      *
173      */

174     public String JavaDoc getLang() {
175         return lang;
176     }
177     
178     /**
179      * Sets the preferred language
180      *
181      * @param lang the preferred language
182      */

183     public void setLang(String JavaDoc lang) {
184         this.lang = lang;
185     }
186         
187     /**
188      * Returns data
189      *
190      * @return data
191      *
192      */

193     public Data getData() {
194         return data;
195     }
196     
197     /**
198      * Sets data
199      *
200      * @param data the command's data - NOT NULL
201      *
202      * @throws IllegalArgumentException id data is null
203      */

204     public void setData(Data data) {
205         if (data == null) {
206             throw new IllegalArgumentException JavaDoc("data cannot be null");
207         }
208         this.data = data;
209     }
210     
211     /**
212      * Returns the command name
213      *
214      * @return the command name
215      */

216     public String JavaDoc getName() {
217         return Search.COMMAND_NAME;
218     }
219 }
220
Popular Tags