svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / exportto / impl / DefaultExporttoService.java @ 34981
History | View | Annotate | Download (4.59 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.impl; |
23 |
|
24 |
import org.cresques.cts.IProjection; |
25 |
|
26 |
import org.gvsig.exportto.ExporttoService; |
27 |
import org.gvsig.exportto.ExporttoServiceException; |
28 |
import org.gvsig.exportto.ExporttoServiceFinishAction; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataManager; |
31 |
import org.gvsig.fmap.dal.DataServerExplorer; |
32 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
33 |
import org.gvsig.fmap.dal.feature.Feature; |
34 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
37 |
import org.gvsig.tools.dispose.DisposableIterator; |
38 |
import org.gvsig.tools.dispose.DisposeUtils; |
39 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
40 |
|
41 |
/**
|
42 |
* Default {@link ExporttoService} implementation.
|
43 |
*
|
44 |
* @author gvSIG Team
|
45 |
* @version $Id$
|
46 |
*/
|
47 |
public class DefaultExporttoService extends AbstractMonitorableTask implements ExporttoService { |
48 |
|
49 |
private DataServerExplorer dataServerExplorer;
|
50 |
private NewDataStoreParameters newDataStoreParameters;
|
51 |
|
52 |
private ExporttoServiceFinishAction exporttoServiceFinishAction;
|
53 |
|
54 |
/**
|
55 |
* {@link DefaultExporttoService} constructor
|
56 |
|
57 |
*/
|
58 |
public DefaultExporttoService(DataServerExplorer dataServerExplorer,
|
59 |
NewDataStoreParameters newDataStoreParameters) { |
60 |
super("Exportto"); |
61 |
this.dataServerExplorer = dataServerExplorer;
|
62 |
this.newDataStoreParameters = newDataStoreParameters;
|
63 |
} |
64 |
|
65 |
public void export(FeatureStore featureStore, IProjection projection, |
66 |
FeatureSet featureSet) throws ExporttoServiceException {
|
67 |
// TODO Auto-generated method stub
|
68 |
|
69 |
} |
70 |
public void export(FeatureSet featureSet) throws ExporttoServiceException { |
71 |
|
72 |
String providerName = newDataStoreParameters.getDataStoreName();
|
73 |
String explorerName = dataServerExplorer.getProviderName();
|
74 |
|
75 |
DisposableIterator it = null;
|
76 |
FeatureStore target = null;
|
77 |
try {
|
78 |
taskStatus.setRangeOfValues(0, featureSet.getSize());
|
79 |
|
80 |
DataManager dataManager = DALLocator.getDataManager(); |
81 |
|
82 |
dataManager.newStore(explorerName, providerName, newDataStoreParameters, true);
|
83 |
target = (FeatureStore) dataManager.openStore(providerName, newDataStoreParameters); |
84 |
|
85 |
FeatureType targetType = target.getDefaultFeatureType(); |
86 |
|
87 |
target.edit(FeatureStore.MODE_APPEND); |
88 |
it = featureSet.fastIterator(); |
89 |
|
90 |
long featureCount = 0; |
91 |
while (it.hasNext()) {
|
92 |
Feature feature = (Feature) it.next(); |
93 |
target.insert(target.createNewFeature(targetType, feature)); |
94 |
|
95 |
featureCount++; |
96 |
this.taskStatus.setCurValue(featureCount);
|
97 |
|
98 |
if (this.taskStatus.isCancellationRequested()) { |
99 |
return;
|
100 |
} |
101 |
} |
102 |
target.finishEditing(); |
103 |
|
104 |
this.taskStatus.terminate();
|
105 |
this.taskStatus.remove();
|
106 |
} catch (Exception e) { |
107 |
throw new ExporttoServiceException(e); |
108 |
} finally{
|
109 |
if (target != null){ |
110 |
target.dispose(); |
111 |
} |
112 |
if (it != null){ |
113 |
it.dispose(); |
114 |
} |
115 |
if (featureSet != null){ |
116 |
featureSet.dispose(); |
117 |
} |
118 |
DisposeUtils.dispose(it); |
119 |
} |
120 |
|
121 |
if (exporttoServiceFinishAction != null){ |
122 |
exporttoServiceFinishAction.finished(newDataStoreParameters.getDataStoreName(), newDataStoreParameters); |
123 |
} |
124 |
} |
125 |
|
126 |
public void setFinishAction( |
127 |
ExporttoServiceFinishAction exporttoServiceFinishAction) { |
128 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction;
|
129 |
} |
130 |
|
131 |
} |