Class TLcdWFSModelDecoderDecorator

java.lang.Object
com.luciad.ogc.wfs.client.TLcdWFSModelDecoderDecorator
All Implemented Interfaces:
ILcdModelDecoder, ILcdWFSModelDecoder

@LcdService(service=ILcdModelDecoder.class, priority=20000) public class TLcdWFSModelDecoderDecorator extends Object implements ILcdWFSModelDecoder, ILcdModelDecoder
An ILcdModelDecoder and ILcdWFSModelDecoder implementation that allows to access a WFS server and retrieve data from it.

Input

To load data from a WFS server, two parameters are generally required: the URL pointing to a WFS server and a WFS feature type name identifying the desired data set. This information can be supplied in two ways: The resulting model automatically loads the relevant feature type data when the model content is accessed. By default, support is provided for feature type data encoded in a GML-based format (following GML versions 2.1.2, 3.1.1 or 3.2). Through the constructor, a custom ILcdWFSModelDecoder can be supplied to support other feature type data formats. If the format is XML-based and you have a corresponding data model representation, you can also supply the data model instead of a ILcdWFSModelDecoder. This decoder automatically handles WFS service exception reports, regardless whether support for a custom format is supplied.

Additionally, this decoder can also be used decode raw WFS GetFeature response data represented by an InputStream, through decodeModel(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String, java.util.Properties).

Supported transfer protocols

  • This model decoder supports http and https protocols.

Model structure

  • This model decoder creates a model per WFS feature type name.
  • All models returned by this model decoder implement ILcd2DBoundsIndexedModel.

Model descriptor

All models returned by this decoder have a TLcdDataModelDescriptor.

Model reference

The model reference is obtained from the GML-based feature data, which relies on srsName XML attributes to represent a reference. The parsing of this srsName reference is delegated to a default ILcdModelReferenceParser, which can optionally be set through setModelReferenceParser(com.luciad.model.ILcdModelReferenceParser).

Model elements

The model elements represent the feature type's features and are of type ILcdDataObject.

Thread safety

  • The decoded models are thread-safe for read access when taking a read lock.

Sample code

Decoding a WFS data source:

    String serverURL = "https://sampleservices.luciad.com/wfs";
    String featureTypeName = "t_rivers__c__1212";

    //Create the data source
    TLcdWFSDataSource dataSource = TLcdWFSDataSource.newBuilder()
                                                    .uri(serverURL)
                                                    .featureTypeName(featureTypeName)
                                                    .build();

    //Decode the model
    ILcdModelDecoder decoder = new TLcdWFSModelDecoderDecorator();
    ILcdModel model = decoder.decodeSource(dataSource);

Decoding a string containing the server URL and WFS feature type name

    String serverURL = "https://sampleservices.luciad.com/wfs";
    String featureTypeName = "t_rivers__c__1212";

    //Concat the url and layer name to a single string
    String sourceName = String.format("%s?data=%s", serverURL, featureTypeName);

    //Decode the model
    ILcdModelDecoder decoder = new TLcdWFSModelDecoderDecorator();
    ILcdModel model = decoder.decode(sourceName);

Supported versions and specifications

  • This model decoder supports WFS servers that comply with the OGC WFS 1.0, 1.1 or 2.0 specification. For more information about the OGC WFS specification, please refer to http://www.opengeospatial.org.
Since:
8.2
  • Constructor Details

    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator()
      Constructs a new TLcdWFSModelDecoderDecorator.
    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator(ILcdOWSTransport aTransport)
      Constructs a new TLcdWFSModelDecoderDecorator that uses the given transport to interact with a WFS server.
      Parameters:
      aTransport - The transport to be used to interact with a WFS server. Must not be null.
      Since:
      2019.0
    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator(ILcdWFSModelDecoder aWFSModelDecoder)
      Constructs a new TLcdWFSModelDecoderDecorator that relies on the given ILcdWFSModelDecoder to decode data from the WFS.
      Parameters:
      aWFSModelDecoder - An ILcdWFSModelDecoder to which is delegated to decode data from the WFS, except for service exception reports.
    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator(ILcdWFSModelDecoder aWFSModelDecoder, ILcdOWSTransport aTransport)
      Constructs a new TLcdWFSModelDecoderDecorator that relies on the given ILcdWFSModelDecoder to decode data from the WFS data and that uses the given transport to interact with a WFS server.
      Parameters:
      aWFSModelDecoder - An ILcdWFSModelDecoder to which is delegated to decode data from the WFS, except for service exception reports.
      aTransport - The transport to be used to interact with a WFS server. Must not be null.
      Since:
      2019.0
    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator(TLcdDataModel aDataModel)
      Constructs a new TLcdWFSModelDecoderDecorator which uses the given data model to configure an XML decoder to decode data from the WFS.
      Parameters:
      aDataModel - A data model which will be used to decode XML. A union of data models can be used to support multiple data models.
    • TLcdWFSModelDecoderDecorator

      public TLcdWFSModelDecoderDecorator(TLcdDataModel aDataModel, ILcdOWSTransport aTransport)
      Constructs a new TLcdWFSModelDecoderDecorator which uses the given data model to configure an XML decoder to decode data from the WFS. The given transport is used to interact with a WFS server.
      Parameters:
      aDataModel - A data model which will be used to decode XML. A union of data models can be used to support multiple data models.
      aTransport - The transport to be used to interact with a WFS server. Must not be null.
      Since:
      2019.0
  • Method Details

    • canDecodeModel

      public boolean canDecodeModel(String aOutputFormat)
      Given the name of an output format advertised by a WFS, determines whether or not that format can be read by this decoder.

      In case this decoder is decorated with another ILcdWFSModelDecoder, the method is delegated to this decoder. Otherwise, true is returned if the output format equals "GML2", "GML.2", "GML3", "GML.3", "GML32", "text/xml; subtype=gml/2.1.2", "text/xml; subtype=gml/3.1.1" or "application/gml+xml; version=3.2".

      Specified by:
      canDecodeModel in interface ILcdWFSModelDecoder
      Parameters:
      aOutputFormat - the name of a format, e.g. "GML2"
      Returns:
      true if the specified format can be read
    • decodeModel

      public ILcdModel decodeModel(String aOutputFormat, String aContentType, InputStream aInputStream, String aSourceName, Properties aRequestProperties) throws IOException
      Decodes a model from the given input stream.

      In case this decoder is decorated with another ILcdWFSModelDecoder, the method is delegated to this decoder, except when a service exception report is received. This is detected if the content type equals application/vnd.ogc.se_xml.

      Specified by:
      decodeModel in interface ILcdWFSModelDecoder
      Parameters:
      aOutputFormat - the format of the data
      aContentType - the mime content type of the data obtained from the WFS in response to a GetFeature request
      aInputStream - the stream from which the model is read
      aSourceName - the base source name that could be used to build relative paths if needed.
      aRequestProperties - the request properties that could be used for following additional links (e.g. XML schema links).
      Returns:
      a model
      Throws:
      TLcdOWSServerException - if a service exception report is received
      IOException - if the model could not be decoded
    • decodeModel

      public ILcdModel decodeModel(String aOutputFormat, String aWFSVersion, String aContentType, InputStream aInputStream, String aSourceName, Properties aRequestProperties) throws IOException
      Description copied from interface: ILcdWFSModelDecoder
      Decodes a model from the given input stream.

      This default method delegates to decodeModel, but you can override this to obtain the WFS version information.

      Specified by:
      decodeModel in interface ILcdWFSModelDecoder
      Parameters:
      aOutputFormat - the format of the data contained in the given input stream, as advertised in the WFS capabilities (e.g. "GML32)
      aWFSVersion - the WFS version of the response, null if unknown
      aContentType - the MIME content type of the data contained in the given input stream (e.g. "text/xml")
      aInputStream - the input stream containing the response of a WFS GetFeature request
      aSourceName - the WFS server's URL, which could be used to build relative paths if needed. Can be null.
      aRequestProperties - an optional set of request properties that could be used for additional web service connections (e.g. XML Schema links contained in the WFS feature data). Can be null.
      Returns:
      a model
      Throws:
      IOException - if the model could not be decoded
    • setModelReferenceParser

      public void setModelReferenceParser(ILcdModelReferenceParser aModelReferenceParser)
      Sets the parser that is used to create ILcdModelReference instances given an srsName. This parser will not be used if a custom model decoder is provided.
      Parameters:
      aModelReferenceParser - the model reference parser for this decoder
      Since:
      10.1
    • getModelReferenceParser

      public ILcdModelReferenceParser getModelReferenceParser()
      Returns the model reference parser that is set on this decoder. By default no model reference parser is set, which means that a default set of known model references is supported.
      Returns:
      A model reference parser or null
      Since:
      10.1
      See Also:
    • isUseLegacyXMLFramework

      public boolean isUseLegacyXMLFramework()
      Returns whether or not the backwards compatibility mode with LuciadMap versions prior to 9.0 is enabled.
      Returns:
      whether or not the legacy XML framework is used
      See Also:
    • setUseLegacyXMLFramework

      public void setUseLegacyXMLFramework(boolean aUseLegacyXMLFramework)
      Specifies whether or not the decoder should use the legacy XML framework used in LuciadMap versions prior to 9.0. This option is available for backwards compatibility purposes but is switched off by default.
      Parameters:
      aUseLegacyXMLFramework - true if the backwards compatibility mode should be enabled
    • setUseApplicationSchemaCache

      public void setUseApplicationSchemaCache(boolean aUseCache)
      Turn application schema caching on. This is not supported when using the legacy xml framework or a custom WFS model decoder.
      Parameters:
      aUseCache - If true, caching is turned on. Otherwise, it's turned off and the cache is cleared.
      See Also:
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdModelDecoder
      Returns a short, displayable name for the format that is decoded by this ILcdModelDecoder.
      Specified by:
      getDisplayName in interface ILcdModelDecoder
      Returns:
      the displayable name of this ILcdModelDecoder.
    • canDecodeSource

      public boolean canDecodeSource(String aSourceName)
      Checks whether the given source is a WFS server.

      Returns true if the source is a HTTP or HTTPS url referring to a WFS server. The WFS server test is done by performing a GetCapabilities operation and verifying the result.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aSourceName - the source to be verified.
      Returns:
      true if the source represents a WFS server, false otherwise.
      Since:
      2018.0
      See Also:
    • decode

      public ILcdModel decode(String aSourceName) throws IOException
      Creates a new model for the WFS data in the server. aSourceName is expected in the format of URI?data=FeatureTypeName.
      • If you only provide the server URI, the feature type list is requested from the server and the first feature type is used to make a request from the WFS server.
      • If you provide both URI and feature type name, it will return the model for specified feature type name.
      Specified by:
      decode in interface ILcdModelDecoder
      Parameters:
      aSourceName - the source to be decoded, can be a formatted as URI?data=FeatureTypeName to identify the server URI and feature type name.
      Returns:
      The decoded model
      Throws:
      IOException - If the connections to the server fails, or if the server is not a WFS server, or if aSourceName is not well formatted.
      Since:
      2018.0
      See Also:
    • decodeSource

      public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
      Creates a new model for the WFS data in the server represented by a TLcdWFSDataSource.
      Specified by:
      decodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the source to be decoded, must be a TLcdWFSDataSource.
      Returns:
      The decoded model
      Throws:
      IOException - If the connections to the server fails, or if the server is not a WFS server.
      Since:
      2018.0
      See Also:
    • canDecodeSource

      public boolean canDecodeSource(ILcdDataSource aDataSource)
      Checks whether the given source represents WFS data.

      Returns true if the object is a TLcdWFSDataSource.

      This call will not make a connection to the server.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the source to be verified.
      Returns:
      true if the source is a TLcdWFSDataSource, false otherwise.
      Since:
      2018.0
      See Also:
    • setLinearElementsUseGeodesicInterpolationForGeodeticSrs

      public void setLinearElementsUseGeodesicInterpolationForGeodeticSrs(boolean aUseGeodesicInterpolationForGeodeticSrs)
      Sets whether a geodesic interpolation needs to be used for linear GML elements in case of a geodetic reference. Please refer to TLcdGMLModelDecoder.setLinearElementsUseGeodesicInterpolationForGeodeticSrs(boolean) for more information.
      Parameters:
      aUseGeodesicInterpolationForGeodeticSrs - whether a geodesic interpolation needs to be used in case of a geodetic reference
      Since:
      2020.1
      See Also:
    • isLinearElementsUseGeodesicInterpolationForGeodeticSrs

      public boolean isLinearElementsUseGeodesicInterpolationForGeodeticSrs()
      Returns true if a geodesic interpolation needs to be used for linear GML elements in case of a geodetic reference. By default, true is returned.
      Returns:
      true if a geodesic interpolation needs to be used for linear GML elements in case of a geodetic reference.
      Since:
      2020.1
      See Also: