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;
}
Aggregations