Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created March 21, 2013 15:01
Show Gist options
  • Save lucascs/5213718 to your computer and use it in GitHub Desktop.
Save lucascs/5213718 to your computer and use it in GitHub Desktop.
Resource handler para poder fazer: `${linkTo[controllers.MeuController].metodo}` ou `${linkTo[gerenciador.MeuController]}`
@Component // do vraptor
@ApplicationScoped
@org.springframework.stereotype.Component("stereotypeHandler") // só se for spring
public class PackageResourceHandler implements StereotypeHandler {
private final Map<String, Class> controllers;
private final Map<String, Class> gerenciador;
public PackageResourceHandler(ServletContext context) {
context.setAttribute("controllers", controllers);
context.setAttribute("gerenciador", gerenciador);
}
public void handle(Class<?> annotatedType) {
if (annotatedType.getPackage().getName().endsWith("controllers"))
controllers.put(annotatedType.getSimpleName(), annotatedType);
if (annotatedType.getPackage().getName().endsWith("gerenciador"))
gerenciador.put(annotatedType.getSimpleName(), annotatedType);
}
public Class<? extends Annotation> stereotype() {
return Resource.class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment