fnug.resource
Class AbstractCompiledResource

java.lang.Object
  extended by fnug.resource.AbstractResource
      extended by fnug.resource.DefaultResource
          extended by fnug.resource.AbstractCompiledResource
All Implemented Interfaces:
HasBundle, HasLastModifiedBytes, Resource
Direct Known Subclasses:
DustCompiledResource

public abstract class AbstractCompiledResource
extends DefaultResource
implements HasBundle


Nested Class Summary
 
Nested classes/interfaces inherited from class fnug.resource.AbstractResource
AbstractResource.Entry
 
Field Summary
 
Fields inherited from class fnug.resource.DefaultResource
DEFAULT_CHECK_MODIFIED_INTERVAL
 
Fields inherited from class fnug.resource.AbstractResource
CONTENT_TYPE_TEXT_CSS, CONTENT_TYPE_TEXT_JAVASCRIPT
 
Constructor Summary
AbstractCompiledResource(String basePath, String path)
          Constructs setting base path and path.
 
Method Summary
 boolean checkModified()
          Ditches the compiled bytes if the superclass indicates that modified has changed.
protected abstract  byte[] compile(byte[] source)
          Subclasses must implement to do the compilation of this resource.
 Bundle getBundle()
          Returns the associated bundle.
 byte[] getBytes()
          Returns the compiled bytes.
protected  byte[] getBytesForFindRequires()
          Overridden to return the uncompiled bytes.
 void setBundle(Bundle bundle)
          (Optionally) sets the bundle.
 
Methods inherited from class fnug.resource.DefaultResource
decode, doGetResourceURL, extractJarFile, findRequiresTags, getResourceURL, readEntry, readLastModified, readLastModifiedAllowed
 
Methods inherited from class fnug.resource.AbstractResource
contentTypeForPath, ensureReadEntry, getBasePath, getContentType, getFullPath, getLastModified, getPath, isCss, isJs, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractCompiledResource

public AbstractCompiledResource(String basePath,
                                String path)
Constructs setting base path and path.

Parameters:
basePath - The base path of the resource. See AbstractResource.getBasePath().
path - The path of the resource. See AbstractResource.getPath().
Method Detail

getBundle

public Bundle getBundle()
Returns the associated bundle.

Specified by:
getBundle in interface HasBundle
Returns:
the associated bundle.

setBundle

public void setBundle(Bundle bundle)
(Optionally) sets the bundle.

Parameters:
bundle - the bundle to associate resource with.

getBytes

public byte[] getBytes()
Returns the compiled bytes. The bytes that is this resource data. Notice that resource data is held in memory. This method only triggers an actual file system read if this is the first time the resource is being accessed. Likewise, aggregated resources are only built on first access, and then held. To trigger rebuilding call Resource.checkModified().

Notice that for resources pointing to non-existant files Resource.getBytes() return an empty array, never null (but Resource.getLastModified() returns -1).

Specified by:
getBytes in interface HasLastModifiedBytes
Specified by:
getBytes in interface Resource
Overrides:
getBytes in class AbstractResource
Returns:
the timestamped bytes.

getBytesForFindRequires

protected byte[] getBytesForFindRequires()
Overridden to return the uncompiled bytes. Overridable method for getting the bytes to use for finding requires tags.

Overrides:
getBytesForFindRequires in class DefaultResource
Returns:
the bytes to use. Defaults to AbstractResource.getBytes()

checkModified

public boolean checkModified()
Ditches the compiled bytes if the superclass indicates that modified has changed. Compares this resource in memory held last modified date with the one on disk (or for aggregated resource, all the aggregates are checked). If the last modified on disk is found to be newer than the one in memory, the in memory data is dropped and reread on next Resource.getBytes() or Resource.getLastModified().

Specified by:
checkModified in interface Resource
Overrides:
checkModified in class AbstractResource
Returns:
true if the file system resource (or aggregates in case of aggregated resources) has a newer last modified date which caused the in memory held data to be dropped.

compile

protected abstract byte[] compile(byte[] source)
Subclasses must implement to do the compilation of this resource.

Parameters:
source - the source bytes.
Returns:
the compiled bytes`


Copyright © 2012. All Rights Reserved.