// Save the instance that we are adapting for
this.instance = instance;
// Look up the @FacesFacesListener annotation for this class
FacesPhaseListener fpl = instance.getClass().getAnnotation(FacesPhaseListener.class);
if (fpl == null) {
throw new IllegalArgumentException("Implementing class "
+ instance.getClass().getName()
+ " does not have the @FacesPhaseListener annotation");
}
// Extract the relevant before and after event methods from the
// underlying class
Method[] methods = instance.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
Class[] signature = method.getParameterTypes();
if (method.getAnnotation(BeforePhase.class) != null) {
if (signature.length != 1) {
throw new IllegalArgumentException("Method " + method.getName()
+ " of class " + instance.getClass().getName()
+ " does not take a exactly one parameter");
} else if (!(signature[0] == PhaseEvent.class)) {
throw new IllegalArgumentException("Method " + method.getName()
+ " of class " + instance.getClass().getName()
+ " does not take a javax.faces.event.PhaaseEvent parameter");
} else {
this.beforePhase = method;
}
} else if (method.getAnnotation(AfterPhase.class) != null) {
if (signature.length != 1) {
throw new IllegalArgumentException("Method " + method.getName()
+ " of class " + instance.getClass().getName()
+ " does not take a exactly one parameter");
} else if (!(signature[0] == PhaseEvent.class)) {
throw new IllegalArgumentException("Method " + method.getName()
+ " of class " + instance.getClass().getName()
+ " does not take a javax.faces.event.PhaaseEvent parameter");
} else {
this.afterPhase = method;
}
}
}
// Extract the relevant phase identifer from the underlying class
FacesPhaseListener.PhaseId pi = fpl.phaseId();
if (pi == FacesPhaseListener.PhaseId.ANY_PHASE) {
this.phaseId = PhaseId.ANY_PHASE;
} else if (pi == FacesPhaseListener.PhaseId.RESTORE_VIEW) {
this.phaseId = PhaseId.RESTORE_VIEW;
} else if (pi == FacesPhaseListener.PhaseId.APPLY_REQUEST_VALUES) {