001: /* ZKFacesContextImpl.java
002: {{IS_NOTE
003: Purpose:
004:
005: Description:
006:
007: History:
008: Jul 25, 2007 10:03:38 AM , Created by Dennis Chen
009: }}IS_NOTE
010:
011: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
012:
013: {{IS_RIGHT
014: This program is distributed under GPL Version 2.0 in the hope that
015: it will be useful, but WITHOUT ANY WARRANTY.
016: }}IS_RIGHT
017: */
018: package org.zkoss.seam.jsf;
019:
020: import javax.faces.application.Application;
021: import javax.faces.context.FacesContext;
022: import javax.servlet.ServletContext;
023: import javax.servlet.ServletRequest;
024: import javax.servlet.ServletResponse;
025:
026: import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
027: import org.zkoss.seam.OpenWindow;
028:
029: /**
030: * This class is for integrate ZK with Seam, You should not use this class directly.<br/>
031: * The main purpose of this class is ,
032: * <ol>
033: * <li>
034: * Keep zkLoading or uiUpdate information of current request.
035: * </li>
036: * <li>
037: * Set self the current instance of FacesContext
038: * </li>
039: * </ol>
040: *
041: * @author Dennis.Chen
042: *
043: */
044: public class ZKFacesContextImpl extends ServletFacesContextImpl {
045:
046: private Application _application;
047:
048: boolean _uiUpdate = false;
049:
050: OpenWindow _openWindow = null;
051:
052: public ZKFacesContextImpl(ServletContext servletContext,
053: ServletRequest servletRequest,
054: ServletResponse servletResponse, boolean uiUpdate) {
055: super (servletContext, servletRequest, servletResponse);
056: super .setExternalContext(new ZKExternalContextImpl(
057: servletContext, servletRequest, servletResponse));
058: Application sapp = super .getApplication();
059: _application = new ZKApplicationImpl(sapp);
060: _application.setViewHandler(new ZKViewHandlerImpl(sapp
061: .getViewHandler()));
062: _uiUpdate = uiUpdate;
063: }
064:
065: public Application getApplication() {
066: return _application;
067: }
068:
069: public void setExternalContext(ZKExternalContextImpl extContext) {
070: super .setExternalContext(extContext);
071: FacesContext.setCurrentInstance(this );
072: }
073:
074: public void release() {
075: super .release();
076: _application = null;
077: }
078:
079: public boolean isUiUpdate() {
080: return _uiUpdate;
081: }
082:
083: public OpenWindow getOpenWindow() {
084: return _openWindow;
085: }
086:
087: public void setOpenWindow(OpenWindow ow) {
088: _openWindow = ow;
089: }
090:
091: public static boolean isCurrentZKFacesContext() {
092: if (FacesContext.getCurrentInstance() instanceof ZKFacesContextImpl) {
093: return true;
094: }
095: return false;
096: }
097:
098: public static boolean isCurrentZKUiUpdate() {
099: FacesContext context = FacesContext.getCurrentInstance();
100: if (context instanceof ZKFacesContextImpl) {
101: return ((ZKFacesContextImpl) context).isUiUpdate();
102: }
103: return false;
104: }
105:
106: public static ZKFacesContextImpl getCurrentZKInstance() {
107: FacesContext context = FacesContext.getCurrentInstance();
108: if (context instanceof ZKFacesContextImpl) {
109: return ((ZKFacesContextImpl) context);
110: }
111: return null;
112: }
113:
114: }
|