svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src / org / gvsig / geocoding / pattern / impl / DefaultPatterngeocoding.java @ 28375
History | View | Annotate | Download (5.47 KB)
1 | 27904 | vsanjaime | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 Prodevelop S.L. main development
|
||
26 | */
|
||
27 | |||
28 | package org.gvsig.geocoding.pattern.impl; |
||
29 | |||
30 | import java.io.File; |
||
31 | 28295 | vsanjaime | import java.io.FileReader; |
32 | import java.io.FileWriter; |
||
33 | 27904 | vsanjaime | import java.io.IOException; |
34 | 28295 | vsanjaime | import java.io.Reader; |
35 | import java.io.Writer; |
||
36 | 27904 | vsanjaime | |
37 | import org.gvsig.geocoding.pattern.GeocodingSettings; |
||
38 | import org.gvsig.geocoding.pattern.GeocodingSource; |
||
39 | import org.gvsig.geocoding.pattern.Patterngeocoding; |
||
40 | 28295 | vsanjaime | import org.gvsig.tools.ToolsLocator; |
41 | 27904 | vsanjaime | import org.gvsig.tools.persistence.PersistenceException; |
42 | 28295 | vsanjaime | import org.gvsig.tools.persistence.PersistenceManager; |
43 | 27904 | vsanjaime | import org.gvsig.tools.persistence.PersistentState; |
44 | import org.slf4j.Logger; |
||
45 | import org.slf4j.LoggerFactory; |
||
46 | |||
47 | /**
|
||
48 | 28375 | vsanjaime | * Patterngeocoding class implementation.
|
49 | 27904 | vsanjaime | *
|
50 | * This class is the geocoding pattern. This pattern has your name (name), the
|
||
51 | * settings (settings) and the data source (source)
|
||
52 | *
|
||
53 | * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
||
54 | * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
||
55 | */
|
||
56 | public class DefaultPatterngeocoding implements Patterngeocoding { |
||
57 | |||
58 | @SuppressWarnings("unused") |
||
59 | private static final Logger log = LoggerFactory |
||
60 | .getLogger(DefaultPatterngeocoding.class); |
||
61 | |||
62 | 28375 | vsanjaime | private static final String PATTERNNAME = "gpatternname"; |
63 | private static final String SOURCE = "gsource"; |
||
64 | private static final String SETTINGS = "gsettings"; |
||
65 | 27904 | vsanjaime | |
66 | private String name; |
||
67 | private GeocodingSettings settings;
|
||
68 | private GeocodingSource source;
|
||
69 | |||
70 | /**
|
||
71 | * Default constructor
|
||
72 | */
|
||
73 | public DefaultPatterngeocoding() {
|
||
74 | this.setSource(new DefaultGeocodingSource()); |
||
75 | this.setSettings(new DefaultGeocodingSettings()); |
||
76 | } |
||
77 | |||
78 | /**
|
||
79 | * Constructor with parameters
|
||
80 | */
|
||
81 | public DefaultPatterngeocoding(GeocodingSource source,
|
||
82 | GeocodingSettings settings) { |
||
83 | this.setSource(source);
|
||
84 | this.setSettings(settings);
|
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * Constructor with pattern name
|
||
89 | *
|
||
90 | * @param name
|
||
91 | */
|
||
92 | public DefaultPatterngeocoding(String name) { |
||
93 | this();
|
||
94 | this.setPatternName(name);
|
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * Returns the value of field 'patternname'.
|
||
99 | *
|
||
100 | * @return name
|
||
101 | */
|
||
102 | public String getPatternname() { |
||
103 | return this.name; |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * Returns the value of field 'Settings'.
|
||
108 | *
|
||
109 | * @return settings
|
||
110 | */
|
||
111 | public GeocodingSettings getSettings() {
|
||
112 | return this.settings; |
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * Returns the value of field 'source'.
|
||
117 | *
|
||
118 | * @return source.
|
||
119 | */
|
||
120 | public GeocodingSource getSource() {
|
||
121 | return this.source; |
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * Sets the value of field 'settings'.
|
||
126 | *
|
||
127 | * @param settings
|
||
128 | */
|
||
129 | public void setSettings(GeocodingSettings _settings) { |
||
130 | this.settings = _settings;
|
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * Sets the value of field 'patternname'.
|
||
135 | *
|
||
136 | * @param name
|
||
137 | *
|
||
138 | */
|
||
139 | public void setPatternName(String _name) { |
||
140 | this.name = _name;
|
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * Sets the value of field 'source'.
|
||
145 | *
|
||
146 | * @param source
|
||
147 | * the value of field 'source'.
|
||
148 | */
|
||
149 | public void setSource(GeocodingSource _source) { |
||
150 | this.source = _source;
|
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * Save the pattern to XML file
|
||
155 | *
|
||
156 | * @param file
|
||
157 | 28295 | vsanjaime | * @throws PersistenceException
|
158 | 27904 | vsanjaime | * @throws IOException
|
159 | */
|
||
160 | 28295 | vsanjaime | public void saveToXML(File file) throws PersistenceException, IOException { |
161 | 27904 | vsanjaime | |
162 | 28295 | vsanjaime | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
163 | 28375 | vsanjaime | |
164 | 28295 | vsanjaime | Writer writer = new FileWriter(file); |
165 | PersistentState state = manager.getState(this);
|
||
166 | state.save(writer); |
||
167 | writer.close(); |
||
168 | 27904 | vsanjaime | } |
169 | |||
170 | /**
|
||
171 | * Load the pattern from XML file
|
||
172 | *
|
||
173 | * @param reader
|
||
174 | * @throws PersistenceException
|
||
175 | * @throws IOException
|
||
176 | * @throws IOException
|
||
177 | * @throws ClassNotFoundException
|
||
178 | */
|
||
179 | public void loadFromXML(File file) throws PersistenceException, IOException { |
||
180 | 28295 | vsanjaime | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
181 | Reader reader = new FileReader(file); |
||
182 | PersistentState state = manager.loadState(reader); |
||
183 | this.setState(state);
|
||
184 | reader.close(); |
||
185 | 27904 | vsanjaime | } |
186 | |||
187 | /**
|
||
188 | 28295 | vsanjaime | * Set the state of the pattern from the state passed as parameter.
|
189 | 27904 | vsanjaime | *
|
190 | * @param state
|
||
191 | */
|
||
192 | 28295 | vsanjaime | public void setState(PersistentState state) throws PersistenceException { |
193 | this.name = ((String) state.get(PATTERNNAME)).trim(); |
||
194 | this.source = (GeocodingSource) state.get(SOURCE);
|
||
195 | this.settings = (GeocodingSettings) state.get(SETTINGS);
|
||
196 | 27904 | vsanjaime | } |
197 | |||
198 | /**
|
||
199 | 28295 | vsanjaime | * Saves the internal state of the object on the provided PersistentState
|
200 | * object.
|
||
201 | 27904 | vsanjaime | *
|
202 | * @param state
|
||
203 | */
|
||
204 | 28295 | vsanjaime | public void saveToState(PersistentState state) throws PersistenceException { |
205 | 27904 | vsanjaime | state.set(PATTERNNAME, this.name);
|
206 | state.set(SOURCE, this.source);
|
||
207 | state.set(SETTINGS, this.settings);
|
||
208 | } |
||
209 | |||
210 | } |