|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.mit.jsemcor.main.URLConcordance
public abstract class URLConcordance
This abstract implementation of the IConcordance
interface is
appropriate for all concordances that retrieve their data from URLs. This
implementation has basic facilities for a size-limited LRU cache. Caching,
the cache size limit, can be set with the constructors, or the appropriate
methods.
Nested Class Summary | |
---|---|
protected class |
URLConcordance.ContextIterator
Delivers context objects in order from this concordance. |
Field Summary | |
---|---|
protected Map<IContextID,IContext> |
cache
The cache where context objects are stored. |
protected Map<IContextID,URL> |
contextMap
The map that contains IContextID objects mapped to their
URL locations. |
static int |
DEFAULT_CACHE_LIMIT
The default cache size |
protected IContextParser |
parser
The context parser used by this concordance to translate context data into IContext objects. |
Constructor Summary | |
---|---|
URLConcordance(URL url)
Constructs a new concordance whose base directory is the specified URL. |
|
URLConcordance(URL url,
boolean cache)
Constructs a new concordance whose base directory is the specified URL, with caching turned on or off according to the flag. |
|
URLConcordance(URL url,
boolean cache,
int cacheLimit)
Constructs a new concordance whose base directory is the specified URL, with caching turned on or off according to the flag, and the specified cache limit. |
Method Summary | |
---|---|
protected void |
checkOpen()
If the concordance is not open, calling this method will result in a ConcordanceClosedException ; if the provider is open, nothing
will happen. |
void |
close()
This closes the concordance by disposing of data backing objects or connections. |
protected abstract ITagIndex |
createTagIndex()
This method is called during open() to construct the tag index
object. |
protected abstract String |
extractConcordanceName(URL url)
Returns the concordance name given the concordance URL . |
protected abstract boolean |
fillContextURLMap(Map<IContextID,URL> map)
This method is called during open() to construct a map from
context id objects to the URLs from which the context contents can be
downloaded. |
Map<IContextID,IContext> |
getCache()
Returns the actual cache map object, so that it can be directly manipulated by clients. |
int |
getCacheLimit()
Returns the current cache limit set on this concordance set |
IContext |
getContext(IContextID id)
A convenience method that first checks to see if the IContextID.getContextName() equals this concordance's name; if
so, the result is the same as calling IConcordance.getContext(String) . |
IContext |
getContext(String contextName)
A convenience method, identical to IConcordance.getContext(IContextID) |
Set<IContextID> |
getContextIDs()
Returns a set of context id objects for all contexts in this concordance. |
String |
getName()
Returns the name of the concordance, which is a non-null, non-empty string. |
protected IContextParser |
getParser()
Returns the parser that should be used to parse raw context contents into an IContext object. |
ITagIndex |
getTagIndex()
Returns the tag index object for this concordance, if one exists. |
URL |
getURL()
Returns the URL that points to the root directory of this concordance. |
boolean |
isCaching()
Returns whether this concordance is currently caching the results of calls to getContext(IContextID) . |
boolean |
isOpen()
Returns whether the concordance is in a state such that it can provide context objects on demand. |
Iterator<IContext> |
iterator()
Returns an iterator over context objects contained in this concordance. |
protected IContextParser |
makeParser()
Returns a new instance of the parser that should be used to parse raw context contents into an IContext object. |
boolean |
open()
Performs all the necessary operations to prepare this concordance to provide contexts. |
protected void |
pruneCache()
Removes items from the cache so that the cache size is below the cache limit. |
boolean |
setCacheLimit(int limit)
Sets the cache limit on this concordance. |
boolean |
setCaching(boolean value)
Turns caching on or off for this concordance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_CACHE_LIMIT
protected IContextParser parser
IContext
objects.
protected final Map<IContextID,URL> contextMap
IContextID
objects mapped to their
URL
locations.
protected Map<IContextID,IContext> cache
Constructor Detail |
---|
public URLConcordance(URL url)
NullPointerException
- if the specified URL is null
public URLConcordance(URL url, boolean cache)
NullPointerException
- if the specified URL is null
public URLConcordance(URL url, boolean cache, int cacheLimit)
NullPointerException
- if the specified URL is null
Method Detail |
---|
public String getName()
IConcordance
IContextID.getConcordanceName()
method for contexts in this
concordance.
getName
in interface IConcordance
public URL getURL()
public boolean open()
IConcordance
false
, then subsequent calls to IConcordance.isOpen()
will return false
as well. If the concordance is already
open, this method does nothing.
open
in interface IConcordance
true
if there were no errors in initialization;
false
otherwise.protected abstract String extractConcordanceName(URL url)
URL
. This
method is called in the URLConcordance
constructor to extract the
concordance's name from the specified URL.
URL
NullPointerException
- if the specified URL
is null
protected abstract boolean fillContextURLMap(Map<IContextID,URL> map) throws IOException
open()
to construct a map from
context id objects to the URLs from which the context contents can be
downloaded.
true
if the operation completed successfully;
false
otherwise.
IOException
- if there is a problem extracting the list of context ids from
the root URL
location.protected abstract ITagIndex createTagIndex() throws IOException
open()
to construct the tag index
object. If this concordance does not contain the necessary data to create
the tag index, this method will return null
.
ITagIndex
for this concordance, or null
if no tag index exists.
IOException
- if there is an IO error when creating the tag index.protected IContextParser getParser()
IContext
object. This method returns the singleton instance of
the parser that this concordance uses. If subclasses which to change the
parser, they should override the makeParser()
method.
protected IContextParser makeParser()
IContext
object. Usually this method is
only ever called once, to create the parser when it is first requested.
The URLConcordance
implementation then caches that instance and
returns on future requests for a parser.
IContext
objects.protected void checkOpen()
ConcordanceClosedException
; if the provider is open, nothing
will happen.
ConcordanceClosedException
- if the concordance is closedpublic boolean isOpen()
IConcordance
isOpen
in interface IConcordance
true
if the concordance is open;
false
otherwise.public void close()
IConcordance
IConcordance.open()
should put the concordance back in the ready state. If
the concordance is already closed, this method does nothing.
close
in interface IConcordance
public Set<IContextID> getContextIDs()
IConcordance
getContextIDs
in interface IConcordance
public ITagIndex getTagIndex()
IConcordance
null
.
getTagIndex
in interface IConcordance
ITagIndex
object, if one can be created; otherwise,
null
public IContext getContext(String contextName)
IConcordance
IConcordance.getContext(IContextID)
getContext
in interface IConcordance
null
otherwise.public IContext getContext(IContextID id)
IConcordance
IContextID.getContextName()
equals this concordance's name; if
so, the result is the same as calling IConcordance.getContext(String)
. If
not, returns null
.
getContext
in interface IConcordance
null
otherwise.public Iterator<IContext> iterator()
IConcordance
iterator
in interface IConcordance
iterator
in interface Iterable<IContext>
IContext
objects.Iterable.iterator()
public boolean isCaching()
getContext(IContextID)
.
public boolean setCaching(boolean value)
getContext(IContextID)
method. To clear the cache, obtain
the cache map instance via getCache()
method and call
Map.clear()
.
public boolean setCacheLimit(int limit)
setCaching(boolean)
method.
true
if the cache limit was changed;
false
otherwisepublic int getCacheLimit()
public Map<IContextID,IContext> getCache()
protected void pruneCache()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |