@LcdService(service=ILcdModelDecoder.class, priority=20000) public class TLcdOGCWMSProxyModelDecoder extends Object implements ILcdModelDecoder,ILcdDataSourceModelDecoder
ILcdModelDecoder
implementation that allows to access a WMS
server and retrieve data from it.
TLcdWMSDataSource
, containing a WMS base URL and one or more WMS layer identifiers.data=layerName
key/value pair.decode(String)
and decodeSource(com.luciad.model.ILcdDataSource)
methods returns an ILcdModel
containing one ALcdWMSProxy
element. This element can be used to
access the capabilities of the OGC WMS server, and to configure the layer data to be retrieved
(if not yet set through the input supplied to this decoder).
The returned model is also an ILcdMultiDimensionalModel
,
with support for OGC WMS dimensions time, elevation, depth and altitude.
If a WMS layer is registered on the ALcdWMSProxy
that defines one
of more of these dimensions, they are automatically picked up by the model.
TLcdWMSProxyModelDescriptor
.
ALcdWMSProxy
object.
ALcdWMSProxy
object.
This object can be configured for the actual WMS layers one is interested in.
When the model is decoded just using a URL the ALcdWMSProxy
is configured with the first WMS layer
found in the capabilities. This behavior can be switched off by passing an argument within the constructor.
Decoding a WMS data source:
String serverURL = "https://sampleservices.luciad.com/wms";
String wmsLayerName = "cities";
//Create the data source
TLcdWMSDataSource dataSource = TLcdWMSDataSource.newBuilder()
.uri(serverURL)
.addLayer(wmsLayerName)
.build();
//Decode the model
ILcdModelDecoder decoder = new TLcdOGCWMSProxyModelDecoder();
ILcdModel model = decoder.decodeSource(dataSource);
Decoding a string containing the server URL and WMS layer
String serverURL = "https://sampleservices.luciad.com/wms";
String wmsLayerName = "cities";
//Concat the url and layer name to a single string
String sourceName = String.format("%s?data=%s", serverURL, wmsLayerName);
//Decode the model
ILcdModelDecoder decoder = new TLcdOGCWMSProxyModelDecoder();
ILcdModel model = decoder.decode(sourceName);
ALcdWMSProxy
Constructor and Description |
---|
TLcdOGCWMSProxyModelDecoder()
Creates a new
TLcdOGCWMSProxyModelDecoder instance. |
TLcdOGCWMSProxyModelDecoder(ILcdOWSTransport aTransport,
TLcdDataModel[] aSLDDataModels)
Creates a new
TLcdOGCWMSProxyModelDecoder instance,
configured with the given transport and SLD extension data models. |
TLcdOGCWMSProxyModelDecoder(TLcdDataModel[] aSLDDataModels)
Creates a new
TLcdOGCWMSProxyModelDecoder instance,
configured with the given SLD extension data models. |
Modifier and Type | Method and Description |
---|---|
void |
addAdditionalXYWorldReferenceFormatter(ILcdXYWorldReferenceFormatter aXYWorldReferenceFormatter)
Adds additional formatters for
ILcdXYWorldReference objects onto a string representation. |
boolean |
canDecodeSource(ILcdDataSource aDataSource)
Checks whether this model decoder can decode the data source(s), identified by the passed
ILcdDataSource . |
boolean |
canDecodeSource(String aServerURLAsString)
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(String aSourceName)
Creates an
ILcdModel containing one ALcdWMSProxy element,
which can be used to access the specified WMS server. |
ILcdModel |
decode(TLcdWMSClient aClient)
Creates an
ILcdModel containing one ALcdWMSProxy element,
which can be used to access the specified WMS server. |
ILcdModel |
decodeSource(ILcdDataSource aDataSource)
This method supports decoding a
TLcdWMSDataSource and a TLcdDataSource . |
String |
getDisplayName()
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
String |
getSAXParser()
Deprecated.
This method has been kept for compatibility reasons with LuciadMap.
The method
SAXParserFactory.newInstance() is now used to
create a SAX parser. |
boolean |
isUseEmptyProxyForUrlOnly()
Returns whether the decoder returns a model containing an empty
wms proxy object. |
boolean |
isValidating()
Returns whether XML validation is enabled for the XML capabilities document provided by a server.
|
void |
setEntityLocation(String aSystemEntity,
URL aEntityURL)
Sets the URL to be used for an entity defined in the WMS capabilities document provided
by a server.
|
void |
setRequestProperty(String aKey,
String aValue)
Sets the general request property.
|
void |
setSAXParser(String aSAXParser)
Deprecated.
This method has been kept for compatibility reasons with LuciadMap.
The method
SAXParserFactory.newInstance() is now used to
create a SAX parser. |
void |
setUseEmptyProxyForUrlOnly(boolean aUseEmptyProxyForUrlOnly)
Sets the new value for how the model is constructed in case only a URL is provided.
|
void |
setValidating(boolean aValidating)
Specifies whether XML validation (DTD and XML Schema) is enabled for the WMS capabilities document
provided by a server.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
decodeModelMetadata, decodeModelMetadata, discoverDataSources
public TLcdOGCWMSProxyModelDecoder()
TLcdOGCWMSProxyModelDecoder
instance.public TLcdOGCWMSProxyModelDecoder(TLcdDataModel[] aSLDDataModels)
TLcdOGCWMSProxyModelDecoder
instance,
configured with the given SLD extension data models.
SLD extension data models are needed if the client wants to submit
an SLD to the WMS that uses an extension of the OGC SLD specification.
For instance, if a custom symbolizer is introduced to address
specific styling requirements. The data models of such extensions are needed
to be able to encode any configured SLD (see ALcdWMSProxy.setStyledLayerDescriptor(com.luciad.wms.sld.model.TLcdSLDStyledLayerDescriptor)
)
to XML, for embedding in requests.
aSLDDataModels
- a list of SLD extension data modelspublic TLcdOGCWMSProxyModelDecoder(ILcdOWSTransport aTransport, TLcdDataModel[] aSLDDataModels)
TLcdOGCWMSProxyModelDecoder
instance,
configured with the given transport and SLD extension data models.
SLD extension data models are needed if the client wants to submit
an SLD to the WMS that uses an extension of the OGC SLD specification.
For instance, if a custom symbolizer is introduced to address
specific styling requirements. The data models of such extensions are needed
to be able to encode any configured SLD (see ALcdWMSProxy.setStyledLayerDescriptor(com.luciad.wms.sld.model.TLcdSLDStyledLayerDescriptor)
)
to XML, for embedding in requests.
aTransport
- The transport. Must not be null.
The transport will be used when decoding the model, except when you call the decode(TLcdWMSClient)
method
directly.aSLDDataModels
- a list of SLD extension data models. Use null
or an empty array when no extensions are needed.public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.getDisplayName
in interface ILcdModelDecoder
ILcdModelDecoder
.public void setRequestProperty(String aKey, String aValue)
aKey
- the keyword by which the request is known (e.g., "accept
").aValue
- the value associated with it.URLConnection.setRequestProperty(java.lang.String, java.lang.String)
public void setEntityLocation(String aSystemEntity, URL aEntityURL)
null
as location for an entity, a previously specified location can be removed.
A typical example of an entity definition in an XML document is a reference to a DTD or
XML Schema. By using this method, one can replace such a reference with a reference
to a locally stored copy of the DTD or XML Schema.aSystemEntity
- The entity to be relocated.aEntityURL
- The URL to be used for a given entity.public void setValidating(boolean aValidating)
false
.aValidating
- Whether XML validation should be enabled.public boolean isValidating()
false
.public boolean isUseEmptyProxyForUrlOnly()
wms proxy
object.
The default value is false
.
When decoding using a URL only the model returned by the decoder contains a wms proxy
which is configured with one WMS layer such that you get a proper visualization of the WMS layer.
When the value is true
the wms proxy
object within the model is not configured
with any of the layers served by the WMS service.
In this case you need to configure the layers you want yourself or nothing will be displayed on the map for this model.wms proxy
object.public void setUseEmptyProxyForUrlOnly(boolean aUseEmptyProxyForUrlOnly)
aUseEmptyProxyForUrlOnly
- the new value for how the model is constructed in case only a URL is provided.isUseEmptyProxyForUrlOnly()
public void addAdditionalXYWorldReferenceFormatter(ILcdXYWorldReferenceFormatter aXYWorldReferenceFormatter)
ILcdXYWorldReference
objects onto a string representation.aXYWorldReferenceFormatter
- additional formatter.@Deprecated public void setSAXParser(String aSAXParser)
SAXParserFactory.newInstance()
is now used to
create a SAX parser.aSAXParser
- the new SAXParser class name.getSAXParser()
,
SAXParserFactory.newInstance()
@Deprecated public String getSAXParser()
SAXParserFactory.newInstance()
is now used to
create a SAX parser.setSAXParser(java.lang.String)
public boolean canDecodeSource(String aServerURLAsString)
ILcdModelDecoder
true
for a source name while decode
throws an exception for that same source name.
For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
canDecodeSource
in interface ILcdModelDecoder
aServerURLAsString
- the data source to be verified; typically a file name or a URL.true
if this decoder can likely decode the data specified by the source name, false
otherwise.ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
ILcdModel
containing one ALcdWMSProxy
element,
which can be used to access the specified WMS server.
The ALcdWMSProxy
object contained in the returned model has the following properties:
ALcdWMSProxy.createImageInputStream(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
and ALcdWMSProxy.createImage(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
, which
are used to send GetMap requests, are thread-safe. Multiple threads can use these methods concurrently on the
same ALcdWMSProxy
object, without the need for extra synchronization.ALcdWMSProxy.clone()
returns a shallow clone, except for the internal data structures
that are used to store the additional parameters, request properties, entity locations, reference formatters
and styled named layer wrappers: these structures are cloned (not their contents), allowing to set different
configuration parameters on the cloned object than on the source object. The capabilities itself are not cloned.aSourceName
the source to be decoded, can be a formatted as URI?data=LayerName
to identify the server URI and layer name.
model
which is configured with the first layer found in the WMS capabilities
unless this decoder's property isUseEmptyProxyForUrlOnly()
returns true
.
model
with the specified layer data.
decode
in interface ILcdModelDecoder
aSourceName
- The URL of the WMS server.ILcdModel
with a ALcdWMSProxy
element.TLcdOGCWMSServiceException
- when the server sends a service exception report.TLcdOGCWMSHttpException
- when a HTTP error is received.TLcdOGCWMSException
- in all other cases.IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost
always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException,
IllegalArgumentException, ...) on unexpected places, implementations are advised to catch
RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated
in the code snippet below.
public ILcdModel decode( String aSourceName ) throws IOException {
try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) {
// Perform decoding ...
} catch (RuntimeException e) {
throw new IOException(e);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)
public ILcdModel decode(TLcdWMSClient aClient) throws IOException
ILcdModel
containing one ALcdWMSProxy
element,
which can be used to access the specified WMS server.
The ALcdWMSProxy
object contained in the returned model has the following properties:
ALcdWMSProxy.createImageInputStream(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
and ALcdWMSProxy.createImage(int, int, com.luciad.view.ILcdXYWorldReference, com.luciad.shape.ILcdBounds, java.awt.Color)
,
which are used to send GetMap requests, are thread-safe. Multiple threads can use these methods concurrently on the
same ALcdWMSProxy
object, without the need for extra synchronization.ALcdWMSProxy.clone()
returns a shallow clone, except for the internal data structures
that are used to store the additional parameters, request properties, entity locations, reference formatters
and styled named layer wrappers: these structures are cloned (not their contents), allowing to set different
configuration parameters on the cloned object than on the source object. The capabilities itself are not cloned.
The WMS client will not be cloned.aClient
- The TLcdWMSClient
which will be used to perform all requests in the ALcdWMSProxy
ILcdModel
with a ALcdWMSProxy
element.TLcdOGCWMSServiceException
- when the server sends a service exception report.TLcdOGCWMSHttpException
- when a HTTP error is received.TLcdOGCWMSException
- in all other cases.IOException
public boolean canDecodeSource(ILcdDataSource aDataSource)
ILcdModelDecoder
Checks whether this model decoder can decode the data source(s), identified by the passed ILcdDataSource
.
For performance reasons, we strongly recommend that this will only be a simple test.
For example: check the instance class of aDataSource
,
or check the file extension if it is a TLcdDataSource
.
The default implementation of this method will check if the given ILcdDataSource
is a
TLcdDataSource
. If not, this method returns false. Otherwise, it delegates
the source to the ILcdModelDecoder.canDecodeSource(String)
method.
canDecodeSource
in interface ILcdModelDecoder
aDataSource
- the ILcdModelSource
to be verified.true
if this decoder can likely decode the data specified by aDataSource
, false
otherwise.ILcdModelDecoder.decodeSource(ILcdDataSource)
,
ILcdModelDecoder.decodeModelMetadata(ILcdDataSource)
public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
TLcdWMSDataSource
and a TLcdDataSource
.
The latter data source behaves the same as calling the method decode(String)
.
The minimum requirements for the TLcdWMSDataSource
is the availability of the WMS server URI and one or more layers.
Other values are optional and defaults are chosen.
Mandatory information that has to be correct in the data source is the following.
For the optional information the decoding is more lenient.
true
when the server does not support querying for that layer. The querying is switched off to honour the capabilities of the server.decodeSource
in interface ILcdModelDecoder
aDataSource
- the ILcdDataSource
to be decoded.IOException
- when decoding the data source fails.ILcdModelDecoder.canDecodeSource(ILcdDataSource)