Class TLcdCompositeModelDecoder

java.lang.Object
com.luciad.model.TLcdCompositeModelDecoder
All Implemented Interfaces:
ILcdInputStreamFactoryCapable, ILcdDataSourceModelDecoder, ILcdModelDecoder

public class TLcdCompositeModelDecoder extends Object implements ILcdModelDecoder, ILcdDataSourceModelDecoder, ILcdInputStreamFactoryCapable
Composite implementation of ILcdModelDecoder.

Any number of model decoders can be added to this composite.

The decode(java.lang.String) delegates, in order, to the decoders in the list who can decode the source. See decode(String) for details.

Example usage:

To create a composite instance which uses all default available ILcdModelDecoder instances, you can use:
    ILcdModelDecoder modelDecoder =
        new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
This will use all model decoders annotated with the @LcdService annotation.
Since:
2013.0
  • Constructor Details

    • TLcdCompositeModelDecoder

      public TLcdCompositeModelDecoder()
      Creates a new, empty composite model decoder. This decoder will not be able to create models until delegate model decoders are added to the model decoder list.
    • TLcdCompositeModelDecoder

      public TLcdCompositeModelDecoder(Iterable<? extends ILcdModelDecoder> aModelDecoders)
      Creates a new composite model decoder that lazily uses the given Iterable to delegate to.
      Parameters:
      aModelDecoders - an Iterable of model decoders
    • TLcdCompositeModelDecoder

      public TLcdCompositeModelDecoder(ILcdModelDecoder... aModelDecoders)
      Creates a new composite model decoder containing the supplied delegate decoders.
      Parameters:
      aModelDecoders - delegate decoders to be added to the composite
  • Method Details

    • getModelDecoders

      public List<ILcdModelDecoder> getModelDecoders()
      Returns the list of delegate model decoders contained in this composite. If the factory does not use an Iterable, delegates can be added or removed by modifying this list.
      Returns:
      the list of delegate model decoders in this composite
    • findModelDecoders

      public List<ILcdModelDecoder> findModelDecoders(String aSourceName)
      Returns all model decoders that can decode the given source name
      Parameters:
      aSourceName - the source name to return the compatible model decoders for.
      Returns:
      a list containing all decoders that can open the given source
    • findModelDecoders

      public List<ILcdModelDecoder> findModelDecoders(ILcdDataSource aDataSource)
      Returns all model decoders that can decode the given data source
      Parameters:
      aDataSource - the data source to return the compatible model decoders for.
      Returns:
      a list containing all decoders that can open the given source
      Since:
      2017.0
    • 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.
    • setDisplayName

      public void setDisplayName(String aDisplayName)
      Sets the display name for this model decoder
      Parameters:
      aDisplayName - The display name
      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
      Decode the given data source through a suitable delegate model decoder.

      Notes:

      • Tries all delegate decoders that can decode the source, in order.
      • The first successfully created non-null model is returned.

      Creates a new model from the given data source.

      Specified by:
      decode in interface ILcdModelDecoder
      Parameters:
      aSourceName - the source for which a model should be created
      Returns:
      a model created by the selected delegate decoder
      Throws:
      IOException -
      • If a delegate model decoder returns a null value, an IOException will be thrown.
      • If no delegate model decoder returns a non-null value, an IOException will be thrown.
      • If one or more delegate model decoders throw an IOException and no other delegate model decoder returns a non-null value, an IOException will be thrown containing every suppressed exception.
      • If a delegate decoder throws an InterruptedIOException, the decoding stops and that exception is re-thrown.
      See Also:
    • canDecodeSource

      public boolean canDecodeSource(ILcdDataSource aDataSource)
      Description copied from interface: 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.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the ILcdModelSource to be verified.
      Returns:
      true if this decoder can likely decode the data specified by aDataSource, false otherwise.
      See Also:
    • decodeSource

      public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
      Decode the given data source through a suitable delegate model decoder.

      See decode(String) for details.

      Specified by:
      decodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the data source for which a model should be created
      Returns:
      a model created by the selected delegate decoder
      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:
    • discoverDataSources

      public List<? extends ILcdDataSource> discoverDataSources(String aPath) throws IOException
      Delegates to all decoders whose canDecodeSource(String) returns true for the given path.

      The first successfully created model is returned. If a decoder fails with an IOException or RuntimeException, the next decoder is tried.

      Specified by:
      discoverDataSources in interface ILcdModelDecoder
      Parameters:
      aPath - A path to the data source to be decoded; typically a file name or a URL.
      Returns:
      A set of data sources for the given path
      Throws:
      IOException - When
      • No delegate model decoders return true for canDecodeSource(String) for the supplied path.
      • Any delegate model decoder throws an IOException, and no data sources could be retrieved.
      • an IOException will be thrown containing every suppressed exception.
    • decodeModelMetadata

      public TLcdModelMetadata decodeModelMetadata(String aSourceName) throws IOException
      Decodes the model metadata of the given data source through a suitable delegate model decoder.

      Notes:

      Specified by:
      decodeModelMetadata in interface ILcdModelDecoder
      Parameters:
      aSourceName - the source from which model metadata should be extracted.
      Returns:
      a TLcdModelMetadata instance, created by the selected delegate model decoder
      Throws:
      IOException -
      • If no delegate model decoder successfully decodes the source, an IOException will be thrown.
      • If one or more delegate model decoders throw an IOException and no other delegate model decoder successfully decodes the source, an IOException will be thrown containing every suppressed exception.
      • If a delegate decoder throws a InterruptedIOException, the decoding stops and that exception is re-thrown.
      See Also:
    • decodeModelMetadata

      public TLcdModelMetadata decodeModelMetadata(ILcdDataSource aDataSource) throws IOException
      Decodes the model metadata of the given data source through a suitable delegate model decoder.

      Notes:

      Specified by:
      decodeModelMetadata in interface ILcdModelDecoder
      Parameters:
      aDataSource - the data source from which model metadata should be extracted.
      Returns:
      a TLcdModelMetadata instance, created by the selected delegate model decoder
      Throws:
      IOException -
      • If no delegate model decoder successfully decodes the source, an IOException will be thrown.
      • If one or more delegate model decoders throw an IOException and no other delegate model decoder successfully decodes the source, an IOException will be thrown containing every suppressed exception.
      • If a delegate decoder throws a InterruptedIOException, the decoding stops and that exception is re-thrown.
      See Also:
    • setInputStreamFactory

      public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      If not null, overrides the input stream factory of the contained model decoders with the given factory.
      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.