Revision 28375 branches/v2_0_0_prep/libraries/libGeocoding/src-test/org/gvsig/geocoding/persistence/TestPersistence.java
TestPersistence.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.geocoding.persistence; |
29 | 29 |
|
30 |
import java.io.BufferedWriter; |
|
31 | 30 |
import java.io.File; |
32 |
import java.io.FileOutputStream; |
|
31 |
import java.io.FileReader; |
|
32 |
import java.io.FileWriter; |
|
33 | 33 |
import java.io.IOException; |
34 |
import java.io.OutputStreamWriter; |
|
34 |
import java.io.Reader; |
|
35 |
import java.io.Writer; |
|
35 | 36 |
|
36 | 37 |
import junit.framework.TestCase; |
37 | 38 |
|
39 |
import org.cresques.ProjectionLibrary; |
|
40 |
import org.cresques.impl.CresquesCtsLibrary; |
|
38 | 41 |
import org.gvsig.fmap.dal.DALFileLibrary; |
39 | 42 |
import org.gvsig.fmap.dal.DALLibrary; |
40 | 43 |
import org.gvsig.fmap.dal.DALLocator; |
41 | 44 |
import org.gvsig.fmap.dal.DataManager; |
45 |
import org.gvsig.fmap.dal.DataStore; |
|
42 | 46 |
import org.gvsig.fmap.dal.exception.DataException; |
43 | 47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
44 | 48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
45 | 49 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
46 | 50 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
47 | 51 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
52 |
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary; |
|
48 | 53 |
import org.gvsig.geocoding.address.Literal; |
49 | 54 |
import org.gvsig.geocoding.address.impl.DefaultLiteral; |
50 | 55 |
import org.gvsig.geocoding.address.impl.DefaultRelationsComponent; |
... | ... | |
77 | 82 |
.getLogger(TestPersistence.class); |
78 | 83 |
|
79 | 84 |
private DataManager dataManager = null; |
80 |
private FeatureStore streetsStore = null;
|
|
85 |
private DataStore streetsStore = null;
|
|
81 | 86 |
|
82 | 87 |
private Patterngeocoding pat = null; |
83 | 88 |
|
... | ... | |
87 | 92 |
public TestPersistence() { |
88 | 93 |
|
89 | 94 |
try { |
90 |
Library tools = new ToolsLibrary(); |
|
91 |
tools.initialize(); |
|
95 |
|
|
96 |
DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary(); |
|
97 |
defGeomLib.initialize(); |
|
98 |
defGeomLib.postInitialize(); |
|
99 |
|
|
100 |
ToolsLibrary tools = new ToolsLibrary(); |
|
101 |
tools.initialize(); |
|
102 |
ToolsLocator.registerPersistenceManager(org.exolab.castor.xml.Marshaller.class); |
|
92 | 103 |
tools.postInitialize(); |
93 | 104 |
|
94 | 105 |
Library dlib = new DALLibrary(); |
... | ... | |
103 | 114 |
shpLib.initialize(); |
104 | 115 |
shpLib.postInitialize(); |
105 | 116 |
|
117 |
Library proj = new CresquesCtsLibrary(); |
|
118 |
proj.initialize(); |
|
119 |
proj.postInitialize(); |
|
120 |
|
|
106 | 121 |
} catch (Exception e) { |
107 | 122 |
e.printStackTrace(); |
108 | 123 |
} |
... | ... | |
116 | 131 |
SHPStoreParameters strParam = (SHPStoreParameters) dataManager |
117 | 132 |
.createStoreParameters(SHPStoreProvider.NAME); |
118 | 133 |
strParam.setFile(streets); |
119 |
streetsStore = (FeatureStore) dataManager.createStore(strParam); |
|
134 |
strParam.setSRSID("EPSG:23030"); |
|
135 |
streetsStore = dataManager.createStore(strParam); |
|
120 | 136 |
assertNotNull(streetsStore); |
121 | 137 |
|
122 | 138 |
} catch (Exception e) { |
... | ... | |
151 | 167 |
*/ |
152 | 168 |
public void testPersistPattern() throws IOException, PersistenceException { |
153 | 169 |
|
170 |
|
|
154 | 171 |
File file = new File("c:/pat.xml"); |
155 | 172 |
// File file = File.createTempFile("pat", "xml"); |
156 |
|
|
173 |
|
|
157 | 174 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
158 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( |
|
159 |
new FileOutputStream(file), "Cp1252")); |
|
160 |
writer.write("<?xml version=\"1.0\" encoding=\"Cp1252\"?>\n"); |
|
175 |
Writer writer = new FileWriter(file); |
|
161 | 176 |
PersistentState state = manager.getState(pat); |
162 | 177 |
state.save(writer); |
163 | 178 |
writer.close(); |
179 |
|
|
164 | 180 |
} |
165 | 181 |
|
166 | 182 |
/** |
... | ... | |
182 | 198 |
source.setLayerSource(streetsStore); |
183 | 199 |
|
184 | 200 |
AbstractGeocodingStyle style = new SimpleCentroid(); |
185 |
FeatureType ftype = streetsStore.getDefaultFeatureType(); |
|
201 |
FeatureType ftype = ((FeatureStore) streetsStore) |
|
202 |
.getDefaultFeatureType(); |
|
186 | 203 |
Literal relations = new DefaultLiteral(); |
187 |
relations.add(new DefaultRelationsComponent("Calle", ftype |
|
188 |
.getAttributeDescriptor("STREET_NAM"))); |
|
204 |
relations.add(new DefaultRelationsComponent("Calle","STREET_NAM")); |
|
189 | 205 |
|
190 | 206 |
style.setRelationsLiteral(relations); |
191 | 207 |
source.setStyle(style); |
Also available in: Unified diff