Search in sources :

Example 1 with WebappSource

use of org.onebusaway.presentation.services.resources.WebappSource in project onebusaway-application-modules by camsys.

the class ClientBundleFactory method processBundleMethods.

/**
 **
 * Private Methods
 *
 * @return
 ***
 */
private List<ResourcePrototypeImpl> processBundleMethods(Class<?> bundleType, ClientBundleImpl bundle) throws MalformedURLException {
    List<ResourcePrototypeImpl> resources = new ArrayList<ResourcePrototypeImpl>();
    for (Method method : bundleType.getMethods()) {
        String methodName = method.getName();
        WebappSource source = method.getAnnotation(WebappSource.class);
        if (source == null) {
            _log.warn("no Resource annotation found: " + methodName);
            continue;
        }
        String[] values = source.value();
        if (values == null || values.length != 1)
            throw new IllegalStateException("@WebappSource has no value: " + bundleType.getName() + "#" + methodName);
        String resourceName = values[0];
        Class<?> returnType = method.getReturnType();
        URL localURL = getBundleResourceAsLocalUrl(bundleType, resourceName);
        if (localURL == null) {
            _log.warn("could not find ClientBundle resource for " + bundleType.getName() + "#" + methodName + " source=" + resourceName);
            continue;
        }
        File localFile = getBundleResourceAsLocalFile(resourceName, localURL);
        String name = getMethodNameAsPropertyName(methodName);
        if (name == null) {
            _log.warn("invalid resource name: " + bundleType.getName() + "#" + methodName);
            continue;
        }
        if (CssResource.class.isAssignableFrom(returnType)) {
            CssResourceImpl resourceImpl = new CssResourceImpl(_context, bundle, methodName, localURL);
            if (localFile != null)
                resourceImpl.setLocalFile(localFile);
            resources.add(resourceImpl);
            ResourcePrototype resourceProxy = (ResourcePrototype) Proxy.newProxyInstance(bundleType.getClassLoader(), new Class[] { returnType, ResourceWithUrl.class }, resourceImpl);
            bundle.addResource(resourceProxy);
        } else if (ImageResource.class.isAssignableFrom(returnType)) {
            ImageResourceImpl resourceImpl = new ImageResourceImpl(_context, bundle, methodName, localURL);
            bundle.addResource(resourceImpl);
            resources.add(resourceImpl);
        }
    }
    return resources;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) URL(java.net.URL) ResourcePrototype(com.google.gwt.resources.client.ResourcePrototype) ImageResource(com.google.gwt.resources.client.ImageResource) File(java.io.File) WebappSource(org.onebusaway.presentation.services.resources.WebappSource)

Aggregations

ImageResource (com.google.gwt.resources.client.ImageResource)1 ResourcePrototype (com.google.gwt.resources.client.ResourcePrototype)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 WebappSource (org.onebusaway.presentation.services.resources.WebappSource)1