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 @ 44395
History | View | Annotate | Download (7.09 KB)
1 |
package org.gvsig.export.impl; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import org.cresques.cts.ICoordTrans; |
5 |
import org.cresques.cts.IProjection; |
6 |
import org.gvsig.export.ExportException; |
7 |
import org.gvsig.export.ExportLocator; |
8 |
import org.gvsig.export.ExportParameters; |
9 |
import org.gvsig.export.ExportParametersGeometry; |
10 |
import org.gvsig.export.ExportProcess; |
11 |
import org.gvsig.export.spi.ExportService; |
12 |
import org.gvsig.export.spi.ExportServiceFactory; |
13 |
import org.gvsig.export.spi.ExportServiceManager; |
14 |
import org.gvsig.expressionevaluator.Expression; |
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 |
private Object context; |
36 |
private Expression filterExpression; |
37 |
private int featuresToUse; |
38 |
// private AttributeNamesTranslator attributeNamesTranslator;
|
39 |
|
40 |
public DefaultExportProcess() {
|
41 |
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public void setOutputFormat(String serviceName) throws ExportException { |
46 |
|
47 |
ExportServiceManager serviceManager = ExportLocator.getServiceManager(); |
48 |
this.factory = serviceManager.getServiceFactory(serviceName);
|
49 |
this.parameters = this.factory.createParameters(); |
50 |
this.service = this.factory.createService(this.parameters); |
51 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
52 |
if (this.parameters instanceof ExportParametersGeometry) { |
53 |
ExportParametersGeometry params = (ExportParametersGeometry) this.parameters;
|
54 |
params.setContextProjection(this.contextProjection);
|
55 |
params.setSourceProjection(this.sourceProjection);
|
56 |
params.setSourceTransformation(this.sourceTransformation);
|
57 |
params.setContext(this.context);
|
58 |
} |
59 |
this.parameters.setFilterExpresion(this.filterExpression); |
60 |
this.parameters.setFeaturesToUse(this.featuresToUse); //valor que use la expression si no es nula |
61 |
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void setParameters(ExportParameters params) { |
66 |
this.parameters = params;
|
67 |
this.factory = this.parameters.getFactory(); |
68 |
this.service = this.factory.createService(this.parameters); |
69 |
this.parameters.setSourceFeatureStore(this.sourceFeatureStore); |
70 |
this.parameters.setContext(this.context); |
71 |
|
72 |
this.featuresToUse = this.parameters.getFeaturesToUse(); |
73 |
this.filterExpression = this.parameters.getFilterExpresion(); |
74 |
if (this.parameters instanceof ExportParametersGeometry) { |
75 |
ExportParametersGeometry pa = (ExportParametersGeometry) this.parameters;
|
76 |
this.contextProjection = pa.getContextProjection();
|
77 |
this.sourceProjection = pa.getSourceProjection();
|
78 |
this.sourceTransformation = pa.getSourceTransformation();
|
79 |
} |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public void setSourceFeatureStore(FeatureStore store) { |
84 |
this.sourceFeatureStore = store;
|
85 |
if (this.parameters != null) { |
86 |
this.parameters.setSourceFeatureStore(sourceFeatureStore);
|
87 |
} |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public void setContextProjection(IProjection projection) { |
92 |
this.contextProjection = projection;
|
93 |
if (this.parameters instanceof ExportParametersGeometry) { |
94 |
((ExportParametersGeometry) this.parameters).setContextProjection(projection);
|
95 |
} |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void setSourceTransformation(ICoordTrans transformation) { |
100 |
this.sourceTransformation = transformation;
|
101 |
if (this.parameters instanceof ExportParametersGeometry) { |
102 |
((ExportParametersGeometry) this.parameters).setSourceTransformation(transformation);
|
103 |
} |
104 |
} |
105 |
|
106 |
@Override
|
107 |
public void setSourceProjection(IProjection projection) { |
108 |
this.sourceProjection = projection;
|
109 |
if (this.parameters instanceof ExportParametersGeometry) { |
110 |
((ExportParametersGeometry) this.parameters).setSourceProjection(projection);
|
111 |
} |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public Object getContext() { |
116 |
return context;
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public void setContext(Object context) { |
121 |
this.context = context;
|
122 |
if (this.parameters != null) { |
123 |
this.parameters.setContext(context);
|
124 |
} |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public ExportParameters getParameters() {
|
129 |
return this.parameters; |
130 |
} |
131 |
|
132 |
@Override
|
133 |
public TaskStatus getTaskStatus() {
|
134 |
if (this.service == null) { |
135 |
throw new IllegalStateException("Can't access task status at this moment, need setting output format."); |
136 |
} |
137 |
return this.service.getTaskStatus(); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void run() { |
142 |
if (this.factory == null) { |
143 |
throw new IllegalStateException("Can't start export process, need setting output format."); |
144 |
} |
145 |
if (this.parameters == null) { |
146 |
throw new IllegalStateException("Can't start export process, need setting parameters."); |
147 |
} |
148 |
try {
|
149 |
FeatureSet featureSet; |
150 |
switch (this.parameters.getFeaturesToUse()) { |
151 |
case ExportParameters.USE_ALL_FEATURES:
|
152 |
default:
|
153 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet();
|
154 |
break;
|
155 |
case ExportParameters.USE_SELECTED_FEATURES:
|
156 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSelection();
|
157 |
break;
|
158 |
case ExportParameters.USE_FILTERED_FEATURES:
|
159 |
featureSet = this.parameters.getSourceFeatureStore().getFeatureSet(this.parameters.getFilterExpresion()); |
160 |
break;
|
161 |
} |
162 |
this.service.export(featureSet);
|
163 |
} catch (Exception ex) { |
164 |
throw new RuntimeException(ex); |
165 |
} |
166 |
} |
167 |
|
168 |
@Override
|
169 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() { |
170 |
if (this.service == null) { |
171 |
return null; |
172 |
} |
173 |
try {
|
174 |
return this.service.getTargetOpenStoreParameters(); |
175 |
} catch (ExportException ex) { |
176 |
throw new RuntimeException("Can't create target open store parameters.", ex); |
177 |
} |
178 |
} |
179 |
|
180 |
@Override
|
181 |
public void setFilterExpression(Expression expression) { |
182 |
this.filterExpression = expression;
|
183 |
if (this.parameters != null) { |
184 |
this.parameters.setFilterExpresion(expression);
|
185 |
} |
186 |
if (expression == null) { |
187 |
this.setFeaturesToUse(ExportParameters.USE_ALL_FEATURES);
|
188 |
} else {
|
189 |
this.setFeaturesToUse(ExportParameters.USE_FILTERED_FEATURES);
|
190 |
} |
191 |
} |
192 |
|
193 |
@Override
|
194 |
public void setFeaturesToUse(int featuresToUse) { |
195 |
this.featuresToUse = featuresToUse;
|
196 |
if (this.parameters != null) { |
197 |
this.parameters.setFeaturesToUse(featuresToUse);
|
198 |
} |
199 |
} |
200 |
|
201 |
} |