Class KMLNetworkLink
- java.lang.Object
-
- All Implemented Interfaces:
MessageListener,KMLRenderable,XMLEventParser,java.beans.PropertyChangeListener,java.util.EventListener
public class KMLNetworkLink extends KMLAbstractContainer implements java.beans.PropertyChangeListener
Represents the KML NetworkLink element and provides access to its contents.During rendering,
KMLNetworkLinkretrieves and loads its network resource whenever necessary. Upon a successful retrieval,KMLNetworkLinksends anAVKey.RETRIEVAL_STATE_SUCCESSFULproperty change event to this link's property change listeners. Once retrieved and loaded,KMLNetworkLinkstores its network resource by callingsetNetworkResource, draws its network resource during preRendering and rendering, and forwards property change events from the network resource to its property change listeners.During retrieval,
KMLNetworkLinkattempts to use either theLinkor theUrl. TheLinkis the preferred method for encoding a KML NetworkLink's address since KML version 2.1, therefore we give it priority overUrl.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classKMLNetworkLink.RequestTaskAttempts to find this network link resource file locally, and if that fails attempts to find it remotely.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicLongfirstRetrievalTimeprotected booleaninvalidTargetFlag that is raised if the link retrieves a files that is not a KML document.protected KMLLinklinkprotected booleanlinkFetchedFlag to indicate that the Link has been fetched from the hash map.protected java.util.concurrent.atomic.AtomicReference<KMLRoot>networkResourceIndicates the network resource referenced by thisKMLNetworkLink.protected java.util.concurrent.atomic.AtomicLongnetworkResourceRetrievalTimeTime, in milliseconds since the Epoch, at which thisKMLNetworkLink'snetwork resource was last retrieved.protected KMLRootrootCache the root of this network link.-
Fields inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractContainer
features
-
Fields inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractFeature
balloon, region, styleSelectors, visibility
-
Fields inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
MSG_BOX_CHANGED, MSG_GEOMETRY_CHANGED, MSG_LINK_CHANGED, MSG_STYLE_CHANGED, MSG_TIME_CHANGED, MSG_VIEW_CHANGED
-
Fields inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
CHARACTERS_CONTENT, fields, namespaceURI, parent
-
-
Constructor Summary
Constructors Constructor Description KMLNetworkLink(java.lang.String namespaceURI)Construct an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyChange(KMLAbstractObject sourceValues)protected longcomputeExpiryRefreshTime(KMLRoot root, java.lang.String address)Indicates the expiration time of a linked resource.protected voiddoPreRender(KMLTraversalContext tc, DrawContext dc)Pre-renders the network resource referenced by thisKMLNetworkLink.protected voiddoRender(KMLTraversalContext tc, DrawContext dc)Renders the network resource referenced by thisKMLNetworkLink.java.lang.StringgetDescription()java.lang.BooleangetFlyToView()protected KMLLinkgetLinkOrUrl()Returns thisNetworkLink'sLinkelement or itsUrlelement, depending on which is available.java.lang.StringgetName()KMLLinkgetNetworkLink()KMLRootgetNetworkResource()Indicates the network resource referenced by thisKMLNetworkLink.java.lang.BooleangetRefreshVisibility()KMLRootgetRoot()Overridden to cache the root instead of climbing the parse tree each time.java.lang.ObjectgetSnippet()KMLLinkgetUrl()protected booleanhasNetworkLinkControl()protected booleanisFeatureActive(KMLTraversalContext tc, DrawContext dc)Indicates whether thisKMLAbstractContaineris active and should be rendered on the specifiedDrawContext.booleanisLinkCacheable()Indicates whether the network resource references by thisKMLNetworkLinkshould be retrieved to the WorldWind cache or to a temporary location.protected booleanmustRetrieveNetworkResource()Returns whether thisKMLNetworkLinkmust retrieve its network resource.voidonChange(Message msg)voidonMessage(Message msg)Invoked when a message is received.voidpropertyChange(java.beans.PropertyChangeEvent evt)Forward property change events from the innerKMLRootto this object's parent KMLRoot.protected voidrequestResource(DrawContext dc)Thread's off a task to determine whether the resource is local or remote and then retrieves it either from disk cache or a remote server.protected voidreset()protected voidretrieveNetworkResource(java.lang.String address)Initiates a retrieval of the network resource referenced by thisKMLNetworkLink.voidsetNetworkResource(KMLRoot kmlRoot)Specifies the network resource referenced by thisKMLNetworkLink, ornullif this link has no resource.-
Methods inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractContainer
addFeature, beginRendering, doAddEventContent, endRendering, getFeatures, mergeFeatures, preRenderFeatures, removeFeature, renderFeatures
-
Methods inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractFeature
addStyleSelector, getAddress, getAddressDetails, getAuthor, getBalloon, getExtendedData, getLink, getOpen, getPhoneNumber, getRegion, getSnippetText, getStyleSelectors, getStyleUrl, getSubStyle, getTimePrimitive, getView, getVisibility, hasStyle, hasStyleSelectors, mergeStyleSelectors, preRender, render, renderBalloon, setBalloon, setRegion, setTimePrimitive, setView, setVisibility
-
Methods inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
getId, getTargetId
-
Methods inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
allocate, doAddCharacters, doAddEventAttribute, doParseEventAttributes, doParseEventContent, freeResources, getAConstructor, getCharacters, getField, getField, getFields, getNamespaceURI, getParent, hasField, hasField, hasFields, mergeFields, newInstance, overrideFields, parse, parseCharacterContent, removeField, setField, setField, setFields, setNamespaceURI, setParent
-
-
-
-
Field Detail
-
networkResource
protected java.util.concurrent.atomic.AtomicReference<KMLRoot> networkResource
Indicates the network resource referenced by thisKMLNetworkLink. Initiallynull.
-
networkResourceRetrievalTime
protected java.util.concurrent.atomic.AtomicLong networkResourceRetrievalTime
Time, in milliseconds since the Epoch, at which thisKMLNetworkLink'snetwork resource was last retrieved. Initially-1, indicating that the network resource has not been retrieved.
-
firstRetrievalTime
protected java.util.concurrent.atomic.AtomicLong firstRetrievalTime
-
linkFetched
protected boolean linkFetched
Flag to indicate that the Link has been fetched from the hash map.
-
link
protected KMLLink link
-
invalidTarget
protected boolean invalidTarget
Flag that is raised if the link retrieves a files that is not a KML document. In this case, do not attempt to retrieve the resource again until the link changes. If the link changes then target file may also have changed.
-
root
protected KMLRoot root
Cache the root of this network link. Accessing the root by climbing up a deep network link tree can be a performance bottleneck.
-
-
Method Detail
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
Forward property change events from the innerKMLRootto this object's parent KMLRoot.- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Parameters:
evt- Event to forward.
-
onMessage
public void onMessage(Message msg)
Description copied from interface:MessageListenerInvoked when a message is received.- Specified by:
onMessagein interfaceMessageListener- Overrides:
onMessagein classKMLAbstractContainer- Parameters:
msg- The message that was received.
-
getRoot
public KMLRoot getRoot()
Overridden to cache the root instead of climbing the parse tree each time.- Overrides:
getRootin classKMLAbstractObject
-
getRefreshVisibility
public java.lang.Boolean getRefreshVisibility()
-
getFlyToView
public java.lang.Boolean getFlyToView()
-
getNetworkLink
public KMLLink getNetworkLink()
-
getUrl
public KMLLink getUrl()
-
getLinkOrUrl
protected KMLLink getLinkOrUrl()
Returns thisNetworkLink'sLinkelement or itsUrlelement, depending on which is available.Linkis the preferred method for encoding aNetworkLinksince KML version 2.1, therefore we give it priority. If aLinkis not specified, the deprecatedUrlelement is returned.- Returns:
- this
NetworkLink'sLinkelement, if one is specified. Otherwise, thisNetworkLink'sUrlelement. Returnsnullif neitherLinkor aUrlare specified.
-
getNetworkResource
public KMLRoot getNetworkResource()
Indicates the network resource referenced by thisKMLNetworkLink. This returnsnullif this link has no resource.- Returns:
- this link's network resource, or
nullto indicate that this link has no resource. - See Also:
setNetworkResource(KMLRoot)
-
isFeatureActive
protected boolean isFeatureActive(KMLTraversalContext tc, DrawContext dc)
Indicates whether thisKMLAbstractContaineris active and should be rendered on the specifiedDrawContext. This returnstrueif this container'svisibilityis unspecified (null) or is set totrue.Regions do not apply directly to KML containers, because a descendant features can override the container's Region with its own. Since a descendant Region may be larger or have a less restrictive LOD range than this container, we cannot determine the visibility of the entire tree based on this container's Region. A container's Region is inherited by any descendants that do not specify a Region, and Region visibility is determined at the leaf nodes. Overridden to apply region culling according to the same rules as in KMLAbstractFeature. This prevents retrieving network links in inactive regions.
- Overrides:
isFeatureActivein classKMLAbstractContainer- Parameters:
tc- the current KML traversal context. This parameter is ignored.dc- the draw context. This parameter is ignored.- Returns:
trueif this container should be rendered, otherwisefalse.
-
hasNetworkLinkControl
protected boolean hasNetworkLinkControl()
-
getName
public java.lang.String getName()
- Overrides:
getNamein classKMLAbstractFeature
-
getDescription
public java.lang.String getDescription()
- Overrides:
getDescriptionin classKMLAbstractFeature
-
getSnippet
public java.lang.Object getSnippet()
- Overrides:
getSnippetin classKMLAbstractFeature
-
setNetworkResource
public void setNetworkResource(KMLRoot kmlRoot)
Specifies the network resource referenced by thisKMLNetworkLink, ornullif this link has no resource. If the specifiedkmlRootis notnull, this link draws thekmlRootduring preRendering and rendering, and forwards property change events from thekmlRootto this link's property change listeners.- Parameters:
kmlRoot- the network resource referenced by thisKMLNetworkLink. May benull.- See Also:
getNetworkResource()
-
doPreRender
protected void doPreRender(KMLTraversalContext tc, DrawContext dc)
Pre-renders the network resource referenced by thisKMLNetworkLink. If this link must retrieve its network resource, this initiates a retrieval and does nothing until the resource is retrieved and loaded. Once the network resource is retrieved and loaded, this callsto specify this link's new network resource, and sends ansetNetworkResource(KMLRoot)property change event to this link's property change listeners.AVKey.RETRIEVAL_STATE_SUCCESSFUL- Overrides:
doPreRenderin classKMLAbstractContainer- Parameters:
tc- the current KML traversal context.dc- the current draw context.- See Also:
getNetworkResource()
-
doRender
protected void doRender(KMLTraversalContext tc, DrawContext dc)
Renders the network resource referenced by thisKMLNetworkLink. This does nothing if this link has no network resource.- Overrides:
doRenderin classKMLAbstractContainer- Parameters:
tc- the current KML traversal context.dc- the current draw context.
-
mustRetrieveNetworkResource
protected boolean mustRetrieveNetworkResource()
Returns whether thisKMLNetworkLinkmust retrieve its network resource. This always returnsfalseif thisKMLNetworkLinkhas noKMLLink.- Returns:
trueif thisKMLNetworkLinkmust retrieve its network resource, otherwisefalse.
-
requestResource
protected void requestResource(DrawContext dc)
Thread's off a task to determine whether the resource is local or remote and then retrieves it either from disk cache or a remote server.- Parameters:
dc- the current draw context.
-
retrieveNetworkResource
protected void retrieveNetworkResource(java.lang.String address)
Initiates a retrieval of the network resource referenced by thisKMLNetworkLink. Once the network resource is retrieved and loaded, this callsto specify this link's new network resource, and sends ansetNetworkResource(KMLRoot)property change event to this link's property change listeners.AVKey.RETRIEVAL_STATE_SUCCESSFULThis does nothing if this
KMLNetworkLinkhas noKMLLink.- Parameters:
address- the address of the resource to retrieve
-
computeExpiryRefreshTime
protected long computeExpiryRefreshTime(KMLRoot root, java.lang.String address)
Indicates the expiration time of a linked resource. The expiration time is specified by (in order of priority): a NetworkLinkControl/expires element in the target document, a HTTP Cache-Control header, or an HTTP Expires header.- Parameters:
root- Root of target resource.address- Address of linked resource.- Returns:
- The expiration time of the resource, in milliseconds since the Epoch. Zero indicates that there is no expiration time.
-
isLinkCacheable
public boolean isLinkCacheable()
Indicates whether the network resource references by thisKMLNetworkLinkshould be retrieved to the WorldWind cache or to a temporary location. This returnstrueif all of the following conditions are met, andfalseotherwise:- This network link has either a
Linkor aUrlelement. - The Link or Url
element's
refreshModeis notonIntervaloronExpire. - The Link or
Url element's
viewRefreshModeis notonStop.
- Returns:
trueif this link's network resource can should be stored in a cache, orfalseif it should be stored in a temporary location.
- This network link has either a
-
applyChange
public void applyChange(KMLAbstractObject sourceValues)
- Overrides:
applyChangein classKMLAbstractContainer
-
onChange
public void onChange(Message msg)
- Overrides:
onChangein classKMLAbstractObject
-
reset
protected void reset()
-
-