PathAnnotationRoutesParser that uses an interface if the controller has one

  • Download Gist
InterfaceBasedPathAnnotationRoutesParser.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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];
}
};
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.