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 @ 44387
History | View | Annotate | Download (4.54 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.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.export.ExportAttributes; |
8 |
import org.gvsig.export.ExportLocator; |
9 |
import org.gvsig.fmap.dal.exception.DataException; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.export.ExportParameters; |
13 |
import org.gvsig.expressionevaluator.Expression; |
14 |
|
15 |
/**
|
16 |
*
|
17 |
* @author jjdelcerro
|
18 |
*/
|
19 |
public abstract class AbstractExportParameters implements ExportParameters { |
20 |
|
21 |
private FeatureStore sourceFeatureStore;
|
22 |
private Expression filterExpression; |
23 |
private int featuresToUse; |
24 |
private Object context; |
25 |
protected ExportAttributes exportAttributes = null; |
26 |
private Date date = new Date(); |
27 |
private final ExportServiceFactory factory; |
28 |
|
29 |
public AbstractExportParameters(ExportServiceFactory factory) {
|
30 |
this.factory = factory;
|
31 |
this.exportAttributes = ExportLocator.getServiceManager().createExportAttributes();
|
32 |
} |
33 |
|
34 |
@Override
|
35 |
public boolean needsSelectTargetProjection() { |
36 |
return false; |
37 |
} |
38 |
|
39 |
@Override
|
40 |
public FeatureType getSourceFeatureType() {
|
41 |
if (!(this.exportAttributes == null)) { |
42 |
return this.exportAttributes.getSourceFeatureType(); |
43 |
} else {
|
44 |
return null; |
45 |
} |
46 |
} |
47 |
|
48 |
@Override
|
49 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
50 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType);
|
51 |
} |
52 |
|
53 |
@Override
|
54 |
public void setSourceFeatureStore(FeatureStore sourceFeatureStore) { |
55 |
this.sourceFeatureStore = sourceFeatureStore;
|
56 |
try {
|
57 |
FeatureType sourceFeatureType = sourceFeatureStore.getDefaultFeatureType(); |
58 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType);
|
59 |
} catch (DataException ex) {
|
60 |
throw new RuntimeException("Can't set feature type", ex); |
61 |
} |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public FeatureStore getSourceFeatureStore() {
|
66 |
return this.sourceFeatureStore; |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public Expression getFilterExpresion() { |
71 |
return this.filterExpression; |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void setFilterExpresion(Expression expression) { |
76 |
this.filterExpression = expression;
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
public int getFeaturesToUse() { |
81 |
return featuresToUse;
|
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void setFeaturesToUse(int featuresToUse) { |
86 |
this.featuresToUse = featuresToUse;
|
87 |
} |
88 |
|
89 |
@Override
|
90 |
public Object getContext() { |
91 |
return context;
|
92 |
} |
93 |
|
94 |
@Override
|
95 |
public void setContext(Object context) { |
96 |
this.context = context;
|
97 |
} |
98 |
|
99 |
@Override
|
100 |
public ExportAttributes getExportAttributes() {
|
101 |
return this.exportAttributes; |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void setExportAttributes(ExportAttributes export) { |
106 |
this.exportAttributes = export; |
107 |
} |
108 |
|
109 |
@Override
|
110 |
public ExportParameters clone() throws CloneNotSupportedException { |
111 |
ExportParameters clone = (ExportParameters) super.clone();
|
112 |
clone.setContext(new Date()); |
113 |
|
114 |
if (this.filterExpression != null) { |
115 |
clone.setFilterExpresion(this.filterExpression.clone());
|
116 |
} |
117 |
if (this.exportAttributes != null) { |
118 |
clone.setExportAttributes(this.exportAttributes.clone());
|
119 |
} |
120 |
|
121 |
return clone;
|
122 |
} |
123 |
|
124 |
@Override
|
125 |
public Date getCreationDate() { |
126 |
return this.date; |
127 |
} |
128 |
|
129 |
public void setCreationDate(Date date) { |
130 |
this.date = date;
|
131 |
} |
132 |
|
133 |
@Override
|
134 |
public String getLabel() { |
135 |
StringBuilder builder = new StringBuilder(); |
136 |
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); |
137 |
String dateName;
|
138 |
dateName = df.format(this.getCreationDate());
|
139 |
builder.append(dateName); |
140 |
builder.append(": ");
|
141 |
|
142 |
String serviceName;
|
143 |
if (this.getServiceName() != null) { |
144 |
serviceName = this.getServiceName();
|
145 |
} else {
|
146 |
serviceName = "Null service";
|
147 |
} |
148 |
builder.append(serviceName); |
149 |
|
150 |
if (this.getSourceFeatureStore() != null) { |
151 |
String storeName = this.getSourceFeatureStore().getName(); |
152 |
builder.append(" - ");
|
153 |
builder.append(storeName); |
154 |
} |
155 |
|
156 |
return builder.toString();
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public Object getValue() { |
161 |
return this; |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public String toString() { |
166 |
return this.getLabel(); |
167 |
} |
168 |
|
169 |
@Override
|
170 |
public ExportServiceFactory getFactory() {
|
171 |
return this.factory; |
172 |
} |
173 |
|
174 |
} |