KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This is a base class for "command" classes
24  *
25  * @author Stefano Fornari @ Funambol
26  *
27  * @version $Id: AbstractCommand.java,v 1.5 2005/03/02 20:57:37 harrie Exp $
28  */

29 public abstract class AbstractCommand
30 implements java.io.Serializable JavaDoc {
31     
32     // ---------------------------------------------------------- Protected data
33
protected CmdID cmdID ;
34     protected Boolean JavaDoc noResp ;
35     protected Meta meta ;
36     protected Cred credential;
37     
38     // ------------------------------------------------------------ Constructors
39

40     /** For serialization purposes */
41     protected AbstractCommand() {}
42
43     /**
44      * Create a new AbstractCommand object with the given commandIdentifier
45      * and noResponse
46      *
47      * @param cmdID the command identifier - NOT NULL
48      * @param noResp true if the command doesn't require a response
49      *
50      */

51     public AbstractCommand(final CmdID cmdID, final boolean noResp) {
52         setCmdID(cmdID);
53         this.noResp = (noResp) ? new Boolean JavaDoc(noResp) : null;
54     }
55
56     /**
57      * Create a new AbstractCommand object with the given commandIdentifier
58      *
59      * @param cmdID the command identifier - NOT NULL
60      *
61      */

62     public AbstractCommand(final CmdID cmdID) {
63         this(cmdID, false);
64     }
65
66     /**
67      * Create a new AbstractCommand object with the given commandIdentifier
68      * and noResponse
69      *
70      * @param cmdID the command identifier - NOT NULL
71      * @param noResponse true if the command doesn't require a response
72      * @param meta the Meta object
73      */

74     public AbstractCommand(final CmdID cmdID,
75                            final boolean noResp,
76                            final Meta meta) {
77         setCmdID(cmdID);
78         this.noResp = (noResp) ? new Boolean JavaDoc(noResp) : null;
79         setMeta(meta);
80     }
81     
82     // ---------------------------------------------------------- Public methods
83
/**
84      * Get CommandIdentifier property
85      *
86      * @return the command identifier - NOT NULL
87      */

88     public CmdID getCmdID() {
89         return this.cmdID;
90     }
91     
92     /**
93      * Sets the CommandIdentifier property
94      *
95      * @param cmdID the command identifier
96      *
97      */

98     public void setCmdID(CmdID cmdID) {
99         if (cmdID == null) {
100             throw new IllegalArgumentException JavaDoc("cmdID cannot be null");
101         }
102         this.cmdID = cmdID;
103     }
104
105     /**
106      * Gets noResp property
107      *
108      * @return true if the command doesn't require a response, false otherwise
109      */

110     public boolean isNoResp() {
111         return (noResp != null);
112     }
113
114     public Boolean JavaDoc getNoResp() {
115         if ((noResp != null) && !noResp.booleanValue()) {
116             return null;
117         }
118         return noResp;
119     }
120     
121     /**
122      * Sets noResp true if no response is required
123      *
124      * @param noResp is true if no response is required
125      *
126      */

127     public void setNoResp(Boolean JavaDoc noResp) {
128         this.noResp = (noResp.booleanValue()) ? noResp : null;
129     }
130     
131     /**
132      * Gets Credential object
133      *
134      * @return the Credential object
135      */

136     public Cred getCred() {
137         return credential;
138     }
139     
140     /**
141      * Sets authentication credential
142      *
143      * @param cred the authentication credential
144      *
145      */

146     public void setCred(Cred cred) {
147         this.credential = cred;
148     }
149     
150     /**
151      * Gets an Meta object
152      *
153      * @return an Meta object
154      */

155     public Meta getMeta() {
156         return meta;
157     }
158     
159     /**
160      * Sets Meta object
161      *
162      * @param meta the meta object
163      *
164      */

165     public void setMeta(Meta meta) {
166         this.meta = meta;
167     }
168     
169     /**
170      * Get name property
171      *
172      * @return the name of the command
173      */

174     public abstract String JavaDoc getName();
175 }
176
Popular Tags