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 / service / DefaultExportAttributes.java @ 44297
History | View | Annotate | Download (5.73 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.impl.service; |
7 |
|
8 |
import java.util.ArrayList; |
9 |
import java.util.Iterator; |
10 |
import java.util.List; |
11 |
import org.apache.commons.collections.ListUtils; |
12 |
import org.apache.commons.lang3.StringUtils; |
13 |
import org.gvsig.export.ExportAttributes; |
14 |
import org.gvsig.export.ExportLocator; |
15 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
17 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
18 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
19 |
import org.gvsig.fmap.dal.feature.FeatureType; |
20 |
import org.gvsig.tools.dataTypes.DataType; |
21 |
import org.gvsig.tools.util.UnmodifiableBasicListAdapter; |
22 |
|
23 |
public class DefaultExportAttributes implements ExportAttributes { |
24 |
|
25 |
private List<ExportAttribute> exportAttributes; |
26 |
private AttributeNamesTranslator namesTranslator;
|
27 |
private FeatureType sourceFeatureType;
|
28 |
|
29 |
public DefaultExportAttributes(FeatureType ftype) {
|
30 |
//TODO
|
31 |
//rellenar pirmero sin el suggest name
|
32 |
//rellamar al algorito de suggest
|
33 |
this.fillExportAttributes(ftype);
|
34 |
this.setSourceFeatureType(ftype);
|
35 |
|
36 |
} |
37 |
|
38 |
public void fillExportAttributes(FeatureType ftype) { |
39 |
ArrayList attrs = new ArrayList(); |
40 |
for (FeatureAttributeDescriptor fad : ftype) {
|
41 |
DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad);
|
42 |
exportAttribute.setNewName(fad.getName()); |
43 |
exportAttribute.setNewType(fad.getDataType().getType()); |
44 |
exportAttribute.setSize(fad.getSize()); |
45 |
exportAttribute.setExported(true);
|
46 |
attrs.add(exportAttribute); |
47 |
} |
48 |
this.exportAttributes = attrs;
|
49 |
|
50 |
} |
51 |
|
52 |
@Override
|
53 |
public void setNamesTranslator(AttributeNamesTranslator namesTranslator) { |
54 |
//TODO tb hay que rehacer todos los suggestname.
|
55 |
this.namesTranslator = namesTranslator;
|
56 |
} |
57 |
|
58 |
@Override
|
59 |
public AttributeNamesTranslator getNamesTranslator() {
|
60 |
return this.namesTranslator; |
61 |
} |
62 |
|
63 |
@Override
|
64 |
public List<ExportAttribute> toList() { |
65 |
return this.exportAttributes; |
66 |
} |
67 |
|
68 |
@Override
|
69 |
public boolean isEmpty() { |
70 |
return this.exportAttributes.isEmpty(); |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public int size() { |
75 |
return this.exportAttributes.size(); |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public Iterator<ExportAttribute> iterator() { |
80 |
return this.exportAttributes.iterator(); |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public ExportAttribute get(int position) { |
85 |
return this.exportAttributes.get(position); |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public ExportAttribute getExportAttribute(String name) { |
90 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
91 |
if (StringUtils.equals(exportAttribute.getName(), name)) {
|
92 |
return exportAttribute;
|
93 |
} |
94 |
} |
95 |
return null; |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public FeatureType getTargetFeatureType() {
|
100 |
EditableFeatureType targetFeatureType = this.getSourceFeatureType().getCopy().getEditable();
|
101 |
for (FeatureAttributeDescriptor attrSource : this.getSourceFeatureType()) { |
102 |
FeatureAttributeDescriptor attr = targetFeatureType.getAttributeDescriptor(attrSource.getName()); |
103 |
String name = attr.getName();
|
104 |
ExportAttribute exportAttr = this.getExportAttribute(name);
|
105 |
if (!exportAttr.isExported()) {
|
106 |
targetFeatureType.remove(name); |
107 |
continue;
|
108 |
} |
109 |
|
110 |
EditableFeatureAttributeDescriptor eAttr = targetFeatureType.getEditableAttributeDescriptor(name); |
111 |
if (this.getTargetName(name) == null ? name != null : !this.getTargetName(name).equals(name)) { |
112 |
eAttr.setName(this.getTargetName(name));
|
113 |
} |
114 |
int type = attr.getDataType().getType();
|
115 |
if (type != this.getTargetType(name)) { |
116 |
eAttr.setDataType(this.getTargetType(name));
|
117 |
eAttr.setDefaultValue(null); // TODO: delete default value |
118 |
} |
119 |
int size = exportAttr.getSize();
|
120 |
eAttr.setSize(size); |
121 |
} |
122 |
return targetFeatureType.getNotEditableCopy();
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
127 |
this.sourceFeatureType = sourceFeatureType;
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public FeatureType getSourceFeatureType() {
|
132 |
return this.sourceFeatureType; |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public String getTargetName(String name) { |
137 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
138 |
if (StringUtils.equals(exportAttribute.getName(), name)) {
|
139 |
return exportAttribute.getNewName();
|
140 |
} |
141 |
} |
142 |
return null; |
143 |
} |
144 |
|
145 |
@Override
|
146 |
public String getSourceName(String name) { |
147 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
148 |
if (StringUtils.equalsIgnoreCase(exportAttribute.getNewName(), name)) {
|
149 |
return exportAttribute.getName();
|
150 |
} |
151 |
} |
152 |
return null; |
153 |
} |
154 |
|
155 |
@Override
|
156 |
public int getTargetType(String name) { |
157 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
158 |
if (StringUtils.equals(exportAttribute.getName(), name)) {
|
159 |
return exportAttribute.getNewDataType();
|
160 |
} |
161 |
} |
162 |
return 0; |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public int getSourceType(String name) { |
167 |
for (ExportAttribute exportAttribute : this.exportAttributes) { |
168 |
if (StringUtils.equals(exportAttribute.getNewName(), name)) {
|
169 |
return exportAttribute.getDataType();
|
170 |
} |
171 |
} |
172 |
return 0; |
173 |
} |
174 |
|
175 |
} |