org.norther.tammi.core.cache
Class PlainResource

java.lang.Object
  extended by org.norther.tammi.core.cache.PlainResource
All Implemented Interfaces:
Serializable, EventListener, CacheListener, Resource
Direct Known Subclasses:
AbstractResourceResolver.AbstractResource, BufferedResource

public class PlainResource
extends Object
implements Resource, CacheListener, Serializable

A plain implementation of CachedResource supporting file and URL resources but no caching of content.

Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
PlainResource(String name, Object src)
          Constructs a new resource.
 
Method Summary
 void activated(CachedEntryEvent event)
          Notifies the object that it has been activated to the cache.
 void expired(CachedEntryEvent event)
          Notifies the object that it has been expired from the cache.
 long getCheckInterval()
          Gets the interval of checking validity of the resource.
 byte[] getContents()
          Gets the contents of the resource as bytes.
protected  byte[] getContents(InputStream in)
          Gets the contents from the specified stream as bytes.
 InputStream getInputStream()
          Gets the resource as a stream.
 long getLastModified()
          Gets the resource modification time.
 long getLength()
          Gets the length of the resource.
 String getName()
          Gets the name of the resource.
 String getPath()
          Gets the path of the resource.
 int getSizeLimit()
          Gets the size limit for a cached resource.
 Object getSource()
          Gets the source of the resource.
 boolean isDeleteOnRelease()
          Checks whether the resource source should be deleted on release.
 boolean isValid()
          Checks whether the original resource is still valid.
 void passivated(CachedEntryEvent event)
          Notifies the object that it has been passivated from the cache.
 void release()
          Releases the cached resource.
 void setCheckInterval(long msecs)
          Sets the interval of checking validity of the resource.
 void setDeleteOnRelease(boolean flag)
          Sets whether the resource source should be deleted on release.
 void setPath(String path)
          Sets the path of the resource.
 void setSizeLimit(int limit)
          Sets a size limit for a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainResource

public PlainResource(String name,
                     Object src)
Constructs a new resource.

Parameters:
name - the name.
src - the source.
Method Detail

getName

public String getName()
Description copied from interface: Resource
Gets the name of the resource.

Specified by:
getName in interface Resource
Returns:
the resource name.

getSource

public Object getSource()
Description copied from interface: Resource
Gets the source of the resource.

Specified by:
getSource in interface Resource
Returns:
the resurce source.

getLength

public long getLength()
Description copied from interface: Resource
Gets the length of the resource.

Specified by:
getLength in interface Resource
Returns:
the resource length or -1 if not known.

getLastModified

public long getLastModified()
Description copied from interface: Resource
Gets the resource modification time.

Specified by:
getLastModified in interface Resource
Returns:
the resource modification time.

getCheckInterval

public long getCheckInterval()
Description copied from interface: Resource
Gets the interval of checking validity of the resource.

Specified by:
getCheckInterval in interface Resource
Returns:
the check interval in milliseconds.

setCheckInterval

public void setCheckInterval(long msecs)
Description copied from interface: Resource
Sets the interval of checking validity of the resource.

Specified by:
setCheckInterval in interface Resource
Parameters:
msecs - the check interval in milliseconds (-1 = only once).

isDeleteOnRelease

public boolean isDeleteOnRelease()
Description copied from interface: Resource
Checks whether the resource source should be deleted on release.

Specified by:
isDeleteOnRelease in interface Resource
Returns:
true if to be deleted, false otherwise.

setDeleteOnRelease

public void setDeleteOnRelease(boolean flag)
Description copied from interface: Resource
Sets whether the resource source should be deleted on release.

Specified by:
setDeleteOnRelease in interface Resource
Parameters:
flag - true if to be deleted, false otherwise.

getSizeLimit

public int getSizeLimit()
Description copied from interface: Resource
Gets the size limit for a cached resource.

Specified by:
getSizeLimit in interface Resource
Returns:
the limit for a resource size in bytes.

setSizeLimit

public void setSizeLimit(int limit)
Description copied from interface: Resource
Sets a size limit for a resource.

Specified by:
setSizeLimit in interface Resource
Parameters:
limit - a limit for a resource size in bytes (-1 = unlimited).

getPath

public String getPath()
Description copied from interface: Resource
Gets the path of the resource.

Specified by:
getPath in interface Resource
Returns:
the path of the resource.

setPath

public void setPath(String path)
Description copied from interface: Resource
Sets the path of the resource.

Specified by:
setPath in interface Resource
Parameters:
path - the path of the resource.

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: Resource
Gets the resource as a stream.

Specified by:
getInputStream in interface Resource
Returns:
the resource as a stream.
Throws:
IOException - on I/O errors.

getContents

public byte[] getContents()
                   throws IOException
Description copied from interface: Resource
Gets the contents of the resource as bytes.

Specified by:
getContents in interface Resource
Returns:
the resource contents as bytes.
Throws:
IOException - on I/O errors.

isValid

public boolean isValid()
Description copied from interface: Resource
Checks whether the original resource is still valid.

Specified by:
isValid in interface Resource
Returns:
true for a valid resource, otherwise false.

release

public void release()
Description copied from interface: Resource
Releases the cached resource.

Specified by:
release in interface Resource

expired

public void expired(CachedEntryEvent event)
Description copied from interface: CacheListener
Notifies the object that it has been expired from the cache.

Specified by:
expired in interface CacheListener
Parameters:
event - the cached entry event.

passivated

public void passivated(CachedEntryEvent event)
Description copied from interface: CacheListener
Notifies the object that it has been passivated from the cache.

Specified by:
passivated in interface CacheListener
Parameters:
event - the cached entry event.

activated

public void activated(CachedEntryEvent event)
Description copied from interface: CacheListener
Notifies the object that it has been activated to the cache.

Specified by:
activated in interface CacheListener
Parameters:
event - the cached entry event.

getContents

protected byte[] getContents(InputStream in)
                      throws IOException
Gets the contents from the specified stream as bytes.

Parameters:
in - the input stream to read from.
Returns:
the resource contents as bytes.
Throws:
IOException - on I/O errors.


Copyright © 2004 The Norther Organization. All rights reserved.