Revision 42775 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/impl/DefaultFilesystemServerExplorer.java
DefaultFilesystemServerExplorer.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl; |
25 | 24 |
|
... | ... | |
50 | 49 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
51 | 50 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
52 | 51 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
52 |
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
|
53 | 53 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
54 | 54 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
55 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
|
56 | 55 |
import org.gvsig.tools.exception.BaseException; |
57 | 56 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
58 | 57 |
|
59 |
public class DefaultFilesystemServerExplorer extends AbstractDisposable
|
|
60 |
implements FilesystemServerExplorerProviderServices,
|
|
61 |
FilesystemFileFilter {
|
|
58 |
public class DefaultFilesystemServerExplorer extends AbstractDataServerExplorer
|
|
59 |
implements FilesystemServerExplorerProviderServices,
|
|
60 |
FilesystemFileFilter {
|
|
62 | 61 |
|
63 |
FilesystemServerExplorerParameters parameters; |
|
62 |
private File root; |
|
63 |
private File current; // Current path |
|
64 |
private List serverProviders; |
|
64 | 65 |
|
65 |
private File root; |
|
66 |
public DefaultFilesystemServerExplorer( |
|
67 |
FilesystemServerExplorerParameters parameters, |
|
68 |
DataServerExplorerProviderServices services) |
|
69 |
throws InitializeException { |
|
70 |
super(parameters, services); |
|
71 |
if (this.getFSParameters().getRoot() != null) { |
|
72 |
this.root = new File(this.getFSParameters().getRoot()); |
|
73 |
} |
|
74 |
if (this.getFSParameters().getInitialpath() != null) { |
|
75 |
this.current = new File(this.getFSParameters().getInitialpath()); |
|
76 |
} |
|
77 |
if (this.root == null && this.current == null) { |
|
78 |
// throw new InitializeException(this.getName(), |
|
79 |
// new IllegalArgumentException()); |
|
80 |
} else if (this.current == null) { |
|
81 |
this.current = new File(this.getFSParameters().getRoot()); |
|
82 |
} |
|
83 |
} |
|
66 | 84 |
|
67 |
private File current; // Current path |
|
85 |
private FilesystemServerExplorerParameters getFSParameters() { |
|
86 |
return (FilesystemServerExplorerParameters) this.getParameters(); |
|
87 |
} |
|
68 | 88 |
|
69 |
private DataServerExplorerProviderServices providerServices; |
|
89 |
@Override |
|
90 |
protected void doDispose() throws BaseException { |
|
91 |
this.root = null; |
|
92 |
super.doDispose(); |
|
93 |
} |
|
70 | 94 |
|
71 |
private List serverProviders; |
|
95 |
@Override |
|
96 |
public List list(int mode) throws DataException { |
|
97 |
if (this.current == null) { |
|
98 |
throw new IllegalStateException(); |
|
99 |
} |
|
100 |
if (!this.current.exists()) { |
|
101 |
throw new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
|
102 |
} |
|
72 | 103 |
|
73 |
public DefaultFilesystemServerExplorer( |
|
74 |
FilesystemServerExplorerParameters parameters, |
|
75 |
DataServerExplorerProviderServices services) |
|
76 |
throws InitializeException { |
|
77 |
this.parameters = parameters; |
|
78 |
this.providerServices = services; |
|
79 |
if (this.parameters.getRoot() != null) { |
|
80 |
this.root = new File(this.parameters.getRoot()); |
|
81 |
} |
|
82 |
if (this.parameters.getInitialpath() != null) { |
|
83 |
this.current = new File(this.parameters.getInitialpath()); |
|
84 |
} |
|
85 |
if (this.root == null && this.current == null) { |
|
86 |
// throw new InitializeException(this.getName(), |
|
87 |
// new IllegalArgumentException()); |
|
88 |
} else if (this.current == null) { |
|
89 |
this.current = new File(this.parameters.getRoot()); |
|
90 |
} |
|
91 |
} |
|
104 |
if (!this.current.isDirectory()) { |
|
105 |
throw new IllegalArgumentException(this.getProviderName() |
|
106 |
+ ": Path not a directory '" + this.current + "'"); |
|
107 |
} |
|
92 | 108 |
|
93 |
public DataServerExplorerParameters getParameters() {
|
|
94 |
return parameters;
|
|
95 |
}
|
|
109 |
List files = new ArrayList(); // return files
|
|
110 |
List providers = this.getProviders(mode);
|
|
111 |
String allfiles[] = this.current.list();
|
|
96 | 112 |
|
97 |
protected void doDispose() throws BaseException { |
|
98 |
this.parameters = null; |
|
99 |
this.root = null; |
|
100 |
} |
|
113 |
for (int i = 0; i < allfiles.length; i++) { |
|
114 |
File file = new File(this.root, allfiles[i]); |
|
115 |
Iterator providersit = providers.iterator(); |
|
116 |
while (providersit.hasNext()) { |
|
117 |
FilesystemServerExplorerProvider provider = (FilesystemServerExplorerProvider) providersit |
|
118 |
.next(); |
|
119 |
if (provider.accept(file)) { |
|
120 |
DataStoreParameters dsp = this.createStoreParameters(file); |
|
121 |
if (dsp != null) { |
|
122 |
files.add(dsp); |
|
123 |
} |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
return files; |
|
129 |
} |
|
101 | 130 |
|
102 |
public List list(int mode) throws DataException { |
|
103 |
if (this.current == null) { |
|
104 |
throw new IllegalStateException(); |
|
105 |
} |
|
106 |
if (!this.current.exists()) { |
|
107 |
new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
|
108 |
} |
|
131 |
public List list() throws DataException { |
|
132 |
if (this.current == null) { |
|
133 |
throw new IllegalStateException(); // FIXME |
|
134 |
} |
|
135 |
if (!this.current.exists()) { |
|
136 |
// TODO crear excepcion de Data?? |
|
137 |
new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
|
138 |
} |
|
109 | 139 |
|
110 |
if (!this.current.isDirectory()) {
|
|
111 |
new IllegalArgumentException(this.getProviderName()
|
|
112 |
+ ": Path not a directory '" + this.current + "'");
|
|
113 |
}
|
|
140 |
if (!this.current.isDirectory()) {
|
|
141 |
new IllegalArgumentException(this.getProviderName()
|
|
142 |
+ ": Path not a directory '" + this.current + "'");
|
|
143 |
}
|
|
114 | 144 |
|
115 |
List files = new ArrayList(); // return files |
|
116 |
List providers = this.getProviders(mode); |
|
117 |
String allfiles[] = this.current.list(); |
|
145 |
String files[] = this.current.list(); |
|
146 |
int i; |
|
147 |
File theFile; |
|
148 |
ArrayList list = new ArrayList(); |
|
149 |
DataStoreParameters dsp = null; |
|
118 | 150 |
|
119 |
for (int i = 0; i < allfiles.length; i++) { |
|
120 |
File file = new File(this.root, allfiles[i]); |
|
121 |
Iterator providersit = providers.iterator(); |
|
122 |
while (providersit.hasNext()) { |
|
123 |
FilesystemServerExplorerProvider provider = (FilesystemServerExplorerProvider) providersit |
|
124 |
.next(); |
|
125 |
if( provider.accept(file)) { |
|
126 |
DataStoreParameters dsp = this.createStoreParameters(file); |
|
127 |
if (dsp != null) { |
|
128 |
files.add(dsp); |
|
129 |
} |
|
130 |
break; |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
return files; |
|
135 |
} |
|
151 |
for (i = 0; i < files.length; i++) { |
|
152 |
theFile = new File(this.root, files[i]); |
|
153 |
dsp = this.createStoreParameters(theFile); |
|
154 |
if (dsp != null) { |
|
155 |
list.add(dsp); |
|
156 |
} |
|
157 |
} |
|
158 |
return list; |
|
159 |
} |
|
136 | 160 |
|
137 |
public List list() throws DataException { |
|
138 |
if (this.current == null) { |
|
139 |
throw new IllegalStateException(); // FIXME |
|
140 |
} |
|
141 |
if (!this.current.exists()) { |
|
142 |
// TODO crear excepcion de Data?? |
|
143 |
new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
|
144 |
} |
|
161 |
public void setCurrentPath(File path) throws FileNotFoundException { |
|
162 |
// FIXME Comprobar si es un directorio existente |
|
163 |
if (!path.exists()) { |
|
164 |
throw new FileNotFoundException(path); |
|
165 |
} |
|
166 |
if (!path.isDirectory()) { |
|
167 |
throw new IllegalArgumentException(path.getPath() |
|
168 |
+ " is not a directory"); |
|
169 |
} |
|
170 |
if (!isFromRoot(path)) { |
|
171 |
throw new IllegalArgumentException(path.getPath() |
|
172 |
+ " is not from root"); |
|
145 | 173 |
|
146 |
if (!this.current.isDirectory()) { |
|
147 |
new IllegalArgumentException(this.getProviderName() |
|
148 |
+ ": Path not a directory '" + this.current + "'"); |
|
149 |
} |
|
174 |
} |
|
150 | 175 |
|
151 |
String files[] = this.current.list(); |
|
152 |
int i; |
|
153 |
File theFile; |
|
154 |
ArrayList list = new ArrayList(); |
|
155 |
DataStoreParameters dsp = null; |
|
176 |
this.current = path; |
|
177 |
} |
|
156 | 178 |
|
157 |
for (i = 0; i < files.length; i++) { |
|
158 |
theFile = new File(this.root, files[i]); |
|
159 |
dsp = this.createStoreParameters(theFile); |
|
160 |
if (dsp != null) { |
|
161 |
list.add(dsp); |
|
162 |
} |
|
163 |
} |
|
164 |
return list; |
|
165 |
} |
|
179 |
public File getCurrentPath() { |
|
180 |
return this.current; |
|
181 |
} |
|
166 | 182 |
|
167 |
public void setCurrentPath(File path) throws FileNotFoundException { |
|
168 |
// FIXME Comprobar si es un directorio existente |
|
169 |
if (!path.exists()) { |
|
170 |
throw new FileNotFoundException(path); |
|
171 |
} |
|
172 |
if (!path.isDirectory()) { |
|
173 |
throw new IllegalArgumentException(path.getPath() |
|
174 |
+ " is not a directory"); |
|
175 |
} |
|
176 |
if (!isFromRoot(path)) { |
|
177 |
throw new IllegalArgumentException(path.getPath() |
|
178 |
+ " is not from root"); |
|
183 |
public File getRoot() { |
|
184 |
return this.root; |
|
185 |
} |
|
179 | 186 |
|
180 |
} |
|
187 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
|
188 |
String providerName = dsp.getDataStoreName(); |
|
189 |
try { |
|
190 |
this.checkIsMine(dsp); |
|
191 |
FilesystemServerExplorerProvider provider = this |
|
192 |
.getProvider(providerName); |
|
181 | 193 |
|
182 |
this.current = path; |
|
183 |
} |
|
194 |
provider.remove(dsp); |
|
195 |
} catch (DataException e) { |
|
196 |
throw new RemoveException(this.getProviderName(), e); |
|
197 |
} |
|
198 |
} |
|
184 | 199 |
|
185 |
public File getCurrentPath() { |
|
186 |
return this.current; |
|
187 |
} |
|
200 |
public boolean add(String providerName, NewDataStoreParameters ndsp, |
|
201 |
boolean overwrite) throws DataException { |
|
188 | 202 |
|
189 |
public File getRoot() { |
|
190 |
return this.root; |
|
191 |
} |
|
203 |
try { |
|
204 |
this.checkIsMine(ndsp); |
|
205 |
FilesystemServerExplorerProvider provider = this |
|
206 |
.getProvider(providerName); |
|
192 | 207 |
|
193 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
|
194 |
String providerName = dsp.getDataStoreName(); |
|
195 |
try { |
|
196 |
this.checkIsMine(dsp); |
|
197 |
FilesystemServerExplorerProvider provider = this |
|
198 |
.getProvider(providerName); |
|
208 |
ndsp.validate(); |
|
209 |
provider.create(ndsp, overwrite); |
|
210 |
return true; |
|
211 |
} catch (DataException e) { |
|
212 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
|
213 |
} catch (ValidateDataParametersException e) { |
|
214 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
|
215 |
} |
|
216 |
} |
|
199 | 217 |
|
200 |
provider.remove(dsp); |
|
201 |
} catch (DataException e) { |
|
202 |
throw new RemoveException(this.getProviderName(), e); |
|
203 |
} |
|
204 |
} |
|
218 |
public boolean canAdd() { |
|
219 |
return this.root.canWrite(); |
|
220 |
} |
|
205 | 221 |
|
206 |
public boolean add(String providerName, NewDataStoreParameters ndsp, |
|
207 |
boolean overwrite) throws DataException { |
|
222 |
public String getProviderName() { |
|
223 |
return FilesystemServerExplorer.NAME; |
|
224 |
} |
|
208 | 225 |
|
209 |
try { |
|
210 |
this.checkIsMine(ndsp); |
|
211 |
FilesystemServerExplorerProvider provider = this |
|
212 |
.getProvider(providerName); |
|
226 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
227 |
throws DataException { |
|
228 |
FilesystemServerExplorerProvider provider = this.getProvider(storeName); |
|
229 |
if (provider == null) { |
|
230 |
throw new IllegalArgumentException( |
|
231 |
"Not registered in this explorer"); // FIXME |
|
232 |
} |
|
213 | 233 |
|
214 |
ndsp.validate(); |
|
215 |
provider.create(ndsp, overwrite); |
|
216 |
return true; |
|
217 |
} catch (DataException e) { |
|
218 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
|
219 |
} catch (ValidateDataParametersException e) { |
|
220 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
|
221 |
} |
|
222 |
} |
|
234 |
NewDataStoreParameters nParams = provider.getCreateParameters(); |
|
235 |
// nParams.setAttribute("path", this.getCurrentPath().getPath()); |
|
236 |
return nParams; |
|
237 |
} |
|
223 | 238 |
|
224 |
public boolean canAdd() { |
|
225 |
return this.root.canWrite(); |
|
226 |
} |
|
239 |
public boolean canAdd(String storeName) throws DataException { |
|
240 |
if (storeName == null) { |
|
241 |
return false;// CanAdd with genericFilter |
|
242 |
} |
|
243 |
FilesystemServerExplorerProvider provider = this.getProvider(storeName); |
|
244 |
if (provider == null) { |
|
245 |
throw new IllegalArgumentException( |
|
246 |
"Not registered in this explorer"); // FIXME |
|
247 |
} |
|
227 | 248 |
|
228 |
public String getProviderName() { |
|
229 |
return FilesystemServerExplorer.NAME; |
|
230 |
} |
|
249 |
return provider.canCreate(); |
|
231 | 250 |
|
232 |
public NewDataStoreParameters getAddParameters(String storeName) |
|
233 |
throws DataException { |
|
234 |
FilesystemServerExplorerProvider provider = this.getProvider(storeName); |
|
235 |
if (provider == null) { |
|
236 |
throw new IllegalArgumentException( |
|
237 |
"Not registered in this explorer"); // FIXME |
|
238 |
} |
|
251 |
} |
|
239 | 252 |
|
240 |
NewDataStoreParameters nParams = provider.getCreateParameters(); |
|
241 |
// nParams.setAttribute("path", this.getCurrentPath().getPath()); |
|
242 |
return nParams; |
|
243 |
} |
|
253 |
// ========================================== |
|
254 |
private FilesystemServerExplorerProvider getProvider(String storeName) |
|
255 |
throws InitializeException, ProviderNotRegisteredException { |
|
256 |
Iterator providers = getProviders(FilesystemServerExplorer.MODE_ALL).iterator(); |
|
257 |
FilesystemServerExplorerProvider provider; |
|
258 |
while (providers.hasNext()) { |
|
259 |
provider = (FilesystemServerExplorerProvider) providers.next(); |
|
260 |
if (provider.getDataStoreProviderName().equals(storeName)) { |
|
261 |
return provider; |
|
262 |
} |
|
263 |
} |
|
264 |
return null; |
|
265 |
} |
|
244 | 266 |
|
245 |
public boolean canAdd(String storeName) throws DataException { |
|
246 |
if (storeName == null) { |
|
247 |
return false;// CanAdd with genericFilter |
|
248 |
} |
|
249 |
FilesystemServerExplorerProvider provider = this.getProvider(storeName); |
|
250 |
if (provider == null) { |
|
251 |
throw new IllegalArgumentException( |
|
252 |
"Not registered in this explorer"); // FIXME |
|
253 |
} |
|
267 |
private DataManagerProviderServices getManager() { |
|
268 |
return (DataManagerProviderServices) DALLocator.getDataManager(); |
|
269 |
} |
|
254 | 270 |
|
255 |
return provider.canCreate();
|
|
271 |
public DataStoreParameters createStoreParameters(File file, String providerName) throws DataException {
|
|
256 | 272 |
|
257 |
} |
|
273 |
return this.getParametersFor(file, providerName, true); |
|
274 |
} |
|
258 | 275 |
|
259 |
// ==========================================
|
|
276 |
public DataStoreParameters createStoreParameters(File file) throws DataException {
|
|
260 | 277 |
|
261 |
private FilesystemServerExplorerProvider getProvider(String storeName) |
|
262 |
throws InitializeException, ProviderNotRegisteredException { |
|
263 |
Iterator providers = getProviders(FilesystemServerExplorer.MODE_ALL).iterator(); |
|
264 |
FilesystemServerExplorerProvider provider; |
|
265 |
while (providers.hasNext()) { |
|
266 |
provider = (FilesystemServerExplorerProvider) providers.next(); |
|
267 |
if (provider.getDataStoreProviderName().equals(storeName)) { |
|
268 |
return provider; |
|
269 |
} |
|
270 |
} |
|
271 |
return null; |
|
272 |
} |
|
278 |
return this.getParametersFor(file, null, true); |
|
279 |
} |
|
273 | 280 |
|
274 |
private DataManagerProviderServices getManager() { |
|
275 |
return (DataManagerProviderServices) DALLocator.getDataManager(); |
|
276 |
} |
|
277 |
|
|
278 |
public DataStoreParameters createStoreParameters(File file, String providerName) throws DataException { |
|
281 |
public DataStoreParameters getParametersFor(File file, String providerName, boolean checksExist) throws DataException { |
|
279 | 282 |
|
280 |
return this.getParametersFor(file, providerName, true); |
|
281 |
} |
|
283 |
if (checksExist) { |
|
284 |
if (!file.exists()) { |
|
285 |
return null; |
|
286 |
} |
|
287 |
if (!file.isFile()) { |
|
288 |
return null; |
|
289 |
} |
|
290 |
if (!file.canRead()) { |
|
291 |
return null; |
|
292 |
} |
|
293 |
if (file.isHidden()) { // XXX ??? |
|
294 |
return null; |
|
295 |
} |
|
296 |
} |
|
297 |
if (providerName == null) { |
|
298 |
providerName = this.getProviderName(file); |
|
299 |
} |
|
300 |
if (providerName != null) { |
|
301 |
DataStoreParameters params = this.getManager() |
|
302 |
.createStoreParameters(providerName); |
|
303 |
((FilesystemStoreParameters) params).setFile(file); |
|
304 |
return params; |
|
282 | 305 |
|
283 |
public DataStoreParameters createStoreParameters(File file) throws DataException { |
|
306 |
} |
|
307 |
return null; |
|
308 |
} |
|
284 | 309 |
|
285 |
return this.getParametersFor(file, null, true); |
|
286 |
} |
|
287 |
|
|
288 |
public DataStoreParameters getParametersFor(File file, String providerName, boolean checksExist) throws DataException { |
|
289 |
|
|
290 |
if (checksExist) { |
|
291 |
if (!file.exists()) { |
|
292 |
return null; |
|
293 |
} |
|
294 |
if (!file.isFile()) { |
|
295 |
return null; |
|
296 |
} |
|
297 |
if (!file.canRead()) { |
|
298 |
return null; |
|
299 |
} |
|
300 |
if (file.isHidden()) { // XXX ??? |
|
301 |
return null; |
|
302 |
} |
|
303 |
} |
|
304 |
if(providerName == null) |
|
305 |
providerName = this.getProviderName(file); |
|
306 |
if (providerName != null) { |
|
307 |
DataStoreParameters params = this.getManager() |
|
308 |
.createStoreParameters(providerName); |
|
309 |
((FilesystemStoreParameters) params).setFile(file); |
|
310 |
return params; |
|
310 |
public List getProviderNameList(File file) { |
|
311 |
Iterator filters = getFilters(); |
|
312 |
List list = new ArrayList(); |
|
313 |
while (filters.hasNext()) { |
|
314 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
315 |
if (filter.accept(file)) { |
|
316 |
list.add(filter.getDataStoreProviderName()); |
|
317 |
} |
|
318 |
} |
|
319 |
return list; |
|
320 |
} |
|
311 | 321 |
|
312 |
} |
|
313 |
return null; |
|
314 |
} |
|
315 |
|
|
316 |
public List getProviderNameList(File file) { |
|
317 |
Iterator filters = getFilters(); |
|
318 |
List list = new ArrayList(); |
|
319 |
while (filters.hasNext()) { |
|
320 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
321 |
if (filter.accept(file)) { |
|
322 |
list.add(filter.getDataStoreProviderName()); |
|
323 |
} |
|
324 |
} |
|
325 |
return list; |
|
326 |
} |
|
322 |
public String getProviderName(File file) { |
|
323 |
Iterator filters = getFilters(); |
|
324 |
while (filters.hasNext()) { |
|
325 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
326 |
if (filter.accept(file)) { |
|
327 |
return filter.getDataStoreProviderName(); |
|
328 |
} |
|
329 |
} |
|
330 |
return null; |
|
331 |
} |
|
327 | 332 |
|
328 |
public String getProviderName(File file) { |
|
329 |
Iterator filters = getFilters(); |
|
330 |
while (filters.hasNext()) { |
|
331 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
332 |
if (filter.accept(file)) { |
|
333 |
return filter.getDataStoreProviderName(); |
|
334 |
} |
|
335 |
} |
|
336 |
return null; |
|
337 |
} |
|
333 |
public List getDataStoreProviderNames() { |
|
334 |
Set names = new HashSet(); |
|
338 | 335 |
|
339 |
public List getDataStoreProviderNames() { |
|
340 |
Set names = new HashSet(); |
|
341 |
|
|
342 |
Iterator filters = getFilters(); |
|
343 |
while (filters.hasNext()) { |
|
344 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
345 |
names.add(filter.getDataStoreProviderName()); |
|
346 |
} |
|
347 |
return new ArrayList(names); |
|
348 |
} |
|
336 |
Iterator filters = getFilters(); |
|
337 |
while (filters.hasNext()) { |
|
338 |
FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
|
339 |
names.add(filter.getDataStoreProviderName()); |
|
340 |
} |
|
341 |
return new ArrayList(names); |
|
342 |
} |
|
349 | 343 |
|
350 |
private void checkIsMine(DataStoreParameters dsp)
|
|
351 |
throws IllegalArgumentException, DataException {
|
|
352 |
// FIXME Exception ???
|
|
353 |
if (!(dsp instanceof FilesystemStoreParameters)) {
|
|
354 |
new IllegalArgumentException(
|
|
355 |
"not instance of FilesystemStoreParameters");
|
|
356 |
}
|
|
357 |
Iterator filters = getFilters();
|
|
358 |
File file = ((FilesystemStoreParameters) dsp).getFile();
|
|
359 |
if (!this.isFromRoot(file)) {
|
|
360 |
throw new IllegalArgumentException("worng explorer");
|
|
361 |
}
|
|
362 |
FilesystemFileFilter filter;
|
|
363 |
while (filters.hasNext()) {
|
|
364 |
filter = (FilesystemFileFilter) filters.next();
|
|
365 |
if (dsp.getDataStoreName()
|
|
366 |
.equals(filter.getDataStoreProviderName())) {
|
|
367 |
return;
|
|
368 |
}
|
|
369 |
}
|
|
370 |
throw new IllegalArgumentException("worng explorer");
|
|
371 |
}
|
|
344 |
private void checkIsMine(DataStoreParameters dsp)
|
|
345 |
throws IllegalArgumentException, DataException {
|
|
346 |
// FIXME Exception ???
|
|
347 |
if (!(dsp instanceof FilesystemStoreParameters)) {
|
|
348 |
new IllegalArgumentException(
|
|
349 |
"not instance of FilesystemStoreParameters");
|
|
350 |
}
|
|
351 |
Iterator filters = getFilters();
|
|
352 |
File file = ((FilesystemStoreParameters) dsp).getFile();
|
|
353 |
if (!this.isFromRoot(file)) {
|
|
354 |
throw new IllegalArgumentException("worng explorer");
|
|
355 |
}
|
|
356 |
FilesystemFileFilter filter;
|
|
357 |
while (filters.hasNext()) {
|
|
358 |
filter = (FilesystemFileFilter) filters.next();
|
|
359 |
if (dsp.getDataStoreName()
|
|
360 |
.equals(filter.getDataStoreProviderName())) {
|
|
361 |
return;
|
|
362 |
}
|
|
363 |
}
|
|
364 |
throw new IllegalArgumentException("worng explorer");
|
|
365 |
}
|
|
372 | 366 |
|
373 |
private boolean isFromRoot(File file) {
|
|
374 |
if (this.root == null) {
|
|
375 |
return true;
|
|
376 |
}
|
|
377 |
return file.getAbsolutePath().startsWith(this.root.getAbsolutePath());
|
|
378 |
}
|
|
367 |
private boolean isFromRoot(File file) {
|
|
368 |
if (this.root == null) {
|
|
369 |
return true;
|
|
370 |
}
|
|
371 |
return file.getAbsolutePath().startsWith(this.root.getAbsolutePath());
|
|
372 |
}
|
|
379 | 373 |
|
380 |
public List getProviders() {
|
|
381 |
if (this.serverProviders == null) {
|
|
382 |
Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
|
|
383 |
.getRegisteredProviders();
|
|
384 |
this.serverProviders = new ArrayList();
|
|
385 |
Extension ext;
|
|
386 |
FilesystemServerExplorerProvider provider;
|
|
387 |
while (iter.hasNext()) {
|
|
388 |
ext = (Extension) iter.next();
|
|
389 |
try {
|
|
390 |
provider = (FilesystemServerExplorerProvider) ext.create();
|
|
391 |
} catch (Exception e) {
|
|
392 |
throw new RuntimeException(e);// FIXME !!!
|
|
393 |
}
|
|
394 |
provider.initialize(this);
|
|
395 |
this.serverProviders.add(provider);
|
|
396 |
}
|
|
397 |
}
|
|
398 |
return this.serverProviders;
|
|
399 |
}
|
|
374 |
public List getProviders() {
|
|
375 |
if (this.serverProviders == null) {
|
|
376 |
Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
|
|
377 |
.getRegisteredProviders();
|
|
378 |
this.serverProviders = new ArrayList();
|
|
379 |
Extension ext;
|
|
380 |
FilesystemServerExplorerProvider provider;
|
|
381 |
while (iter.hasNext()) {
|
|
382 |
ext = (Extension) iter.next();
|
|
383 |
try {
|
|
384 |
provider = (FilesystemServerExplorerProvider) ext.create();
|
|
385 |
} catch (Exception e) {
|
|
386 |
throw new RuntimeException(e);// FIXME !!!
|
|
387 |
}
|
|
388 |
provider.initialize(this);
|
|
389 |
this.serverProviders.add(provider);
|
|
390 |
}
|
|
391 |
}
|
|
392 |
return this.serverProviders;
|
|
393 |
}
|
|
400 | 394 |
|
401 |
public List getProviders(int mode) {
|
|
402 |
Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
|
|
403 |
.getRegisteredProviders();
|
|
404 |
List providers = new ArrayList();
|
|
405 |
Extension ext;
|
|
406 |
FilesystemServerExplorerProvider provider;
|
|
407 |
while (iter.hasNext()) {
|
|
408 |
ext = (Extension) iter.next();
|
|
409 |
try {
|
|
410 |
provider = (FilesystemServerExplorerProvider) ext.create();
|
|
411 |
} catch (Exception e) {
|
|
412 |
throw new RuntimeException(e);// FIXME !!!
|
|
413 |
}
|
|
414 |
if (provider.isMode(mode)) {
|
|
415 |
provider.initialize(this);
|
|
416 |
providers.add(provider);
|
|
417 |
}
|
|
418 |
}
|
|
419 |
return providers;
|
|
420 |
}
|
|
395 |
public List getProviders(int mode) {
|
|
396 |
Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
|
|
397 |
.getRegisteredProviders();
|
|
398 |
List providers = new ArrayList();
|
|
399 |
Extension ext;
|
|
400 |
FilesystemServerExplorerProvider provider;
|
|
401 |
while (iter.hasNext()) {
|
|
402 |
ext = (Extension) iter.next();
|
|
403 |
try {
|
|
404 |
provider = (FilesystemServerExplorerProvider) ext.create();
|
|
405 |
} catch (Exception e) {
|
|
406 |
throw new RuntimeException(e);// FIXME !!!
|
|
407 |
}
|
|
408 |
if (provider.isMode(mode)) {
|
|
409 |
provider.initialize(this);
|
|
410 |
providers.add(provider);
|
|
411 |
}
|
|
412 |
}
|
|
413 |
return providers;
|
|
414 |
}
|
|
421 | 415 |
|
422 |
public Iterator getFilters(int mode) { |
|
423 |
return this.getProviders(mode).iterator(); |
|
424 |
} |
|
425 |
|
|
426 |
public Iterator getFilters() { |
|
427 |
return this.getProviders().iterator(); |
|
428 |
} |
|
416 |
public Iterator getFilters(int mode) { |
|
417 |
return this.getProviders(mode).iterator(); |
|
418 |
} |
|
429 | 419 |
|
430 |
public FilesystemFileFilter getFilter(int mode, final String description ) { |
|
431 |
|
|
432 |
final List filters = new ArrayList(); |
|
433 |
Iterator it = this.getFilters(mode); |
|
434 |
while( it.hasNext() ) { |
|
435 |
filters.add( it.next() ); |
|
436 |
} |
|
437 |
FilesystemFileFilter filter = new FilesystemFileFilter() { |
|
438 |
|
|
439 |
public boolean accept(File f) { |
|
440 |
if (f.isDirectory()) { |
|
441 |
return true; |
|
442 |
} |
|
443 |
for(int i=0; i<filters.size(); i++) { |
|
444 |
if( ((FilesystemFileFilter)filters.get(i)).accept(f) ) { |
|
445 |
return true; |
|
446 |
} |
|
447 |
} |
|
448 |
return false; |
|
449 |
} |
|
450 |
|
|
451 |
public String getDescription() { |
|
452 |
return description; |
|
453 |
} |
|
454 |
|
|
455 |
public String getDataStoreProviderName() { |
|
456 |
return null; |
|
457 |
} |
|
458 |
}; |
|
459 |
return filter; |
|
460 |
} |
|
420 |
public Iterator getFilters() { |
|
421 |
return this.getProviders().iterator(); |
|
422 |
} |
|
461 | 423 |
|
462 |
public FilesystemFileFilter getGenericFilter() { |
|
463 |
// FIXME: Este metodo, getGenericFilter, no tengo claro que deba existir (jjdc) |
|
464 |
return this; |
|
465 |
} |
|
424 |
public FilesystemFileFilter getFilter(int mode, final String description) { |
|
466 | 425 |
|
467 |
public String getDataStoreProviderName() { |
|
468 |
return null; |
|
469 |
} |
|
426 |
final List filters = new ArrayList(); |
|
427 |
Iterator it = this.getFilters(mode); |
|
428 |
while (it.hasNext()) { |
|
429 |
filters.add(it.next()); |
|
430 |
} |
|
431 |
FilesystemFileFilter filter = new FilesystemFileFilter() { |
|
470 | 432 |
|
471 |
public String getDescription() { |
|
472 |
return "All supporteds"; |
|
473 |
} |
|
433 |
public boolean accept(File f) { |
|
434 |
if (f.isDirectory()) { |
|
435 |
return true; |
|
436 |
} |
|
437 |
for (int i = 0; i < filters.size(); i++) { |
|
438 |
if (((FilesystemFileFilter) filters.get(i)).accept(f)) { |
|
439 |
return true; |
|
440 |
} |
|
441 |
} |
|
442 |
return false; |
|
443 |
} |
|
474 | 444 |
|
475 |
public boolean accept(File pathname) { |
|
476 |
try { |
|
477 |
return this.createStoreParameters(pathname) != null; |
|
478 |
} catch (DataException e) { |
|
479 |
throw new RuntimeException(e); // FIXME excpetion?? |
|
480 |
} |
|
481 |
} |
|
445 |
public String getDescription() { |
|
446 |
return description; |
|
447 |
} |
|
482 | 448 |
|
483 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() { |
|
484 |
return this.providerServices; |
|
485 |
} |
|
449 |
public String getDataStoreProviderName() { |
|
450 |
return null; |
|
451 |
} |
|
452 |
}; |
|
453 |
return filter; |
|
454 |
} |
|
486 | 455 |
|
487 |
public DataStore open(File file) throws DataException, |
|
488 |
ValidateDataParametersException { |
|
489 |
DataManager manager = DALLocator.getDataManager(); |
|
490 |
String providerName = this.getProviderName(file); |
|
491 |
|
|
456 |
public FilesystemFileFilter getGenericFilter() { |
|
457 |
// FIXME: Este metodo, getGenericFilter, no tengo claro que deba existir (jjdc) |
|
458 |
return this; |
|
459 |
} |
|
460 |
|
|
461 |
public String getDataStoreProviderName() { |
|
462 |
return null; |
|
463 |
} |
|
464 |
|
|
465 |
public String getDescription() { |
|
466 |
return "All supporteds"; |
|
467 |
} |
|
468 |
|
|
469 |
public boolean accept(File pathname) { |
|
470 |
try { |
|
471 |
return this.createStoreParameters(pathname) != null; |
|
472 |
} catch (DataException e) { |
|
473 |
throw new RuntimeException(e); // FIXME excpetion?? |
|
474 |
} |
|
475 |
} |
|
476 |
|
|
477 |
public DataStore open(File file) throws DataException, |
|
478 |
ValidateDataParametersException { |
|
479 |
DataManager manager = DALLocator.getDataManager(); |
|
480 |
String providerName = this.getProviderName(file); |
|
481 |
|
|
492 | 482 |
DataStoreParameters params = this.getAddParameters(file); |
493 |
return manager.openStore(providerName, params);
|
|
494 |
}
|
|
483 |
return manager.openStore(providerName, params);
|
|
484 |
}
|
|
495 | 485 |
|
496 |
public NewDataStoreParameters getAddParameters(File file)
|
|
497 |
throws DataException {
|
|
498 |
DataStoreParameters params = this.getParametersFor(file, null, false);
|
|
499 |
NewDataStoreParameters newParams = this.getAddParameters(params
|
|
500 |
.getDataStoreName());
|
|
501 |
((FilesystemStoreParameters) newParams)
|
|
502 |
.setFile(((FilesystemStoreParameters) params).getFile());
|
|
503 |
return newParams;
|
|
504 |
}
|
|
486 |
public NewDataStoreParameters getAddParameters(File file)
|
|
487 |
throws DataException {
|
|
488 |
DataStoreParameters params = this.getParametersFor(file, null, false);
|
|
489 |
NewDataStoreParameters newParams = this.getAddParameters(params
|
|
490 |
.getDataStoreName());
|
|
491 |
((FilesystemStoreParameters) newParams)
|
|
492 |
.setFile(((FilesystemStoreParameters) params).getFile());
|
|
493 |
return newParams;
|
|
494 |
}
|
|
505 | 495 |
|
506 |
public File getResourcePath(DataStore dataStore, String resourceName) throws DataException { |
|
507 |
FilesystemServerExplorerProvider provider = |
|
508 |
this.getProvider(dataStore.getProviderName()); |
|
509 |
if (provider == null){ |
|
510 |
return null; |
|
511 |
} |
|
512 |
String rootPath = provider.getResourceRootPathName(dataStore); |
|
513 |
if (rootPath == null){ |
|
514 |
return null; |
|
515 |
} |
|
516 |
return new File(rootPath + "." + resourceName); |
|
517 |
} |
|
496 |
public File getResourcePath(DataStore dataStore, String resourceName) throws DataException { |
|
497 |
FilesystemServerExplorerProvider provider |
|
498 |
= this.getProvider(dataStore.getProviderName()); |
|
499 |
if (provider == null) { |
|
500 |
return null; |
|
501 |
} |
|
502 |
String rootPath = provider.getResourceRootPathName(dataStore); |
|
503 |
if (rootPath == null) { |
|
504 |
return null; |
|
505 |
} |
|
506 |
return new File(rootPath + "." + resourceName); |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public DataStoreParameters get(String name) throws DataException { |
|
511 |
File theFile = new File(this.current,name); |
|
512 |
DataStoreParameters dsp = this.createStoreParameters(theFile); |
|
513 |
return dsp; |
|
514 |
} |
|
518 | 515 |
} |
Also available in: Unified diff