Class TLcdS63UnifiedModelDecoder

java.lang.Object
com.luciad.format.s63.TLcdS63UnifiedModelDecoder
All Implemented Interfaces:
ILcdMetadataDecoder, ILcdInputStreamFactoryCapable, ILcdDataSourceModelDecoder, ILcdModelDecoder

The equivalent decoder of TLcdS57UnifiedModelDecoder for S-57 data which is encrypted according to the S-63 standard. These formats are published by the International Hydrographic Organization in "IHO Transfer Standard for Digital Hydrographic Data, Special Publications No. 57 and No. 63"

To decode S-63 data, the following properties should be set on the decoder:

  • the location of the SA (scheme administrator) public key: this can be done by either
    • setting the SA certificate file (setSACertificateSource(String aSourceName)) or
    • setting the SA public key file (setSAPublicKeySource(String aSourceName))
  • the location of the permit file(s) containing the cell permit entries: this can be done by either
    • making sure the basic permit file or meta permit file is located in the same directory as the file which is decoded (a category file or cell file). The model decoder will then auto-detect the permit file and use it.
    • setting the basic permit file(s) (setBasicPermitSource(String aSourceName) or setBasicPermitSources(List<String> aSourceNames)) or
    • setting the meta permit file(s) (setMetaPermitSource(String aSourceName)) or setMetaPermitSources(List<String> aSourceNames)

Additionally, when you are not an Ecdis manufacturer yourself, the running LuciadLightspeed license should contain a valid S-63 User Permit. The model decoder will only work with S-63 files which were provided for this User Permit. Consult the developer guide for more information on how to work with User Permits.

The decoded models have the same structure as the models from the TLcdS57UnifiedModelDecoder, which depends on whether a catalogue or a single cell is decoded. The only difference is that the model descriptor is a TLcdS63ModelDescriptor on the individual cell models.

Input files

File Required Entry point Description
CATALOG.031 x x An S-63 catalog
*.000 x x An S-63 individual cell

Supported file transfer protocols

  • This model decoder supports all transfer protocols that are supported by the ILcdInputStreamFactory of this decoder.

Model structure

See model structure described in TLcdS57UnifiedModelDecoder.

Model descriptor

Model reference

  • All models returned by this model decoder have a TLcdGeodeticReference, as described by the specification.

Model elements

  • See the documentation of TLcdS57ModelDecoder for more information on domain objects.

Useful settings

Sample code


 ILcdModelDecoder decoder = new TLcdS63UnifiedModelDecoder();
 ILcdModel model = decoder.decode("/path/to/CATALOG.031");
 // Or ILcdModel model = decoder.decode("/path/to/GB4D132.000");

 // To add to a Lightspeed view:
 lspView.addLayer(TLspS52LayerBuilder.newBuilder().model(model).build());
 // To add to a GXY view:
 gxyView.addLayer(new TLcdS52GXYLayerFactory().createGXYLayer(model));
 

Performance tips

Thread safety

  • The decoding of models is thread-safe, as long as no properties are changed during the decoding.
  • The decoded models are thread-safe for read access.

Error handling

You can configure how errors are handled while decoding cells or catalogs through setIgnoreInvalidCells(boolean) and setInvalidCellExceptionHandler(com.luciad.format.s57.ILcdS57InvalidCellExceptionHandler).

By default, ignore invalid cells is set to false, and the exception handler logs and re-throws all exceptions, except for missing cell files: these are simply logged and ignored.

For missing cell files, you can expect an FileNotFoundException as error.

Your handler's handleCellWarnings will be called during decode(java.lang.String) with TLcdS63Exceptions to notify you of issues with cells}:

  • Cells for which there is no permit (SSE_011). These cells will not be loaded.
  • Cells for which the subscription is about to expire (SSE_020). The cells will still be loaded.
  • Cells for which the subscription expired (SSE_015). The cells will still be loaded.

Since cells in a catalog are lazy-loaded, exceptions can occur not only during the decode(java.lang.String), but also when accessing the data later, for example listing elements, or by accessing some properties of TLcdS57ModelDescriptor.

If a cell is ignored, a empty stub model is inserted in place of the actual model.

Supported versions and specifications

Known limitations

Requirements

  • The current implementation requires JRE 1.2 or higher.
  • The current implementation requires native libraries.
Since:
2013.1
  • Constructor Details

    • TLcdS63UnifiedModelDecoder

      public TLcdS63UnifiedModelDecoder()
      Create a new unified model decoder instance.
  • Method Details

    • setS63CustomerSystemID

      public static void setS63CustomerSystemID(String aS63CustomerSystemId)
      Configures the S63 Customer System ID, a unique ID used to identify an S-63 system.

      Alternatively, you can set the JVM system property com.luciad.format.s63.s63CustomerSystemID:

        -Dcom.luciad.format.s63.s63CustomerSystemID=mys63id
       
      The system property will be overridden if the setter method is used.
      In Lucy, you can also use TLcyS63FormatAddOn.s63CustomerSystemID configuration setting of the S-63 add-on (TLcyS63FormatAddOn.cfg).

      If your LuciadLightspeed license is not linked to an S-63 Customer System ID, you should not use this method.

      If your LuciadLightspeed license is linked to an S-63 Customer System ID, you must set the ID before using canDecodeSource(java.lang.String) or decode(java.lang.String), or they will return false and throw IllegalArgumentException, respectively.

      The ID is verified against the ID linked to your LuciadLightspeed license. If the ID does not match:

      Parameters:
      aS63CustomerSystemId - The ID to validate with
      Throws:
      IllegalArgumentException - if the given ID does not match the ID linked with your license.
    • setUnencryptedHardwareID

      public static void setUnencryptedHardwareID(String aHardwareID)

      Sets an unencrypted version of the hardware ID (HW_ID) of this system. This method will encrypt the hardware ID, and pass it to the setEncryptedHardwareID(String) method.

      For convenience, this method is available on all of the S-63 model decoder classes (TLcdS63UnifiedModelDecoder, TLcdS63CatalogueModelDecoder and TLcdS63ModelDecoder). It is sufficient to call this method once on any of model decoders.

      Parameters:
      aHardwareID - The 5-digit hexadecimal number. For example "A79AB"
      Since:
      2015.1
      See Also:
    • setEncryptedHardwareID

      public static void setEncryptedHardwareID(String aHardwareID)

      Sets an encrypted version of the hardware ID (HW_ID) of this system. This method can only be called when you are a manufacturer of ECDIS systems, and have bought a corresponding license.
      You can check whether your license supports this by opening the development_license.txt file (this file is located inside the development_license.jar file). It must contain the s63Manufacturer = true key-value pair.

      If you want to specify the hardware ID using the API and do not want to do the encryption yourself, you can use the setUnencryptedHardwareID(String) method instead.

      If you want to do the encryption yourself, you can use the following code which uses an RSA encryption:

      
         String hardwareID =  ... ;//5-digit hexadecimal number (for example "A79AB")
      
         byte[] rsa_n = {0, -51, -16, -29, -89, -15, -58, -106, -80, -113, -6, 64, -111, -85, -60, -10, 47};
         byte[] rsa_e = {0, -128, -23};
      
         BigInteger hw_id_encrypted = new BigInteger(hardwareID, 16).modPow(new BigInteger(rsa_e), new BigInteger(rsa_n));
         return hw_id_encrypted.toString(16);
       

      The encrypted hardware ID can also be specified using a system property. Setting the unencrypted hardware ID using the system property is not supported.

      
         -Dcom.luciad.format.s63.encryptedHardwareID=xxxxxxx
       

      The S-63 specification requires that manufacturers take the necessary precautions to ensure that the HW_ID remains unknown to the end-user of the system. This method works with an encrypted form of the HW_ID, but this is not sufficient to ensure proper protection of the HW_ID. It is up to the manufacturer using the Luciad API to ensure that the end-user has no access to the runtime environment, and that the (encoded) version of the HW_ID is not accessible by the user.

      Note: this method should be called before triggering any S-63 related code. Calling this method a second time after any S-63 related code has been triggered has no effect.

      For convenience, this method is available on all of the S-63 model decoder classes (TLcdS63UnifiedModelDecoder, TLcdS63CatalogueModelDecoder and TLcdS63ModelDecoder). It is sufficient to call this method once on any of model decoders.

      Parameters:
      aHardwareID - The encrypted version of the 5-digit hexadecimal number.
      Since:
      2015.1
      See Also:
    • setDoAuthentication

      public void setDoAuthentication(boolean aDoAuthentication)
    • setSAPublicKeySources

      public void setSAPublicKeySources(List<String> aSourceNames)
    • setBasicPermitSources

      public void setBasicPermitSources(List<String> aSourceNames)
    • getSACertificateSources

      public List<String> getSACertificateSources()
    • getBasicPermitSources

      public List<String> getBasicPermitSources()
    • setMetaPermitSources

      public void setMetaPermitSources(List<String> aSourceNames)
    • setSACertificateSources

      public void setSACertificateSources(List<String> aSourceNames)
    • getUserPermit

      public String getUserPermit()
    • getMetaPermitSources

      public List<String> getMetaPermitSources()
    • getSAPublicKeySources

      public List<String> getSAPublicKeySources()
    • 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.
    • setInputStreamFactory

      public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      Description copied from interface: ILcdInputStreamFactoryCapable
      Sets the input stream factory to be used.
      Specified by:
      setInputStreamFactory in interface ILcdInputStreamFactoryCapable
      Parameters:
      aInputStreamFactory - the input stream factory to be used.
    • getInputStreamFactory

      public ILcdInputStreamFactory getInputStreamFactory()
      Description copied from interface: ILcdInputStreamFactoryCapable
      Returns the input stream factory that is used.
      Specified by:
      getInputStreamFactory in interface ILcdInputStreamFactoryCapable
      Returns:
      the input stream factory that is used.
    • setInvalidCellExceptionHandler

      public void setInvalidCellExceptionHandler(ILcdS57InvalidCellExceptionHandler aHandler)
      Sets the cell exception handler to be used when decoding individual cells in a catalog. This exception handler will be called whenever a cell could not be decoded correctly.

      See class javadoc section "Error handling" for details.

      This handler is not invoked when decoding an individual faulty cell directly (not through a catalog). Instead, an exception will be thrown from the decode(java.lang.String) method.

      Parameters:
      aHandler - the exception handler to be used when decoding individual cells.
      See Also:
    • getInvalidCellExceptionHandler

      public ILcdS57InvalidCellExceptionHandler getInvalidCellExceptionHandler()
      Return the cell exception handler to be used when decoding individual cells.
      Returns:
      the cell exception handler to be used when decoding individual cells.
      See Also:
    • setIgnoreInvalidCells

      public void setIgnoreInvalidCells(boolean aIgnoreInvalidCells)
      Specifies whether to ignore invalid cells in a catalog or not.

      See class javadoc section "Error handling" for details.

      This setting has no effect when decoding an individual faulty cell directly (not through a catalog). Instead, an exception will be thrown from the decode(java.lang.String) method.

      Parameters:
      aIgnoreInvalidCells - true when invalid cells should be ignored
      See Also:
    • isIgnoreInvalidCells

      public boolean isIgnoreInvalidCells()
      Returns whether to ignore invalid cells or not.
      Returns:
      true if invalid cells have to be ignored, false otherwise.
      See Also:
    • setVerifyChecksum

      public void setVerifyChecksum(boolean aVerifyChecksum)
      Sets whether to compute the checksum of the ENC cells and verify it with the corresponding checksum in the catalogue. This feature is disabled by default, and is not supported for S-63 encrypted files.
      Parameters:
      aVerifyChecksum - boolean indicating whether to verify the ENC cell checksums.
    • isVerifyChecksum

      public boolean isVerifyChecksum()
      Returns whether to compute the checksum of the ENC cells and verify it with the corresponding checksum in the catalogue.
      Returns:
      whether to verify the ENC cell checksums.
    • setUseSENCCache

      public void setUseSENCCache(boolean aUseSENCCache)
      Enables or disables the use of SENC (System ENC) caches. If enabled, each S-57 cell will be converted into SENC format and cached in the SENC cache dir when it is decoded. The next time the S-57 cell is read, the cached SENC copy will be used instead.

      See the class javadoc for more information on SENC and its limitations.

      If SENC caching is enabled, a suitable caching dir should be set as well, see setSENCCacheDir(File).

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Parameters:
      aUseSENCCache - flag indicating whether to use the SENC cache or not.
      See Also:
    • isUseSENCCache

      public boolean isUseSENCCache()
      Returns true if the SENC cache is being used, false otherwise.

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Returns:
      true if the SENC cache is being used, false otherwise.
      See Also:
    • setSENCCacheDir

      public void setSENCCacheDir(File aSENCCacheDir)
      Sets the SENC cache dir where the converted SENC copies of S-57 cells should be stored. The default location is the .senccache directory in the user's home folder. If the specified directory does not exist yet, it will be automatically created by the decoder.

      SENC caches are not thread-safe: they should not be used simultaneously by multiple decoder instances; if multiple decoder instances run simultaneously they should all have their own SENC cache dir.

      Parameters:
      aSENCCacheDir - the SENC cache dir where the converted SENC copies of S-57 cells should be stored.
      See Also:
    • getSENCCacheDir

      public File getSENCCacheDir()
      Returns the SENC cache dir where the converted SENC copies of S-57 cells should be stored.

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Returns:
      the SENC cache dir where the converted SENC copies of S-57 cells should be stored.
      See Also:
    • canDecodeSource

      public boolean canDecodeSource(String aSourceName)
      Description copied from interface: ILcdModelDecoder
      Checks whether this model decoder can decode the specified data source. It is acceptable for this method to return 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.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source to be verified; typically a file name or a URL.
      Returns:
      true if this decoder can likely decode the data specified by the source name, false otherwise.
      See Also:
    • decode

      public ILcdModel decode(String aSourceName) throws IOException
      Description copied from interface: ILcdModelDecoder
      Creates a new model from the given data source.
      Specified by:
      decode in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source to be decoded; typically a file name or a URL.
      Returns:
      A model containing the decoded data. While null is allowed, implementors are advised to throw an error instead.
      Throws:
      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);
            }
         }
       
      See Also:
    • decodeModelMetadata

      public TLcdModelMetadata decodeModelMetadata(String aSourceName) throws IOException
      Decodes metadata for the specified data source.
      Specified by:
      decodeModelMetadata in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source for which the model metadata will be decoded.
      Returns:
      the model metadata for the data source, never null.
      Throws:
      IOException - if the metadata cannot be decoded for some reason.
      See Also:
    • canDecodeMetadata

      public boolean canDecodeMetadata(String aSourceName)
      Description copied from interface: ILcdMetadataDecoder
      Tells whether this metadata decoder can likely decode metadata for a given source name.
      Specified by:
      canDecodeMetadata in interface ILcdMetadataDecoder
      Parameters:
      aSourceName - the source name to decode metadata for
      Returns:
      true if this metadata decoder can decode metadata for the given source name, false otherwise
    • decodeMetadata

      public TLcdISO19115Metadata decodeMetadata(String aSourceName) throws IOException
      The S-63 metadata has a similar structure as the S-57 one. The signatures are added as support files to the data sets of the cells. The permit file(s) "ENC.PMT" and/or "PERMIT.TXT" are added as support files to the aggregate. These permit files need to be next to the "CATALOG.031" file in the catalog directory. Permits in other (user-defined) directories are not part of the metadata.
      Specified by:
      decodeMetadata in interface ILcdMetadataDecoder
      Parameters:
      aSourceName - the source name to decode metadata from
      Returns:
      a metadata object
      Throws:
      IOException - if the metadata cannot be decoded for some reason
      See Also:
    • canDecodeSource

      public boolean canDecodeSource(ILcdDataSource aDataSource)
      Checks whether this model decoder can decode the data source.

      Return true if:

      • The source is a TLcdS57CatalogueDataSource.
      • It contains at least one base (non-update) cell, either directly or in a catalogue.
      • The cell can be decoded and is an ENC or AML cell.
      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the data source
      Returns:
      true if the data source can be decoded, false otherwise
      See Also:
    • decodeSource

      public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
      Description copied from interface: ILcdModelDecoder

      Creates a new model from the given data source.

      By default, this method:

      Specified by:
      decodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the ILcdDataSource to be decoded.
      Returns:
      a model containing the decoded data. While null is allowed, implementors are advised to throw an error instead.
      Throws:
      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 decodeSource(ILcdDataSource aDataSource) throws IOException {
         try {
           // Perform decoding ...
         } catch (RuntimeException e) {
           throw new IOException(e);
         }
       }
       
      See Also: