*/
protected void executePhase(FacesContext facesContext, PhaseId phase)
{
if (lifecycle instanceof LifecycleImpl)
{
LifecycleImpl lifecycleImpl = (LifecycleImpl) lifecycle;
int phaseId = phase.equals(PhaseId.RESTORE_VIEW) ? 0 :
phase.equals(PhaseId.APPLY_REQUEST_VALUES) ? 1 :
phase.equals(PhaseId.PROCESS_VALIDATIONS) ? 2 :
phase.equals(PhaseId.UPDATE_MODEL_VALUES) ? 3 :
phase.equals(PhaseId.INVOKE_APPLICATION) ? 4 : 5 ;
Method executePhaseMethod = null;
Object phaseManager = null;
Object phaseExecutor = null;
try
{
if (phaseId < 5)
{
Field lifecycleExecutorsField;
lifecycleExecutorsField = lifecycleImpl.getClass().getDeclaredField("lifecycleExecutors");
if (!lifecycleExecutorsField.isAccessible())
{
lifecycleExecutorsField.setAccessible(true);
}
phaseExecutor = ((Object[])lifecycleExecutorsField.get(lifecycleImpl))[phaseId];
}
else
{
Field renderExecutorField = lifecycleImpl.getClass().getDeclaredField("renderExecutor");
if (!renderExecutorField.isAccessible())
{
renderExecutorField.setAccessible(true);
}
phaseExecutor = renderExecutorField.get(lifecycleImpl);
}
phaseManager = facesContext.getAttributes().get(PHASE_MANAGER_INSTANCE);
if (phaseManager == null)
{
Method getPhaseListenersMethod = lifecycleImpl.getClass().getDeclaredMethod("getPhaseListeners");
if (!getPhaseListenersMethod.isAccessible())
{
getPhaseListenersMethod.setAccessible(true);
}
Constructor<?> plmc = PHASE_MANAGER_CLASS.getDeclaredConstructor(
new Class[]{Lifecycle.class, FacesContext.class, PhaseListener[].class});
if (!plmc.isAccessible())
{
plmc.setAccessible(true);
}
phaseManager = plmc.newInstance(lifecycle, facesContext,
getPhaseListenersMethod.invoke(lifecycleImpl, null));
facesContext.getAttributes().put(PHASE_MANAGER_INSTANCE, phaseManager);
}
executePhaseMethod = lifecycleImpl.getClass().getDeclaredMethod("executePhase", new Class[]{
FacesContext.class, PHASE_EXECUTOR_CLASS, PHASE_MANAGER_CLASS});
if (!executePhaseMethod.isAccessible())
{
executePhaseMethod.setAccessible(true);
}