Skip to content

Commit f3849e2

Browse files
authored
Merge pull request NASAWorldWind#45 from gbburkhardt/WCS-error-handling
Wcs error handling
2 parents 40244ce + d24f32f commit f3849e2

File tree

8 files changed

+121
-14
lines changed

8 files changed

+121
-14
lines changed

src/gov/nasa/worldwind/data/BasicRasterServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ protected void init(Object o)
140140
String message = Logging.getMessage("generic.DataSetLimitedAvailability", this.getDataSetName() );
141141
Logging.logger().severe(message);
142142
}
143+
144+
config.dispose();
143145
}
144146

145147
protected String getDataSetName()

src/gov/nasa/worldwind/data/RasterServerConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ public RasterServerConfiguration(Object docSource)
143143

144144
this.initialize();
145145
}
146+
147+
public void dispose()
148+
{
149+
try
150+
{
151+
eventReader.close();
152+
}
153+
catch (XMLStreamException e)
154+
{
155+
e.printStackTrace();
156+
}
157+
WWXML.closeEventReader(eventReader, "RasterServerConfiguration");
158+
freeResources();
159+
}
146160

147161
protected void initialize()
148162
{

src/gov/nasa/worldwind/terrain/BasicElevationModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ protected ElevationTile createTile(TileKey key)
385385
Angle minLongitude = ElevationTile.computeColumnLongitude(key.getColumn(), dLon, lonOrigin);
386386

387387
Sector tileSector = new Sector(minLatitude, minLatitude.add(dLat), minLongitude, minLongitude.add(dLon));
388+
// Clip tile sector by the layer's coverage extent
389+
tileSector = levels.getSector().intersection(tileSector);
388390

389391
return new ElevationTile(tileSector, level, key.getRow(), key.getColumn());
390392
}

src/gov/nasa/worldwind/util/DataConfigurationUtils.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,9 @@ public static AVList getWMSLayerConfigParams(WMSCapabilities caps, String[] form
766766
WMSLayerCapabilities layerCaps = caps.getLayerByName(name);
767767
if (layerCaps == null)
768768
{
769-
Logging.logger().warning(Logging.getMessage("WMS.LayerNameMissing", name));
770-
continue;
769+
String msg = Logging.getMessage("WMS.LayerNameMissing", name);
770+
Logging.logger().warning(msg);
771+
throw new WWRuntimeException(msg);
771772
}
772773

773774
if (layerCaps.hasCoordinateSystem("EPSG:4326"))
@@ -916,6 +917,13 @@ public static AVList getWCSConfigParameters(WCS100Capabilities caps, WCS100Descr
916917
throw new IllegalArgumentException(message);
917918
}
918919

920+
if (coverage.getCoverageOfferings().size() == 0)
921+
{
922+
String message = Logging.getMessage("AbsentResourceList.WCSDescribeCoverage");
923+
Logging.logger().severe(message);
924+
throw new IllegalArgumentException(message);
925+
}
926+
919927
if (params == null)
920928
{
921929
String message = Logging.getMessage("nullValue.ParametersIsNull");
@@ -1148,6 +1156,11 @@ protected static String makeTitle(WMSCapabilities caps, String layerNames, Strin
11481156

11491157
String layerName = lNames[i];
11501158
WMSLayerCapabilities layer = caps.getLayerByName(layerName);
1159+
if (layer == null)
1160+
{
1161+
continue; // layer not found
1162+
}
1163+
11511164
String layerTitle = layer.getTitle();
11521165
sb.append(layerTitle != null ? layerTitle : layerName);
11531166

src/gov/nasa/worldwind/util/MessageStrings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ AbsentResourceList.MaxTriesLessThanOne=The specified maximum number of tries is
743743
AbsentResourceList.CheckIntervalLessThanZero=The specified check interval is less than 0
744744
AbsentResourceList.RetryIntervalLessThanZero=The specified retry interval is less than 0
745745
AbsentResourceList.MaximumListSizeLessThanOne=The requested maximum list size is less than 1
746+
AbsentResourceList.WCSDescribeCoverage=No coverage offering from WCS
746747

747748
AVAAccessibleImpl.AttributeValueForKeyIsNotAString=Attribute value for key is not a String. Key {0}
748749

src/gov/nasa/worldwind/util/WWXML.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class WWXML
3939
{
4040
public static final String XLINK_URI = "http://www.w3.org/1999/xlink";
4141

42+
private static Map<XMLEventReader, InputStream> inputSources = new HashMap<XMLEventReader, InputStream>();
43+
4244
/**
4345
* Create a DOM builder.
4446
*
@@ -161,9 +163,16 @@ public static Document openDocumentFile(String filePath, Class c)
161163
throw new IllegalArgumentException(message);
162164
}
163165

164-
InputStream inputStream = WWIO.openFileOrResourceStream(filePath, c);
165-
166-
return inputStream != null ? openDocumentStream(inputStream) : null;
166+
try (InputStream inputStream = WWIO.openFileOrResourceStream(filePath, c))
167+
{
168+
return inputStream != null ? openDocumentStream(inputStream) : null;
169+
}
170+
catch (IOException e)
171+
{
172+
String message = Logging.getMessage("generic.ExceptionClosingStream", filePath);
173+
Logging.logger().severe(message);
174+
return null;
175+
}
167176
}
168177

169178
/**
@@ -264,10 +273,8 @@ public static void saveDocumentToFile(Document doc, String filePath)
264273
throw new IllegalArgumentException(message);
265274
}
266275

267-
try
276+
try (java.io.FileOutputStream outputStream = new java.io.FileOutputStream(filePath))
268277
{
269-
java.io.FileOutputStream outputStream = new java.io.FileOutputStream(filePath);
270-
271278
saveDocumentToStream(doc, outputStream);
272279
}
273280
catch (IOException e)
@@ -347,7 +354,9 @@ public static XMLEventReader openEventReaderStream(InputStream inputStream, bool
347354

348355
try
349356
{
350-
return inputFactory.createXMLEventReader(inputStream);
357+
XMLEventReader reader = inputFactory.createXMLEventReader(inputStream);
358+
inputSources.put(reader, inputStream);
359+
return reader;
351360
}
352361
catch (XMLStreamException e)
353362
{
@@ -431,7 +440,9 @@ public static XMLEventReader openEventReaderURL(URL url, boolean isNamespaceAwar
431440
try
432441
{
433442
InputStream inputStream = url.openStream();
434-
return openEventReaderStream(inputStream, isNamespaceAware);
443+
XMLEventReader reader = openEventReaderStream(inputStream, isNamespaceAware);
444+
inputSources.put(reader, inputStream);
445+
return reader;
435446
}
436447
catch (IOException e)
437448
{
@@ -517,11 +528,28 @@ else if (!(docSource instanceof String))
517528
public static void closeEventReader(XMLEventReader eventReader, String name)
518529
{
519530
if (eventReader == null)
531+
{
520532
return;
533+
}
521534

522535
try
523536
{
524537
eventReader.close();
538+
InputStream is = inputSources.get(eventReader);
539+
if (is != null)
540+
{
541+
try
542+
{
543+
is.close();
544+
}
545+
catch (IOException e)
546+
{
547+
String message = Logging.getMessage("generic.ExceptionClosingStream",
548+
name != null ? name : "Unknown");
549+
Logging.logger().severe(message);
550+
}
551+
inputSources.remove(eventReader);
552+
}
525553
}
526554
catch (XMLStreamException e)
527555
{

src/gov/nasa/worldwindx/examples/layermanager/ElevationModelManagerPanel.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public ElevationModelManagerPanel(final WorldWindow wwd)
5555
public void propertyChange(PropertyChangeEvent propertyChangeEvent)
5656
{
5757
if (propertyChangeEvent.getPropertyName().equals(AVKey.ELEVATION_MODEL))
58+
{
5859
if (!SwingUtilities.isEventDispatchThread())
60+
{
5961
SwingUtilities.invokeLater(new Runnable()
6062
{
6163
public void run()
@@ -69,8 +71,12 @@ public void run()
6971
});
7072
}
7173
});
74+
}
7275
else
76+
{
7377
update(wwd);
78+
}
79+
}
7480
}
7581
});
7682
}
@@ -89,7 +95,9 @@ protected void fill(WorldWindow wwd)
8995
// Populate this manager with an entry for each elevation model in the WorldWindow.
9096

9197
if (this.isUpToDate(wwd))
98+
{
9299
return;
100+
}
93101

94102
// First remove all the existing entries.
95103
this.modelPanels.clear();
@@ -111,7 +119,9 @@ protected void fill(WorldWindow wwd)
111119
for (ElevationModel elevationModel : cem.getElevationModels())
112120
{
113121
if (elevationModel.getValue(AVKey.IGNORE) != null)
122+
{
114123
continue;
124+
}
115125

116126
ElevationModelPanel elevationModelPanel = new ElevationModelPanel(wwd, this, elevationModel);
117127
this.modelPanels.add(elevationModelPanel);
@@ -127,18 +137,26 @@ protected boolean isUpToDate(WorldWindow wwd)
127137

128138
if (!(wwd.getModel().getGlobe().getElevationModel() instanceof CompoundElevationModel))
129139
{
130-
return this.modelPanels.get(0).getElevationModel() == wwd.getModel().getGlobe().getElevationModel();
140+
if (this.modelPanels.size() == 0)
141+
{
142+
return false;
143+
}
144+
return this.modelPanels.get(0).getElevationModel() == wwd.getModel().getGlobe().getElevationModel();
131145
}
132146

133147
CompoundElevationModel cem = (CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel();
134148

135149
if (this.modelPanels.size() != cem.getElevationModels().size())
150+
{
136151
return false;
152+
}
137153

138154
for (int i = 0; i < cem.getElevationModels().size(); i++)
139155
{
140156
if (cem.getElevationModels().get(i) != this.modelPanels.get(i).getElevationModel())
157+
{
141158
return false;
159+
}
142160
}
143161

144162
return true;

src/gov/nasa/worldwindx/examples/util/WCSCoveragePanel.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,21 @@ protected void load()
100100
{
101101
e.printStackTrace();
102102
Container c = WCSCoveragePanel.this.getParent();
103-
c.remove(WCSCoveragePanel.this);
103+
if (c != null)
104+
{
105+
c.remove(WCSCoveragePanel.this);
106+
}
107+
104108
JOptionPane.showMessageDialog((Component) wwd, "Unable to connect to server " + serverURI.toString(),
105109
"Server Error", JOptionPane.ERROR_MESSAGE);
106110
return;
107111
}
108112

109113
final java.util.List<WCS100CoverageOfferingBrief> coverages = caps.getContentMetadata().getCoverageOfferings();
110114
if (coverages == null)
115+
{
111116
return;
117+
}
112118

113119
try
114120
{
@@ -193,14 +199,22 @@ public void actionPerformed(ActionEvent actionEvent)
193199
if (((JCheckBox) actionEvent.getSource()).isSelected())
194200
{
195201
if (this.component == null)
202+
{
196203
this.component = createComponent(coverageInfo.caps, coverageInfo);
204+
if (this.component == null)
205+
{
206+
return;
207+
}
208+
}
197209

198210
updateComponent(this.component, true);
199211
}
200212
else
201213
{
202214
if (this.component != null)
215+
{
203216
updateComponent(this.component, false);
217+
}
204218
}
205219

206220
// Tell the WorldWindow to update.
@@ -224,13 +238,28 @@ protected CoverageInfo createCoverageInfo(WCS100Capabilities caps, WCS100Coverag
224238
protected void updateComponent(Object component, boolean enable)
225239
{
226240
ElevationModel model = (ElevationModel) component;
227-
CompoundElevationModel compoundModel =
228-
(CompoundElevationModel) this.wwd.getModel().getGlobe().getElevationModel();
241+
CompoundElevationModel compoundModel;
242+
243+
// Guarantee that we have a compound elevation model, so additional elevation models can be added.
244+
ElevationModel em = this.wwd.getModel().getGlobe().getElevationModel();
245+
246+
if (!(em instanceof CompoundElevationModel))
247+
{
248+
compoundModel = new CompoundElevationModel();
249+
compoundModel.addElevationModel(em);
250+
this.wwd.getModel().getGlobe().setElevationModel(compoundModel);
251+
}
252+
else
253+
{
254+
compoundModel = (CompoundElevationModel) em;
255+
}
229256

230257
if (enable)
231258
{
232259
if (!compoundModel.getElevationModels().contains(model))
260+
{
233261
compoundModel.addElevationModel(model);
262+
}
234263
}
235264
else
236265
{

0 commit comments

Comments
 (0)