myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r981353 - in /myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit: ConvertedValueCache.java ConvertedValueCacheEntry.java ExtValLazyRendererProxy.java ExtValRendererWrapper.java
Date Mon, 02 Aug 2010 02:27:33 GMT
Author: gpetracek
Date: Mon Aug  2 02:27:33 2010
New Revision: 981353

URL: http://svn.apache.org/viewvc?rev=981353&view=rev
Log:
EXTVAL-80 alternative to ExtValRendererProxy (for #getConvertedValue)

Added:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCache.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCacheEntry.java
Modified:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValLazyRendererProxy.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRendererWrapper.java

Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCache.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCache.java?rev=981353&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCache.java
(added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCache.java
Mon Aug  2 02:27:33 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.renderkit;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ConvertedValueCache
+{
+    private static ThreadLocal<ConvertedValueCacheEntry> value = new ThreadLocal<ConvertedValueCacheEntry>();
+
+    public static void reset()
+    {
+        value.set(null);
+        value.remove();
+    }
+
+    //needed because null is a valid value
+    static boolean isCachedValueAvailable()
+    {
+        return getCacheEntry().isCachedValueAvailable();
+    }
+
+    static Object getCachedValue()
+    {
+        return getCacheEntry().getCachedValue();
+    }
+
+    static void setCachedValue(Object convertedObject)
+    {
+        getCacheEntry().setCachedValue(convertedObject);
+    }
+
+    private static ConvertedValueCacheEntry getCacheEntry()
+    {
+        ConvertedValueCacheEntry entry = value.get();
+
+        if(entry == null)
+        {
+            entry = new ConvertedValueCacheEntry();
+            value.set(entry);
+        }
+        return entry;
+    }
+}

Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCacheEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCacheEntry.java?rev=981353&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCacheEntry.java
(added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ConvertedValueCacheEntry.java
Mon Aug  2 02:27:33 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.renderkit;
+
+/**
+ * @author Gerhard Petracek
+ */
+class ConvertedValueCacheEntry
+{
+    private boolean cachedValueAvailable;
+    private Object cachedValue;
+
+    void setCachedValue(Object cachedValue)
+    {
+        this.cachedValue = cachedValue;
+        this.cachedValueAvailable = true;
+    }
+
+    public Object getCachedValue()
+    {
+        return cachedValue;
+    }
+
+    public boolean isCachedValueAvailable()
+    {
+        return cachedValueAvailable;
+    }
+}

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValLazyRendererProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValLazyRendererProxy.java?rev=981353&r1=981352&r2=981353&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValLazyRendererProxy.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValLazyRendererProxy.java
Mon Aug  2 02:27:33 2010
@@ -92,17 +92,35 @@ class ExtValLazyRendererProxy extends Re
     public Object getCachedConvertedValue(FacesContext facesContext, UIComponent uiComponent,
Object o)
         throws ConverterException
     {
-        if(getLazyRenderer() instanceof RendererProxy)
+        Renderer renderer = getLazyRenderer();
+        if(renderer instanceof RendererProxy)
         {
             return ((RendererProxy)getLazyRenderer()).getCachedConvertedValue(facesContext,
uiComponent, o);
         }
-        return getLazyRenderer().getConvertedValue(facesContext, uiComponent, o);
+
+        //by default there is no proxy - so we use a local cache
+        if(ConvertedValueCache.isCachedValueAvailable())
+        {
+            return ConvertedValueCache.getCachedValue();
+        }
+
+        Object result = renderer.getConvertedValue(facesContext, uiComponent, o);
+        ConvertedValueCache.setCachedValue(result);
+        return result;
     }
 
     @Override
     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object
o)
         throws ConverterException
     {
+        if(getLazyRenderer() == this.wrapped)
+        {
+            if(ConvertedValueCache.isCachedValueAvailable())
+            {
+                return ConvertedValueCache.getCachedValue();
+            }
+        }
+
         return getLazyRenderer().getConvertedValue(facesContext, uiComponent, o);
     }
 
@@ -137,4 +155,9 @@ class ExtValLazyRendererProxy extends Re
     {
         return this.wrapped;
     }
+
+    void resetConvertedValueCache()
+    {
+        ConvertedValueCache.reset();
+    }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRendererWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRendererWrapper.java?rev=981353&r1=981352&r2=981353&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRendererWrapper.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRendererWrapper.java
Mon Aug  2 02:27:33 2010
@@ -350,59 +350,71 @@ public class ExtValRendererWrapper exten
 
         try
         {
-            for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+            try
             {
-                logger.finest("start beforeGetConvertedValue of " + rendererInterceptor.getClass().getName());
-
-                try
-                {
-                    rendererInterceptor.beforeGetConvertedValue(facesContext, uiComponent,
o, this.wrapped);
-                }
-                catch (SkipRendererDelegationException e)
+                for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
                 {
-                    convertedObject = e.getReturnValueOnException(convertedObject);
+                    logger.finest("start beforeGetConvertedValue of " + rendererInterceptor.getClass().getName());
 
-                    logger.log(Level.FINEST, "getConvertedValue delegation canceled", e);
+                    try
+                    {
+                        rendererInterceptor.beforeGetConvertedValue(facesContext, uiComponent,
o, this.wrapped);
+                    }
+                    catch (SkipRendererDelegationException e)
+                    {
+                        convertedObject = e.getReturnValueOnException(convertedObject);
 
-                    delegateToWrappedRenderer = false;
+                        logger.log(Level.FINEST, "getConvertedValue delegation canceled",
e);
 
-                    if(e.isSkipOtherInterceptors())
-                    {
-                        break;
+                        delegateToWrappedRenderer = false;
+
+                        if(e.isSkipOtherInterceptors())
+                        {
+                            break;
+                        }
                     }
-                }
 
-                logger.finest("beforeGetConvertedValue of " +
-                    rendererInterceptor.getClass().getName() + " finished");
+                    logger.finest("beforeGetConvertedValue of " +
+                        rendererInterceptor.getClass().getName() + " finished");
+                }
+            }
+            catch (SkipBeforeInterceptorsException e)
+            {
+                logger.log(Level.FINEST, "beforeGetConvertedValue interceptors canceled",
e);
             }
-        }
-        catch (SkipBeforeInterceptorsException e)
-        {
-            logger.log(Level.FINEST, "beforeGetConvertedValue interceptors canceled", e);
-        }
 
-        /*
-         * delegate
-         */
-        if(delegateToWrappedRenderer)
-        {
-            convertedObject = wrapped.getConvertedValue(facesContext, uiComponent, o);
-        }
+            /*
+             * delegate
+             */
+            if(delegateToWrappedRenderer)
+            {
+                convertedObject = wrapped.getConvertedValue(facesContext, uiComponent, o);
+            }
 
-        try
-        {
-            for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+            try
             {
-                logger.finest("start afterGetConvertedValue of " + rendererInterceptor.getClass().getName());
+                for(RendererInterceptor rendererInterceptor : extValContext.getRendererInterceptors())
+                {
+                    logger.finest(
+                            "start afterGetConvertedValue of " + rendererInterceptor.getClass().getName());
 
-                rendererInterceptor.afterGetConvertedValue(facesContext, uiComponent, o,
this.wrapped);
+                    rendererInterceptor.afterGetConvertedValue(facesContext, uiComponent,
o, this.wrapped);
 
-                logger.finest("afterGetConvertedValue of " + rendererInterceptor.getClass().getName()
+ " finished");
+                    logger.finest(
+                            "afterGetConvertedValue of " + rendererInterceptor.getClass().getName()
+ " finished");
+                }
+            }
+            catch (SkipAfterInterceptorsException e)
+            {
+                logger.log(Level.FINEST, "afterGetConvertedValue interceptors canceled",
e);
             }
         }
-        catch (SkipAfterInterceptorsException e)
+        finally
         {
-            logger.log(Level.FINEST, "afterGetConvertedValue interceptors canceled", e);
+            if(this.wrapped instanceof ExtValLazyRendererProxy)
+            {
+                ((ExtValLazyRendererProxy)this.wrapped).resetConvertedValueCache();
+            }
         }
 
         return convertedObject;



Mime
View raw message