Revision 44386 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

View differences:

DefaultExportAttributes.java
8 8
import java.util.ArrayList;
9 9
import java.util.Iterator;
10 10
import java.util.List;
11
import java.util.logging.Level;
11 12
import org.apache.commons.collections.ListUtils;
12 13
import org.apache.commons.lang3.StringUtils;
13 14
import org.gvsig.export.ExportAttributes;
14 15
import org.gvsig.export.ExportLocator;
15 16
import org.gvsig.export.spi.AttributeNamesTranslator;
17
import org.gvsig.export.spi.DummyAttributeNamesTranslator;
16 18
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
17 19
import org.gvsig.fmap.dal.feature.EditableFeatureType;
18 20
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
29 31
    private FeatureType sourceFeatureType;
30 32
    static final Logger LOGGER = LoggerFactory.getLogger(DefaultExportAttributes.class);
31 33

  
32

  
33
    public DefaultExportAttributes(FeatureType ftype) {
34
        this.setSourceFeatureType(ftype);
34
    public DefaultExportAttributes() { //FeatureType ftype) {
35
//        this.setSourceFeatureType(ftype);
36
        this.namesTranslator = new DummyAttributeNamesTranslator();
35 37
    }
36 38

  
37 39
    public void fillExportAttributes(FeatureType ftype) {
......
39 41
        if (ftype != null) {
40 42
            for (FeatureAttributeDescriptor fad : ftype) {
41 43
                DefaultExportAttribute exportAttribute = new DefaultExportAttribute(fad);
42
                exportAttribute.setNewName(fad.getName());
44
                String newName = this.getNamesTranslator().getNameSuggestion(fad.getName());
45
                exportAttribute.setNewName(newName);
43 46
                exportAttribute.setNewType(fad.getDataType().getType());
44 47
                exportAttribute.setSize(fad.getSize());
45 48
                exportAttribute.setExported(true);
46 49
                attrs.add(exportAttribute);
47 50
            }
48 51
        }
49
        this.exportAttributes = attrs;
52
        this.setExportAttributes(attrs);
53
        this.fixAttributeNames();
50 54

  
51 55
    }
52 56

  
53 57
    @Override
54 58
    public void setNamesTranslator(AttributeNamesTranslator namesTranslator) {
55 59
        this.namesTranslator = namesTranslator;
56
        //this.fixAttributeNames();
60
        if (this.sourceFeatureType != null) {
61
            this.fillExportAttributes(sourceFeatureType);
62
        }
57 63
    }
58 64

  
59 65
    @Override
......
100 106
    public FeatureType getTargetFeatureType() {
101 107
        if (!this.isAttributeNamesValid()) {
102 108
            this.fixAttributeNames();
109
            LOGGER.warn("An extra fix attributes names in the feature type has been made");
103 110
        }
104 111
        EditableFeatureType targetFeatureType = this.getSourceFeatureType().getCopy().getEditable();
105 112
        for (FeatureAttributeDescriptor attrSource : this.getSourceFeatureType()) {
......
128 135

  
129 136
    @Override
130 137
    public void setSourceFeatureType(FeatureType sourceFeatureType) {
131
        this.sourceFeatureType = sourceFeatureType;
132
        this.fillExportAttributes(sourceFeatureType);
138
        if (sourceFeatureType != this.sourceFeatureType) {
139
            this.sourceFeatureType = sourceFeatureType;
140
            this.fillExportAttributes(this.sourceFeatureType);
141
        }
133 142
    }
134 143

  
135 144
    @Override
......
186 195

  
187 196
    @Override
188 197
    public boolean isAttributeNamesValid() {
189
        if (this.namesTranslator==null) {
198
        if (this.namesTranslator == null) {
190 199
            return true;
191 200
        }
192 201
        for (int i = 0; i < exportAttributes.size(); i++) {
......
203 212
        if (this.isAttributeNamesValid() == true) {
204 213
            return;
205 214
        }
206
        if (this.namesTranslator==null) {
215
        if (this.namesTranslator == null) {
207 216
            return;
208 217
        }
209 218
        int n = 0;
......
216 225
                    attr.setNewName(sug);
217 226
                }
218 227
            }
219
            if (n>5000) {
228
            if (n > 5000) {
220 229
                LOGGER.warn("Not been able to fix attribute field names, it will require a manual operation");
221 230
                break;
222 231
            }
......
225 234

  
226 235
    }
227 236

  
237
    @Override
238
    public ExportAttributes clone() throws CloneNotSupportedException {
239
        DefaultExportAttributes clone = (DefaultExportAttributes) super.clone();
240
        //clone.setSourceFeatureType(this.sourceFeatureType.getCopy());
241
        this.namesTranslator.clone();
242
        clone.setNamesTranslator(this.namesTranslator.clone());
243
        
244
        List cloneListAttribute = new ArrayList();
245
        for (ExportAttribute exportAttribute : exportAttributes) {
246
            cloneListAttribute.add(exportAttribute.clone());
247
        }
248
        clone.setExportAttributes(cloneListAttribute);
249

  
250
        return clone;
251
    }
252
//    private List<ExportAttribute> exportAttributes;
253
//    private AttributeNamesTranslator namesTranslator = null;
254
//    private FeatureType sourceFeatureType;
255

  
256
    @Override
257
    public void setExportAttributes(List<ExportAttribute> exportAttributes) {
258
        this.exportAttributes = exportAttributes;
259
    }
228 260
}

Also available in: Unified diff