-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathRasterServerConfiguration.java
More file actions
266 lines (216 loc) · 7.63 KB
/
RasterServerConfiguration.java
File metadata and controls
266 lines (216 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Copyright (C) 2015 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.data;
import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.util.*;
import gov.nasa.worldwind.util.xml.*;
import javax.xml.namespace.QName;
import javax.xml.stream.*;
import javax.xml.stream.events.XMLEvent;
import java.util.*;
/**
* Parses a raster server configuration document.
*
* @author tag
* @version $Id: RasterServerConfiguration.java 2813 2015-02-18 23:35:24Z tgaskins $
*/
public class RasterServerConfiguration extends AbstractXMLEventParser
{
protected static class Property extends AbstractXMLEventParser
{
public Property(String namespaceURI)
{
super(namespaceURI);
}
public String getName()
{
return (String) this.getField("name");
}
public String getValue()
{
return (String) this.getField("value");
}
}
protected static class RasterSector extends AbstractXMLEventParser
{
public RasterSector(String namespaceURI)
{
super(namespaceURI);
}
public Sector getSector()
{
AbstractXMLEventParser corner = (AbstractXMLEventParser) this.getField("SouthWest");
AbstractXMLEventParser latLon = (AbstractXMLEventParser) corner.getField("LatLon");
Double minLat = Double.valueOf((String) latLon.getField("latitude"));
Double minLon = Double.valueOf((String) latLon.getField("longitude"));
String units = (String) latLon.getField("units");
corner = (AbstractXMLEventParser) this.getField("NorthEast");
latLon = (AbstractXMLEventParser) corner.getField("LatLon");
Double maxLat = Double.valueOf((String) latLon.getField("latitude"));
Double maxLon = Double.valueOf((String) latLon.getField("longitude"));
if (units.equals("radians"))
return Sector.fromRadians(minLat, maxLat, minLon, maxLon);
else
return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
}
}
protected static class Corner extends AbstractXMLEventParser
{
public Corner(String namespaceURI)
{
super(namespaceURI);
}
}
public static class Source extends AbstractXMLEventParser
{
public Source(String namespaceURI)
{
super(namespaceURI);
}
public String getPath()
{
return (String) this.getField("path");
}
public String getType()
{
return (String) this.getField("type");
}
public Sector getSector()
{
return ((RasterSector) this.getField("Sector")).getSector();
}
}
protected static class Sources extends AbstractXMLEventParser
{
protected ArrayList<Source> sources = new ArrayList<Source>();
public Sources(String namespaceURI)
{
super(namespaceURI);
}
public ArrayList<Source> getSources()
{
return this.sources;
}
protected void doParseEventContent(XMLEventParserContext ctx, XMLEvent event, Object... args)
throws XMLStreamException
{
if (ctx.isStartElement(event, "Source"))
{
Source s = (Source) ctx.getParser(event).parse(ctx, event);
this.sources.add(s);
}
else
{
super.doParseEventContent(ctx, event, args);
}
}
}
protected static String namespaceURI;
protected XMLEventReader eventReader;
protected XMLEventParserContext parserContext;
protected HashMap<String, String> properties = new HashMap<String, String>();
public RasterServerConfiguration(Object docSource)
{
super(namespaceURI);
this.eventReader = this.createReader(docSource);
this.initialize();
}
public void dispose() {
try {
eventReader.close();
} catch (XMLStreamException e) {
e.printStackTrace();
}
WWXML.closeEventReader(eventReader, "RasterServerConfiguration");
freeResources();
}
protected void initialize()
{
this.parserContext = this.createParserContext(this.eventReader);
}
protected XMLEventReader createReader(Object docSource)
{
return WWXML.openEventReader(docSource);
}
protected XMLEventParserContext createParserContext(XMLEventReader reader)
{
this.parserContext = new BasicXMLEventParserContext(reader);
this.parserContext.setDefaultNamespaceURI(this.getNamespaceURI());
return this.parserContext;
}
public XMLEventParserContext getParserContext()
{
return this.parserContext;
}
public String getVersion()
{
return (String) this.getField("version");
}
public Sector getSector()
{
RasterSector sector = (RasterSector) this.getField("Sector");
return sector != null ? sector.getSector() : null;
}
public HashMap<String, String> getProperties()
{
return this.properties;
}
public ArrayList<Source> getSources()
{
return ((Sources) this.getField("Sources")).getSources();
}
public RasterServerConfiguration parse(Object... args) throws XMLStreamException
{
XMLEventParserContext ctx = this.parserContext;
QName capsName = new QName(this.getNamespaceURI(), "RasterServer");
for (XMLEvent event = ctx.nextEvent(); ctx.hasNext(); event = ctx.nextEvent())
{
if (event == null)
continue;
if (event.isStartElement() && event.asStartElement().getName().equals(capsName))
{
// Parse the attributes in order to get the version number in order to determine the namespaces.
this.doParseEventAttributes(ctx, event);
ctx.setDefaultNamespaceURI(this.getNamespaceURI());
// Now register the parsers.
this.registerParsers(ctx);
super.parse(ctx, event, args);
return this;
}
}
return null;
}
protected void doParseEventContent(XMLEventParserContext ctx, XMLEvent event, Object... args)
throws XMLStreamException
{
if (ctx.isStartElement(event, "Property"))
{
Property p = (Property) ctx.getParser(event).parse(ctx, event);
this.properties.put(p.getName(), p.getValue());
}
else
{
super.doParseEventContent(ctx, event, args);
}
}
protected void registerParsers(XMLEventParserContext ctx)
{
ctx.registerParser(new QName(this.getNamespaceURI(), "Property"),
new Property(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "LatLon"),
new AttributesOnlyXMLEventParser(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "SouthWest"),
new Corner(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "NorthEast"),
new Corner(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "Sector"),
new RasterSector(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "Source"),
new Source(this.getNamespaceURI()));
ctx.registerParser(new QName(this.getNamespaceURI(), "Sources"),
new Sources(this.getNamespaceURI()));
}
}