Comment by [email protected]:
Hi Below is my code, when i applied @Dirtycheck it was not applied at all.
Please suggest where I m getting wrong.
package com.csdcsystems.amanda.interceptor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;
@Retention (RetentionPolicy.RUNTIME)
@Target( {ElementType.METHOD})
@BindingAnnotation
public @interface DirtyCheck
{
}
package com.csdcsystems.amanda.interceptor;
import com.google.inject.AbstractModule;
import com.google.inject.matcher.Matchers;
public class DirtyCheckModule extends AbstractModule {
public void configure() {
DirtyCheckInterceptor intercepter = new DirtyCheckInterceptor();
// requestInjection(intercepter);
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(DirtyCheck.class), intercepter);
}
}
package com.csdcsystems.amanda.interceptor;
import com.csdcsystems.amanda.web.viewmodel.PermitEditViewModel;
import com.google.inject.Inject;
import java.lang.reflect.Method;
import java.util.Map;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class DirtyCheckInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
System.out.println("hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
Method method = invocation.getMethod();
//PermitEditViewModel
pViewModel=(PermitEditViewModel)invocation.getClass();
//pViewModel.get_initValues();
// pViewModel.get_dirtyValues();
DirtyCheck annotation =
method.getAnnotation(DirtyCheck.class);
// Make sure the intercepter was called for a transaction
method
if (annotation == null) {
return invocation.proceed();
}
if (invocation.getArguments().length == 0 ||
(invocation.getArguments()[0]. equals("Mukesh"))) {
throw new Exception("First parameter must not be Mukesh: " +
method.getName());
}
else
{
Object objModifiedValue=invocation.getArguments()[0];
System.out.print(objModifiedValue);
// if (objModifiedValue != null
//
&& !org.zkoss.lang.Objects.equals(pViewModel.get_initValues().get("StatusCode"),
//
objModifiedValue)) {
// pViewModel.get_dirtyValues().put("StatusCode",
new Boolean(true));
//
// } else {
//
pViewModel.get_dirtyValues().put("StatusCode", new Boolean(false));
// }
}
return invocation.proceed();
}
}
@DirtyCheck
public void setStatusCode(SelectOption<String> statusCode) {
this.statusCode = statusCode;
updateDirtyValues(FIELD_STATUSCODE, statusCode);
}
For more information:
http://code.google.com/p/google-guice/wiki/AOP
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.