org.szegedi.spring.core.io
Class ResourceRepresentation

java.lang.Object
  extended by org.szegedi.spring.core.io.ResourceRepresentation
Direct Known Subclasses:
PropertyResourceRepresentation

public abstract class ResourceRepresentation
extends java.lang.Object

Represents a class that is capable of loading and caching a parsed representation of contents of a Spring resource. In case the resource has a URL representation and it changes, the object will be reloaded. The code also has a special optimization for "file:" URLs. All subclasses have to do is implement the loadRepresentation(InputStream) method.

Version:
$Id: $
Author:
Attila Szegedi

Constructor Summary
ResourceRepresentation(org.springframework.core.io.Resource resource)
          Constructs a new representation for the specified resource.
 
Method Summary
 java.lang.Object getRepresentation()
          Returns the representation of the resource.
 java.lang.Object getRepresentation(long noStaleCheckPeriod)
          Returns the representation of the resource.
 org.springframework.core.io.Resource getResource()
           
protected abstract  java.lang.Object loadRepresentation(java.io.InputStream in)
          Implement in subclasses to load the representation of the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceRepresentation

public ResourceRepresentation(org.springframework.core.io.Resource resource)
Constructs a new representation for the specified resource.

Parameters:
resource -
Method Detail

getRepresentation

public java.lang.Object getRepresentation(long noStaleCheckPeriod)
                                   throws java.lang.Exception
Returns the representation of the resource.

Parameters:
noStaleCheckPeriod - If the resource's timestamp was last checked no earlier than the specified number of milliseconds, it won't be checked and the cached representation will be returned instead.
Returns:
the representation of the resource
Throws:
java.lang.Exception - if there was an exception during loading of the representation

getRepresentation

public java.lang.Object getRepresentation()
                                   throws java.lang.Exception
Returns the representation of the resource. Equal to getRepresentation(long) with 0 parameter, although a bit more optimized.

Returns:
the representation of the resource
Throws:
java.lang.Exception - if there was an exception during loading of the representation

getResource

public org.springframework.core.io.Resource getResource()

loadRepresentation

protected abstract java.lang.Object loadRepresentation(java.io.InputStream in)
                                                throws java.io.IOException
Implement in subclasses to load the representation of the resource.

Parameters:
in - the input stream with resource bytes
Returns:
the object representing the resource.
Throws:
java.io.IOException