Class TLcyLspSafeGuardFormatWrapper


public class TLcyLspSafeGuardFormatWrapper extends ALcyLspFormatWrapper

Decorator for an ALcyLspFormat that safe guards all operations on layers to make sure no invalid layers are ever accepted or handled. It relies on the implementation of ALcyLspFormat.canHandleModel(com.luciad.model.ILcdModel) of the given format to determine which models are passed to the layer factory. In order to decide which layers are accepted or handled, it keeps track of all layers created by this format in either the layer factory or the layer workspace codec. Only the instances created in this format will be accepted.

As a result, implementers of an ALcyLspFormat can simplify this type of code:


 protected ALcyWorkspaceObjectCodec[] createLayerWorkspaceObjectCodec() {
   return new ALcyWorkspaceObjectCodec[]{new ALcyWorkspaceObjectCodec() {
     public boolean canEncodeObject( ALcyWorkspaceCodec aWSCodec, Object aObject, Object aParent ) {
       return aObject instanceof ILspLayer && isLayerOfFormat( ( ILspLayer ) aObject );
     }

     public void encodeObject( ALcyWorkspaceCodec aWSCodec, Object aObject, Object aParent, OutputStream aOut ) throws IOException, TLcyWorkspaceAbortedException {
       //do something
     }
   }};
 }
 
to this:

  protected ALcyWorkspaceObjectCodec[] createLayerWorkspaceObjectCodec() {
   return new ALcyWorkspaceObjectCodec[]{new ALcyWorkspaceObjectCodec() {
     public boolean canEncodeObject( ALcyWorkspaceCodec aWSCodec, Object aObject, Object aParent ) {
       return true;
     }

     public void encodeObject( ALcyWorkspaceCodec aWSCodec, Object aObject, Object aParent, OutputStream aOut ) throws IOException, TLcyWorkspaceAbortedException {
       //do something
     }
   }};
 }
 
which is easier and less error prone. Similar simplifications apply to all other concepts such as ILspLayerFactory, ILcyCustomizerPanelFactory etc.

Since:
2012.0
  • Constructor Details

    • TLcyLspSafeGuardFormatWrapper

      public TLcyLspSafeGuardFormatWrapper(ALcyLspFormat aFormat)
      Creates a new TLcyLspSafeGuardFormatWrapper around the given ALcyLspFormat
      Parameters:
      aFormat - The format to wrap
  • Method Details

    • createLayerFactory

      public ILspLayerFactory createLayerFactory()

      Creates the layer factory for this format. The default implementation returns null.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against model instances which do not pass the canHandleModel method of this format.

      Overrides:
      createLayerFactory in class ALcyLspFormatWrapper
      Returns:
      The ILspLayerFactory for this format. May be null
      See Also:
    • createBalloonContentProviders

      protected ILcdBalloonContentProvider[] createBalloonContentProviders()

      Creates the ILcdBalloonContentProviders for this format.

      The default implementation returns an empty array.

      This implementations returns the instance created by the decorated format.

      The returned instances will be safe-guarded against TLcdModelElementBalloonDescriptor instances where the layer does not belong to the format.

      Overrides:
      createBalloonContentProviders in class ALcyLspFormatWrapper
      Returns:
      the ILcdBalloonContentProviders for this format. Must not be null. The array may be empty but must not contain null.
      See Also:
    • createLayerStyleProviders

      public ILcyLayerStyleProvider[] createLayerStyleProviders()

      Creates the style provider instances that can retrieve and encode the style of the layers created by the layer factory of this format.

      The default implementation returns an empty array.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerStyleProviders in class ALcyLspFormatWrapper
      Returns:
      The style provider to retrieve and encode the style of the layers. Must not be null. The array may be empty, but must not contain null.
      See Also:
    • createLayerStyleCodecs

      public ILcyLayerStyleCodec[] createLayerStyleCodecs()

      Creates the ILcyLayerStyleCodec instances which can encode/decode the style of the layers created by the layer factory of this format.

      The default implementation returns an empty array.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerStyleCodecs in class ALcyLspFormatWrapper
      Returns:
      an array of ILcyLayerStyleCodec instances. Must not be null. The array may be empty, but must not contain null.
      See Also:
    • createLayerCustomizerPanelFactories

      protected ILcyCustomizerPanelFactory[] createLayerCustomizerPanelFactories()

      Creates the ILcyCustomizerPanelFactory factories that can create ILcyCustomizerPanel instances for the layers created by the layer factories of this format.

      The default implementation returns a zero-length array.

      If you're looking for the fall back behavior when no factories are registered, see TLcyLspLayerCustomizerAddOn. If you want to customize the behavior for this format only, see TLcyLspStyledLayerCustomizerPanelFactory.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerCustomizerPanelFactories in class ALcyLspFormatWrapper
      Returns:
      An array of ILcyCustomizerPanelFactory instances. Must not be null. The array may be empty, but must not contain null.
      See Also:
    • createLayerCustomizerPanelWorkspaceCodecs

      protected ALcyWorkspaceObjectCodec[] createLayerCustomizerPanelWorkspaceCodecs()

      Creates the ALcyWorkspaceObjectCodec codecs for the ILcyCustomizerPanel instances for the layers created by the layer factories of this format.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerCustomizerPanelWorkspaceCodecs in class ALcyLspFormatWrapper
      Returns:
      An array containing the ALcyWorkspaceObjectCodec instances. Must not be null, but may have length 0. Must not contain null.
      See Also:
    • createLayerWorkspaceCodecs

      public ALcyWorkspaceObjectCodec[] createLayerWorkspaceCodecs()

      Creates the ALcyWorkspaceObjectCodecs that can encode the state of the layers created by the layer factory of this format.

      The default implementation returns an array with a single codec which uses the layer factory and the layer style codecs of the format.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerWorkspaceCodecs in class ALcyLspFormatWrapper
      Returns:
      The array of ALcyWorkspaceObjectCodecs to encode the state of the layers. May be empty but not null. Must not contain null
      See Also:
    • createLayerSelectionTransferHandlers

      protected ALcyLayerSelectionTransferHandler[] createLayerSelectionTransferHandlers()

      Creates the ALcyLayerSelectionTransferHandler transfer handlers that can transfer the selection of the layers created by the layer factories of this format.

      The default implementation returns a zero-length array.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerSelectionTransferHandlers in class ALcyLspFormatWrapper
      Returns:
      An array of ALcyLayerSelectionTransferHandler instances. Must not be null but may have length 0. Must not contain null.
      See Also:
    • createFormatBarFactory

      protected ALcyFormatBarFactory createFormatBarFactory()

      Creates the ALcyFormatBarFactory that can create a bar to manipulate layers of this format.

      The default implementation returns null.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createFormatBarFactory in class ALcyLspFormatWrapper
      Returns:
      An ALcyFormatBarFactory. May be null.
    • createLayerMeasureProviderFactory

      protected ILcdLayerMeasureProviderFactory createLayerMeasureProviderFactory()

      Creates a ILcdLayerMeasureProviderFactory that can create measure providers for a layer created by the layer factories of this format.

      The default implementation returns null.

      This implementations returns the instance created by the decorated format.

      The returned instance will be safe-guarded against layer instances that were not created by this format.

      Overrides:
      createLayerMeasureProviderFactory in class ALcyLspFormatWrapper
      Returns:
      an ILcdLayerMeasureProviderFactory instance. Can be null.
      See Also:
    • isLayerOfFormat

      public boolean isLayerOfFormat(ILspLayer aLayer)

      Returns true if and only if the given layer is a layer of this format.

      The default implementation uses the ALcyLspFormat.canHandleModel(com.luciad.model.ILcdModel) to determine whether aLayer is a layer of this format.

      This class keeps track of all layers created in this format, and only returns true for those layers.

      Overrides:
      isLayerOfFormat in class ALcyLspFormatWrapper
      Parameters:
      aLayer - The layer to check
      Returns:
      true if and only if the given layer is a layer of this format
    • canHandleModel

      public boolean canHandleModel(ILcdModel aModel)
      Description copied from class: ALcyLspFormat

      Returns true if and only if the given model can be visualized by this format.

      Overrides:
      canHandleModel in class ALcyLspFormatWrapper
      Parameters:
      aModel - The model to check
      Returns:
      true if and only if the given model can be visualized by this format.