Class ALcdModel
- All Implemented Interfaces:
ILcdModel
,ILcdDisposable
,Serializable
,AutoCloseable
- Direct Known Subclasses:
ALfnTileStoreModel
,TLcd2DBoundsIndexedModel
,TLcd2DRegularTiledBoundsIndexedModel
,TLcdASTERIXFilteredModel
,TLcdDatabaseModel
,TLcdDatabaseReadOnlyModel
,TLcdFeatureIndexedAnd2DBoundsIndexedModel
,TLcdKML22DynamicModel
,TLcdKML22RenderableModel
,TLcdModelList
,TLcdMultilevel2DBoundsIndexedModel
,TLcdMultilevelGridCoordinateModel
,TLcdRegularTiled2DBoundsIndexedModel
,TLcdTrackModel
,TLcdVectorModel
,TLcdWFSProxyModel
ILcdModel
to minimize the effort required to implement this
interface.
To implement an unmodifiable model, the user needs to extend this class and implement the
ILcdModel.elements()
method.
To implement a modifiable model, the user must additionally override the following methods:
To achieve better performance, one should also consider:- implementing
ILcd2DBoundsIndexedModel
for allowing spatial queries - implementing
ILcdIntegerIndexedModel
for allowing integer-based queries - overriding the
removeAllElements(int)
method
Threading and locking
Models have a set of threading rules to obey, please refer to ILcdModel
or the developer's guide.
By enabling debug-level logging on ALcdModel, write lock violations of the threading rules are reported on the log. Applications or developers should never solely rely on this mechanism, it is intended to be used for debugging purposes. Its behavior may change in future versions.
Logging can be enabled via config files:
com.luciad.model.ALcdModel.level = FINE
or via code:
Logger.getLogger(ALcdModel.class.getName()).setLevel(Level.FINE);
The violations themselves are reported at the error level.
Limitations
- Enabling logging via code requires the standard Java logging to be used.
- Logging must be enabled before any model is created.
- If correct threading is guaranteed on the application level rather than through using locks, this gets reported while there is no issue in practice. For example, this sequence of events will not cause issues, but does get flagged: access a model on thread-1 without locks, thread-1 dies, access the same model on thread-2 without locks.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.luciad.model.ILcdModel
ILcdModel.Query
-
Field Summary
Modifier and TypeFieldDescriptionprotected TLcdModelChangedEventSupport
Support for firing model changed events.Fields inherited from interface com.luciad.model.ILcdModel
FIRE_LATER, FIRE_NOW, NO_EVENT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addElement
(Object aElement, int aEventMode) Adds the specified element to this model.void
addElements
(Vector aElements, int aFireEventMode) Adds all of the elements in the specified vector to this model.void
addModelListener
(ILcdModelListener aModelListener) Registers the specified model listener to receive notifications of model changes on this model.void
allElementsChanged
(int aFireEventMode) Notifies this model that all elements have changed.protected void
allElementsRemoved
(int aFireEventMode) Sends aTLcdModelChangedEvent
to the listeners.boolean
canAddElement
(Object aElement) Returnstrue
if the specified element can be added to this model,false
otherwise.boolean
canRemoveElement
(Object aElement) Returnstrue
if the specified element can be removed from this model,false
otherwise.void
dispose()
Disposes of this model and allows it to release any system resources that it is holding.protected void
elementAdded
(Object aElement, int aFireEventMode) Sends aTLcdModelChangedEvent
to the listeners.void
elementChanged
(Object aElement, int aFireEventMode) Notifies this model that the specified element has changed.protected void
elementRemoved
(Object aElement, int aFireEventMode) Sends aTLcdModelChangedEvent
to the listeners.protected void
elementsAdded
(Vector aElements, int aFireEventMode) Notifies this model that the specified elements have been added.void
elementsChanged
(Vector aElements, int aFireEventMode) Notifies this model that the elements in the specified vector have changed.protected void
elementsRemoved
(Vector aElements, int aFireEventMode) Sends aTLcdModelChangedEvent
to the listeners.void
Notifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.Returns theILcdModelDescriptor
providing meta information about this model and its elements.Returns, if available, a model encoder that is capable of encoding this model, (encoder.canEncode(this)
),null
otherwise.Collects and returns metadata about the model, using this model's model metadata function.Returns theILcdModelReference
describing how the geometry of the elements contained in this model should be interpreted.protected void
Initializes transient values.static boolean
Deprecated.This method has been deprecated.boolean
Deprecated.This method has been deprecated.void
removeAllElements
(int aEventMode) Removes all elements from this model.void
removeElement
(Object aElement, int aEventMode) Removes the specified element from this model.void
removeElements
(Vector aElements, int aFireEventMode) Removes all of the elements in the specified vector from this model.void
removeModelListener
(ILcdModelListener aModelListener) Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setModelDescriptor
(ILcdModelDescriptor aModelDescriptor) Sets the model descriptor providing meta information about this model and its elements.final void
setModelDisposer
(Consumer<ILcdModel> aModelDisposer) Sets the method to call when disposing the model.void
setModelEncoder
(ILcdModelEncoder aModelEncoder) Sets a model encoder on this model that can be used to encode this model.final void
setModelMetadataFunction
(Function<ALcdModel, TLcdModelMetadata> aModelMetadataFunction) Sets the function that is used to collect the model metadata returned bygetModelMetadata()
.void
setModelReference
(ILcdModelReference aModelReference) Sets the model reference describing how the geometry of the elements contained in this model should be interpreted.void
setTraceOn
(boolean aTraceOn) Deprecated.This method has been deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.util.ILcdDisposable
close
-
Field Details
-
fModelEventSupport
Support for firing model changed events.
-
-
Constructor Details
-
ALcdModel
public ALcdModel()
-
-
Method Details
-
setClassTraceOn
public static void setClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for all instances of this class. If the argument istrue
then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.- Parameters:
aClassTraceOn
- if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
-
isClassTraceOn
public static boolean isClassTraceOn()Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Returnstrue
if tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
setTraceOn
public void setTraceOn(boolean aTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for this class instance. Calling this method with eithertrue
orfalse
as argument automatically turns off tracing for all other class instances for whichsetTraceOn
has not been called. If the argument isfalse
then only the informative, warning and error log messages are recorded.- Parameters:
aTraceOn
- if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.
-
isTraceOn
public boolean isTraceOn()Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Returnstrue
if tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
getModelReference
Returns theILcdModelReference
describing how the geometry of the elements contained in this model should be interpreted.- Specified by:
getModelReference
in interfaceILcdModel
- Returns:
- the
ILcdModelReference
of thisILcdModel
. - See Also:
-
setModelReference
Sets the model reference describing how the geometry of the elements contained in this model should be interpreted.- Parameters:
aModelReference
- the model reference for this model.- See Also:
-
getModelDescriptor
Returns theILcdModelDescriptor
providing meta information about this model and its elements.- Specified by:
getModelDescriptor
in interfaceILcdModel
- Returns:
- the
ILcdModelDescriptor
of thisILcdModel
. Should not benull
. - See Also:
-
setModelDescriptor
Sets the model descriptor providing meta information about this model and its elements.- Parameters:
aModelDescriptor
- the model descriptor for this model.- See Also:
-
getModelEncoder
Returns, if available, a model encoder that is capable of encoding this model, (encoder.canEncode(this)
),null
otherwise.- Specified by:
getModelEncoder
in interfaceILcdModel
- Returns:
- a model encoder that is capable of encoding this model if available,
null
otherwise. - See Also:
-
setModelEncoder
Sets a model encoder on this model that can be used to encode this model.- Parameters:
aModelEncoder
- a model encoder capable of encoding this model.- Preconditions:
- The specified model encoder should be capable of encoding this model (
encoder.canEncode(this)
).
-
getModelMetadata
Collects and returns metadata about the model, using this model's model metadata function. The model metadata function can be changed withsetModelMetadataFunction(Function)
. The default metadata function usesTLcdModelMetadata.Builder.fromModel(com.luciad.model.ILcdModel)
, but subclasses may set an adjusted default function.- Specified by:
getModelMetadata
in interfaceILcdModel
- Returns:
- Metadata about the model.
- See Also:
-
setModelMetadataFunction
public final void setModelMetadataFunction(Function<ALcdModel, TLcdModelMetadata> aModelMetadataFunction) Sets the function that is used to collect the model metadata returned bygetModelMetadata()
. This function will be called every time thegetModelMetadata()
method is called, providing this model instance as parameter:
The default model metadata function usespublic TLcdModelMetadata getModelMetadata() { return aModelMetadataFunction.apply(this); }
TLcdModelMetadata.Builder.fromModel(ILcdModel)
, but subclasses may set an adjusted default function.- Since:
- 2018.1
-
setModelDisposer
Sets the method to call when disposing the model. This allows a decoder to register specific logic to free resources when the model is disposed.The disposable is called within the method
dispose()
.- Parameters:
aModelDisposer
- the disposable that takes care of freeing resources held by the model.- Since:
- 2018.1
-
addElement
Adds the specified element to this model.Models that support this operation may place limitations on what elements may be added to this model. For example, implementations that are based on a spatial indexing structure will require that elements implement
ILcdBounded
.When adding an element, the user should make sure that
canAddElement(aElement)
holds, and that the element's geometry is expressed in the same model reference as this model. It is generally undefined what happens if an invalid element is added.Implementations of this interface should clearly specify in their documentation any restrictions on what elements may be added. Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
), whenever possible.This implementation always throws an
UnsupportedOperationException
.- Specified by:
addElement
in interfaceILcdModel
- Parameters:
aElement
- the element to be added to this model.aEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.- See Also:
-
canAddElement
Returnstrue
if the specified element can be added to this model,false
otherwise.Note that this method generally does not validate whether the specified element is expressed in the same model reference as this model. It is the responsibility of the user of this model to make sure this precondition is fulfilled when an element is added to this model.
This implementation always returns
false
.- Specified by:
canAddElement
in interfaceILcdModel
- Parameters:
aElement
- the element to be verified.- Returns:
true
if the specified element can be added to this model,false
otherwise.
-
addElements
Adds all of the elements in the specified vector to this model. Models that support this operation may place limitations on what elements may be added to this model. For example, implementations that are based on a spatial indexing structure will require that elements implementILcdBounded
. Implementations of this interface should clearly specify in their documentation any restrictions on what elements may be added.The behavior of this operation is undefined if the specified vector is modified while the operation is in progress.
The specified elements will be added to this model in the order they are specified in the vector. If an element cannot be added, this method will return at the first failure. Succeeding elements won't be added.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
), whenever possible.This implementation iterates over all elements in the specified vector, and calls
addElement(Object, int)
for each element to be added, using event modeNO_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. If the specified event mode isFIRE_NOW
,fireCollectedModelChanges()
is called afterwards.- Specified by:
addElements
in interfaceILcdModel
- Parameters:
aElements
- the vector of elements to be added to this model.aFireEventMode
- the mode for sending the model change events This can beFIRE_LATER
orNO_EVENT
.- See Also:
-
removeElement
Removes the specified element from this model. If the specified element is not contained in this model, this method has no effect.Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
), whenever possible.This implementation always throws an
UnsupportedOperationException
.- Specified by:
removeElement
in interfaceILcdModel
- Parameters:
aElement
- the element to be removed from this model.aEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.- See Also:
-
canRemoveElement
Returnstrue
if the specified element can be removed from this model,false
otherwise. Note that this method generally does not check whether the specified element is actually contained in this model.This implementation always returns
false
.- Specified by:
canRemoveElement
in interfaceILcdModel
- Parameters:
aElement
- the element to be verified.- Returns:
true
if the specified element can be removed from this model,false
otherwise.
-
removeElements
Removes all of the elements in the specified vector from this model. If one of the elements in the specified vector is not contained in this model, this element will be ignored.The behavior of this operation is undefined if the specified vector is modified while the operation is in progress.
The specified elements will be removed from this model in the order they are specified in the vector. If an element cannot be removed, this method will return at the first failure. Succeeding elements won't be removed.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
), whenever possible.This implementation iterates over all elements in the specified vector, and calls
removeElement(Object, int)
for each element to be removed, using event modeNO_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. If the specified event mode isFIRE_NOW
,fireCollectedModelChanges()
is called afterwards.- Specified by:
removeElements
in interfaceILcdModel
- Parameters:
aElements
- the vector of elements to be removed from this model.aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.- See Also:
-
removeAllElements
public void removeAllElements(int aEventMode) Removes all elements from this model.If an element cannot be removed, this method will return at the first failure. Succeeding elements won't be removed.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException
), whenever possible.This implementation iterates over all elements in the model, and calls
removeElement(Object, int)
for each element to be removed, using event modeNO_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. If the specified event mode isFIRE_NOW
,fireCollectedModelChanges()
is called afterwards.- Specified by:
removeAllElements
in interfaceILcdModel
- Parameters:
aEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.
-
fireCollectedModelChanges
public void fireCollectedModelChanges()Notifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.This implementation calls
#TLcdModelChangedEventSupport#fireCollectedModelChanges()
.- Specified by:
fireCollectedModelChanges
in interfaceILcdModel
- See Also:
-
elementsChanged
Notifies this model that the elements in the specified vector have changed.This implementation calls
TLcdModelChangedEventSupport#elementsChanged(java.util.Vector, int)
.- Specified by:
elementsChanged
in interfaceILcdModel
- Parameters:
aElements
- the vector of elements that have changed.aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.
-
allElementsChanged
public void allElementsChanged(int aFireEventMode) Notifies this model that all elements have changed.This implementation calls
TLcdModelChangedEventSupport#allElementsChanged(int)
.- Parameters:
aFireEventMode
- the mode for sending out the model change event. This can be one ofFIRE_NOW
,FIRE_LATER
orNO_EVENT
. In case ofFIRE_NOW
mode, only one event will be fired, containing all changes.
-
elementChanged
Notifies this model that the specified element has changed.This implementation calls
TLcdModelChangedEventSupport#elementChanged(Object, int)
.- Specified by:
elementChanged
in interfaceILcdModel
- Parameters:
aElement
- the element that has changed.aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.
-
elementsAdded
Notifies this model that the specified elements have been added.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementsAdded(java.util.Vector, int)
.- Parameters:
aElements
- theVector
of Objects that has been added to the model.aFireEventMode
- the mode for sending out the model event. This can be FIRE_NOW, LATER or NO_EVENT.
-
elementAdded
Sends aTLcdModelChangedEvent
to the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementAdded(Object, int)
.- Parameters:
aElement
- theObject
that has been added to the model.aFireEventMode
- the mode for sending out the model event. This can be FIRE_NOW, LATER or NO_EVENT.
-
elementsRemoved
Sends aTLcdModelChangedEvent
to the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementsRemoved(java.util.Vector, int)
.- Parameters:
aElements
- theVector
of Objects that has been removed from the model.aFireEventMode
- the mode for sending out the model event. This can be FIRE_NOW, LATER or NO_EVENT.
-
elementRemoved
Sends aTLcdModelChangedEvent
to the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementRemoved(Object, int)
.- Parameters:
aElement
- theObject
that has been removed from the model.aFireEventMode
- the mode for sending out the model event. This can be FIRE_NOW, LATER or NO_EVENT.
-
allElementsRemoved
protected void allElementsRemoved(int aFireEventMode) Sends aTLcdModelChangedEvent
to the listeners.- Parameters:
aFireEventMode
- the mode for sending out the model event. This can be FIRE_NOW, LATER or NO_EVENT.
-
addModelListener
Registers the specified model listener to receive notifications of model changes on this model.
Model changes are sent out when an element has been added, removed or changed. Model changes can be sent out individually, grouped or silently applied without notifications, depending on the
ILcdFireEventMode
that was specified with the change.In case you need to register a listener which keeps a reference to an object with a shorter life-time than this model, you can use a
ALcdWeakModelListener
instance as model listener.This implementation calls
TLcdModelChangedEventSupport#addModelListener(ILcdModelListener)
.- Specified by:
addModelListener
in interfaceILcdModel
- Parameters:
aModelListener
- theILcdModelListener
to register on this model.- See Also:
-
removeModelListener
Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.This implementation calls
TLcdModelChangedEventSupport#removeModelListener(ILcdModelListener)
.- Specified by:
removeModelListener
in interfaceILcdModel
- Parameters:
aModelListener
- theILcdModelListener
to remove.- See Also:
-
dispose
public void dispose()Disposes of this model and allows it to release any system resources that it is holding. The result of calling any other method (other thanfinalize
) on this model subsequent to a call to this method is undefined.When a model disposer has been provided it is called, otherwise this method does nothing. When overriding this method it is recommended to call
super.dispose()
.- Specified by:
dispose
in interfaceILcdDisposable
- Specified by:
dispose
in interfaceILcdModel
- See Also:
-
initializeTransientValues
protected void initializeTransientValues()Initializes transient values. Subclasses that redefine this method MUST callsuper.initializeTransientValues()
before doing any processing to any transient instance variables of the subclass.
-