svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / 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 @ 43502
History | View | Annotate | Download (5.68 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.exportto.swing.prov.file; |
||
25 | |||
26 | import java.io.File; |
||
27 | |||
28 | import org.gvsig.exportto.ExporttoLocator; |
||
29 | import org.gvsig.exportto.ExporttoManager; |
||
30 | import org.gvsig.exportto.ExporttoService; |
||
31 | import org.gvsig.exportto.ExporttoServiceException; |
||
32 | import org.gvsig.exportto.ExporttoServiceFinishAction; |
||
33 | import org.gvsig.fmap.dal.DALLocator; |
||
34 | import org.gvsig.fmap.dal.DataManager; |
||
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
37 | import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
39 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
40 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
41 | 43364 | jjdelcerro | import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
42 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
43 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
44 | import org.gvsig.tools.task.TaskStatus; |
||
45 | 43502 | jjdelcerro | import org.slf4j.Logger; |
46 | import org.slf4j.LoggerFactory; |
||
47 | 40435 | jjdelcerro | |
48 | /**
|
||
49 | * @author gvSIG Team
|
||
50 | * @version $Id$
|
||
51 | *
|
||
52 | */
|
||
53 | public abstract class AbstractExporttoFileService implements ExporttoService { |
||
54 | |||
55 | 43502 | jjdelcerro | protected static final Logger LOG = LoggerFactory.getLogger(AbstractExporttoFileService.class); |
56 | |||
57 | 40435 | jjdelcerro | protected static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator |
58 | .getManager(); |
||
59 | protected File file; |
||
60 | protected FeatureStore featureStore;
|
||
61 | protected ExporttoService exporttoService;
|
||
62 | |||
63 | private NewFeatureStoreParameters newFeatureStoreParameters;
|
||
64 | 43364 | jjdelcerro | private OpenFeatureStoreParameters openFeatureStoreParameters;
|
65 | 40435 | jjdelcerro | private ExporttoServiceFinishAction exporttoServiceFinishAction;
|
66 | |||
67 | public AbstractExporttoFileService(File file, FeatureStore featureStore) { |
||
68 | super();
|
||
69 | this.featureStore = featureStore;
|
||
70 | this.file = file;
|
||
71 | } |
||
72 | |||
73 | public void open() throws ExporttoServiceException { |
||
74 | String path = file.getAbsolutePath();
|
||
75 | |||
76 | String extension = "." + getFileExtension(); |
||
77 | |||
78 | if (!(path.toLowerCase().endsWith(extension))) {
|
||
79 | path = path + extension; |
||
80 | } |
||
81 | |||
82 | File newFile = new File(path); |
||
83 | DataManager dataManager = DALLocator.getDataManager(); |
||
84 | |||
85 | FilesystemServerExplorerParameters explorerParams; |
||
86 | try {
|
||
87 | explorerParams = |
||
88 | (FilesystemServerExplorerParameters) dataManager |
||
89 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
90 | } catch (InitializeException e) {
|
||
91 | throw new ExporttoServiceException(e); |
||
92 | } catch (ProviderNotRegisteredException e) {
|
||
93 | throw new ExporttoServiceException(e); |
||
94 | } |
||
95 | explorerParams.setRoot(newFile.getParent()); |
||
96 | |||
97 | FilesystemServerExplorer explorer; |
||
98 | try {
|
||
99 | 43396 | jjdelcerro | explorer = (FilesystemServerExplorer) dataManager.openServerExplorer( |
100 | "FilesystemExplorer", explorerParams
|
||
101 | ); |
||
102 | String providerName = explorer.getProviderName(file);
|
||
103 | openFeatureStoreParameters = (OpenFeatureStoreParameters) dataManager.createStoreParameters(providerName); |
||
104 | // openFeatureStoreParameters = (OpenFeatureStoreParameters) explorer.createStoreParameters(newFile);
|
||
105 | 43364 | jjdelcerro | addParameters(openFeatureStoreParameters); |
106 | newFeatureStoreParameters = (NewFeatureStoreParameters) explorer.getAddParameters(newFile); |
||
107 | 40435 | jjdelcerro | addParameters(newFeatureStoreParameters); |
108 | |||
109 | 43364 | jjdelcerro | exporttoService = EXPORTTO_MANAGER.getExporttoService( |
110 | explorer, |
||
111 | newFeatureStoreParameters, |
||
112 | openFeatureStoreParameters |
||
113 | ); |
||
114 | |||
115 | |||
116 | 43396 | jjdelcerro | } catch (Exception e) { |
117 | 40435 | jjdelcerro | throw new ExporttoServiceException(e); |
118 | } |
||
119 | } |
||
120 | |||
121 | public abstract void addParameters( |
||
122 | NewFeatureStoreParameters newFeatureStoreParameters) |
||
123 | throws DataException;
|
||
124 | |||
125 | 43364 | jjdelcerro | public abstract void addParameters( |
126 | OpenFeatureStoreParameters openFeatureStoreParameters) |
||
127 | throws DataException;
|
||
128 | |||
129 | 40435 | jjdelcerro | public abstract String getFileExtension(); |
130 | |||
131 | public void export(FeatureSet featureSet) throws ExporttoServiceException { |
||
132 | exporttoService.export(featureSet); |
||
133 | if (exporttoServiceFinishAction != null) { |
||
134 | exporttoServiceFinishAction.finished(file.getName(), |
||
135 | 43364 | jjdelcerro | openFeatureStoreParameters); |
136 | 40435 | jjdelcerro | } |
137 | } |
||
138 | |||
139 | public void setFinishAction( |
||
140 | ExporttoServiceFinishAction exporttoServiceFinishAction) { |
||
141 | this.exporttoServiceFinishAction = exporttoServiceFinishAction;
|
||
142 | } |
||
143 | |||
144 | public TaskStatus getTaskStatus() {
|
||
145 | return exporttoService.getTaskStatus();
|
||
146 | } |
||
147 | |||
148 | public boolean isCancellationRequested() { |
||
149 | return exporttoService.isCancellationRequested();
|
||
150 | } |
||
151 | |||
152 | public void cancelRequest() { |
||
153 | exporttoService.cancelRequest(); |
||
154 | } |
||
155 | } |