KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This is the base (and abstract) class for response commands
26  *
27  * @author Stefano Fornari @ Funambol
28  *
29  * @version $Id: ResponseCommand.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
30  */

31 public abstract class ResponseCommand
32 extends ItemizedCommand
33 implements java.io.Serializable JavaDoc {
34     
35     // ---------------------------------------------------------- Protected data
36

37     /**
38      * Message reference
39      */

40     protected String JavaDoc msgRef;
41     
42     /**
43      * Command reference
44      */

45     protected String JavaDoc cmdRef;
46     
47     /**
48      * Target references
49      */

50     protected ArrayList targetRef = new ArrayList();
51     
52     /**
53      * Source references
54      */

55     protected ArrayList sourceRef = new ArrayList();
56     
57     // ------------------------------------------------------------ Constructors
58

59     /**
60      * For serialization purposes
61      */

62     protected ResponseCommand() {}
63     
64     /**
65      * Creates a new ResponseCommand object.
66      *
67      * @param cmdID the command idendifier - NOT NULL
68      * @param msgRef message reference
69      * @param cmdRef command reference - NOT NULL
70      * @param targetRefs target references
71      * @param sourceRefs source references
72      * @param items command items
73      *
74      * @throws IllegalArgumentException if any of the NOT NULL parameter is null
75      */

76     public ResponseCommand(
77         final CmdID cmdID ,
78         final String JavaDoc msgRef ,
79         final String JavaDoc cmdRef ,
80         final TargetRef[] targetRefs,
81         final SourceRef[] sourceRefs,
82         final Item[] items ) {
83         super(cmdID, items);
84         
85         setCmdRef(cmdRef);
86         
87         this.msgRef = msgRef;
88         
89         setTargetRef(targetRefs);
90         setSourceRef(sourceRefs);
91     }
92     
93     // ---------------------------------------------------------- Public methods
94

95     /**
96      * Returns the message reference
97      *
98      * @return the message reference
99      *
100      */

101     public String JavaDoc getMsgRef() {
102         return this.msgRef;
103     }
104     
105     /**
106      * Sets the message reference
107      *
108      * @param msgRef message reference
109      */

110     public void setMsgRef(String JavaDoc msgRef) {
111         this.msgRef = msgRef;
112     }
113     
114     /**
115      * Returns the command reference
116      *
117      * @return the command reference
118      *
119      */

120     public String JavaDoc getCmdRef() {
121         return cmdRef;
122     }
123     
124     /**
125      * Sets the command reference
126      *
127      * @param cmdRef commandreference - NOT NULL
128      *
129      * @throws IllegalArgumentException if cmdRef is null
130      */

131     public void setCmdRef(String JavaDoc cmdRef) {
132         if (cmdRef == null) {
133             throw new IllegalArgumentException JavaDoc("cmdRef cannot be null");
134         }
135         this.cmdRef = cmdRef;
136     }
137     
138     /**
139      * Returns the target references
140      *
141      * @return the target references
142      *
143      */

144     public ArrayList getTargetRef() {
145         return this.targetRef;
146     }
147     
148     /**
149      * Sets the target references
150      *
151      * @param targetRefs target refrences
152      */

153     public void setTargetRef(TargetRef[] targetRefs) {
154         if (targetRefs == null) {
155             this.targetRef = null;
156         } else {
157             this.targetRef.clear();
158             this.targetRef.addAll(Arrays.asList(targetRefs));
159         }
160     }
161     
162     /**
163      * Returns the source references
164      *
165      * @return the source references
166      *
167      */

168     public ArrayList getSourceRef() {
169         return this.sourceRef;
170     }
171     
172     /**
173      * Sets the source references
174      *
175      * @param sourceRefs source refrences
176      */

177     public void setSourceRef(SourceRef[] sourceRefs) {
178         if (sourceRefs == null) {
179             this.sourceRef = null;
180         } else {
181             this.sourceRef.clear();
182             this.sourceRef.addAll(Arrays.asList(sourceRefs));
183         }
184     }
185     
186     /**
187      * Returns the command name. It must be redefined by subclasses.
188      *
189      * @return the command name
190      */

191     abstract public String JavaDoc getName();
192     
193 }
194
Popular Tags