Created
August 16, 2011 14:03
-
-
Save andrerigon/1149159 to your computer and use it in GitHub Desktop.
PathAnnotationRoutesParser that uses an interface if the controller has one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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