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 / DefaultExportAttribute.java @ 44860
History | View | Annotate | Download (4.46 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 org.gvsig.export.ExportAttributes; |
9 |
import org.gvsig.export.ExportAttributes.ExportAttribute; |
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
11 |
import org.gvsig.tools.ToolsLocator; |
12 |
import org.gvsig.tools.dynobject.DynStruct; |
13 |
import org.gvsig.tools.namestranslator.NamesTranslator; |
14 |
import org.gvsig.tools.persistence.PersistenceManager; |
15 |
import org.gvsig.tools.persistence.PersistentState; |
16 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
17 |
|
18 |
public class DefaultExportAttribute implements ExportAttributes.ExportAttribute { |
19 |
|
20 |
private FeatureAttributeDescriptor fad;
|
21 |
private int newDataType; |
22 |
private int size; |
23 |
private boolean exported; |
24 |
private boolean computed; |
25 |
private NamesTranslator translator;
|
26 |
|
27 |
public DefaultExportAttribute(FeatureAttributeDescriptor fad, NamesTranslator namesTranslator) {
|
28 |
this.fad = fad;
|
29 |
this.translator = namesTranslator;
|
30 |
this.computed = this.fad.isComputed(); |
31 |
} |
32 |
|
33 |
public DefaultExportAttribute() {
|
34 |
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public FeatureAttributeDescriptor getDescriptor() {
|
39 |
return this.fad; |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public String getName() { |
44 |
return this.fad.getName(); |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public int getDataType() { |
49 |
return this.fad.getDataType().getType(); |
50 |
} |
51 |
|
52 |
@Override
|
53 |
public String getNewName() { |
54 |
if (translator==null) { |
55 |
return this.getName(); |
56 |
} |
57 |
return translator.getTranslation(this.getName()); |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public int getNewDataType() { |
62 |
|
63 |
return this.newDataType; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public boolean isExported() { |
68 |
return this.exported; |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public boolean isComputed() { |
73 |
return this.computed; |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public int setNewName(String newName) { |
78 |
if (translator==null) { |
79 |
return -1; |
80 |
} |
81 |
int indexChanged = this.translator.setTranslation(this.getName(), newName); |
82 |
return indexChanged;
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public void setExported(boolean exported) { |
87 |
this.exported = exported;
|
88 |
} |
89 |
|
90 |
@Override
|
91 |
public void setComputed(boolean computed) { |
92 |
this.computed = computed;
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public void setNewType(int dataType) { |
97 |
this.newDataType = dataType;
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public int getSize() { |
102 |
return this.size; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public void setSize(int size) { |
107 |
this.size = size;
|
108 |
} |
109 |
|
110 |
@Override
|
111 |
public ExportAttribute clone() throws CloneNotSupportedException { |
112 |
DefaultExportAttribute clone = (DefaultExportAttribute) super.clone();
|
113 |
clone.fad = (FeatureAttributeDescriptor) fad.clone(); |
114 |
return clone;
|
115 |
} |
116 |
|
117 |
public static void registerPersistence() { |
118 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
119 |
if (manager.getDefinition("ExportAttribute") == null) { |
120 |
DynStruct definition = manager.addDefinition(DefaultExportAttribute.class, |
121 |
"ExportAttribute", "ExportAttribute persistence definition", null, null); |
122 |
definition.addDynFieldObject("fad").setClassOfValue(FeatureAttributeDescriptor.class);
|
123 |
// definition.addDynFieldString("newName").setMandatory(false);
|
124 |
definition.addDynFieldInt("newDataType").setMandatory(false); |
125 |
definition.addDynFieldInt("size").setMandatory(false); |
126 |
definition.addDynFieldBoolean("exported").setMandatory(false); |
127 |
definition.addDynFieldBoolean("calculated").setMandatory(false); |
128 |
} |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public void saveToState(PersistentState state) throws PersistenceException { |
133 |
state.set("fad", this.fad); |
134 |
state.set("newDataType", this.newDataType); |
135 |
state.set("size", this.size); |
136 |
state.set("exported", this.exported); |
137 |
state.set("calculated", this.computed); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void loadFromState(PersistentState state) throws PersistenceException { |
142 |
FeatureAttributeDescriptor stateFad = (FeatureAttributeDescriptor) state.get("fad");
|
143 |
this.fad = stateFad;
|
144 |
this.newDataType = state.getInt("newDataType"); |
145 |
this.size = state.getInt("size"); |
146 |
this.exported = state.getBoolean("exported"); |
147 |
this.computed = state.getBoolean("calculated"); |
148 |
} |
149 |
|
150 |
} |