svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.file / src / main / java / org / gvsig / exportto / swing / prov / file / AbstractExporttoFileService.java @ 37780
History | View | Annotate | Download (5.21 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
9 |
* of the License, or (at your option) any later version.
|
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.
|
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.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.exportto.swing.prov.file; |
23 |
|
24 |
import java.io.File; |
25 |
|
26 |
import org.gvsig.exportto.ExporttoLocator; |
27 |
import org.gvsig.exportto.ExporttoManager; |
28 |
import org.gvsig.exportto.ExporttoService; |
29 |
import org.gvsig.exportto.ExporttoServiceException; |
30 |
import org.gvsig.exportto.ExporttoServiceFinishAction; |
31 |
import org.gvsig.fmap.dal.DALLocator; |
32 |
import org.gvsig.fmap.dal.DataManager; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
36 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
37 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
39 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
40 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
41 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
42 |
import org.gvsig.tools.task.TaskStatus; |
43 |
|
44 |
/**
|
45 |
* @author gvSIG Team
|
46 |
* @version $Id$
|
47 |
*
|
48 |
*/
|
49 |
public abstract class AbstractExporttoFileService implements ExporttoService { |
50 |
|
51 |
protected static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator |
52 |
.getManager(); |
53 |
protected File file; |
54 |
protected FeatureStore featureStore;
|
55 |
protected ExporttoService exporttoService;
|
56 |
|
57 |
private NewFeatureStoreParameters newFeatureStoreParameters;
|
58 |
private ExporttoServiceFinishAction exporttoServiceFinishAction;
|
59 |
|
60 |
public AbstractExporttoFileService(File file, FeatureStore featureStore) { |
61 |
super();
|
62 |
this.featureStore = featureStore;
|
63 |
this.file = file;
|
64 |
} |
65 |
|
66 |
public void open() throws ExporttoServiceException { |
67 |
String path = file.getAbsolutePath();
|
68 |
|
69 |
String extension = "." + getFileExtension(); |
70 |
|
71 |
if (!(path.toLowerCase().endsWith(extension))) {
|
72 |
path = path + extension; |
73 |
} |
74 |
|
75 |
File newFile = new File(path); |
76 |
DataManager dataManager = DALLocator.getDataManager(); |
77 |
|
78 |
FilesystemServerExplorerParameters explorerParams; |
79 |
try {
|
80 |
explorerParams = |
81 |
(FilesystemServerExplorerParameters) dataManager |
82 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
83 |
} catch (InitializeException e) {
|
84 |
throw new ExporttoServiceException(e); |
85 |
} catch (ProviderNotRegisteredException e) {
|
86 |
throw new ExporttoServiceException(e); |
87 |
} |
88 |
explorerParams.setRoot(newFile.getParent()); |
89 |
|
90 |
FilesystemServerExplorer explorer; |
91 |
try {
|
92 |
explorer = |
93 |
(FilesystemServerExplorer) dataManager.openServerExplorer( |
94 |
"FilesystemExplorer", explorerParams);
|
95 |
} catch (ValidateDataParametersException e) {
|
96 |
throw new ExporttoServiceException(e); |
97 |
} catch (InitializeException e) {
|
98 |
throw new ExporttoServiceException(e); |
99 |
} catch (ProviderNotRegisteredException e) {
|
100 |
throw new ExporttoServiceException(e); |
101 |
} |
102 |
|
103 |
try {
|
104 |
newFeatureStoreParameters = |
105 |
(NewFeatureStoreParameters) explorer.getAddParameters(newFile); |
106 |
addParameters(newFeatureStoreParameters); |
107 |
|
108 |
exporttoService = |
109 |
EXPORTTO_MANAGER.getExporttoService(explorer, |
110 |
newFeatureStoreParameters); |
111 |
} catch (DataException e) {
|
112 |
throw new ExporttoServiceException(e); |
113 |
} |
114 |
} |
115 |
|
116 |
public abstract void addParameters( |
117 |
NewFeatureStoreParameters newFeatureStoreParameters) |
118 |
throws DataException;
|
119 |
|
120 |
public abstract String getFileExtension(); |
121 |
|
122 |
public void export(FeatureSet featureSet) throws ExporttoServiceException { |
123 |
exporttoService.export(featureSet); |
124 |
if (exporttoServiceFinishAction != null) { |
125 |
exporttoServiceFinishAction.finished(file.getName(), |
126 |
newFeatureStoreParameters); |
127 |
} |
128 |
} |
129 |
|
130 |
public void setFinishAction( |
131 |
ExporttoServiceFinishAction exporttoServiceFinishAction) { |
132 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction;
|
133 |
} |
134 |
|
135 |
public TaskStatus getTaskStatus() {
|
136 |
return exporttoService.getTaskStatus();
|
137 |
} |
138 |
|
139 |
public boolean isCancellationRequested() { |
140 |
return exporttoService.isCancellationRequested();
|
141 |
} |
142 |
|
143 |
public void cancelRequest() { |
144 |
exporttoService.cancelRequest(); |
145 |
} |
146 |
} |