ucar.unidata.util
Class ResourceCollection

java.lang.Object
  extended by ucar.unidata.util.ResourceCollection
Direct Known Subclasses:
XmlResourceCollection

public class ResourceCollection
extends Object

Version:
$Revision: 1.47 $ $Date: 2006/10/30 18:10:31 $
Author:
Metapps development team

Nested Class Summary
static class ResourceCollection.Resource
          Class Resource holds a string path which may be a file, url or java resource path.
 
Field Summary
protected  String description
          The description
protected  String id
          The id of this collection
protected  Hashtable idToPath
          A mapping from id (String) to the resource path
protected  Hashtable pathToId
          A mapping from resource path to id
protected  int writableIndex
          Index of the writable index
protected  ResourceCollection.Resource writableResource
          Path to the writable resource
 
Constructor Summary
ResourceCollection(String id)
          Create a ResourceCollection with the given id.
ResourceCollection(String id, List resources)
          Ctor
ResourceCollection(String id, String description)
          Create a ResourceCollection with the given id ad description
ResourceCollection(String id, String writable, List resources)
          Deprecated. not good anymore
 
Method Summary
 void addLabels(Hashtable labelMap)
          Deprecated. not used anymore
 void addResource(ResourceCollection.Resource resource)
          Add the resource.
 void addResource(String resource)
          Add the resource.
 void addResourceAtStart(String resourcePath)
          Add the resource.
 void addResourceAtStart(String resourcePath, String label)
           
 void addResources(List rs)
          Add the list of resources
 void clearCache()
          Clear the cache
 boolean contains(String path)
          Do we contain the given path
 void deleteAllFiles()
          Delete, if possible, all resource files.
 Object get(int i)
          Return the name of the i'th resource
 boolean getCanLoadMore()
          Should we keep loading resources from this collection.
 String getDescription()
          Get the Description property.
 String getId()
          The id of the resource collection
 String getLabel(int resourceIdx)
          Return the label (or null if none defined) for the given resource.
 String getPathFromId(String id)
          Find the path for the given id
 String getProperty(String name, int resourceIdx)
          _more_
 String getResourceId(int idx)
          Find the id for the given resource index
 List getResources()
          Get the list of resources
 String getShortName(int resourceIdx)
          Return an abbreviated name of the given resource for display purposes.
 String getWritable()
          Get the string path of the writable file resource.
 boolean hasWritableResource()
          Do we have a writable resource
 boolean isHttp(int i)
          Is the given index an http based path
 boolean isHttp(String resource)
          Is the given path an http based path
 boolean isValid(int i)
          Is the given resource index valid.
 boolean isWritable(int i)
          Is the i'th resource writable
 boolean isWritableResource(int i)
          Is the ith resource a writable resource
 String read(int i)
          Read the ith resource
 String read(int i, boolean lookAtCache)
          Read the ith resource
protected  String read(ResourceCollection.Resource resource, boolean lookAtCache)
          Read and return the contents of the resource.
 String readWritableResource()
          Read in the writable resource file
 void removeAll()
          Reset all structures
 void removeWritable()
          Delete, if possible, the writable resource file
 void setCanLoadMore(boolean lm)
          Set if we can keep loading resources
 void setDescription(String value)
          Set the Description property.
 void setId(String id)
          Set the id of the resource collection
 void setIdForPath(String id, String path)
          Associate the resource id with the path
 int size()
          How many resources
 String toString()
          The toString method
 void writeWritableResource(String contents)
          Write the given contents into the writable resource file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected String id
The id of this collection


description

protected String description
The description


idToPath

protected Hashtable idToPath
A mapping from id (String) to the resource path


pathToId

protected Hashtable pathToId
A mapping from resource path to id


writableResource

protected ResourceCollection.Resource writableResource
Path to the writable resource


writableIndex

protected int writableIndex
Index of the writable index

Constructor Detail

ResourceCollection

public ResourceCollection(String id)
Create a ResourceCollection with the given id. The description of this collection is the id.

Parameters:
id - The id of this ResourceCollection

ResourceCollection

public ResourceCollection(String id,
                          String description)
Create a ResourceCollection with the given id ad description

Parameters:
id - The id of this ResourceCollection
description - The description of this ResourceCollection

ResourceCollection

public ResourceCollection(String id,
                          List resources)
Ctor

Parameters:
id - Resource id
resources - List of resources

ResourceCollection

public ResourceCollection(String id,
                          String writable,
                          List resources)
Deprecated. not good anymore

Ctor

Parameters:
id - Resource id
resources - List of resources
writable - The writable resource
Method Detail

contains

public boolean contains(String path)
Do we contain the given path

Parameters:
path - the resource path
Returns:
do we contain the resource path

setIdForPath

public void setIdForPath(String id,
                         String path)
Associate the resource id with the path

Parameters:
id - The id
path - The path

getPathFromId

public String getPathFromId(String id)
Find the path for the given id

Parameters:
id - The id
Returns:
The path

getResourceId

public String getResourceId(int idx)
Find the id for the given resource index

Parameters:
idx - The resource index
Returns:
The id. May be null.

getCanLoadMore

public boolean getCanLoadMore()
Should we keep loading resources from this collection. Have we seen the loadmore=false yet.

Returns:
Keep loading resources

setCanLoadMore

public void setCanLoadMore(boolean lm)
Set if we can keep loading resources

Parameters:
lm - value

getId

public String getId()
The id of the resource collection

Returns:
resource id

setId

public void setId(String id)
Set the id of the resource collection

Parameters:
id - The id

isValid

public boolean isValid(int i)
Is the given resource index valid. We try to read that resource.

Parameters:
i - Resource index
Returns:
Do we have it

getLabel

public String getLabel(int resourceIdx)
Return the label (or null if none defined) for the given resource.

Parameters:
resourceIdx -
Returns:
A short name for the given resource.

getProperty

public String getProperty(String name,
                          int resourceIdx)
_more_

Parameters:
name - _more_
resourceIdx - _more_
Returns:
_more_

getShortName

public String getShortName(int resourceIdx)
Return an abbreviated name of the given resource for display purposes.

Parameters:
resourceIdx -
Returns:
A short name for the given resource.

addLabels

public void addLabels(Hashtable labelMap)
Deprecated. not used anymore

Add in the given maps of path to label.

Parameters:
labelMap - Pat to label map

addResources

public void addResources(List rs)
Add the list of resources

Parameters:
rs - List of Resource-s

addResource

public void addResource(String resource)
Add the resource. We create a new Resource

Parameters:
resource - The resource path

addResource

public void addResource(ResourceCollection.Resource resource)
Add the resource.

Parameters:
resource - The resource

addResourceAtStart

public void addResourceAtStart(String resourcePath)
Add the resource.

Parameters:
resourcePath - the path to the resource

addResourceAtStart

public void addResourceAtStart(String resourcePath,
                               String label)

size

public int size()
How many resources

Returns:
How many resources

isWritable

public boolean isWritable(int i)
Is the i'th resource writable

Parameters:
i - Resource index
Returns:
Is it a writable file

isHttp

public boolean isHttp(String resource)
Is the given path an http based path

Parameters:
resource - Resource path
Returns:
Is it http

isHttp

public boolean isHttp(int i)
Is the given index an http based path

Parameters:
i - Resource index
Returns:
Is it http

get

public Object get(int i)
Return the name of the i'th resource

Parameters:
i - The resource index
Returns:
The name of the i'th resource

isWritableResource

public boolean isWritableResource(int i)
Is the ith resource a writable resource

Parameters:
i - Resource index
Returns:
is writable

readWritableResource

public String readWritableResource()
Read in the writable resource file

Returns:
The writable resource contents or null

writeWritableResource

public void writeWritableResource(String contents)
                           throws FileNotFoundException,
                                  IOException
Write the given contents into the writable resource file

Parameters:
contents -
Throws:
FileNotFoundException
IOException

read

protected String read(ResourceCollection.Resource resource,
                      boolean lookAtCache)
Read and return the contents of the resource. Return null if cannot be read.

Parameters:
resource - The resource
lookAtCache - Should we look in the cache or reread
Returns:
Contents or null

read

public String read(int i,
                   boolean lookAtCache)
Read the ith resource

Parameters:
i - The resource index
lookAtCache - Should we look in the cache or reread
Returns:
Contents or null

read

public String read(int i)
Read the ith resource

Parameters:
i - The resource index
Returns:
Contents or null

getResources

public List getResources()
Get the list of resources

Returns:
List of resources

removeWritable

public void removeWritable()
Delete, if possible, the writable resource file


clearCache

public void clearCache()
Clear the cache


deleteAllFiles

public void deleteAllFiles()
Delete, if possible, all resource files.


removeAll

public void removeAll()
Reset all structures


getWritable

public String getWritable()
Get the string path of the writable file resource.

Returns:
File path

hasWritableResource

public boolean hasWritableResource()
Do we have a writable resource

Returns:
Do we have a writable resource

toString

public String toString()
The toString method

Overrides:
toString in class Object
Returns:
String representation

setDescription

public void setDescription(String value)
Set the Description property.

Parameters:
value - The new value for Description

getDescription

public String getDescription()
Get the Description property.

Returns:
The Description