You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sl...@apache.org on 2007/08/29 20:21:37 UTC

svn commit: r570888 - /myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java

Author: slessard
Date: Wed Aug 29 11:21:36 2007
New Revision: 570888

URL: http://svn.apache.org/viewvc?rev=570888&view=rev
Log:
TRINIDAD-661 : Added two resolveProperty methods to XhtmlRenderer.java to reduce redundant code involved during FacesBean property value evaluation.

Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java?rev=570888&r1=570887&r2=570888&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java Wed Aug 29 11:21:36 2007
@@ -713,6 +713,69 @@
            arc.getAgent().getCapabilities().get(TrinidadAgent.CAP_SCRIPTING_SPEED)));
     _renderTransparent(context, arc, width, height, needsQuoting, id, useScript);
   }
+  
+  /**
+   * This method evaluates the property of the specified bean if it supports 
+   * the specified property key and if the current value is <code>null</code>, 
+   * then evaluate the default value.
+   * <p>
+   * If the bean does not support the specified key, this method returns 
+   * <code>null</code>. Unsupported keys occur when the bean's type its type 
+   * returned <code>null</code> from <code>findKey</code> when 
+   * <code>findTypeConstants</code> method was called.
+   * </p>
+   * 
+   * @param bean the property value holder.
+   * @param key  the key associated to the property to evaluate.
+   * 
+   * @return <code>null</code> if key is <code>null</code>, the current 
+   *         property value in the bean for the specified key if it was 
+   *         set, or the default value if it wasn't.
+   * 
+   * @see #findTypeConstants(org.apache.myfaces.trinidad.bean.FacesBean.Type)
+   */
+  protected Object resolveProperty(FacesBean bean, PropertyKey key)
+  {
+    return resolveProperty(bean, key, true);
+  }
+  
+  /**
+   * This method evaluates the property of the specified bean if it supports 
+   * the specified property key and if the current value is <code>null</code>, 
+   * then evaluate the default value if and only if <code>checkDefault</code> 
+   * is <code>true</code>.
+   * <p>
+   * If the bean does not support the specified key, this method returns 
+   * <code>null</code>. Unsupported keys occur when the bean's type its type 
+   * returned <code>null</code> from <code>findKey</code> when 
+   * <code>findTypeConstants</code> method was called.
+   * </p>
+   * 
+   * @param bean         the property value holder.
+   * @param key          the key associated to the property to evaluate.
+   * @param checkDefault a flag to tell the method to look for the default value 
+   *                     if no value was explicitely set.
+   * 
+   * @return <code>null</code> if key is <code>null</code>, the current 
+   *         property value in the bean for the specified key if it was 
+   *         set, or the default value if it wasn't and checkDefault is 
+   *         <code>true</code>.
+   */
+  protected Object resolveProperty(FacesBean bean, PropertyKey key, boolean checkDefault)
+  {
+    if (key == null)
+    {
+      return null;
+    }
+    
+    Object value = bean.getProperty(key);
+    if (value == null && checkDefault)
+    {
+      value = key.getDefault();
+    }
+    
+    return value;
+  }
 
   private static final class Counter
   {