You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2009/07/16 19:16:47 UTC
svn commit: r794758 - in /myfaces/trinidad/trunk:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/
trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/
Author: arobinson74
Date: Thu Jul 16 17:16:47 2009
New Revision: 794758
URL: http://svn.apache.org/viewvc?rev=794758&view=rev
Log:
TRINIDAD-1533
Add getViewMap methods that will be JSF 2 compatible onto the request context
Modified:
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java
myfaces/trinidad/trunk/trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/MockRequestContext.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java?rev=794758&r1=794757&r2=794758&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java Thu Jul 16 17:16:47 2009
@@ -29,7 +29,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
-
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -37,7 +36,6 @@
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-
import javax.faces.event.PhaseId;
import org.apache.myfaces.trinidad.change.ChangeManager;
@@ -49,6 +47,7 @@
import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
+
/**
* Context class for all per-request and per-webapp information
* required by Trinidad. A <code>RequestContext</code> object can be
@@ -123,6 +122,24 @@
return getPageFlowScope();
}
+ /**
+ * Method to obtain a Map stored on the view.
+ * <p>This calls {@link #getViewMap(boolean)} with a true value for create.</p>
+ * <p>This is a pre-cursor implementation to the JSF 2.0 UIViewRoot.getViewMap() function.
+ * The implementation is taken from the initial UIViewRoot implementation in JSF but without
+ * the event notification support.</p>
+ */
+ public abstract Map<String, Object> getViewMap();
+
+ /**
+ * Method to obtain a Map stored on the view.
+ * <p>This is a pre-cursor implementation to the JSF 2.0 UIViewRoot.getViewMap() function.
+ * The implementation is taken from the initial UIViewRoot implementation in JSF but without
+ * the event notification support.</p>
+ *
+ * @param create if the map should be created if it already does not exist.
+ */
+ public abstract Map<String, Object> getViewMap(boolean create);
//
// Dialog APIs
@@ -232,7 +249,7 @@
* Returns the name of the preferred skin family.
*/
public abstract String getSkinFamily();
-
+
/**
* Determines whether the current View Root is an internal view
* @param context Faces context
@@ -246,14 +263,14 @@
* Output supports accessibility features
*/
DEFAULT("default"),
-
+
/**
* Accessibility-specific constructs are stripped out to optimize output size
*/
INACCESSIBLE("inaccessible"),
-
+
/**
- * Accessibility-specific constructs are added to improve behavior under a screen reader
+ * Accessibility-specific constructs are added to improve behavior under a screen reader
* (but may affect other users negatively)
*/
SCREEN_READER("screenReader");
@@ -494,7 +511,7 @@
//
/**
- * <p>Creates a VisitContext instance for use with
+ * <p>Creates a VisitContext instance for use with
* {@link org.apache.myfaces.trinidad.component.UIXComponent#visitTree UIComponent.visitTree()}.</p>
*
* @param context the FacesContext for the current request
@@ -503,7 +520,7 @@
* @param hints the VisitHints to apply to the visit
* @param phaseId. PhaseId if any for this visit. If PhaseId is specified,
* hints must contain VisitHint.EXECUTE_LIFECYCLE
- * @return a VisitContext instance that is initialized with the
+ * @return a VisitContext instance that is initialized with the
* specified ids and hints.
*/
public abstract VisitContext createVisitContext(
@@ -580,27 +597,27 @@
// check if we have cached it for the request
WindowManager windowManager = _windowManager;
-
+
// get instance using the WindowManagerFactory
if (windowManager == null)
{
// check if we have cached it per session
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
-
+
// create a new instance using the WindowManagerFactory
ConcurrentMap<String, Object> concurrentAppMap =
getCurrentInstance().getApplicationScopedConcurrentMap();
-
+
WindowManagerFactory windowManagerFactory = (WindowManagerFactory)concurrentAppMap.get(
_WINDOW_MANAGER_FACTORY_CLASS_NAME);
-
+
if (windowManagerFactory == null)
{
// we haven't registered a WindowManagerFactory yet, so use the services api to see
// if a factory has been registered
List<WindowManagerFactory> windowManagerFactories =
ClassLoaderUtils.getServices(_WINDOW_MANAGER_FACTORY_CLASS_NAME);
-
+
if (windowManagerFactories.isEmpty())
{
// no factory registered so use the factory that returns dummy stub WindowManagers
@@ -617,22 +634,22 @@
WindowManagerFactory oldWindowManagerFactory = (WindowManagerFactory)
concurrentAppMap.putIfAbsent(_WINDOW_MANAGER_FACTORY_CLASS_NAME,
windowManagerFactory);
-
+
if (oldWindowManagerFactory != null)
windowManagerFactory = oldWindowManagerFactory;
} // create WindowManagerFactory
-
+
// get the WindowManager from the factory. The factory will create a new instance
// for this session if necessary
windowManager = windowManagerFactory.getWindowManager(extContext);
-
+
// remember for the next call on this thread
_windowManager = windowManager;
}
return windowManager;
}
-
+
/**
* Releases the RequestContext object. This method must only
* be called by the code that created the RequestContext.
@@ -711,10 +728,10 @@
{
return _STUB_WINDOW_MANAGER;
}
-
+
private static final WindowManager _STUB_WINDOW_MANAGER = new StubWindowManager();
}
-
+
/**
* Default WindowManager implementation that returns no Windows
*/
@@ -725,21 +742,21 @@
{
return null;
}
-
+
@Override
public Map<String, Window> getWindows(ExternalContext extContext)
{
return Collections.emptyMap();
}
-
+
@Override
public void addWindowLifecycleListener(
ExternalContext extContext,
WindowLifecycleListener windowListener)
- {
+ {
// do nothing
}
-
+
@Override
public void removeWindowLifecycleListener(
ExternalContext extContext,
@@ -756,12 +773,12 @@
}
/* singleton for WindowManagerFactory that returns WindowManagers that don't do anything */
- private static final WindowManagerFactory _STUB_WINDOW_MANAGER_FACTORY =
+ private static final WindowManagerFactory _STUB_WINDOW_MANAGER_FACTORY =
new StubWindowManagerFactory();
-
- private static final String _WINDOW_MANAGER_FACTORY_CLASS_NAME =
+
+ private static final String _WINDOW_MANAGER_FACTORY_CLASS_NAME =
WindowManagerFactory.class.getName();
-
+
@SuppressWarnings({"CollectionWithoutInitialCapacity"})
private static final ConcurrentMap<ClassLoader, ConcurrentMap<String, Object>> _APPLICATION_MAPS =
new ConcurrentHashMap<ClassLoader, ConcurrentMap<String, Object>>();
Modified: myfaces/trinidad/trunk/trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/MockRequestContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/MockRequestContext.java?rev=794758&r1=794757&r2=794758&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/MockRequestContext.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/test/java/org/apache/myfaces/trinidad/context/MockRequestContext.java Thu Jul 16 17:16:47 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -31,7 +31,6 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-
import javax.faces.event.PhaseId;
import org.apache.myfaces.trinidad.change.ChangeManager;
@@ -94,10 +93,10 @@
@Override
public void launchDialog(
- UIViewRoot dialogRoot,
- Map<String, Object> dialogParameters,
- UIComponent source,
- boolean useWindow,
+ UIViewRoot dialogRoot,
+ Map<String, Object> dialogParameters,
+ UIComponent source,
+ boolean useWindow,
Map<String, Object> windowProperties)
{
throw new UnsupportedOperationException("Should not be called during rendering");
@@ -108,7 +107,7 @@
{
return false;
}
-
+
@Override
public boolean isPartialRequest(FacesContext context)
{
@@ -316,14 +315,14 @@
{
// throw new UnsupportedOperationException("Not implemented yet");
}
-
+
/**
* @see org.apache.myfaces.trinidad.context.RequestContext#addPartialTargets(javax.faces.component.UIComponent, java.lang.String[])
*/
@Override
public void addPartialTargets(UIComponent from, String... targets)
{
-
+
}
@Override
@@ -396,17 +395,55 @@
{
throw new UnsupportedOperationException("Not implemented yet");
}
-
+
@Override
public boolean isInternalViewRequest(FacesContext context)
{
return false;
}
+ @Override
+ public Map<String, Object> getViewMap()
+ {
+ return getViewMap(true);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getViewMap(boolean create)
+ {
+ // Note: replace this method body with a call to UIViewRoot.getViewMap(boolean) when
+ // Trinidad is upgraded to use JSF 2.0
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ Map<String, Object> viewMap = null;
+
+ if (viewRoot != null)
+ {
+ Map<String, Object> attrs = viewRoot.getAttributes();
+
+ viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
+ if (viewMap == null && create)
+ {
+ // Note, it is not valid to refer to the request context from outside of the request's
+ // thread. As such, synchronization and thread safety is not an issue here.
+ // This coincides with the JSF 2.0 code not using syncronization and using the non-thread
+ // safe HashMap.
+ viewMap = new HashMap<String, Object>();
+ attrs.put(_VIEW_MAP_KEY, viewMap);
+ }
+ }
+
+ return viewMap;
+ }
static private final TimeZone _FIXED_TIME_ZONE =
TimeZone.getTimeZone("America/Los_Angeles");
+ static private final String _VIEW_MAP_KEY =
+ MockRequestContext.class.getName() + ".VIEW_MAP";
+
private char _numberGroupingSeparator = ',';
private char _decimalSeparator = '.';
private String _currencyCode = null;
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?rev=794758&r1=794757&r2=794758&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Thu Jul 16 17:16:47 2009
@@ -721,17 +721,53 @@
return StateManagerImpl.restoreComponentTree(__getFacesContext(),
state);
}
-
+
@Override
public boolean isInternalViewRequest(FacesContext context)
{
UIViewRoot root = context.getViewRoot();
if (root == null)
return false;
-
+
return ViewHandlerImpl.isInternalViewId(context, root.getViewId());
}
+ @Override
+ public Map<String, Object> getViewMap()
+ {
+ return getViewMap(true);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getViewMap(boolean create)
+ {
+ // Note: replace this method body with a call to UIViewRoot.getViewMap(boolean) when
+ // Trinidad is upgraded to use JSF 2.0
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ Map<String, Object> viewMap = null;
+
+ if (viewRoot != null)
+ {
+ Map<String, Object> attrs = viewRoot.getAttributes();
+
+ viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
+ if (viewMap == null && create)
+ {
+ // Note, it is not valid to refer to the request context from outside of the request's
+ // thread. As such, synchronization and thread safety is not an issue here.
+ // This coincides with the JSF 2.0 code not using syncronization and using the non-thread
+ // safe HashMap.
+ viewMap = new HashMap<String, Object>();
+ attrs.put(_VIEW_MAP_KEY, viewMap);
+ }
+ }
+
+ return viewMap;
+ }
+
void __setPageResolver(PageResolver pageResolver)
{
_pageResolver = pageResolver;
@@ -980,6 +1016,8 @@
"org.apache.myfaces.trinidadinternal.ChangeManager";
static private final String _CHANGE_PERSISTENCE_INIT_PARAM =
"org.apache.myfaces.trinidad.CHANGE_PERSISTENCE";
+ static private final String _VIEW_MAP_KEY =
+ RequestContextImpl.class.getName() + ".VIEW_MAP";
// A mapping from string names (as used in the config file)
// to accessibility objects