GWT 2.5.0.rc2

com.google.gwt.resources.ext
Class ResourceGeneratorUtil

java.lang.Object
  extended by com.google.gwt.resources.ext.ResourceGeneratorUtil

public final class ResourceGeneratorUtil
extends java.lang.Object

Utility methods for building ResourceGenerators.


Method Summary
static void addNamedFile(java.lang.String resourceName, java.io.File file)
          Publish or override resources named by ClientBundle.Source annotations.
static java.lang.String baseName(java.net.URL resource)
          Returns the base filename of a resource.
static java.net.URL[] findResources(TreeLogger logger, java.lang.ClassLoader classLoader, ResourceContext context, JMethod method, java.lang.String[] defaultSuffixes)
          Find all resources referenced by a method in a bundle.
static java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method)
          Find all resources referenced by a method in a bundle.
static java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method, java.lang.String[] defaultSuffixes)
          Find all resources referenced by a method in a bundle.
static JMethod getMethodByPath(JClassType rootType, java.util.List<java.lang.String> pathElements, JType expectedReturnType)
          Finds a method by following a dotted path interpreted as a series of no-arg method invocations from an instance of a given root type.
static java.net.URL tryFindResource(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, java.lang.String resourceName)
          Try to find a resource with the given resourceName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addNamedFile

public static void addNamedFile(java.lang.String resourceName,
                                java.io.File file)
Publish or override resources named by ClientBundle.Source annotations. This method is intended to be called by Generators that create ClientBundle instances and need to pass source data to the ClientBundle system that is not accessible through the classpath.

Parameters:
resourceName - the path at which the contents of file should be made available
file - the File whose contents are to be provided to the ClientBundle system

baseName

public static java.lang.String baseName(java.net.URL resource)
Returns the base filename of a resource. The behavior is similar to the unix command basename.

Parameters:
resource - the URL of the resource
Returns:
the final name segment of the resource

findResources

public static java.net.URL[] findResources(TreeLogger logger,
                                           java.lang.ClassLoader classLoader,
                                           ResourceContext context,
                                           JMethod method,
                                           java.lang.String[] defaultSuffixes)
                                    throws UnableToCompleteException
Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

Loading through a ClassLoader with this method is much slower than the other findResources methods which make use of the compiler's ResourceOracle.

Parameters:
logger - a TreeLogger that will be used to report errors or warnings
context - the ResourceContext in which the ResourceGenerator is operating
classLoader - the ClassLoader to use when locating resources
method - the method to examine for ClientBundle.Source annotations
defaultSuffixes - if the supplied method does not have any ClientBundle.Source annotations, act as though a Source annotation was specified, using the name of the method and each of supplied extensions in the order in which they are specified
Returns:
URLs for each ClientBundle.Source annotation value defined on the method.
Throws:
UnableToCompleteException - if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

findResources

public static java.net.URL[] findResources(TreeLogger logger,
                                           ResourceContext context,
                                           JMethod method)
                                    throws UnableToCompleteException
Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

The compiler's ResourceOracle will be used to resolve resource locations. If the desired resource cannot be found in the ResourceOracle, this method will fall back to using the current thread's context ClassLoader. If it is necessary to alter the way in which resources are located, use the overload that accepts a ClassLoader.

If the method's return type declares the DefaultExtensions annotation, the value of this annotation will be used to find matching resource names if the method lacks a ClientBundle.Source annotation.

Parameters:
logger - a TreeLogger that will be used to report errors or warnings
context - the ResourceContext in which the ResourceGenerator is operating
method - the method to examine for ClientBundle.Source annotations
Returns:
URLs for each ClientBundle.Source annotation value defined on the method.
Throws:
UnableToCompleteException - if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

findResources

public static java.net.URL[] findResources(TreeLogger logger,
                                           ResourceContext context,
                                           JMethod method,
                                           java.lang.String[] defaultSuffixes)
                                    throws UnableToCompleteException
Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

The compiler's ResourceOracle will be used to resolve resource locations. If the desired resource cannot be found in the ResourceOracle, this method will fall back to using the current thread's context ClassLoader. If it is necessary to alter the way in which resources are located, use the overload that accepts a ClassLoader.

Parameters:
logger - a TreeLogger that will be used to report errors or warnings
context - the ResourceContext in which the ResourceGenerator is operating
method - the method to examine for ClientBundle.Source annotations
defaultSuffixes - if the supplied method does not have any ClientBundle.Source annotations, act as though a Source annotation was specified, using the name of the method and each of supplied extensions in the order in which they are specified
Returns:
URLs for each ClientBundle.Source annotation value defined on the method.
Throws:
UnableToCompleteException - if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

getMethodByPath

public static JMethod getMethodByPath(JClassType rootType,
                                      java.util.List<java.lang.String> pathElements,
                                      JType expectedReturnType)
                               throws NotFoundException
Finds a method by following a dotted path interpreted as a series of no-arg method invocations from an instance of a given root type.

Parameters:
rootType - the type from which the search begins
pathElements - a sequence of no-arg method names
expectedReturnType - the expected return type of the method to locate, or null if no constraint on the return type is necessary
Returns:
the requested JMethod
Throws:
NotFoundException - if the requested method could not be found

tryFindResource

public static java.net.URL tryFindResource(TreeLogger logger,
                                           GeneratorContext genContext,
                                           ResourceContext resourceContext,
                                           java.lang.String resourceName)
Try to find a resource with the given resourceName. It will use the default search order to locate the resource as is used by findResources(com.google.gwt.core.ext.TreeLogger, java.lang.ClassLoader, com.google.gwt.resources.ext.ResourceContext, com.google.gwt.core.ext.typeinfo.JMethod, java.lang.String[]).

Parameters:
logger -
genContext -
resourceContext -
resourceName -
Returns:
a URL for the resource, if found

GWT 2.5.0.rc2