Author: jwaldman
Date: Wed Feb 14 13:05:47 2007
New Revision: 507689
URL: http://svn.apache.org/viewvc?view=rev&rev=507689
Log:
ADFFACES-379 patch 1 for Scott o'bryan. This was already applied to the jsf1.2
branch.
Modified:
incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
Modified:
incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?view=diff&rev=507689&r1=507688&r2=507689
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
Wed Feb 14 13:05:47 2007
@@ -163,11 +163,6 @@
}
finally
{
- //=-= Scott O'Bryan =-=
- // HACK: This never actually goes through the lifecycle like it should.
- // So we'll need to set response complete so configurator does its
- // cleanup.
- context.responseComplete();
context.release();
}
}
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?view=diff&rev=507689&r1=507688&r2=507689
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
Wed Feb 14 13:05:47 2007
@@ -182,12 +182,12 @@
// the contract.
if (!_isDisabled(externalContext))
{
+ // If this hasn't been initialized then please initialize
if (!_initialized)
{
init(externalContext);
}
- // If this hasn't been initialized then please initialize
_attachRequestContext(externalContext);
if (externalContext.getRequestMap().get(_IN_REQUEST) == null)
@@ -266,13 +266,8 @@
{
_endConfiguratorServiceRequest(externalContext);
}
-
- final RequestContext context = RequestContext.getCurrentInstance();
- if (context != null)
- {
- context.release();
- assert RequestContext.getCurrentInstance() == null;
- }
+
+ _releaseRequestContext(externalContext);
}
RequestType.clearType(externalContext);
}
@@ -389,7 +384,7 @@
// See if we've got a cached RequestContext instance; if so,
// reattach it
final Object cachedRequestContext = externalContext.getRequestMap().get(
- TrinidadPhaseListener.CACHED_REQUEST_CONTEXT);
+ _REQUEST_CONTEXT);
// Catch both the null scenario and the
// RequestContext-from-a-different-classloader scenario
@@ -403,11 +398,28 @@
final RequestContextFactory factory = RequestContextFactory.getFactory();
assert factory != null;
context = factory.createContext(externalContext);
-
externalContext.getRequestMap().put(TrinidadPhaseListener.CACHED_REQUEST_CONTEXT,
context);
+ externalContext.getRequestMap().put(_REQUEST_CONTEXT, context);
}
assert RequestContext.getCurrentInstance() == context;
}
+
+ private void _releaseRequestContext(final ExternalContext ec)
+ {
+ //If it's not a portal action, we should remove the cached request because
+ //well want to create a new one next request
+ if(RequestType.getType(ec) != RequestType.PORTAL_ACTION)
+ {
+ ec.getRequestMap().remove(_REQUEST_CONTEXT);
+ }
+
+ final RequestContext context = RequestContext.getCurrentInstance();
+ if (context != null)
+ {
+ context.release();
+ assert RequestContext.getCurrentInstance() == null;
+ }
+ }
private void _endConfiguratorServiceRequest(final ExternalContext ec)
{
@@ -436,18 +448,15 @@
}
}
- private boolean _initialized;
-
- private List<Configurator> _services;
-
+ private boolean _initialized;
+ private List<Configurator> _services;
static private final Map<ClassLoader, GlobalConfiguratorImpl> _CONFIGURATORS
= new HashMap<ClassLoader, GlobalConfiguratorImpl>();
-
- static private final String _IN_REQUEST
= GlobalConfiguratorImpl.class
-
.getName()
-
+ ".IN_REQUEST";
-
- static private final TrinidadLogger _LOG
= TrinidadLogger
-
.createTrinidadLogger(GlobalConfiguratorImpl.class);
+ static private final String _IN_REQUEST = GlobalConfiguratorImpl.class
+ .getName()
+ + ".IN_REQUEST";
+ static private final String _REQUEST_CONTEXT =
GlobalConfiguratorImpl.class.getName()
+ +".REQUEST_CONTEXT";
+ static private final TrinidadLogger _LOG =
TrinidadLogger.createTrinidadLogger(GlobalConfiguratorImpl.class);
private enum RequestType
{
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java?view=diff&rev=507689&r1=507688&r2=507689
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
Wed Feb 14 13:05:47 2007
@@ -59,51 +59,27 @@
Object response,
Lifecycle lifecycle)
{
- FacesContext fc = _factory.getFacesContext(context, request, response,
lifecycle);
- ExternalContext ec = fc.getExternalContext();
-
- GlobalConfiguratorImpl config = GlobalConfiguratorImpl.getInstance();
-
- //This should be done only if the filter or other logic was not done
before this
- //we try to retrieve the FacesContext. If this is the case then we'll
need to handle
- //cleanup on the release of the FacesContext. Otherwise the endRequest
should be
- //called by whatever did he origional beginRequest.
-
- if(!GlobalConfiguratorImpl.isRequestStarted(ec))
- {
- config.beginRequest(ec);
- ec.getApplicationMap().put(_CONFIG_IN_CONTEXT, Boolean.TRUE);
- }
-
- return new CacheRenderKit(fc);
+ return new CacheRenderKit(_factory.getFacesContext(context, request,
response, lifecycle));
}
- /**
- * Sets the configurator up to execute an endRequest when it is destroyed
- *
- * @param fc
- */
- @SuppressWarnings("unchecked")
- static void endRequestIfNecessary(FacesContext fc)
- {
- ExternalContext ec = fc.getExternalContext();
- if(Boolean.TRUE.equals(ec.getApplicationMap().remove(_CONFIG_IN_CONTEXT)))
- {
- ec.getApplicationMap().put(_READY_FOR_CLEANUP, Boolean.TRUE);
- }
- }
-
static public class CacheRenderKit extends FacesContext
{
public CacheRenderKit(FacesContext base)
{
_base = base;
-
- //SMO: TODO: is this still needed?
ExternalContext baseExternal = base.getExternalContext();
- ExternalContext external =
- GlobalConfiguratorImpl.getInstance().getExternalContext(baseExternal);
- _external = new OverrideDispatch(external);
+ GlobalConfiguratorImpl config = GlobalConfiguratorImpl.getInstance();
+
+ //This should be done only if beginRequest was not called on the
configurator
+ //before we retrieve the FacesContext. If this is the case then we'll
need to handle
+ //cleanup on the release of the FacesContext. Otherwise the endRequest
should be
+ //called by whatever did he origional beginRequest.
+ if(!GlobalConfiguratorImpl.isRequestStarted(baseExternal))
+ {
+ baseExternal.getRequestMap().put(_CONFIG_IN_CONTEXT, Boolean.TRUE);
+ }
+
+ _external = new
OverrideDispatch(config.getExternalContext(baseExternal));
setCurrentInstance(this);
}
@@ -244,12 +220,8 @@
@Override
public void release()
{
- //=- Scott O'Bryan -=
- // JSR-301 should allow us to call the cleanup. So this and all logic
- // pertaining to creation and cleanup of the configurator per request
- // could probably go away.
ExternalContext ec = getExternalContext();
-
if(Boolean.TRUE.equals(ec.getApplicationMap().remove(_READY_FOR_CLEANUP)))
+ if(Boolean.TRUE.equals(ec.getRequestMap().get(_CONFIG_IN_CONTEXT)))
{
GlobalConfiguratorImpl.getInstance().endRequest(ec);
}
@@ -261,6 +233,8 @@
private final ExternalContext _external;
private String _renderKitId;
private RenderKit _kit;
+
+ static private final String _CONFIG_IN_CONTEXT =
FacesContextFactoryImpl.class.getName()+".CONFIG_IN_CONTEXT";
}
static public class OverrideDispatch extends ExternalContextDecorator
@@ -292,7 +266,5 @@
private final ExternalContext _decorated;
}
- static private final String _CONFIG_IN_CONTEXT =
FacesContextFactoryImpl.class.getName()+".CONFIG_IN_CONTEXT";
- static private final String _READY_FOR_CLEANUP =
FacesContextFactoryImpl.class.getName()+".CONFIG_READY_FOR_CLEANUP";
private final FacesContextFactory _factory;
}
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java?view=diff&rev=507689&r1=507688&r2=507689
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
Wed Feb 14 13:05:47 2007
@@ -30,8 +30,7 @@
import org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl;
/**
- * PhaseListener that hacks to ensure that the RequestContext is
- * available even if the filter doesn't execute.
+ * Performs some trinidad logic and provides some hooks.
*
* @author The Oracle ADF Faces Team
*/
@@ -42,9 +41,6 @@
*/
private static final long serialVersionUID = -1249678874100309402L;
- static public final String CACHED_REQUEST_CONTEXT =
- "org.apache.myfaces.trinidadinternal.context.CachedRequestContext";
-
/**
* Returns true if the request might be a postback request.
*/
@@ -54,8 +50,7 @@
return !Boolean.FALSE.equals(context.getExternalContext().
getRequestMap().get(_POSTBACK_KEY));
}
-
-
+
/**
* Marks that this is a postback request.
*/
@@ -76,21 +71,6 @@
context.getExternalContext().getRequestMap().put(INITIAL_VIEW_ROOT_KEY,
context.getViewRoot());
}
-
- // If we've finished up Render Response, or for some other
- // reason the response is complete, free up the RequestContext
- // if we created.
- // Note, however, that this code is *not* bulletproof! There
- // is nothing stopping an "afterPhase()" listener getting called
- // after this one that calls responseComplete(), in which case
- // we'd never get notified.
- if ((event.getPhaseId() == PhaseId.RENDER_RESPONSE) ||
- (event.getFacesContext().getResponseComplete()))
- {
- _releaseContextIfNecessary(event.getFacesContext());
- FacesContextFactoryImpl.endRequestIfNecessary(context);
- }
-
}
@SuppressWarnings("unchecked")
@@ -100,21 +80,12 @@
// "restore view" would be sufficient, but someone can call
// renderResponse() before even calling Lifecycle.execute(),
// in which case RESTORE_VIEW doesn't actually run.
- if ((event.getPhaseId() == PhaseId.RESTORE_VIEW) ||
- (event.getPhaseId() == PhaseId.RENDER_RESPONSE))
+ if (event.getPhaseId() == PhaseId.RESTORE_VIEW)
{
- if (event.getPhaseId() == PhaseId.RESTORE_VIEW)
- {
- FacesContext context = event.getFacesContext();
- // Assume it's not a postback request
- context.getExternalContext().getRequestMap().put(_POSTBACK_KEY,
- Boolean.FALSE);
-
- //This check doesn't make sense here
- //TrinidadFilterImpl.verifyFilterIsInstalled(context);
- }
-
- _createContextIfNecessary(event.getFacesContext());
+ FacesContext context = event.getFacesContext();
+ // Assume it's not a postback request
+ context.getExternalContext().getRequestMap().put(_POSTBACK_KEY,
+ Boolean.FALSE);
}
// If we've reached "apply request values", this is definitely a
// postback (the ViewHandler should have reached the same conclusion too,
@@ -131,76 +102,11 @@
{
return PhaseId.ANY_PHASE;
}
-
- //
- // Create the RequestContext if necessary; ideally, this is unnecessary
- // because our filter will have executed - but if not, deal.
- //
- @SuppressWarnings("unchecked")
- static private void _createContextIfNecessary(FacesContext fContext)
- {
-
- Map<String, Object> requestMap =
fContext.getExternalContext().getRequestMap();
- Boolean createdContext = (Boolean)
- requestMap.get(_CREATED_CONTEXT_KEY);
- if (createdContext == null)
- {
- RequestContext context = RequestContext.getCurrentInstance();
- // Let our code know if it has to clean up.
- requestMap.put(_CREATED_CONTEXT_KEY,
- context == null ? Boolean.TRUE : Boolean.FALSE);
-
- if (context == null)
- {
- Object cachedRequestContext = requestMap.get(CACHED_REQUEST_CONTEXT);
-
- // Catch both the null scenario and the
- // RequestContext-from-a-different-classloader scenario
- if (cachedRequestContext instanceof RequestContext)
- {
- context = (RequestContext) cachedRequestContext;
- context.attach();
- }
- else
- {
- RequestContextFactory factory = RequestContextFactory.getFactory();
- if (factory == null)
- {
- RequestContextFactory.setFactory(new RequestContextFactoryImpl());
- factory = RequestContextFactory.getFactory();
- }
-
- assert(factory != null);
- context = factory.createContext(fContext.getExternalContext());
- requestMap.put(CACHED_REQUEST_CONTEXT, context);
- }
- }
- }
- }
-
- //
- // Release the RequestContext if we created it.
- //
- static private void _releaseContextIfNecessary(FacesContext fContext)
- {
- Boolean createdContext = (Boolean)
- fContext.getExternalContext().getRequestMap().get(_CREATED_CONTEXT_KEY);
- if (Boolean.TRUE.equals(createdContext))
- {
- RequestContext context = RequestContext.getCurrentInstance();
- if (context != null)
- context.release();
- }
- }
static public final String INITIAL_VIEW_ROOT_KEY =
"org.apache.myfaces.trinidadinternal.InitialViewRoot";
- static private final String _CREATED_CONTEXT_KEY =
-
"org.apache.myfaces.trinidadinternal.context.AdfFacesPhaseListener.CREATED_CONTEXT";
-
static private final String _POSTBACK_KEY =
"org.apache.myfaces.trinidadinternal.context.AdfFacesPhaseListener.POSTBACK";
-
}