NASA World Wind

gov.nasa.worldwind.cache
Class AbstractFileStore

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.cache.AbstractFileStore
All Implemented Interfaces:
AVList, FileStore, MessageListener, WWObject, PropertyChangeListener, EventListener
Direct Known Subclasses:
BasicDataFileStore

public abstract class AbstractFileStore
extends WWObjectImpl
implements FileStore


Nested Class Summary
protected static class AbstractFileStore.StoreLocation
           
 
Field Summary
protected  List<AbstractFileStore.StoreLocation> readLocations
           
protected  AbstractFileStore.StoreLocation writeLocation
           
 
Constructor Summary
AbstractFileStore()
           
 
Method Summary
 void addLocation(int index, String newPath, boolean isInstall)
          Adds a location to search when files are requested from the file store and specifies its location in the search order.
 void addLocation(String newPath, boolean isInstall)
          Adds a location to search when files are requested from the file store.
protected static String buildLocationPath(String property, String append, String wwDir)
           
protected  void buildReadPaths(Node dataFileStoreNode)
           
protected  void buildWritePaths(Node dataFileCacheNode)
           
 boolean containsFile(String fileName)
          Indicates whether the file store contains a specified file.
protected static String determineAllUserLocation()
           
protected static String determineSingleUserLocation()
           
protected  void doListFileNames(AbstractFileStore.StoreLocation location, File dir, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch, Collection<String> names)
           
protected  String[] doListFileNames(String pathName, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch)
           
 URL findFile(String fileName, boolean checkClassPath)
          Searches the file store for a specified file and returns a reference to it if it is.
 List<? extends File> getLocations()
          Returns the locations that the file store will look for files.
protected static String getUserHomeDir()
           
 File getWriteLocation()
          Returns the location that additions to the file store are placed.
protected  void initialize(InputStream xmlConfigStream)
           
 boolean isInstallLocation(String path)
          Indicates whether a specified location is considered an installed-data location and therefore not subject to automatic removal of its contents.
 String[] listAllFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered under a specified file store path name.
protected  boolean listFile(AbstractFileStore.StoreLocation location, File file, FileStoreFilter filter, Collection<String> names)
           
protected  boolean listFileName(AbstractFileStore.StoreLocation location, String fileName, FileStoreFilter filter, Collection<String> names)
           
 String[] listFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered directly under a specified file store path name.
 String[] listTopFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered under a specified file store path name.
protected static File makeAbsoluteFile(File file, String fileName)
           
protected static String makeAbsolutePath(File dir, String fileName)
           
protected static void markFileUsed(File file)
           
 File newFile(String fileName)
          Creates a new, empty file in the file store.
protected static String normalizeFileStoreName(String fileName)
           
protected static String propertyToPath(String propName)
           
 void removeFile(URL url)
          Removes a file from the file store using the URL to the cached file.
 void removeLocation(String path)
          Remove a specified read location from the file store.
protected  AbstractFileStore.StoreLocation storeLocationFor(String path)
           
protected static String storePathForFile(AbstractFileStore.StoreLocation location, File file)
           
 
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
 
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.cache.FileStore
getContentType, getExpirationTime, removeFile, requestFile, requestFile
 
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
 

Field Detail

readLocations

protected final List<AbstractFileStore.StoreLocation> readLocations

writeLocation

protected AbstractFileStore.StoreLocation writeLocation
Constructor Detail

AbstractFileStore

public AbstractFileStore()
Method Detail

addLocation

public void addLocation(int index,
                        String newPath,
                        boolean isInstall)
Description copied from interface: FileStore
Adds a location to search when files are requested from the file store and specifies its location in the search order.

Specified by:
addLocation in interface FileStore
Parameters:
index - the location in the search list at which to add the new location.
newPath - the location to add.
isInstall - indicates whether the location is an installed-data location and therefore not subject to automatic removal of its contents.

addLocation

public void addLocation(String newPath,
                        boolean isInstall)
Description copied from interface: FileStore
Adds a location to search when files are requested from the file store.

Specified by:
addLocation in interface FileStore
Parameters:
newPath - the location to add. If the location already exists in the list of read locations its entry is removed and a new entry is added to the end of the search list.
isInstall - indicates whether the location is an "installed data" location and therefore not subject to automatic removal of its contents.

buildLocationPath

protected static String buildLocationPath(String property,
                                          String append,
                                          String wwDir)

buildReadPaths

protected void buildReadPaths(Node dataFileStoreNode)

buildWritePaths

protected void buildWritePaths(Node dataFileCacheNode)

containsFile

public boolean containsFile(String fileName)
Description copied from interface: FileStore
Indicates whether the file store contains a specified file.

Specified by:
containsFile in interface FileStore
Parameters:
fileName - the file in question.
Returns:
true if the file store contains the file, false if the file store does not contain the file or the specified path is null.

determineAllUserLocation

protected static String determineAllUserLocation()

determineSingleUserLocation

protected static String determineSingleUserLocation()

doListFileNames

protected void doListFileNames(AbstractFileStore.StoreLocation location,
                               File dir,
                               FileStoreFilter filter,
                               boolean recurse,
                               boolean exitBranchOnFirstMatch,
                               Collection<String> names)

doListFileNames

protected String[] doListFileNames(String pathName,
                                   FileStoreFilter filter,
                                   boolean recurse,
                                   boolean exitBranchOnFirstMatch)

findFile

public URL findFile(String fileName,
                    boolean checkClassPath)
Description copied from interface: FileStore
Searches the file store for a specified file and returns a reference to it if it is.

Specified by:
findFile in interface FileStore
Parameters:
fileName - the name of the file to find
checkClassPath - if true, the class path is first searched for the file, otherwise the class path is not searched unless it's one of the explicit paths in the cache search directories
Returns:
a handle to the requested file if it exists in the cache, otherwise null
Throws:
IllegalArgumentException - if fileName is null

getLocations

public List<? extends File> getLocations()
Description copied from interface: FileStore
Returns the locations that the file store will look for files.

Specified by:
getLocations in interface FileStore
Returns:
the list of locations the file store will search when a file is requested.

getUserHomeDir

protected static String getUserHomeDir()

getWriteLocation

public File getWriteLocation()
Description copied from interface: FileStore
Returns the location that additions to the file store are placed.

Specified by:
getWriteLocation in interface FileStore
Returns:
the location at which new entries are placed.

initialize

protected void initialize(InputStream xmlConfigStream)

isInstallLocation

public boolean isInstallLocation(String path)
Description copied from interface: FileStore
Indicates whether a specified location is considered an installed-data location and therefore not subject to automatic removal of its contents.

Specified by:
isInstallLocation in interface FileStore
Parameters:
path - the path in question.
Returns:
true if the location is an installed-data location, otherwise false.

listAllFileNames

public String[] listAllFileNames(String pathName,
                                 FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered under a specified file store path name. If the path name is null, the entire file store will be searched. Otherwise the file store is recursively searched under the specified path name for files accepted by the specified filter, until the entire path tree is exhausted. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listAllFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

listFile

protected boolean listFile(AbstractFileStore.StoreLocation location,
                           File file,
                           FileStoreFilter filter,
                           Collection<String> names)

listFileName

protected boolean listFileName(AbstractFileStore.StoreLocation location,
                               String fileName,
                               FileStoreFilter filter,
                               Collection<String> names)

listFileNames

public String[] listFileNames(String pathName,
                              FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered directly under a specified file store path name. If the path name is null, files under the store root are searched. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

listTopFileNames

public String[] listTopFileNames(String pathName,
                                 FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered under a specified file store path name. If the path name is null, the entire file store will be searched. Otherwise the file store is recursively searched under each branch of the the specified path name until a matching file is found, or that branch is exhausted. Unlike FileStore.listAllFileNames(String, FileStoreFilter), This has the effect of locating the top file name under each branch. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listTopFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

makeAbsoluteFile

protected static File makeAbsoluteFile(File file,
                                       String fileName)

makeAbsolutePath

protected static String makeAbsolutePath(File dir,
                                         String fileName)

markFileUsed

protected static void markFileUsed(File file)

newFile

public File newFile(String fileName)
Description copied from interface: FileStore
Creates a new, empty file in the file store.

If the file store has no write location, the file is not created and null is returned.

Specified by:
newFile in interface FileStore
Parameters:
fileName - the name to give the newly created file
Returns:
a handle to the newly created file if it could be created and added to the file store, otherwise null
Throws:
IllegalArgumentException - if fileName is null

normalizeFileStoreName

protected static String normalizeFileStoreName(String fileName)

propertyToPath

protected static String propertyToPath(String propName)

removeFile

public void removeFile(URL url)
Description copied from interface: FileStore
Removes a file from the file store using the URL to the cached file.

Specified by:
removeFile in interface FileStore
Parameters:
url - the "file:" URL of the file to remove from the file store. Only files in the writable World Wind disk cache or temp file directory are removed by this method.
Throws:
IllegalArgumentException - if url is null

removeLocation

public void removeLocation(String path)
Description copied from interface: FileStore
Remove a specified read location from the file store. The current write location cannot be removed.

Specified by:
removeLocation in interface FileStore
Parameters:
path - the read location to remove.

storeLocationFor

protected AbstractFileStore.StoreLocation storeLocationFor(String path)

storePathForFile

protected static String storePathForFile(AbstractFileStore.StoreLocation location,
                                         File file)

NASA World Wind