Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrerigon/1149159 to your computer and use it in GitHub Desktop.
Save andrerigon/1149159 to your computer and use it in GitHub Desktop.
PathAnnotationRoutesParser that uses an interface if the controller has one
import java.util.List;
import br.com.caelum.vraptor.http.route.PathAnnotationRoutesParser;
import br.com.caelum.vraptor.http.route.Route;
import br.com.caelum.vraptor.http.route.Router;
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.resource.ResourceClass;
@Component
@ApplicationScoped
public class InterfaceBasedPathAnnotationRoutesParser extends PathAnnotationRoutesParser {
public InterfaceBasedPathAnnotationRoutesParser(Router router) {
super(router);
}
@Override
public List<Route> rulesFor(ResourceClass resource) {
final Class<?>[] superClass = resource.getType().getInterfaces();
return super.rulesFor(superClass.length == 0 ? resource : interfaceResourceClass(superClass));
}
private ResourceClass interfaceResourceClass(final Class<?>[] superClass) {
return new ResourceClass() {
@Override
public Class<?> getType() {
return superClass[0];
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment