svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.api / src / main / java / org / gvsig / export / spi / AbstractExportParameters.java @ 44753
History | View | Annotate | Download (7.43 KB)
1 |
package org.gvsig.export.spi; |
---|---|
2 |
|
3 |
import java.text.DateFormat; |
4 |
import java.text.SimpleDateFormat; |
5 |
import java.util.Date; |
6 |
import org.gvsig.export.ExportAttributes; |
7 |
import org.gvsig.export.ExportLocator; |
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
10 |
import org.gvsig.fmap.dal.feature.FeatureType; |
11 |
import org.gvsig.export.ExportParameters; |
12 |
import org.gvsig.expressionevaluator.Expression; |
13 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
14 |
import org.gvsig.tools.ToolsLocator; |
15 |
import org.gvsig.tools.dynobject.DynStruct; |
16 |
import org.gvsig.tools.persistence.PersistenceManager; |
17 |
import org.gvsig.tools.persistence.PersistentState; |
18 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
19 |
import org.slf4j.Logger; |
20 |
import org.slf4j.LoggerFactory; |
21 |
|
22 |
/**
|
23 |
*
|
24 |
* @author jjdelcerro
|
25 |
*/
|
26 |
public abstract class AbstractExportParameters implements ExportParameters { |
27 |
|
28 |
private FeatureStore sourceFeatureStore;
|
29 |
private Expression filterExpression; |
30 |
private int featuresToUse; |
31 |
private Object context; |
32 |
protected ExportAttributes exportAttributes = null; |
33 |
private Date date = new Date(); |
34 |
public ExportServiceFactory factory;
|
35 |
|
36 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractExportParameters.class); |
37 |
private FeatureQuery featureQuery;
|
38 |
|
39 |
public AbstractExportParameters(ExportServiceFactory factory) {
|
40 |
this.factory = factory;
|
41 |
this.exportAttributes = ExportLocator.getServiceManager().createExportAttributes();
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public boolean needsSelectTargetProjection() { |
46 |
return false; |
47 |
} |
48 |
|
49 |
@Override
|
50 |
public FeatureType getSourceFeatureType() {
|
51 |
if (!(this.exportAttributes == null)) { |
52 |
return this.exportAttributes.getSourceFeatureType(); |
53 |
} else {
|
54 |
return null; |
55 |
} |
56 |
} |
57 |
|
58 |
@Override
|
59 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
60 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType, this.featureQuery); |
61 |
} |
62 |
|
63 |
@Override
|
64 |
public void setSourceFeatureStore(FeatureStore sourceFeatureStore) { |
65 |
this.sourceFeatureStore = sourceFeatureStore;
|
66 |
try {
|
67 |
FeatureType sourceFeatureType = sourceFeatureStore.getDefaultFeatureType(); |
68 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType, this.featureQuery); |
69 |
} catch (DataException ex) {
|
70 |
throw new RuntimeException("Can't set feature type", ex); |
71 |
} |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public FeatureStore getSourceFeatureStore() {
|
76 |
return this.sourceFeatureStore; |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public Expression getFilterExpresion() { |
81 |
return this.filterExpression; |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void setFilterExpresion(Expression expression) { |
86 |
this.filterExpression = expression;
|
87 |
} |
88 |
|
89 |
@Override
|
90 |
public FeatureQuery getFeatureQuery() {
|
91 |
return this.featureQuery; |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public void setFeatureQuery(FeatureQuery query) { |
96 |
this.featureQuery = query;
|
97 |
} |
98 |
|
99 |
@Override
|
100 |
public int getFeaturesToUse() { |
101 |
return featuresToUse;
|
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void setFeaturesToUse(int featuresToUse) { |
106 |
this.featuresToUse = featuresToUse;
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public Object getContext() { |
111 |
return context;
|
112 |
} |
113 |
|
114 |
@Override
|
115 |
public void setContext(Object context) { |
116 |
this.context = context;
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public ExportAttributes getExportAttributes() {
|
121 |
return this.exportAttributes; |
122 |
} |
123 |
|
124 |
@Override
|
125 |
public void setExportAttributes(ExportAttributes export) { |
126 |
this.exportAttributes = export; |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public ExportParameters clone() throws CloneNotSupportedException { |
131 |
ExportParameters clone = (ExportParameters) super.clone();
|
132 |
|
133 |
if (this.filterExpression != null) { |
134 |
clone.setFilterExpresion(this.filterExpression.clone());
|
135 |
} |
136 |
if (this.featureQuery!=null) { |
137 |
clone.setFeatureQuery(this.featureQuery.getCopy());
|
138 |
} |
139 |
if (this.exportAttributes != null) { |
140 |
clone.setExportAttributes(this.exportAttributes.clone());
|
141 |
} |
142 |
|
143 |
return clone;
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public Date getCreationDate() { |
148 |
return this.date; |
149 |
} |
150 |
|
151 |
public void setCreationDate(Date date) { |
152 |
this.date = date;
|
153 |
} |
154 |
|
155 |
@Override
|
156 |
public String getLabel() { |
157 |
StringBuilder builder = new StringBuilder(); |
158 |
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); |
159 |
String dateName;
|
160 |
dateName = df.format(this.getCreationDate());
|
161 |
builder.append(dateName); |
162 |
builder.append(": ");
|
163 |
|
164 |
String serviceName;
|
165 |
if (this.getServiceName() != null) { |
166 |
serviceName = this.getServiceName();
|
167 |
} else {
|
168 |
serviceName = "Null service";
|
169 |
} |
170 |
builder.append(serviceName); |
171 |
|
172 |
if (this.getSourceFeatureStore() != null) { |
173 |
String storeName = this.getSourceFeatureStore().getName(); |
174 |
builder.append(" - ");
|
175 |
builder.append(storeName); |
176 |
} |
177 |
|
178 |
return builder.toString();
|
179 |
} |
180 |
|
181 |
@Override
|
182 |
public Object getValue() { |
183 |
return this; |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public String toString() { |
188 |
return this.getLabel(); |
189 |
} |
190 |
|
191 |
@Override
|
192 |
public ExportServiceFactory getFactory() {
|
193 |
return this.factory; |
194 |
} |
195 |
|
196 |
@Override
|
197 |
public FeatureType getTargetFeatureType() {
|
198 |
if (this.getExportAttributes() == null) { |
199 |
LOGGER.warn("Not been able to get target feature type from export attributes because it's null");
|
200 |
return null; |
201 |
} |
202 |
return this.getExportAttributes().getTargetFeatureType(); |
203 |
} |
204 |
|
205 |
public static void registerPersistence() { |
206 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
207 |
if (manager.getDefinition("AbstractExportParameters") == null) { |
208 |
DynStruct definition = manager.addDefinition(AbstractExportParameters.class, |
209 |
"AbstractExportParameters", "AbstractExportParameters persistence definition", null, null); |
210 |
definition.addDynFieldInt("featuresToUse").setMandatory(false); |
211 |
definition.addDynFieldObject("filterExpression").setClassOfValue(Expression.class).setMandatory(false); |
212 |
definition.addDynFieldObject("exportAttributes").setClassOfValue(ExportAttributes.class).setMandatory(false); |
213 |
definition.addDynFieldDate("dateCreation").setMandatory(false); |
214 |
definition.addDynFieldString("factory");
|
215 |
} |
216 |
} |
217 |
|
218 |
public void saveToState(PersistentState state) throws PersistenceException { |
219 |
state.set("featuresToUse", this.featuresToUse); |
220 |
state.set("filterExpression", this.filterExpression); |
221 |
state.set("exportAttributes", this.exportAttributes); |
222 |
state.set("dateCreation", this.date); |
223 |
state.set("factory", this.factory.getName()); |
224 |
} |
225 |
|
226 |
public void loadFromState(PersistentState state) throws PersistenceException { |
227 |
this.featuresToUse = state.getInt("featuresToUse"); |
228 |
this.filterExpression = (Expression) state.get("filterExpression"); |
229 |
this.exportAttributes = (ExportAttributes) state.get("exportAttributes"); |
230 |
this.date = state.getDate("dateCreation"); |
231 |
String nameFactory = state.getString("factory"); |
232 |
ExportServiceFactory statefactory = ExportLocator.getServiceManager().getServiceFactory(nameFactory); |
233 |
this.factory = statefactory;
|
234 |
} |
235 |
|
236 |
|
237 |
@Override
|
238 |
public void resetVolatileValues() { |
239 |
|
240 |
} |
241 |
|
242 |
} |