You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2006/12/20 20:12:37 UTC
svn commit: r489187 [1/3] - in
/incubator/adffaces/branches/jwaldman-portal/trinidad:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/
trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/
trinidad-api/src/main/java/org/apache/m...
Author: jwaldman
Date: Wed Dec 20 12:12:35 2006
New Revision: 489187
URL: http://svn.apache.org/viewvc?view=rev&rev=489187
Log:
apply Scott's branch: 8-ADFFACES-234.patch
Added:
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ExternalContextDecorator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/AbstractAttributeMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/EnumerationIterator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/NullEnumeration.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/PortletRequestParameterMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/PortletRequestParameterValuesMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletApplicationMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletCookieMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletInitParameterMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestHeaderValuesMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestParameterMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletRequestParameterValuesMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletSessionMap.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ExternalContextUtils.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/ActionRequestWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/ActionResponseWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletRequestDispatcherWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletRequestWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletResponseWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/RenderRequestWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/RenderResponseWrapper.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator
Removed:
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/external/
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/
Modified:
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/Configurator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GenericConfigurator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GlobalConfigurator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/ExternalContextDecorator.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/util/MultipartFormHandler.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadFilterImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/TrinidadListenerImpl.java
incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.GlobalConfigurator
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/Configurator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/Configurator.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/Configurator.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/Configurator.java Wed Dec 20 12:12:35 2006
@@ -15,15 +15,21 @@
*/
package org.apache.myfaces.trinidad.config;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import javax.faces.context.ExternalContext;
+import javax.servlet.ServletRequest;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
/**
- * This defines an interface for the Configurator. Classes implementing
- * this interface should be listed in the jar's /META-INF/services folder
- * inside of a text file named "org.apache.trinidad.GlobalConfigurator".
+ * This defines an abstract class for the Configurator. Classes implementing
+ * this abstraction should be listed in the jar's /META-INF/services folder
+ * inside of a text file named "org.apache.trinidad.Configurator".
* These services will then be run by Trinidad's global configurator.
*
- * This interface allows Trinidad and various renderkits to move some of
+ * This abstract class allows Trinidad and various renderkits to move some of
* their initialization and request/response wrapping code into a configurator
* so that they may be handled in a container agnostic fashion supporting
* both Portlets and Servlets. This allows Trinidad and its various
@@ -34,16 +40,17 @@
* during the actual request. The only thing guaranteed to Configurator
* developers are the constraints listed below in the following methods.
*
- * Use of this interface is encouraged, where possible, instead of using
+ * Use of this abstract class is encouraged, where possible, instead of using
* Trinidad filter services. While configurators and filter services should
* be able to coexist, any services provided by the filter service will not
* run in a portal and should therefore be considered optional to the run of
* the renderkit or application if Portal compatibility is important.
+ *
*
* @author Scott O'Bryan (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public interface Configurator
+public class Configurator
{
/**
* Initializes the Configurator. This method is guaranteed to run before
@@ -63,7 +70,7 @@
* @param externalContext a mocked up external context providing access
* to the native context object.
*/
- void init(ExternalContext externalContext);
+ public void init(ExternalContext externalContext) {}
/**
* Cleans up the Configurator. This method is guaranteed to run at some
@@ -71,7 +78,7 @@
* the exact time of it's execution is not guaranteed and will typically
* be determined by the garbage collector.
*/
- void destroy();
+ public void destroy() {}
/**
* This is called at the beginning of each "physical" request, sometime
@@ -97,7 +104,7 @@
* access to the native request, response, and context
* objects.
*/
- void beginRequest(ExternalContext externalContext);
+ public void beginRequest(ExternalContext externalContext) {}
/**
* Returns an ExternalContext wrapper based on the provided ExternalContext.
@@ -115,7 +122,10 @@
* @param externalContext the ExternalContext to wrap
* @return a wrapper of the ExternalContext
*/
- ExternalContext getExternalContext(ExternalContext externalContext);
+ public ExternalContext getExternalContext(ExternalContext externalContext)
+ {
+ return externalContext;
+ }
/**
* Executed at the end of each "physical" request. There will be a call to
@@ -128,5 +138,68 @@
*
* @param externalContext the external context
*/
- void endRequest(ExternalContext externalContext);
+ public void endRequest(ExternalContext externalContext){}
+
+ /**
+ * Disables Configurator services for the current request. When this method
+ * has been called on a request, then calls to beginRequest, endRequest, and
+ * getExternalContext will not execute any of the associated services or
+ * initialize the RequestContext. After the physical request is complete
+ * then this flag will automatically be cleared.
+ *
+ * <p><string>Note:</strong> that this command should be execured before
+ * {@link Configurator#beginRequest(ExternalContext)}.</p>
+ *
+ * @param request the HttpServletRequest for which to disable this configurator
+ * @throws InvocationTargetException
+ * @throws IllegalAccessException
+ * @throws IllegalArgumentException
+ *
+ * @throws IllegalStateException when this is run after a beginRequest on
+ * the current request.
+ */
+ public static final void disableConfiguratorServices(final ServletRequest request)
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null)
+ _LOG.severe("Could not find context class loader.");
+ else
+ {
+ try
+ {
+ //We have to use the IMPL method because this is final so people don't override it
+ Method disable = loader.loadClass("org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl")
+ .getMethod("disableConfiguratorServicesImpl", _SERVLET_REQUEST_ARRAY);
+ Object[] paramArray = {request};
+ disable.invoke(null, paramArray);
+ }
+ catch (ClassNotFoundException e)
+ {
+ _LOG.severe(e);
+ }
+ catch (SecurityException e)
+ {
+ _LOG.severe(e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ _LOG.severe(e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ _LOG.severe(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ _LOG.severe(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ _LOG.severe(e);
+ }
+ }
+ }
+
+ private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(Configurator.class);
+ private static final Class[] _SERVLET_REQUEST_ARRAY = {ServletRequest.class};
}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GenericConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GenericConfigurator.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GenericConfigurator.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GenericConfigurator.java Wed Dec 20 12:12:35 2006
@@ -1,66 +0,0 @@
-/*
- * Copyright 2004-2006 The Apache Software Foundation.
- *
- * Licensed 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 KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.trinidad.config;
-
-import javax.faces.context.ExternalContext;
-
-/**
- * This is an implementation of the {@link Configurator} interface.
- * Subclasses need only override methods they wish provide functionality
- * for.
- *
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-
-public class GenericConfigurator implements Configurator
-{
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
- */
- public void beginRequest(ExternalContext externalContext)
- {
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#destroy()
- */
- public void destroy()
- {
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#endRequest(javax.faces.context.ExternalContext)
- */
- public void endRequest(ExternalContext externalContext)
- {
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#getExternalContext(javax.faces.context.ExternalContext)
- */
- public ExternalContext getExternalContext(ExternalContext externalContext)
- {
- return externalContext;
- }
-
- /* (non-Javadoc)
- * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
- */
- public void init(ExternalContext externalContext)
- {
- }
-}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GlobalConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GlobalConfigurator.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GlobalConfigurator.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/GlobalConfigurator.java Wed Dec 20 12:12:35 2006
@@ -1,96 +0,0 @@
-/*
- * Copyright 2004-2006 The Apache Software Foundation.
- *
- * Licensed 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 KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.trinidad.config;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
-/**
- * This is Trinidad's GlobalConfigurator. It is a special configurator
- * that is designed to provide access to all the other configuratiors in
- * the system as well as provide some utilities which should allow
- * Configurators to manage state.
- *
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public abstract class GlobalConfigurator implements Configurator
-{
- /**
- * Returns a GlobalConfigurator instance for the current context's class loader.
- *
- * @return a GlobalConfigurator or <code>null</code> is one was unable to be obtained.
- */
- public static GlobalConfigurator getInstance()
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- if (loader == null)
- _LOG.severe("Could not find context class loader.");
- else
- {
- synchronized(_configurators)
- {
- GlobalConfigurator config = _configurators.get(loader);
- if(config == null)
- {
- try
- {
- Class<?> proxiedClass = loader.loadClass("org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl");
- config = (GlobalConfigurator) proxiedClass.newInstance();
- _configurators.put(loader, config);
- }
- catch (ClassNotFoundException cnfe)
- {
- _LOG.severe(cnfe);
- }
- catch (IllegalAccessException iae)
- {
- _LOG.severe(iae);
- }
- catch (InstantiationException ie)
- {
- _LOG.severe(ie);
- }
- catch (RuntimeException e)
- {
- // OC4J was not reporting these errors properly:
- _LOG.severe(e);
- throw e;
- }
- _LOG.fine("GlobalConfigurator has been created.");
- }
- return config;
- }
- }
- return null;
- }
-
- /**
- * Tells whether or not the GlobalConfigurator has been initialized or not.
- *
- * @return a boolean indicating <code>true</code> if the GlobalConfigurator has
- * been initialized or <code>false</code> it it has not.
- */
- public abstract boolean isInitialized();
-
- static private final Map<ClassLoader, GlobalConfigurator> _configurators = new HashMap<ClassLoader, GlobalConfigurator>();
- static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(GlobalConfigurator.class);
-}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ExternalContextDecorator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ExternalContextDecorator.java?view=auto&rev=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ExternalContextDecorator.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ExternalContextDecorator.java Wed Dec 20 12:12:35 2006
@@ -0,0 +1,255 @@
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed 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 KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.myfaces.trinidad.context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Set;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+
+
+/**
+ * Base class for decorating ExternalContexts.
+ *
+ * @author The Oracle ADF Faces Team
+ */
+abstract public class ExternalContextDecorator extends ExternalContext
+{
+ @Override
+ public void dispatch(String path) throws IOException
+ {
+ getExternalContext().dispatch(path);
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return getExternalContext().getContext();
+ }
+
+ @Override
+ public Object getRequest()
+ {
+ return getExternalContext().getRequest();
+ }
+
+ @Override
+ public Object getResponse()
+ {
+ return getExternalContext().getResponse();
+ }
+
+ @Override
+ public Object getSession(boolean create)
+ {
+ return getExternalContext().getSession(create);
+ }
+
+ @Override
+ public String getRequestContextPath()
+ {
+ return getExternalContext().getRequestContextPath();
+ }
+
+ @Override
+ public String getRequestPathInfo()
+ {
+ return getExternalContext().getRequestPathInfo();
+ }
+
+ @Override
+ public String getRequestServletPath()
+ {
+ return getExternalContext().getRequestServletPath();
+ }
+
+ @Override
+ public String getInitParameter(String name)
+ {
+ return getExternalContext().getInitParameter(name);
+ }
+
+ @Override
+ public String encodeResourceURL(String url)
+ {
+ return getExternalContext().encodeResourceURL(url);
+ }
+
+ @Override
+ public String encodeActionURL(String url)
+ {
+ return getExternalContext().encodeActionURL(url);
+ }
+
+ @Override
+ public String encodeNamespace(String ns)
+ {
+ return getExternalContext().encodeNamespace(ns);
+ }
+
+ @Override
+ public String getAuthType()
+ {
+ return getExternalContext().getAuthType();
+ }
+
+ @Override
+ public String getRemoteUser()
+ {
+ return getExternalContext().getRemoteUser();
+ }
+
+ @Override
+ public Principal getUserPrincipal()
+ {
+ return getExternalContext().getUserPrincipal();
+ }
+
+ @Override
+ public boolean isUserInRole(String role)
+ {
+ return getExternalContext().isUserInRole(role);
+ }
+
+ @Override
+ public URL getResource(String path) throws MalformedURLException
+ {
+ return getExternalContext().getResource(path);
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String path)
+ {
+ return getExternalContext().getResourceAsStream(path);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Set getResourcePaths(String path)
+ {
+ return getExternalContext().getResourcePaths(path);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestParameterMap()
+ {
+ return getExternalContext().getRequestParameterMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestParameterValuesMap()
+ {
+ return getExternalContext().getRequestParameterValuesMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator getRequestParameterNames()
+ {
+ return getExternalContext().getRequestParameterNames();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestCookieMap()
+ {
+ return getExternalContext().getRequestCookieMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestHeaderMap()
+ {
+ return getExternalContext().getRequestHeaderMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestHeaderValuesMap()
+ {
+ return getExternalContext().getRequestHeaderValuesMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getInitParameterMap()
+ {
+ return getExternalContext().getInitParameterMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getApplicationMap()
+ {
+ return getExternalContext().getApplicationMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getSessionMap()
+ {
+ return getExternalContext().getSessionMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map getRequestMap()
+ {
+ return getExternalContext().getRequestMap();
+ }
+
+ @Override
+ public Locale getRequestLocale()
+ {
+ return getExternalContext().getRequestLocale();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator getRequestLocales()
+ {
+ return getExternalContext().getRequestLocales();
+ }
+
+ @Override
+ public void log(String message)
+ {
+ getExternalContext().log(message);
+ }
+
+ @Override
+ public void log(String message, Throwable t)
+ {
+ getExternalContext().log(message, t);
+ }
+
+ @Override
+ public void redirect(String url) throws IOException
+ {
+ getExternalContext().redirect(url);
+ }
+
+ abstract protected ExternalContext getExternalContext();
+}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java Wed Dec 20 12:12:35 2006
@@ -1,173 +0,0 @@
-package org.apache.myfaces.trinidad.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import javax.faces.context.ExternalContext;
-import javax.portlet.ActionRequest;
-import javax.servlet.ServletRequest;
-
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
-/**
- * This provides some functionality for determining some things
- * about the native request object that is not provided by the
- * base utils.
- *
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public class ExternalContextUtils
-{
- private ExternalContextUtils(){}
-
- /**
- * Returns <code>true</code> if this externalContext represents an
- * "action". An externalContext from a servlet is always considered
- * an "action" whereas in a Portlet container, it will only return
- * true if there is an action request.
- *
- * @return a boolean of <code>true</code> if this is a ServletRequest
- * or a PortletActionRequest.
- */
- public static boolean isAction(ExternalContext externalContext)
- {
- Object request = externalContext.getRequest();
- if(request instanceof ServletRequest)
- {
- return true;
- }
-
- try
- {
- Class c = Class.forName("javax.portlet.ActionRequest");
- return c.isInstance(request);
- }
- catch (ClassNotFoundException e)
- {
- _LOG.warning("A non-servlet request was submitted and the portlet JARs are not on the classpath. Returning false.");
- }
- return false;
- }
-
- public static boolean isPortlet(ExternalContext externalContext)
- {
- Object request = externalContext.getRequest();
-
- if(request instanceof ServletRequest)
- {
- return false;
- }
-
- try
- {
- Class c = Class.forName("javax.portlet.PortletRequest");
- return c.isInstance(request);
- }
- catch (ClassNotFoundException e)
- {
- _LOG.warning("A non-servlet request was aubmitted and the portlet JARs are not on the classpath. Returning false.");
- }
- return false;
- }
-
- public static String getContentType(ExternalContext externalContext)
- {
- String s = null;
- if(isAction(externalContext))
- {
- try
- {
- Object request = externalContext.getRequest();
- Method m = request.getClass().getMethod("getContentType", (Class[])null);
-
- if(m != null)
- {
- s = (String) m.invoke(request, (Object[])null);
- }
- }
- catch (Exception e)
- {
- _LOG.severe(e);
- }
- }
-
- return s;
- }
-
- public static int getContentLength(ExternalContext externalContext)
- {
- if(isAction(externalContext))
- {
- try
- {
- Object request = externalContext.getRequest();
- Method m = request.getClass().getMethod("getContentLength", (Class[])null);
-
- if(m != null)
- {
- return ((Integer)m.invoke(request, (Object[])null)).intValue();
- }
- }
- catch (Exception e)
- {
- _LOG.severe(e);
- }
- }
- return -1;
- }
-
- public static InputStream getRequestInputStream(ExternalContext externalContext) throws IOException
- {
- InputStream is = null;
- if(isAction(externalContext))
- {
- if(isPortlet(externalContext))
- {
- return getPortletInputStream(externalContext.getRequest());
- }
- else
- {
- return getServletInputStream(externalContext.getRequest());
- }
- }
- return null;
- }
-
- public static String getCharacterEncoding(ExternalContext externalContext)
- {
- if(isAction(externalContext))
- {
- try
- {
- Object request = externalContext.getRequest();
- Method m = request.getClass().getMethod("getCharacterEncoding", (Class[])null);
-
- if(m != null)
- {
- return (String) m.invoke(request, (Object[])null);
- }
- }
- catch (Exception e)
- {
- _LOG.severe(e);
- }
- }
-
- return null;
- }
-
- private static final InputStream getPortletInputStream(Object request) throws IOException
- {
- return ((ActionRequest)request).getPortletInputStream();
- }
-
- private static final InputStream getServletInputStream(Object request) throws IOException
- {
- return ((ServletRequest)request).getInputStream();
- }
-
- private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ExternalContextUtils.class);
-}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java Wed Dec 20 12:12:35 2006
@@ -24,41 +24,36 @@
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.Reader;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
-
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
+import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.myfaces.trinidad.context.external.ServletExternalContext;
-import org.apache.myfaces.trinidad.context.external.TrinidadFacesContext;
+import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.resource.CachingResourceLoader;
import org.apache.myfaces.trinidad.resource.DirectoryResourceLoader;
import org.apache.myfaces.trinidad.resource.ResourceLoader;
import org.apache.myfaces.trinidad.resource.ServletContextResourceLoader;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.faces.event.PhaseListener;
-
/**
* A Servlet which serves up web application resources (images, style sheets,
* JavaScript libraries) by delegating to a ResourceLoader.
@@ -83,6 +78,11 @@
public class ResourceServlet extends HttpServlet
{
/**
+ *
+ */
+ private static final long serialVersionUID = 4547362994406585148L;
+
+ /**
* Override of Servlet.destroy();
*/
@Override
@@ -105,6 +105,26 @@
{
super.init(config);
+ // Acquire our FacesContextFactory instance
+ try
+ {
+ _facesContextFactory = (FacesContextFactory)
+ FactoryFinder.getFactory
+ (FactoryFinder.FACES_CONTEXT_FACTORY);
+ }
+ catch (FacesException e)
+ {
+ Throwable rootCause = e.getCause();
+ if (rootCause == null)
+ {
+ throw e;
+ }
+ else
+ {
+ throw new ServletException(e.getMessage(), rootCause);
+ }
+ }
+
// Acquire our Lifecycle instance
_lifecycle = new _ResourceLifecycle();
_initDebug(config);
@@ -117,13 +137,15 @@
ServletResponse response
) throws ServletException, IOException
{
- //Use trinidad's faces context object rather then FactoryFinder.
- //This will avoid doing unnecessary wrapping.
- FacesContext context = new TrinidadFacesContext(new ServletExternalContext(getServletContext(), request, response));
+ Configurator.disableConfiguratorServices(request);
+
+ //=-= Scott O'Bryan =-=
+ // Be careful. This can be wrapped by other things even though it's meant to be a
+ // Trinidad only resource call.
+ FacesContext context = _facesContextFactory.getFacesContext(getServletContext(), request, response, _lifecycle);
try
{
-
super.service(request, response);
}
catch (ServletException e)
@@ -139,6 +161,11 @@
}
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/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TrinidadListener.java Wed Dec 20 12:12:35 2006
@@ -1,76 +0,0 @@
-/*
- * Copyright 2003-2006 The Apache Software Foundation.
- *
- * Licensed 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 KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.myfaces.trinidad.webapp;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
-/**
- * Trinidad context listener.
- *
- * @author Scott O'Bryan (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public class TrinidadListener implements ServletContextListener
-{
-
- public void contextDestroyed(ServletContextEvent event)
- {
- _impl.contextDestroyed(event);
- _impl = null;
- }
-
- public void contextInitialized(ServletContextEvent event)
- {
- //get the impl
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if (loader == null)
- _LOG.severe("Could not find context class loader.");
- else
- {
- try
- {
- Class<?> proxiedClass = loader.loadClass(
- "org.apache.myfaces.trinidadinternal.webapp.TrinidadListenerImpl");
- _impl = (ServletContextListener) proxiedClass.newInstance();
- _impl.contextInitialized(event);
- }
- catch (ClassNotFoundException cnfe)
- {
- _LOG.severe(cnfe);
- }
- catch (IllegalAccessException iae)
- {
- _LOG.severe(iae);
- }
- catch (InstantiationException ie)
- {
- _LOG.severe(ie);
- }
- catch (RuntimeException e)
- {
- // OC4J was not reporting these errors properly:
- _LOG.severe(e);
- throw e;
- }
- }
- }
-
- private ServletContextListener _impl;
- static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(TrinidadListener.class);
-}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml Wed Dec 20 12:12:35 2006
@@ -79,8 +79,9 @@
<param-name>org.apache.myfaces.trinidad.DIALOG_NAVIGATION_PREFIX</param-name>
<param-value>userInputHere:</param-value>
</context-param-->
+
<listener>
- <listener-class>org.apache.myfaces.trinidad.webapp.TrinidadListener</listener-class>
+ <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<filter>
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld Wed Dec 20 12:12:35 2006
@@ -1,19 +1,19 @@
<?xml version = "1.0" ?>
-<!--
- Copyright 2006 The Apache Software Foundation.
-
- Licensed 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 KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed 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 KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
@@ -22,7 +22,10 @@
<jsp-version>1.2</jsp-version>
<short-name>tr</short-name>
<uri>http://myfaces.apache.org/trinidad</uri>
- <display-name>Apache Trinidad Core</display-name>
+ <display-name>Apache Trinidad Core</display-name>
+ <listener>
+ <listener-class>org.apache.myfaces.trinidadinternal.webapp.TrinidadListenerImpl</listener-class>
+ </listener>
<tag>
<name>attribute</name>
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java Wed Dec 20 12:12:35 2006
@@ -15,12 +15,14 @@
package org.apache.myfaces.trinidadinternal.config;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.faces.context.ExternalContext;
+import javax.servlet.ServletRequest;
import org.apache.myfaces.trinidad.config.Configurator;
-import org.apache.myfaces.trinidad.config.GlobalConfigurator;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.context.RequestContextFactory;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -38,7 +40,7 @@
* @author Scott O'Bryan (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class GlobalConfiguratorImpl extends GlobalConfigurator
+public class GlobalConfiguratorImpl extends Configurator
{
/**
* Returns <code>true</code> is {@link #beginRequest(ExternalContext)} has been called and
@@ -51,15 +53,67 @@
*/
public static boolean isRequestBegun(final ExternalContext ec)
{
- return Boolean.TRUE.equals(ec.getSessionMap().get(_IN_REQUEST));
+ return Boolean.TRUE.equals(ec.getRequestMap().get(_IN_REQUEST));
+ }
+
+ /**
+ *
+ */
+ public static boolean isRequestDisabled(final ExternalContext ec)
+ {
+ return _DISABLED.equals(ec.getRequestMap().get(_IN_REQUEST));
+ }
+
+ /**
+ * Returns a GlobalConfigurator instance for the current context's class loader. The
+ * GlobalConfigurator is responsible for enforcing the contract on the other methods
+ * of this class. This means that if {@link #init(ExternalContext)} is called multiple
+ * times, the global configurator will call all subordinate configurators only once.
+ *
+ * <p>Likewise, the GlobalConfigurator will return exceptions when the contract is
+ * expressly violated (like if {@link #getExternalContext(ExternalContext)} is called
+ * before a {{@link #beginRequest(ExternalContext)}.
+ *
+ * @return a GlobalConfigurator or <code>null</code> is one was unable to be obtained.
+ */
+ public static final GlobalConfiguratorImpl getInstance()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ if (loader == null)
+ _LOG.severe("Could not find context class loader.");
+ else
+ {
+ synchronized(_CONFIGURATORS)
+ {
+ GlobalConfiguratorImpl config = _CONFIGURATORS.get(loader);
+ if(config == null)
+ {
+ try
+ {
+ config = new GlobalConfiguratorImpl();
+ _CONFIGURATORS.put(loader, config);
+ }
+ catch (RuntimeException e)
+ {
+ // OC4J was not reporting these errors properly:
+ _LOG.severe(e);
+ throw e;
+ }
+ _LOG.fine("GlobalConfigurator has been created.");
+ }
+ return config;
+ }
+ }
+ return null;
}
/**
* Default constructor
*/
- public GlobalConfiguratorImpl()
+ private GlobalConfiguratorImpl()
{
- _services = ClassLoaderUtils.getServices(GlobalConfigurator.class.getName());
+ _services = ClassLoaderUtils.getServices(Configurator.class.getName());
}
/*
@@ -71,22 +125,30 @@
public void beginRequest(final ExternalContext externalContext)
{
_checkInitialized();
- _attachRequestContext(externalContext);
-
- // By contract, Configurators beginRequest is only called once per physical request.
- // The globalConfigurator may be called multiple times, however, so we need to enforce
- // the contract.
- if (!isRequestBegun(externalContext))
+
+ if(!isRequestDisabled(externalContext))
{
- externalContext.getSessionMap().put(_IN_REQUEST, Boolean.TRUE);
-
- // If request map is present, we don't have a new request
- // Launch Configurator Services
- for (final Configurator config : _services)
+ _attachRequestContext(externalContext);
+
+ // By contract, Configurators beginRequest is only called once per physical request.
+ // The globalConfigurator may be called multiple times, however, so we need to enforce
+ // the contract.
+ if (!isRequestBegun(externalContext))
{
- config.beginRequest(externalContext);
+ externalContext.getRequestMap().put(_IN_REQUEST, Boolean.TRUE);
+
+ // If request map is present, we don't have a new request
+ // Launch Configurator Services
+ for (final Configurator config : _services)
+ {
+ config.beginRequest(externalContext);
+ }
}
}
+ else
+ {
+ _LOG.fine("GlobalConfigurator: Configurators have been disabled for this request.");
+ }
}
/*
@@ -123,36 +185,46 @@
public void endRequest(final ExternalContext externalContext)
{
_checkInitialized();
-
- if (isRequestBegun(externalContext))
+
+ if (!isRequestDisabled(externalContext))
{
- for (final Configurator config : _services)
+ if (isRequestBegun(externalContext))
+ {
+ for (final Configurator config : _services)
+ {
+ config.endRequest(externalContext);
+ }
+
+ externalContext.getRequestMap().remove(_IN_REQUEST);
+ }
+
+ final RequestContext context = RequestContext.getCurrentInstance();
+
+ if (context != null)
{
- config.endRequest(externalContext);
+ context.release();
+ assert RequestContext.getCurrentInstance() == null;
}
- externalContext.getSessionMap().remove(_IN_REQUEST);
}
-
- final RequestContext context = RequestContext.getCurrentInstance();
-
- if (context != null)
+ else
{
- context.release();
- assert RequestContext.getCurrentInstance() == null;
- }
-
- externalContext.getSessionMap().remove(_PERSISTANT_ATTRIBUTES);
+ externalContext.getRequestMap().remove(_IN_REQUEST);
+ }
}
public ExternalContext getExternalContext(ExternalContext externalContext)
{
_checkInitialized();
- // Wrap ExternalContexts
- for (final Configurator config : _services)
+
+ if(!isRequestDisabled(externalContext))
{
- externalContext = config.getExternalContext(externalContext);
+ // Wrap ExternalContexts
+ for (final Configurator config : _services)
+ {
+ externalContext = config.getExternalContext(externalContext);
+ }
}
-
+
return externalContext;
}
@@ -200,12 +272,25 @@
}
}
- @Override
public boolean isInitialized()
{
return _initialized;
}
+ /* Do not refactor this as it's called using reflection from the API package
+ *
+ * @see org.apache.myfaces.trinidad.config.Configurator#disableConfiguratorServices(javax.servlet.http.HttpServletRequest)
+ */
+ public static void disableConfiguratorServicesImpl(final ServletRequest request)
+ {
+ if(Boolean.TRUE.equals(request.getAttribute(_IN_REQUEST)))
+ {
+ throw new IllegalStateException("Request is already begun.");
+ }
+
+ request.setAttribute(_IN_REQUEST, _DISABLED);
+ }
+
/**
* Sets the maximum number of bytes that MultipartFormItem.writeFile() will be allowed to write.
* This value may be set immediately before or between calls to MultipartFormItem.writeFile(). If
@@ -273,7 +358,7 @@
throw new IllegalStateException("Configurator not initialized!");
}
}
-
+
/*
* (non-Javadoc)
*
@@ -281,19 +366,11 @@
*/
private boolean _initialized = false;
-
private long _maxAllowedBytes;
-
private List<Configurator> _services = null;
-
- static private final String _IN_REQUEST = GlobalConfiguratorImpl.class
- .getName()
- + ".IN_REQUEST";
-
- static private final TrinidadLogger _LOG = TrinidadLogger
- .createTrinidadLogger(GlobalConfiguratorImpl.class);
-
- static private final String _PERSISTANT_ATTRIBUTES = GlobalConfiguratorImpl.class
- .getName()
- + ".PERSISTANT_ATTRIBUTES";
-}
+
+ static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(GlobalConfiguratorImpl.class);
+ 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 String _DISABLED = "disabled";
+ }
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java Wed Dec 20 12:12:35 2006
@@ -22,7 +22,7 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import org.apache.myfaces.trinidad.webapp.wrappers.RenderResponseWrapper;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.RenderResponseWrapper;
@SuppressWarnings("deprecation")
class DispatchRenderResponse extends RenderResponseWrapper
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java Wed Dec 20 12:12:35 2006
@@ -28,10 +28,10 @@
import javax.portlet.RenderResponse;
import javax.servlet.ServletResponse;
-import org.apache.myfaces.trinidad.config.GenericConfigurator;
-import org.apache.myfaces.trinidad.util.ExternalContextUtils;
-import org.apache.myfaces.trinidad.webapp.wrappers.PortletContextWrapper;
-import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidad.config.Configurator;
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletContextWrapper;
/**
* TODO: Document this
@@ -40,7 +40,7 @@
* @version $Revision$ $Date$
*/
-public class DispatchResponseConfiguratorImpl extends GenericConfigurator
+public class DispatchResponseConfiguratorImpl extends Configurator
{
/* (non-Javadoc)
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java Wed Dec 20 12:12:35 2006
@@ -23,13 +23,13 @@
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
-import org.apache.myfaces.trinidad.config.GenericConfigurator;
+import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.model.UploadedFile;
-import org.apache.myfaces.trinidad.util.ExternalContextUtils;
import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
+import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
/**
* This configurator will handle the FileUploads for Trinidad.
@@ -37,7 +37,7 @@
* @author Scott O'Bryan (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class FileUploadConfiguratorImpl extends GenericConfigurator
+public class FileUploadConfiguratorImpl extends Configurator
{
/**
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java Wed Dec 20 12:12:35 2006
@@ -27,12 +27,12 @@
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequest;
-import org.apache.myfaces.trinidad.context.external.PortletRequestParameterMap;
-import org.apache.myfaces.trinidad.context.external.PortletRequestParameterValuesMap;
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidad.webapp.wrappers.ActionRequestWrapper;
-import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidadinternal.context.external.PortletRequestParameterMap;
+import org.apache.myfaces.trinidadinternal.context.external.PortletRequestParameterValuesMap;
import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+import org.apache.myfaces.trinidadinternal.webapp.wrappers.ActionRequestWrapper;
/**
* TODO: Document this
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java Wed Dec 20 12:12:35 2006
@@ -22,9 +22,9 @@
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
-import org.apache.myfaces.trinidad.context.external.ServletRequestParameterMap;
-import org.apache.myfaces.trinidad.context.external.ServletRequestParameterValuesMap;
-import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterMap;
+import org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterValuesMap;
/**
* TODO: Document this
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/ExternalContextDecorator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/ExternalContextDecorator.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/ExternalContextDecorator.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/ExternalContextDecorator.java Wed Dec 20 12:12:35 2006
@@ -1,255 +0,0 @@
-/*
-* Copyright 2006 The Apache Software Foundation.
-*
-* Licensed 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 KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.myfaces.trinidadinternal.context;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Principal;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Set;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-
-
-/**
- * Base class for decorating ExternalContexts.
- *
- * @author The Oracle ADF Faces Team
- */
-abstract public class ExternalContextDecorator extends ExternalContext
-{
- @Override
- public void dispatch(String path) throws IOException
- {
- getExternalContext().dispatch(path);
- }
-
- @Override
- public Object getContext()
- {
- return getExternalContext().getContext();
- }
-
- @Override
- public Object getRequest()
- {
- return getExternalContext().getRequest();
- }
-
- @Override
- public Object getResponse()
- {
- return getExternalContext().getResponse();
- }
-
- @Override
- public Object getSession(boolean create)
- {
- return getExternalContext().getSession(create);
- }
-
- @Override
- public String getRequestContextPath()
- {
- return getExternalContext().getRequestContextPath();
- }
-
- @Override
- public String getRequestPathInfo()
- {
- return getExternalContext().getRequestPathInfo();
- }
-
- @Override
- public String getRequestServletPath()
- {
- return getExternalContext().getRequestServletPath();
- }
-
- @Override
- public String getInitParameter(String name)
- {
- return getExternalContext().getInitParameter(name);
- }
-
- @Override
- public String encodeResourceURL(String url)
- {
- return getExternalContext().encodeResourceURL(url);
- }
-
- @Override
- public String encodeActionURL(String url)
- {
- return getExternalContext().encodeActionURL(url);
- }
-
- @Override
- public String encodeNamespace(String ns)
- {
- return getExternalContext().encodeNamespace(ns);
- }
-
- @Override
- public String getAuthType()
- {
- return getExternalContext().getAuthType();
- }
-
- @Override
- public String getRemoteUser()
- {
- return getExternalContext().getRemoteUser();
- }
-
- @Override
- public Principal getUserPrincipal()
- {
- return getExternalContext().getUserPrincipal();
- }
-
- @Override
- public boolean isUserInRole(String role)
- {
- return getExternalContext().isUserInRole(role);
- }
-
- @Override
- public URL getResource(String path) throws MalformedURLException
- {
- return getExternalContext().getResource(path);
- }
-
- @Override
- public InputStream getResourceAsStream(String path)
- {
- return getExternalContext().getResourceAsStream(path);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Set getResourcePaths(String path)
- {
- return getExternalContext().getResourcePaths(path);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestParameterMap()
- {
- return getExternalContext().getRequestParameterMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestParameterValuesMap()
- {
- return getExternalContext().getRequestParameterValuesMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Iterator getRequestParameterNames()
- {
- return getExternalContext().getRequestParameterNames();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestCookieMap()
- {
- return getExternalContext().getRequestCookieMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestHeaderMap()
- {
- return getExternalContext().getRequestHeaderMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestHeaderValuesMap()
- {
- return getExternalContext().getRequestHeaderValuesMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getInitParameterMap()
- {
- return getExternalContext().getInitParameterMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getApplicationMap()
- {
- return getExternalContext().getApplicationMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getSessionMap()
- {
- return getExternalContext().getSessionMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map getRequestMap()
- {
- return getExternalContext().getRequestMap();
- }
-
- @Override
- public Locale getRequestLocale()
- {
- return getExternalContext().getRequestLocale();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Iterator getRequestLocales()
- {
- return getExternalContext().getRequestLocales();
- }
-
- @Override
- public void log(String message)
- {
- getExternalContext().log(message);
- }
-
- @Override
- public void log(String message, Throwable t)
- {
- getExternalContext().log(message, t);
- }
-
- @Override
- public void redirect(String url) throws IOException
- {
- getExternalContext().redirect(url);
- }
-
- abstract protected ExternalContext getExternalContext();
-}
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java Wed Dec 20 12:12:35 2006
@@ -29,7 +29,8 @@
import javax.faces.lifecycle.Lifecycle;
import javax.faces.render.RenderKit;
-import org.apache.myfaces.trinidad.config.GlobalConfigurator;
+import org.apache.myfaces.trinidad.config.Configurator;
+import org.apache.myfaces.trinidad.context.ExternalContextDecorator;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl;
@@ -57,7 +58,7 @@
Lifecycle lifecycle)
{
FacesContext fc = _factory.getFacesContext(context, request, response, lifecycle);
- GlobalConfigurator config = GlobalConfigurator.getInstance();
+ GlobalConfiguratorImpl config = GlobalConfiguratorImpl.getInstance();
ExternalContext ec = fc.getExternalContext();
if(!config.isInitialized())
@@ -96,7 +97,7 @@
_base = base;
//SMO: TODO: is this still needed?
- ExternalContext external = GlobalConfigurator.getInstance().getExternalContext(base.getExternalContext());
+ ExternalContext external = GlobalConfiguratorImpl.getInstance().getExternalContext(base.getExternalContext());
_external = new OverrideDispatch(external);
setCurrentInstance(this);
}
@@ -245,7 +246,7 @@
ExternalContext ec = getExternalContext();
if(Boolean.TRUE.equals(ec.getApplicationMap().remove(_READY_FOR_CLEANUP)))
{
- GlobalConfigurator.getInstance().endRequest(ec);
+ GlobalConfiguratorImpl.getInstance().endRequest(ec);
}
_base.release();
Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?view=diff&rev=489187&r1=489186&r2=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Wed Dec 20 12:12:35 2006
@@ -63,11 +63,11 @@
import org.apache.myfaces.trinidad.context.PartialPageContext;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlConstants;
import org.apache.myfaces.trinidad.context.RenderingContext;
-import org.apache.myfaces.trinidad.util.ExternalContextUtils;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit;
import org.apache.myfaces.trinidadinternal.share.config.UIXCookie;
import org.apache.myfaces.trinidadinternal.ui.expl.ColorPaletteUtils;
+import org.apache.myfaces.trinidadinternal.util.ExternalContextUtils;
import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
import org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl;
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/AbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/AbstractAttributeMap.java?view=auto&rev=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/AbstractAttributeMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/AbstractAttributeMap.java Wed Dec 20 12:12:35 2006
@@ -0,0 +1,338 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadinternal.context.external;
+
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * Helper Map implementation for use with different Attribute Maps.
+ * This was origionally taken from MyFaces.
+ *
+ * @author Anton Koinov
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractAttributeMap<K, V> implements Map<K, V>
+{
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsKey(final Object key)
+ {
+ return getAttribute(key) != null;
+ }
+
+ public boolean containsValue(final Object findValue)
+ {
+ if (findValue == null)
+ {
+ return false;
+ }
+
+ for (final Enumeration e = getAttributeNames(); e.hasMoreElements();)
+ {
+ final Object value = getAttribute(e.nextElement());
+ if (findValue.equals(value))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public Set<Map.Entry<K, V>> entrySet()
+ {
+ return _entrySet != null ? _entrySet : (_entrySet = new EntrySet());
+ }
+
+ public V get(final Object key)
+ {
+ return getAttribute(key.toString());
+ }
+
+ public boolean isEmpty()
+ {
+ return !getAttributeNames().hasMoreElements();
+ }
+
+ public Set<K> keySet()
+ {
+ return _keySet != null ? _keySet : (_keySet = new KeySet());
+ }
+
+ public V put(final K key, final V value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void putAll(final Map<? extends K, ? extends V> t)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public V remove(final Object key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ int size = 0;
+ for (final Enumeration e = getAttributeNames(); e.hasMoreElements();)
+ {
+ size++;
+ e.nextElement();
+ }
+ return size;
+ }
+
+ public Collection<V> values()
+ {
+ return _values != null ? _values : (_values = new Values());
+ }
+
+ abstract protected V getAttribute(Object key);
+
+ abstract protected Enumeration<K> getAttributeNames();
+
+ private Set<Map.Entry<K, V>> _entrySet;
+
+ private Set<K> _keySet;
+
+ private Collection<V> _values;
+
+ private abstract class BaseAbstractIterator<T> implements Iterator<T>
+ {
+ public boolean hasNext()
+ {
+ return _e.hasMoreElements();
+ }
+
+ public void remove()
+ {
+ // remove() may cause ConcurrentModificationException.
+ // We could throw an exception here, but not throwing an exception
+ // allows one call to remove() to succeed
+ if (_currentKey == null)
+ {
+ throw new NoSuchElementException("You must call next() at least once");
+ }
+ AbstractAttributeMap.this.remove(_currentKey);
+ }
+
+ protected void advance()
+ {
+ _currentKey = _e.nextElement();
+ }
+
+ protected K _currentKey;
+
+ protected final Enumeration<K> _e = getAttributeNames();
+ }
+
+ private abstract class BaseAbstractSet<T> extends AbstractSet<T>
+ {
+ @Override
+ public void clear()
+ {
+ AbstractAttributeMap.this.clear();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return AbstractAttributeMap.this.isEmpty();
+ }
+
+ @Override
+ public int size()
+ {
+ return AbstractAttributeMap.this.size();
+ }
+ }
+
+ /**
+ * Not very efficient since it generates a new instance of <code>Entry</code>
+ * for each element and still internaly uses the <code>KeyIterator</code>.
+ * It is more efficient to use the <code>KeyIterator</code> directly.
+ */
+ private class EntryIterator extends BaseAbstractIterator<Map.Entry<K, V>>
+ {
+ public Map.Entry<K, V> next()
+ {
+ advance();
+ // Must create new Entry every time--value of the entry must stay
+ // linked to the same attribute name
+ return new EntrySetEntry(_currentKey);
+ }
+ }
+
+ private class EntrySet extends BaseAbstractSet<Map.Entry<K, V>>
+ {
+ @Override
+ public boolean contains(final Object o)
+ {
+ if (!(o instanceof Entry))
+ {
+ return false;
+ }
+
+ final Entry entry = (Entry) o;
+ final Object key = entry.getKey();
+ final Object value = entry.getValue();
+ if (key == null || value == null)
+ {
+ return false;
+ }
+
+ return value.equals(AbstractAttributeMap.this.get(key));
+ }
+
+ @Override
+ public Iterator<Map.Entry<K, V>> iterator()
+ {
+ return new EntryIterator();
+ }
+
+ @Override
+ public boolean remove(final Object o)
+ {
+ if (!(o instanceof Entry))
+ {
+ return false;
+ }
+
+ final Entry entry = (Entry) o;
+ final Object key = entry.getKey();
+ final Object value = entry.getValue();
+ if (key == null || value == null || !value.equals(AbstractAttributeMap.this.get(key)))
+ {
+ return false;
+ }
+
+ return AbstractAttributeMap.this.remove(((Entry) o).getKey()) != null;
+ }
+ }
+
+ private class EntrySetEntry implements Map.Entry<K, V>
+ {
+ public EntrySetEntry(final K currentKey)
+ {
+ _currentKey = currentKey;
+ }
+
+ public K getKey()
+ {
+ return _currentKey;
+ }
+
+ public V getValue()
+ {
+ return AbstractAttributeMap.this.get(_currentKey);
+ }
+
+ public V setValue(final V value)
+ {
+ return AbstractAttributeMap.this.put(_currentKey, value);
+ }
+
+ private final K _currentKey;
+ }
+
+ private class KeyIterator extends BaseAbstractIterator<K>
+ {
+ public K next()
+ {
+ advance();
+ return _currentKey;
+ }
+ }
+
+ private class KeySet extends BaseAbstractSet<K>
+ {
+ @Override
+ public boolean contains(final Object o)
+ {
+ return AbstractAttributeMap.this.containsKey(o);
+ }
+
+ @Override
+ public Iterator<K> iterator()
+ {
+ return new KeyIterator();
+ }
+
+ @Override
+ public boolean remove(final Object o)
+ {
+ return AbstractAttributeMap.this.remove(o) != null;
+ }
+
+ }
+
+ private class Values extends BaseAbstractSet<V>
+ {
+ @Override
+ public boolean contains(final Object o)
+ {
+ return AbstractAttributeMap.this.containsValue(o);
+ }
+
+ @Override
+ public Iterator<V> iterator()
+ {
+ return new ValuesIterator();
+ }
+
+ @Override
+ public boolean remove(final Object o)
+ {
+ if (o == null)
+ {
+ return false;
+ }
+
+ for (final Iterator it = iterator(); it.hasNext();)
+ {
+ if (o.equals(it.next()))
+ {
+ it.remove();
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ private class ValuesIterator extends BaseAbstractIterator<V>
+ {
+ public V next()
+ {
+ advance();
+ return AbstractAttributeMap.this.get(_currentKey);
+ }
+ }
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/EnumerationIterator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/EnumerationIterator.java?view=auto&rev=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/EnumerationIterator.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/EnumerationIterator.java Wed Dec 20 12:12:35 2006
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadinternal.context.external;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * This was origionally taken from MyFaces
+ *
+ * @author Manfred Geiler
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+class EnumerationIterator<T> implements Iterator<T>
+{
+ EnumerationIterator(final Enumeration<T> enumeration)
+ {
+ _enumeration = enumeration;
+ }
+
+ public boolean hasNext()
+ {
+ return _enumeration.hasMoreElements();
+ }
+
+ public T next()
+ {
+ return _enumeration.nextElement();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException(this.getClass().getName()
+ + " UnsupportedOperationException");
+ }
+
+ private Enumeration<T> _enumeration;
+}
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java?view=auto&rev=489187
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ModifiableAbstractAttributeMap.java Wed Dec 20 12:12:35 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidadinternal.context.external;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Helper Map implementation for use with different modifiable
+ * Attribute Maps.
+ * This was origionally taken from MyFaces.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+abstract class ModifiableAbstractAttributeMap<K, V> extends AbstractAttributeMap<K, V>
+{
+ @Override
+ public void clear()
+ {
+ final List<K> names = new ArrayList<K>();
+
+ for (final Enumeration<K> e = getAttributeNames(); e.hasMoreElements();)
+ {
+ names.add(e.nextElement());
+ }
+
+ for (final K val : names)
+ {
+ removeAttribute(val);
+ }
+ }
+
+ @Override
+ public V put(final K key, final V value)
+ {
+ final V retval = getAttribute(key);
+ setAttribute(key, value);
+ return retval;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void putAll(final Map<? extends K, ? extends V> t)
+ {
+
+ for (final Map.Entry entry : t.entrySet())
+ {
+ setAttribute((K) entry.getKey(), (V) entry.getValue());
+ }
+ }
+
+ @Override
+ public V remove(final Object key)
+ {
+ final V retval = getAttribute(key);
+ removeAttribute(key);
+ return retval;
+ }
+
+ protected abstract void removeAttribute(Object arg0);
+
+ protected abstract void setAttribute(K arg0, V arg1);
+}