svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / export / impl / DefaultExportProcess.java @ 43925
History | View | Annotate | Download (5.11 KB)
1 |
package org.gvsig.export.impl; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import org.apache.commons.lang3.StringUtils; |
5 |
import org.cresques.cts.ICoordTrans; |
6 |
import org.cresques.cts.IProjection; |
7 |
import org.gvsig.export.ExportException; |
8 |
import org.gvsig.export.ExportLocator; |
9 |
import org.gvsig.export.ExportParameters; |
10 |
import org.gvsig.export.ExportParametersGeometry; |
11 |
import org.gvsig.export.ExportProcess; |
12 |
import org.gvsig.export.spi.ExportService; |
13 |
import org.gvsig.export.spi.ExportServiceFactory; |
14 |
import org.gvsig.export.spi.ExportServiceManager; |
15 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
16 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
18 |
import org.gvsig.tools.task.TaskStatus; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
public class DefaultExportProcess |
25 |
implements ExportProcess
|
26 |
{ |
27 |
private ExportServiceFactory factory;
|
28 |
private ExportService service;
|
29 |
private ExportParameters parameters;
|
30 |
private FeatureStore sourceFeatureStore;
|
31 |
|
32 |
private IProjection contextProjection;
|
33 |
private ICoordTrans sourceTransformation;
|
34 |
private IProjection sourceProjection;
|
35 |
|
36 |
public DefaultExportProcess() {
|
37 |
|
38 |
} |
39 |
|
40 |
@Override
|
41 |
public void setOutputFormat(String serviceName) throws ExportException { |
42 |
if( this.factory!=null && StringUtils.equalsIgnoreCase(serviceName, this.factory.getName())) { |
43 |
return;
|
44 |
} |
45 |
ExportServiceManager serviceManager = ExportLocator.getServiceManager(); |
46 |
this.factory = serviceManager.getServiceFactory(serviceName);
|
47 |
this.parameters = this.factory.createParameters(); |
48 |
this.service = this.factory.createService(this.parameters); |
49 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
50 |
if( this.parameters instanceof ExportParametersGeometry ) { |
51 |
ExportParametersGeometry params = (ExportParametersGeometry) this.parameters;
|
52 |
params.setContextProjection(contextProjection); |
53 |
params.setSourceProjection(sourceProjection); |
54 |
params.setSourceTransformation(sourceTransformation); |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void setSourceFeatureStore(FeatureStore store) { |
61 |
this.sourceFeatureStore = store;
|
62 |
if( this.parameters!= null ) { |
63 |
this.parameters.setSourceFeatureStore(sourceFeatureStore);
|
64 |
} |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void setContextProjection(IProjection projection) { |
69 |
this.contextProjection = projection;
|
70 |
if( this.parameters instanceof ExportParametersGeometry ) { |
71 |
((ExportParametersGeometry)this.parameters).setContextProjection(projection);
|
72 |
} |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public void setSourceTransformation(ICoordTrans transformation) { |
77 |
this.sourceTransformation = transformation;
|
78 |
if( this.parameters instanceof ExportParametersGeometry ) { |
79 |
((ExportParametersGeometry)this.parameters).setSourceTransformation(transformation);
|
80 |
} |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void setSourceProjection(IProjection projection) { |
85 |
this.sourceProjection = projection;
|
86 |
if( this.parameters instanceof ExportParametersGeometry ) { |
87 |
((ExportParametersGeometry)this.parameters).setSourceProjection(projection);
|
88 |
} |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public ExportParameters getParameters() {
|
93 |
return this.parameters; |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public TaskStatus getTaskStatus() {
|
98 |
if( this.service==null ) { |
99 |
throw new IllegalStateException("Can't access task status at this moment, need setting output format."); |
100 |
} |
101 |
return this.service.getTaskStatus(); |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void run() { |
106 |
if( this.factory == null ) { |
107 |
throw new IllegalStateException("Can't start export process, need setting output format."); |
108 |
} |
109 |
if( this.parameters == null ) { |
110 |
throw new IllegalStateException("Can't start export process, need setting parameters."); |
111 |
} |
112 |
try {
|
113 |
FeatureSet featureSet; |
114 |
switch(this.parameters.getFeaturesToUse()) { |
115 |
case ExportParameters.USE_ALL_FEATURES:
|
116 |
default:
|
117 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet();
|
118 |
break;
|
119 |
case ExportParameters.USE_SELECTED_FEATURES:
|
120 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSelection();
|
121 |
break;
|
122 |
case ExportParameters.USE_FILTERED_FEATURES:
|
123 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet(this.parameters.getFilterExpresion()); |
124 |
break;
|
125 |
} |
126 |
this.service.export(featureSet);
|
127 |
} catch (Exception ex) { |
128 |
throw new RuntimeException(ex); |
129 |
} |
130 |
} |
131 |
|
132 |
@Override
|
133 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() { |
134 |
if( this.service==null ) { |
135 |
return null; |
136 |
} |
137 |
try {
|
138 |
return this.service.getTargetOpenStoreParameters(); |
139 |
} catch (ExportException ex) { |
140 |
throw new RuntimeException("Can't create target open store parameters.", ex); |
141 |
} |
142 |
} |
143 |
} |