Created
March 4, 2013 22:42
-
-
Save csokol/5086351 to your computer and use it in GitHub Desktop.
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.io.File; | |
import java.util.ArrayList; | |
import java.util.List; | |
import br.com.caelum.vraptor.InterceptionException; | |
import br.com.caelum.vraptor.core.InterceptorStack; | |
import br.com.caelum.vraptor.interceptor.Interceptor; | |
import br.com.caelum.vraptor.ioc.Component; | |
import br.com.caelum.vraptor.resource.ResourceMethod; | |
@Component | |
public class ArquivosParaDeletar { | |
private List<File> arquivos = new ArrayList<>(); | |
private boolean podeDeletar = false; | |
public void adiciona(File f) { | |
arquivos.add(f); | |
} | |
public void podeDeletar() { | |
podeDeletar = true; | |
} | |
public void deleta() { | |
if (podeDeletar) { | |
for (File f : arquivos) { | |
f.delete(); | |
} | |
} | |
} | |
} | |
class Controller { | |
private ArquivosParaDeletar arquivosParaDeletar; | |
public Controller(ArquivosParaDeletar arquivos) { | |
this.arquivosParaDeletar = arquivos; | |
} | |
public void deleta() { | |
arquivosParaDeletar.adiciona(new File("/tmp/qualquer.txt")); | |
} | |
} | |
class MeuInterceptor implements Interceptor { | |
private ArquivosParaDeletar arquivosParaDeletar; | |
public MeuInterceptor(ArquivosParaDeletar arquivos) { | |
this.arquivosParaDeletar = arquivos; | |
} | |
@Override | |
public boolean accepts(ResourceMethod arg0) { | |
return true; | |
} | |
@Override | |
public void intercept(InterceptorStack s, ResourceMethod m, Object o) | |
throws InterceptionException { | |
s.next(m, o); | |
arquivosParaDeletar.deleta(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment