fnug.resource
Class DefaultBundle

java.lang.Object
  extended by fnug.resource.DefaultBundle
All Implemented Interfaces:
Bundle

public class DefaultBundle
extends Object
implements Bundle

Default implementation of Bundle.

Author:
Martin Algesten

Field Summary
 
Fields inherited from interface fnug.resource.Bundle
BUNDLE_ALLOWED_CHARS
 
Constructor Summary
DefaultBundle(BundleConfig config)
          Constructs a bundle from the given config object.
 
Method Summary
 boolean checkModified()
          Checks whether this bundle is modified by calling checkModified() on the Bundle.getResourceCollections().
 BundleConfig getConfig()
          Returns the config that this bundle was built from.
 JSLintWrapper getJsLinter()
          Returns the configured JSLint instance for the bundle.
 long getLastModified()
          Returns the last modified date of this bundle which comprises the most recent date of the Bundle.getConfig() and all the Bundle.getResourceCollections() resources last modified dates.
 String getName()
          The name of this bundle.
 ResourceCollection[] getResourceCollections()
          Each bundle configures up a number of resources (files) that comprises the bundle, see BundleConfig.files().
protected  Resource makeResource(String path)
          Can be overridden to provide other implementations of Resource than the DefaultBundleResource.
 Resource resolve(String path)
          Resolves a resource under this bundle's base path (see BundleConfig.basePath() Resource.getBasePath().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBundle

public DefaultBundle(BundleConfig config)
Constructs a bundle from the given config object.

Parameters:
config - config to construct from.
Method Detail

getConfig

public BundleConfig getConfig()
Returns the config that this bundle was built from.

Specified by:
getConfig in interface Bundle
Returns:
the config of the bundle.

getName

public String getName()
The name of this bundle.

Specified by:
getName in interface Bundle
Returns:
the name

resolve

public Resource resolve(String path)
Resolves a resource under this bundle's base path (see BundleConfig.basePath() Resource.getBasePath(). The bundle returns the corresponding Resource regardless of whether it exists or not (never return null). If the underlying file does not exist, the resource returned have an empty array of bytes in Resource.getBytes() and a Resource.getLastModified() of -1.

Specified by:
resolve in interface Bundle
Parameters:
path - The path to resolve under this bundle. This must never start with /. See Resource.getPath().
Returns:
the resolved resource, never null.

makeResource

protected Resource makeResource(String path)
Can be overridden to provide other implementations of Resource than the DefaultBundleResource.

Parameters:
path - the path to construct a resource around.
Returns:
the constructed resource, which is an instance of DefaultBundleResource.

getResourceCollections

public ResourceCollection[] getResourceCollections()
Each bundle configures up a number of resources (files) that comprises the bundle, see BundleConfig.files(). Each of these resources may in turn have dependencies on other resources, potentially from other bundles. This method returns an array where each element holds resolved dependent resources for a bundle, the order is important, since that's the resolved order in which the resources/bundles must be loaded to satisfy the dependency chains.

Specified by:
getResourceCollections in interface Bundle
Returns:
An ordered array of a resource collection per bundle for resolved file dependencies.

getLastModified

public long getLastModified()
Returns the last modified date of this bundle which comprises the most recent date of the Bundle.getConfig() and all the Bundle.getResourceCollections() resources last modified dates.

Specified by:
getLastModified in interface Bundle
Returns:
when the bundle was last modified.

checkModified

public boolean checkModified()
Checks whether this bundle is modified by calling checkModified() on the Bundle.getResourceCollections(). This does not call checkModified() on the BundleConfig.configResource() since that is being checked by the Resolver. If any resource is found to have changed, the built Bundle.getResourceCollections() are dropped and (lazily) rebuilt.

Specified by:
checkModified in interface Bundle
Returns:
true if any resource has changed.

getJsLinter

public JSLintWrapper getJsLinter()
Returns the configured JSLint instance for the bundle. Only returns a value if BundleConfig.jsLintArgs() is an non-empty array.

Specified by:
getJsLinter in interface Bundle


Copyright © 2012. All Rights Reserved.