KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 /**
27  * This is a base class for "command" classes
28  *
29  * @author Stefano Fornari @ Funambol
30  *
31  * @version $Id: ItemizedCommand.java,v 1.3 2005/03/02 20:57:37 harrie Exp $
32  */

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

38     //
39
// subclasses must have access the following properties
40
//
41
protected ArrayList JavaDoc items = new ArrayList JavaDoc();
42     protected Meta meta ;
43     
44     // ------------------------------------------------------------ Constructors
45

46     /** For serialization purposes */
47     protected ItemizedCommand() {}
48     
49     /**
50      * Create a new ItemizedCommand object with the given commandIdentifier,
51      * meta object and an array of item
52      *
53      * @param cmdID the command identifier - NOT NULL
54      * @param meta the meta object
55      * @param items an array of item - NOT NULL
56      *
57      */

58     public ItemizedCommand(CmdID cmdID, Meta meta, Item[] items) {
59         super(cmdID);
60         
61         if (cmdID == null) {
62             throw new IllegalArgumentException JavaDoc("cmdID cannot be null or empty");
63         }
64
65         if (items == null) {
66             items = new Item[0];
67         }
68         
69         this.meta = meta;
70         setItems(items);
71     }
72     
73     /**
74      * Create a new ItemizedCommand object with the given commandIdentifier
75      * and an array of item
76      *
77      * @param cmdID the command identifier - NOT NULL
78      * @param items an array of item - NOT NULL
79      *
80      */

81     public ItemizedCommand(final CmdID cmdID, final Item[] items) {
82         this(cmdID, null, items);
83     }
84     
85     // ---------------------------------------------------------- Public methods
86

87     /**
88      * Gets the array of items
89      *
90      * @return the array of items
91      */

92     public java.util.ArrayList JavaDoc getItems() {
93         return this.items;
94     }
95     
96     /**
97      * Sets an array of Item object
98      *
99      * @param items an array of Item object
100      */

101     public void setItems(Item[] items) {
102         if (items != null) {
103             this.items.clear();
104             this.items.addAll(Arrays.asList(items));
105         } else {
106             this.items = null;
107         }
108     }
109     
110     /**
111      * Gets the Meta object
112      *
113      * @return the Meta object
114      */

115     public Meta getMeta() {
116         return meta;
117     }
118
119     /**
120      * Sets the Meta object
121      *
122      * @param meta the Meta object
123      *
124      */

125     public void setMeta(Meta meta) {
126         this.meta = meta;
127     }
128     
129     /**
130      * Gets the name of the command
131      *
132      * @return the name of the command
133      */

134     public abstract String JavaDoc getName();
135 }
Popular Tags