com.sun.faces.lifecycle.LifecycleImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javax.faces Show documentation
Show all versions of javax.faces Show documentation
This is the master POM file for Oracle's Implementation of the JSF 2.1 Specification.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.lifecycle;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.MessageUtils;
/**
* LifecycleImpl is the stock implementation of the standard
* Lifecycle in the JavaServer Faces RI.
*/
public class LifecycleImpl extends Lifecycle {
// -------------------------------------------------------- Static Variables
// Log instance for this class
private static Logger LOGGER = FacesLogger.LIFECYCLE.getLogger();
// ------------------------------------------------------ Instance Variables
// The Phase instance for the render() method
private Phase response = new RenderResponsePhase();
// The set of Phase instances that are executed by the execute() method
// in order by the ordinal property of each phase
private Phase[] phases = {
null, // ANY_PHASE placeholder, not a real Phase
new RestoreViewPhase(),
new ApplyRequestValuesPhase(),
new ProcessValidationsPhase(),
new UpdateModelValuesPhase(),
new InvokeApplicationPhase(),
response
};
// List for registered PhaseListeners
private List listeners =
new CopyOnWriteArrayList();
// ------------------------------------------------------- Lifecycle Methods
// Execute the phases up to but not including Render Response
public void execute(FacesContext context) throws FacesException {
if (context == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("execute(" + context + ")");
}
for (int i = 1, len = phases.length -1 ; i < len; i++) { // Skip ANY_PHASE placeholder
if (context.getRenderResponse() ||
context.getResponseComplete()) {
break;
}
phases[i].doPhase(context, this, listeners.listIterator());
}
}
// Execute the Render Response phase
public void render(FacesContext context) throws FacesException {
if (context == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"));
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("render(" + context + ")");
}
if (!context.getResponseComplete()) {
response.doPhase(context, this, listeners.listIterator());
}
}
// Add a new PhaseListener to the set of registered listeners
public void addPhaseListener(PhaseListener listener) {
if (listener == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "listener"));
}
if (listeners == null) {
listeners = new CopyOnWriteArrayList();
}
if (listeners.contains(listener)) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"jsf.lifecycle.duplicate_phase_listener_detected",
listener.getClass().getName());
}
} else {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"addPhaseListener({0},{1})",
new Object[]{
listener.getPhaseId().toString(),
listener.getClass().getName()});
}
listeners.add(listener);
}
}
// Return the set of PhaseListeners that have been registered
public PhaseListener[] getPhaseListeners() {
return listeners.toArray(new PhaseListener[listeners.size()]);
}
// Remove a registered PhaseListener from the set of registered listeners
public void removePhaseListener(PhaseListener listener) {
if (listener == null) {
throw new NullPointerException
(MessageUtils.getExceptionMessageString
(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "listener"));
}
if (listeners.remove(listener) && LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"removePhaseListener({0})",
new Object[]{listener.getClass().getName()});
}
}
}