KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public final class Status
33 extends ResponseCommand
34 implements java.io.Serializable JavaDoc {
35     
36     // --------------------------------------------------------------- Constants
37

38     public static String JavaDoc COMMAND_NAME = "Status";
39     
40     // ------------------------------------------------------------ Private data
41

42     private Chal chal;
43     private Data data;
44     private String JavaDoc cmd ;
45     
46     // ------------------------------------------------------------ Constructors
47

48     /**
49      * For serialiazaion purposes
50      */

51     protected Status() {}
52     
53     /**
54      * Creates a new Status object.
55      *
56      * @param cmdID command identifier - NOT NULL
57      * @param msgRef message reference
58      * @param cmdRef command reference - NOT NULL
59      * @param cmd command - NOT NULL
60      * @param targetRefs target references. If null
61      * @param sourceRefs source references. If null
62      * @param cred authentication credentials
63      * @param chal authentication challenge
64      * @param data status data - NOT NULL
65      * @param items command items - NOT NULL
66      *
67      * @throws IllegalArgumentException if any NOT NULL argument is null
68      *
69      */

70     public Status(
71                final CmdID cmdID ,
72                final String JavaDoc msgRef ,
73                final String JavaDoc cmdRef ,
74                final String JavaDoc cmd ,
75                final TargetRef[] targetRefs,
76                final SourceRef[] sourceRefs,
77                final Cred cred ,
78                final Chal chal ,
79                final Data data ,
80                final Item[] items ) {
81         super(
82             cmdID,
83             msgRef,
84             cmdRef,
85             targetRefs,
86             sourceRefs,
87             items
88         );
89         
90         setCred(cred);
91         setData(data);
92         setCmd(cmd);
93
94         this.chal = chal;
95     }
96     
97     /**
98      * The same as the previous constructor, but accepting <i>targetRefs</i>
99      * and <i>sourceRefs</i> as String instead of String[].
100      *
101      * @param cmdID command identifier - NOT NULL
102      * @param msgRef message reference
103      * @param cmdRef command reference - NOT NULL
104      * @param cmd command - NOT NULL
105      * @param targetRef target references. If null a TargetRef[0] is used
106      * @param sourceRef source references. If null a SourceRef[0] is used
107      * @param cred authentication credentials
108      * @param chal authentication challenge
109      * @param data status data - NOT NULL
110      * @param items command items - NOT NULL
111      *
112      * @throws IllegalArgumentException if any NOT NULL argument is null
113      *
114      */

115     public Status(
116                final CmdID cmdID ,
117                final String JavaDoc msgRef ,
118                final String JavaDoc cmdRef ,
119                final String JavaDoc cmd ,
120                final TargetRef targetRef,
121                final SourceRef sourceRef,
122                final Cred cred ,
123                final Chal chal ,
124                final Data data ,
125                final Item[] items ) {
126         this(
127             cmdID,
128             msgRef,
129             cmdRef,
130             cmd,
131             (targetRef == null) ? null : new TargetRef[] { targetRef },
132             (sourceRef == null) ? null : new SourceRef[] { sourceRef },
133             cred,
134             chal,
135             data,
136             items
137         );
138     }
139     
140     // ---------------------------------------------------------- Public methods
141

142     /**
143      * Returns the chal element
144      *
145      * @return the chal element
146      *
147      */

148     public Chal getChal() {
149         return chal;
150     }
151     
152     /**
153      * Sets the chal element
154      *
155      * @param chal the new chal
156      */

157     public void setChal(Chal chal) {
158         this.chal = chal;
159     }
160     
161     /**
162      * Returns the status data
163      *
164      * @return the status data
165      *
166      */

167     public Data getData() {
168         return data;
169     }
170     
171     /**
172      * Sets the status data
173      *
174      * @param data the new data
175      *
176      * @throws IllegalArgumentException if data is null
177      */

178     public void setData(Data data) {
179         if (data == null) {
180             throw new IllegalArgumentException JavaDoc("data cannot be null");
181         }
182         this.data = data;
183     }
184     
185     /**
186      * Returns the cmd element
187      *
188      * @return the cmd element
189      */

190     public String JavaDoc getCmd() {
191         return cmd;
192     }
193     
194     /**
195      * Sets the cmd element
196      *
197      * @param cmd the new cmd element - NOT NULL
198      *
199      * @throws IllegalArgumentException if cmd is null
200      */

201     public void setCmd(String JavaDoc cmd) {
202         if (cmd == null) {
203             throw new IllegalArgumentException JavaDoc("cmd cannot be null");
204         }
205         this.cmd = cmd;
206     }
207     
208     /**
209      * Returns the status code as int
210      *
211      * @return the status code as int
212      */

213     public int getStatusCode() {
214         return Integer.parseInt(data.getData());
215     }
216     
217     /**
218      * Returns the command name
219      *
220      * @return the command name
221      */

222     public String JavaDoc getName() {
223         return Status.COMMAND_NAME;
224     }
225 }
226
Popular Tags