Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src / org / gvsig / geocoding / pattern / impl / DefaultGeocodingSource.java @ 32474

History | View | Annotate | Download (4.75 KB)

1
/* 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
 * 2009 Prodevelop S.L. main development
26
 */
27

    
28
package org.gvsig.geocoding.pattern.impl;
29

    
30
import org.gvsig.geocoding.GeocodingTags;
31
import org.gvsig.geocoding.pattern.GeocodingSource;
32
import org.gvsig.geocoding.styles.AbstractGeocodingStyle;
33
import org.gvsig.geocoding.styles.impl.Composed;
34
import org.gvsig.geocoding.styles.impl.DoubleRange;
35
import org.gvsig.geocoding.styles.impl.SimpleCentroid;
36
import org.gvsig.geocoding.styles.impl.SimpleRange;
37
import org.gvsig.utils.XMLEntity;
38
import org.gvsig.utils.XMLException;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

    
42
/**
43
 * GeocodingSource class implementation. This class has the geocoding style and
44
 * the FeatureStore of the data source
45
 * 
46
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
47
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
48
 */
49
public class DefaultGeocodingSource implements GeocodingSource {
50

    
51
        @SuppressWarnings("unused")
52
        private static final Logger log = LoggerFactory
53
                        .getLogger(DefaultGeocodingSource.class);
54

    
55
        private AbstractGeocodingStyle style;
56
        private String layerName;
57
        private String layerProvider;
58

    
59
        /**
60
         * Default constructor
61
         */
62
        public DefaultGeocodingSource() {
63

    
64
        }
65

    
66
        /**
67
         * Constructor with parameters
68
         * 
69
         * @param style
70
         * @param layerName
71
         * @param layerProvider
72
         */
73
        public DefaultGeocodingSource(AbstractGeocodingStyle style,
74
                        String layerName, String layerProvider) {
75
                this();
76
                this.style = style;
77
                this.layerName = layerName;
78
                this.layerProvider = layerProvider;
79
        }
80

    
81
        /**
82
         * Get geocoding style
83
         * 
84
         * @return
85
         */
86
        public AbstractGeocodingStyle getStyle() {
87
                return style;
88
        }
89

    
90
        /**
91
         * Set geocoding style
92
         * 
93
         * @param style
94
         */
95
        public void setStyle(AbstractGeocodingStyle style) {
96
                this.style = style;
97
        }
98

    
99
        /**
100
         * Get layer name
101
         * 
102
         * @return
103
         */
104
        public String getLayerName() {
105
                return this.layerName;
106
        }
107

    
108
        /**
109
         * Set layer name
110
         * 
111
         * @param lyrName
112
         */
113
        public void setLayerName(String lyrName) {
114
                this.layerName = lyrName;
115
        }
116

    
117
        /**
118
         * Get layer provider
119
         * 
120
         * @return
121
         */
122
        public String getLayerProvider() {
123
                return this.layerProvider;
124
        }
125

    
126
        /**
127
         * Set layer provider
128
         * 
129
         * @param lyrProvider
130
         */
131
        public void setLayerProvider(String lyrProvider) {
132
                this.layerProvider = lyrProvider;
133
        }
134

    
135
        /**
136
         * Save
137
         * 
138
         * @return
139
         * @throws XMLException
140
         */
141
        public XMLEntity getXMLEntity() throws XMLException {
142
                XMLEntity xml = new XMLEntity();
143
                xml.setName(GeocodingTags.DATASOURCE);
144
                xml.putProperty(GeocodingTags.LAYERNAME, this.layerName);
145
                xml.putProperty(GeocodingTags.LAYERPROVIDER, this.layerProvider);
146
                xml.addChild(this.style.getXMLEntity());
147

    
148
                return xml;
149
        }
150

    
151
        /**
152
         * Load
153
         * 
154
         * @param xml
155
         * @throws XMLException
156
         */
157
        public void setXMLEntity(XMLEntity xml) throws XMLException {
158
                this.layerName = xml.getStringProperty(GeocodingTags.LAYERNAME);
159
                this.layerProvider = xml.getStringProperty(GeocodingTags.LAYERPROVIDER);
160
                XMLEntity xml2 = xml.getChild(0);
161
                String sstyle = xml2.getStringProperty(GeocodingTags.STYLE);
162
                AbstractGeocodingStyle sty = null;
163
                if (sstyle.compareTo(GeocodingTags.SIMPLECENTROID) == 0) {
164
                        sty = new SimpleCentroid();
165
                        sty.setXMLEntity(xml2);
166
                } else if (sstyle.compareTo(GeocodingTags.SIMPLERANGE) == 0) {
167
                        sty = new SimpleRange();
168
                        sty.setXMLEntity(xml2);
169
                } else if (sstyle.compareTo(GeocodingTags.DOUBLERANGE) == 0) {
170
                        sty = new DoubleRange();
171
                        sty.setXMLEntity(xml2);
172
                } else if (sstyle.compareTo(GeocodingTags.COMPOSED) == 0) {
173
                        sty = new Composed();
174
                        sty.setXMLEntity(xml2);
175
                }
176
                this.style = sty;
177
        }
178

    
179
        /**
180
         * Get this class name
181
         * 
182
         * @return
183
         */
184
        public String getClassName() {
185
                return this.getClass().getName();
186
        }
187

    
188
}