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 | 43925 | jjdelcerro | 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 | 44270 | omartinez | import org.gvsig.expressionevaluator.Expression; |
15 | 43925 | jjdelcerro | 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 | 44300 | omartinez | public class DefaultExportProcess |
25 | implements ExportProcess {
|
||
26 | |||
27 | 43925 | jjdelcerro | private ExportServiceFactory factory;
|
28 | private ExportService service;
|
||
29 | private ExportParameters parameters;
|
||
30 | private FeatureStore sourceFeatureStore;
|
||
31 | 44300 | omartinez | |
32 | 43925 | jjdelcerro | private IProjection contextProjection;
|
33 | private ICoordTrans sourceTransformation;
|
||
34 | private IProjection sourceProjection;
|
||
35 | 44069 | jjdelcerro | private Object context; |
36 | 44270 | omartinez | private Expression filterExpression; |
37 | private int featuresToUse; |
||
38 | 44386 | omartinez | // private AttributeNamesTranslator attributeNamesTranslator;
|
39 | 44300 | omartinez | |
40 | 43925 | jjdelcerro | public DefaultExportProcess() {
|
41 | 44300 | omartinez | |
42 | } |
||
43 | |||
44 | 43925 | jjdelcerro | @Override
|
45 | public void setOutputFormat(String serviceName) throws ExportException { |
||
46 | 44395 | omartinez | |
47 | 43925 | jjdelcerro | 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 | 44300 | omartinez | if (this.parameters instanceof ExportParametersGeometry) { |
53 | 43925 | jjdelcerro | ExportParametersGeometry params = (ExportParametersGeometry) this.parameters;
|
54 | 44069 | jjdelcerro | params.setContextProjection(this.contextProjection);
|
55 | params.setSourceProjection(this.sourceProjection);
|
||
56 | params.setSourceTransformation(this.sourceTransformation);
|
||
57 | params.setContext(this.context);
|
||
58 | 43925 | jjdelcerro | } |
59 | 44270 | omartinez | this.parameters.setFilterExpresion(this.filterExpression); |
60 | this.parameters.setFeaturesToUse(this.featuresToUse); //valor que use la expression si no es nula |
||
61 | 44300 | omartinez | |
62 | 43925 | jjdelcerro | } |
63 | |||
64 | @Override
|
||
65 | 44386 | omartinez | 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 | 43925 | jjdelcerro | public void setSourceFeatureStore(FeatureStore store) { |
84 | this.sourceFeatureStore = store;
|
||
85 | 44300 | omartinez | if (this.parameters != null) { |
86 | 43925 | jjdelcerro | this.parameters.setSourceFeatureStore(sourceFeatureStore);
|
87 | } |
||
88 | } |
||
89 | |||
90 | @Override
|
||
91 | public void setContextProjection(IProjection projection) { |
||
92 | this.contextProjection = projection;
|
||
93 | 44300 | omartinez | if (this.parameters instanceof ExportParametersGeometry) { |
94 | ((ExportParametersGeometry) this.parameters).setContextProjection(projection);
|
||
95 | 43925 | jjdelcerro | } |
96 | } |
||
97 | |||
98 | @Override
|
||
99 | public void setSourceTransformation(ICoordTrans transformation) { |
||
100 | this.sourceTransformation = transformation;
|
||
101 | 44300 | omartinez | if (this.parameters instanceof ExportParametersGeometry) { |
102 | ((ExportParametersGeometry) this.parameters).setSourceTransformation(transformation);
|
||
103 | 43925 | jjdelcerro | } |
104 | } |
||
105 | |||
106 | @Override
|
||
107 | public void setSourceProjection(IProjection projection) { |
||
108 | this.sourceProjection = projection;
|
||
109 | 44300 | omartinez | if (this.parameters instanceof ExportParametersGeometry) { |
110 | ((ExportParametersGeometry) this.parameters).setSourceProjection(projection);
|
||
111 | 43925 | jjdelcerro | } |
112 | } |
||
113 | |||
114 | @Override
|
||
115 | 44069 | jjdelcerro | public Object getContext() { |
116 | return context;
|
||
117 | } |
||
118 | |||
119 | @Override
|
||
120 | public void setContext(Object context) { |
||
121 | this.context = context;
|
||
122 | 44300 | omartinez | if (this.parameters != null) { |
123 | 44069 | jjdelcerro | this.parameters.setContext(context);
|
124 | } |
||
125 | } |
||
126 | |||
127 | @Override
|
||
128 | 43925 | jjdelcerro | public ExportParameters getParameters() {
|
129 | return this.parameters; |
||
130 | } |
||
131 | |||
132 | @Override
|
||
133 | public TaskStatus getTaskStatus() {
|
||
134 | 44300 | omartinez | if (this.service == null) { |
135 | 43925 | jjdelcerro | throw new IllegalStateException("Can't access task status at this moment, need setting output format."); |
136 | } |
||
137 | return this.service.getTaskStatus(); |
||
138 | } |
||
139 | 44300 | omartinez | |
140 | 43925 | jjdelcerro | @Override
|
141 | public void run() { |
||
142 | 44300 | omartinez | if (this.factory == null) { |
143 | 43925 | jjdelcerro | throw new IllegalStateException("Can't start export process, need setting output format."); |
144 | } |
||
145 | 44300 | omartinez | if (this.parameters == null) { |
146 | 43925 | jjdelcerro | throw new IllegalStateException("Can't start export process, need setting parameters."); |
147 | } |
||
148 | try {
|
||
149 | FeatureSet featureSet; |
||
150 | 44300 | omartinez | switch (this.parameters.getFeaturesToUse()) { |
151 | 43925 | jjdelcerro | 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 | 44300 | omartinez | |
168 | 43925 | jjdelcerro | @Override
|
169 | public List<OpenDataStoreParameters> getTargetOpenStoreParameters() { |
||
170 | 44300 | omartinez | if (this.service == null) { |
171 | 43925 | jjdelcerro | 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 | 44300 | omartinez | |
180 | 44270 | omartinez | @Override
|
181 | public void setFilterExpression(Expression expression) { |
||
182 | this.filterExpression = expression;
|
||
183 | 44300 | omartinez | if (this.parameters != null) { |
184 | 44281 | jjdelcerro | this.parameters.setFilterExpresion(expression);
|
185 | } |
||
186 | 44300 | omartinez | if (expression == null) { |
187 | 44281 | jjdelcerro | this.setFeaturesToUse(ExportParameters.USE_ALL_FEATURES);
|
188 | } else {
|
||
189 | this.setFeaturesToUse(ExportParameters.USE_FILTERED_FEATURES);
|
||
190 | } |
||
191 | 44300 | omartinez | } |
192 | |||
193 | 44270 | omartinez | @Override
|
194 | public void setFeaturesToUse(int featuresToUse) { |
||
195 | this.featuresToUse = featuresToUse;
|
||
196 | 44300 | omartinez | if (this.parameters != null) { |
197 | 44281 | jjdelcerro | this.parameters.setFeaturesToUse(featuresToUse);
|
198 | } |
||
199 | 44270 | omartinez | } |
200 | 44386 | omartinez | |
201 | 43925 | jjdelcerro | } |