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
ILcd2DBoundsIndexedModelfor allowing spatial queries - implementing
ILcdIntegerIndexedModelfor 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
FieldsModifier and TypeFieldDescriptionprotected TLcdModelChangedEventSupportSupport for firing model changed events.Fields inherited from interface com.luciad.model.ILcdModel
FIRE_LATER, FIRE_NOW, NO_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddElement(Object aElement, int aEventMode) Adds the specified element to this model.voidaddElements(Vector aElements, int aFireEventMode) Adds all of the elements in the specified vector to this model.voidaddModelListener(ILcdModelListener aModelListener) Registers the specified model listener to receive notifications of model changes on this model.voidallElementsChanged(int aFireEventMode) Notifies this model that all elements have changed.protected voidallElementsRemoved(int aFireEventMode) Sends aTLcdModelChangedEventto the listeners.booleancanAddElement(Object aElement) Returnstrueif the specified element can be added to this model,falseotherwise.booleancanRemoveElement(Object aElement) Returnstrueif the specified element can be removed from this model,falseotherwise.voiddispose()Disposes of this model and allows it to release any system resources that it is holding.protected voidelementAdded(Object aElement, int aFireEventMode) Sends aTLcdModelChangedEventto the listeners.voidelementChanged(Object aElement, int aFireEventMode) Notifies this model that the specified element has changed.protected voidelementRemoved(Object aElement, int aFireEventMode) Sends aTLcdModelChangedEventto the listeners.protected voidelementsAdded(Vector aElements, int aFireEventMode) Notifies this model that the specified elements have been added.voidelementsChanged(Vector aElements, int aFireEventMode) Notifies this model that the elements in the specified vector have changed.protected voidelementsRemoved(Vector aElements, int aFireEventMode) Sends aTLcdModelChangedEventto the listeners.voidNotifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.Returns theILcdModelDescriptorproviding meta information about this model and its elements.Returns, if available, a model encoder that is capable of encoding this model, (encoder.canEncode(this)),nullotherwise.Collects and returns metadata about the model, using this model's model metadata function.Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.protected voidInitializes transient values.static booleanDeprecated.This method has been deprecated.booleanDeprecated.This method has been deprecated.voidremoveAllElements(int aEventMode) Removes all elements from this model.voidremoveElement(Object aElement, int aEventMode) Removes the specified element from this model.voidremoveElements(Vector aElements, int aFireEventMode) Removes all of the elements in the specified vector from this model.voidremoveModelListener(ILcdModelListener aModelListener) Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.static voidsetClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated.voidsetModelDescriptor(ILcdModelDescriptor aModelDescriptor) Sets the model descriptor providing meta information about this model and its elements.final voidsetModelDisposer(Consumer<ILcdModel> aModelDisposer) Sets the method to call when disposing the model.voidsetModelEncoder(ILcdModelEncoder aModelEncoder) Sets a model encoder on this model that can be used to encode this model.final voidsetModelMetadataFunction(Function<ALcdModel, TLcdModelMetadata> aModelMetadataFunction) Sets the function that is used to collect the model metadata returned bygetModelMetadata().voidsetModelReference(ILcdModelReference aModelReference) Sets the model reference describing how the geometry of the elements contained in this model should be interpreted.voidsetTraceOn(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, waitMethods 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 istruethen 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.Returnstrueif 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 eithertrueorfalseas argument automatically turns off tracing for all other class instances for whichsetTraceOnhas not been called. If the argument isfalsethen 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.Returnstrueif tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
getModelReference
Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.- Specified by:
getModelReferencein interfaceILcdModel- Returns:
- the
ILcdModelReferenceof 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 theILcdModelDescriptorproviding meta information about this model and its elements.- Specified by:
getModelDescriptorin interfaceILcdModel- Returns:
- the
ILcdModelDescriptorof 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)),nullotherwise.- Specified by:
getModelEncoderin interfaceILcdModel- Returns:
- a model encoder that is capable of encoding this model if available,
nullotherwise. - 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:
getModelMetadatain 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:
addElementin interfaceILcdModel- Parameters:
aElement- the element to be added to this model.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
-
canAddElement
Returnstrueif the specified element can be added to this model,falseotherwise.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:
canAddElementin interfaceILcdModel- Parameters:
aElement- the element to be verified.- Returns:
trueif the specified element can be added to this model,falseotherwise.
-
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_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.- Specified by:
addElementsin 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_LATERorNO_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:
removeElementin interfaceILcdModel- Parameters:
aElement- the element to be removed from this model.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
-
canRemoveElement
Returnstrueif the specified element can be removed from this model,falseotherwise. 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:
canRemoveElementin interfaceILcdModel- Parameters:
aElement- the element to be verified.- Returns:
trueif the specified element can be removed from this model,falseotherwise.
-
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_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.- Specified by:
removeElementsin 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_LATERorNO_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_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.- Specified by:
removeAllElementsin interfaceILcdModel- Parameters:
aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_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:
fireCollectedModelChangesin 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:
elementsChangedin interfaceILcdModel- Parameters:
aElements- the vector of elements that have changed.aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_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_LATERorNO_EVENT. In case ofFIRE_NOWmode, 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:
elementChangedin interfaceILcdModel- Parameters:
aElement- the element that has changed.aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_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- theVectorof 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 aTLcdModelChangedEventto the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementAdded(Object, int).- Parameters:
aElement- theObjectthat 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 aTLcdModelChangedEventto the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementsRemoved(java.util.Vector, int).- Parameters:
aElements- theVectorof 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 aTLcdModelChangedEventto the listeners.This implementation calls
com.luciad.model.TLcdModelChangedEventSupport#elementRemoved(Object, int).- Parameters:
aElement- theObjectthat 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 aTLcdModelChangedEventto 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
ILcdFireEventModethat 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
ALcdWeakModelListenerinstance as model listener.This implementation calls
TLcdModelChangedEventSupport#addModelListener(ILcdModelListener).- Specified by:
addModelListenerin interfaceILcdModel- Parameters:
aModelListener- theILcdModelListenerto 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:
removeModelListenerin interfaceILcdModel- Parameters:
aModelListener- theILcdModelListenerto 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:
disposein interfaceILcdDisposable- Specified by:
disposein 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.
-