Statistics
| Revision:

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

History | View | Annotate | Download (5.13 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
/**
46
 * @author gvSIG Team
47
 * @version $Id$
48
 *
49
 */
50
public abstract class AbstractExporttoFileService implements ExporttoService {
51
    protected static final  ExporttoManager EXPORTTO_MANAGER = ExporttoLocator.getManager();
52
    protected File file; 
53
    protected FeatureStore featureStore;
54
    protected ExporttoService exporttoService;
55

    
56
    private NewFeatureStoreParameters newFeatureStoreParameters;     
57
    private ExporttoServiceFinishAction exporttoServiceFinishAction;
58
    
59
    public AbstractExporttoFileService(File file, FeatureStore featureStore)  {
60
        super();         
61
        this.featureStore = featureStore;
62
        this.file = file;          
63
    }  
64
    
65
    public void open() throws ExporttoServiceException{
66
        String path = file.getAbsolutePath();
67

    
68
        String extension = "." + getFileExtension();
69
        
70
        if (!(path.toLowerCase().endsWith(extension))){
71
            path = path + extension;
72
        }
73

    
74
        File newFile = new File(path);
75
        DataManager dataManager = DALLocator.getDataManager();
76

    
77
        FilesystemServerExplorerParameters explorerParams;
78
        try {
79
            explorerParams = (FilesystemServerExplorerParameters) dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
80
        } catch (InitializeException e) {
81
            throw new ExporttoServiceException(e);
82
        } catch (ProviderNotRegisteredException e) {
83
            throw new ExporttoServiceException(e);
84
        }
85
        explorerParams.setRoot(newFile.getParent());
86

    
87
        FilesystemServerExplorer explorer;
88
        try {
89
            explorer = (FilesystemServerExplorer) dataManager.openServerExplorer("FilesystemExplorer", explorerParams);
90
        } catch (ValidateDataParametersException e) {
91
            throw new ExporttoServiceException(e);
92
        } catch (InitializeException e) {
93
            throw new ExporttoServiceException(e);
94
        } catch (ProviderNotRegisteredException e) {
95
            throw new ExporttoServiceException(e);
96
        }
97

    
98
        try {          
99
            newFeatureStoreParameters = (NewFeatureStoreParameters) explorer.getAddParameters(newFile);
100
            addParameters(newFeatureStoreParameters);
101

    
102
            exporttoService = EXPORTTO_MANAGER.getExporttoService(explorer, newFeatureStoreParameters);
103
        } catch (DataException e) {
104
            throw new ExporttoServiceException(e);
105
        } 
106
    }
107
    
108
    public abstract void addParameters(NewFeatureStoreParameters newFeatureStoreParameters) throws DataException;
109
    
110
    public abstract String getFileExtension();
111

    
112
    public void export(FeatureSet featureSet) throws ExporttoServiceException {
113
        exporttoService.export(featureSet); 
114
        if (exporttoServiceFinishAction != null){           
115
            exporttoServiceFinishAction.finished(file.getName(), newFeatureStoreParameters);
116
        }
117
    }  
118

    
119
    public void setFinishAction(
120
        ExporttoServiceFinishAction exporttoServiceFinishAction) {
121
        this.exporttoServiceFinishAction = exporttoServiceFinishAction;
122
    }
123
    
124
    public TaskStatus getTaskStatus() {       
125
        return exporttoService.getTaskStatus();
126
    }
127

    
128
    public boolean isCancellationRequested() {
129
        return exporttoService.isCancellationRequested();
130
    }
131

    
132
    public void cancelRequest() {
133
        exporttoService.cancelRequest();
134
    }
135
}