View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  
25  package com.mindtree.techworks.insight.download;
26  
27  import java.util.ArrayList;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /**
32   * <p>
33   * <code>Fileset</code> is a data object. It contains the information for a
34   * list of files that can be downloaded for a particular source.
35   * </p>
36   * 
37   * @author Balaji Seshadri, Bindul Bhowmik
38   * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
39   */
40  public class Fileset {
41  
42  	//
43  	// Constants
44  	//
45  
46  	/**
47  	 * Constants that identify the supported file types
48  	 */
49  	public static final int LOCAL_FILESET = 0;
50  
51  	/**
52  	 * Identifies the fileset as an FTP Fileset
53  	 */
54  	public static final int FTP_FILESET = 1;
55  
56  	/**
57  	 * Identifies the fileset as a HTTP Fileset
58  	 */
59  	public static final int HTTP_FILESET = 2;
60  
61  	/**
62  	 * Identifies the fileset as an SFTP Fileset
63  	 */
64  	public static final int SFTP_FILESET = 3;
65  	
66  	//
67  	// Instance variables
68  	//
69  
70  	/**
71  	 * The name for the Fileset group that is referred
72  	 */
73  	private String filesetName;
74  
75  	/**
76  	 * The url strings of list of files that can be accessed using this fileset
77  	 */
78  	private List fileList;
79  
80  	/**
81  	 * Identifies the type of the fileset.
82  	 */
83  	private int type;
84  
85  	/**
86  	 * String identifying the type of the fileset.
87  	 */
88  	private String typeString;
89  
90  	//
91  	// Constructors
92  	//
93  
94  	/**
95  	 * Creates a Fileset object with the passed name
96  	 * 
97  	 * @param filesetName the name of the fileset.
98  	 * @param type identifies the type of the fileset. Should be one of the type
99  	 *            constants defined in this class.
100 	 */
101 	public Fileset (String filesetName, int type) {
102 
103 		this.filesetName = filesetName;
104 		this.type = type;
105 	}
106 
107 	/**
108 	 * Creates a fileset object with the passed parameters
109 	 * 
110 	 * @param filesetName the name of the fileset.
111 	 * @param type identifies the type of the fileset. Should be one of the type
112 	 *            constants defined in this class.
113 	 * @param typeString String identifying the type
114 	 */
115 	public Fileset (String filesetName, int type, String typeString) {
116 
117 		this(filesetName, type);
118 		this.typeString = typeString;
119 	}
120 
121 	//
122 	// Accessor methods
123 	//
124 
125 	/**
126 	 * @return Returns the typeString.
127 	 */
128 	public String getTypeString () {
129 
130 		return typeString;
131 	}
132 
133 	/**
134 	 * @param typeString The typeString to set.
135 	 */
136 	public void setTypeString (String typeString) {
137 
138 		this.typeString = typeString;
139 	}
140 
141 	/**
142 	 * @return Returns the filesetName.
143 	 */
144 	public String getFilesetName () {
145 
146 		return filesetName;
147 	}
148 
149 	/**
150 	 * Returns the type of the fileset.
151 	 * 
152 	 * @return The type of the fileset.
153 	 */
154 	public int getType () {
155 
156 		return this.type;
157 	}
158 
159 	/**
160 	 * sets the file list for the Fileset
161 	 * 
162 	 * @param fileList list for the Fileset
163 	 */
164 	public void setFileList (List fileList) {
165 
166 		this.fileList = fileList;
167 	}
168 
169 	/**
170 	 * Returns the list of files. If no files are present, it returns an empty
171 	 * ArrayList
172 	 * 
173 	 * @return List list of files for the Fileser
174 	 */
175 	public List getFileList () {
176 
177 		if (null == fileList) {
178 			return new ArrayList();
179 		}
180 		return fileList;
181 	}
182 
183 	/**
184 	 * Adds a filename to the list of files
185 	 * 
186 	 * @param fileName
187 	 */
188 	public void addFile (String fileName) {
189 
190 		if (null == fileList) {
191 			fileList = new ArrayList();
192 		}
193 		fileList.add(fileName);
194 	}
195 
196 	/**
197 	 * Returns the number of files in the Fileset.
198 	 * 
199 	 * @return The count of files in the Fileset
200 	 */
201 	public int getFileCount () {
202 
203 		if (null == fileList) {
204 			return 0;
205 		} else {
206 			return fileList.size();
207 		}
208 	}
209 
210 	/**
211 	 * Returns the file at the index specified.
212 	 * 
213 	 * @param index The index from where to get the file.
214 	 * @return The file at the index specified.
215 	 * @throws ArrayIndexOutOfBoundsException If no files are present or no file
216 	 *             is present at the index specified.
217 	 */
218 	public String getFile (int index) {
219 
220 		if (null == fileList) {
221 			throw new ArrayIndexOutOfBoundsException("No files present");
222 		} else {
223 			return (String) fileList.get(index);
224 		}
225 	}
226 
227 	/**
228 	 * Returns an iterator for the files in the Fileset. If no files are
229 	 * present, it returns an empty iterator.
230 	 * 
231 	 * @return An iterator for the files in the fileList. If no files are
232 	 *         present, returns and empty iterator.
233 	 */
234 	public Iterator iterateFiles () {
235 
236 		if (null == fileList) {
237 			return new ArrayList().iterator();
238 		} else {
239 			return fileList.iterator();
240 		}
241 	}
242 
243 
244 	/**
245 	 * Returns the information about this object.
246 	 * 
247 	 * @see java.lang.Object#toString()
248 	 */
249 	public String toString () {
250 
251 		return this.filesetName;
252 	}
253 
254 }