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