01: package net.sf.crispy.sample.wortschatz;
02:
03: import java.util.List;
04:
05: import net.sf.crispy.InterceptorContext;
06: import net.sf.crispy.Modifier;
07: import net.sf.crispy.sample.wortschatz.service.Frequencies;
08: import net.sf.crispy.sample.wortschatz.service.Wordforms;
09:
10: public class ParameterModifier implements Modifier {
11:
12: public InterceptorContext modifyBeforeInvocation(
13: InterceptorContext pvInterceptorContext) {
14: InterceptorContext lvInterceptorContext = pvInterceptorContext;
15: String lvMethodName = pvInterceptorContext.getMethod()
16: .getName();
17: if (lvMethodName.equals("execute") == true) {
18: Object lvArgs[] = lvInterceptorContext.getArgs();
19: RequestParameter lvParameter = null;
20: if ((lvArgs != null) && (lvArgs.length == 2)) {
21: String lvWord = (String) lvArgs[0];
22: Integer lvLimit = (Integer) lvArgs[1];
23:
24: if (lvInterceptorContext.getDynamicProxy()
25: .getProxyClass().equals(Wordforms.class)) {
26: lvParameter = ParameterConverter.convert("de",
27: lvLimit.toString(), lvWord, "Word");
28: } else {
29: lvParameter = ParameterConverter.convert(lvLimit
30: .toString(), lvWord);
31: }
32: } else if (lvInterceptorContext.getDynamicProxy()
33: .getProxyClass().equals(Frequencies.class)) {
34: lvParameter = ParameterConverter.convertWithoutLimit(
35: "de", (String) lvArgs[0], "Wort");
36: }
37:
38: lvInterceptorContext.setArgs(new Object[] { lvParameter });
39: }
40: return lvInterceptorContext;
41: }
42:
43: public InterceptorContext modifyAfterInvocation(
44: InterceptorContext pvInterceptorContext) {
45: InterceptorContext lvInterceptorContext = pvInterceptorContext;
46: String lvMethodName = pvInterceptorContext.getMethod()
47: .getName();
48: if (lvMethodName.equals("execute") == true) {
49: ResponseParameter lvParameter = (ResponseParameter) lvInterceptorContext
50: .getResult();
51: List lvList = ParameterConverter
52: .convertResponse2StringList(lvParameter);
53: if (lvParameter != null) {
54: lvParameter.setResultList(lvList);
55: }
56: lvInterceptorContext.setResult(lvParameter);
57: }
58: return lvInterceptorContext;
59: }
60:
61: }
|