Statistics
| Revision:

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 @ 43364

History | View | Annotate | Download (5.74 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
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.exception.ValidateDataParametersException;
39
import org.gvsig.fmap.dal.feature.FeatureSet;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
42
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
44
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
45
import org.gvsig.tools.task.TaskStatus;
46

    
47
/**
48
 * @author gvSIG Team
49
 * @version $Id$
50
 * 
51
 */
52
public abstract class AbstractExporttoFileService implements ExporttoService {
53

    
54
    protected static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator
55
        .getManager();
56
    protected File file;
57
    protected FeatureStore featureStore;
58
    protected ExporttoService exporttoService;
59

    
60
    private NewFeatureStoreParameters newFeatureStoreParameters;
61
    private OpenFeatureStoreParameters openFeatureStoreParameters;
62
    private ExporttoServiceFinishAction exporttoServiceFinishAction;
63

    
64
    public AbstractExporttoFileService(File file, FeatureStore featureStore) {
65
        super();
66
        this.featureStore = featureStore;
67
        this.file = file;
68
    }
69

    
70
    public void open() throws ExporttoServiceException {
71
        String path = file.getAbsolutePath();
72

    
73
        String extension = "." + getFileExtension();
74

    
75
        if (!(path.toLowerCase().endsWith(extension))) {
76
            path = path + extension;
77
        }
78

    
79
        File newFile = new File(path);
80
        DataManager dataManager = DALLocator.getDataManager();
81

    
82
        FilesystemServerExplorerParameters explorerParams;
83
        try {
84
            explorerParams =
85
                (FilesystemServerExplorerParameters) dataManager
86
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
87
        } catch (InitializeException e) {
88
            throw new ExporttoServiceException(e);
89
        } catch (ProviderNotRegisteredException e) {
90
            throw new ExporttoServiceException(e);
91
        }
92
        explorerParams.setRoot(newFile.getParent());
93

    
94
        FilesystemServerExplorer explorer;
95
        try {
96
            explorer =
97
                (FilesystemServerExplorer) dataManager.openServerExplorer(
98
                    "FilesystemExplorer", explorerParams);
99
        } catch (ValidateDataParametersException e) {
100
            throw new ExporttoServiceException(e);
101
        } catch (InitializeException e) {
102
            throw new ExporttoServiceException(e);
103
        } catch (ProviderNotRegisteredException e) {
104
            throw new ExporttoServiceException(e);
105
        }
106

    
107
        try {
108
            openFeatureStoreParameters = (OpenFeatureStoreParameters) explorer.createStoreParameters(newFile);
109
            addParameters(openFeatureStoreParameters);
110
            newFeatureStoreParameters = (NewFeatureStoreParameters) explorer.getAddParameters(newFile);
111
            addParameters(newFeatureStoreParameters);
112

    
113
            exporttoService = EXPORTTO_MANAGER.getExporttoService(
114
                    explorer,
115
                    newFeatureStoreParameters,
116
                    openFeatureStoreParameters
117
                );
118

    
119

    
120
        } catch (DataException e) {
121
            throw new ExporttoServiceException(e);
122
        }
123
    }
124

    
125
    public abstract void addParameters(
126
        NewFeatureStoreParameters newFeatureStoreParameters)
127
        throws DataException;
128

    
129
    public abstract void addParameters(
130
        OpenFeatureStoreParameters openFeatureStoreParameters)
131
        throws DataException;
132

    
133
    public abstract String getFileExtension();
134

    
135
    public void export(FeatureSet featureSet) throws ExporttoServiceException {
136
        exporttoService.export(featureSet);
137
        if (exporttoServiceFinishAction != null) {
138
            exporttoServiceFinishAction.finished(file.getName(),
139
                openFeatureStoreParameters);
140
        }
141
    }
142

    
143
    public void setFinishAction(
144
        ExporttoServiceFinishAction exporttoServiceFinishAction) {
145
        this.exporttoServiceFinishAction = exporttoServiceFinishAction;
146
    }
147

    
148
    public TaskStatus getTaskStatus() {
149
        return exporttoService.getTaskStatus();
150
    }
151

    
152
    public boolean isCancellationRequested() {
153
        return exporttoService.isCancellationRequested();
154
    }
155

    
156
    public void cancelRequest() {
157
        exporttoService.cancelRequest();
158
    }
159
}