myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r781895 - in /myfaces/trinidad/trunk: trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal...
Date Fri, 05 Jun 2009 02:29:11 GMT
Author: jwaldman
Date: Fri Jun  5 02:29:11 2009
New Revision: 781895

URL: http://svn.apache.org/viewvc?rev=781895&view=rev
Log:
TRINIDAD-1494 Support java.util.Set as property type
trunk
For Jing Wu

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/xml/XMLUtils.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java?rev=781895&r1=781894&r2=781895&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
Fri Jun  5 02:29:11 2009
@@ -25,7 +25,9 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.TimeZone;
 
 import javax.el.MethodExpression;
@@ -182,6 +184,31 @@
     }
   }
 
+  /**
+   * Set a property of type java.util.Set<java.lang.String>.  If the value
+   * is an EL expression, it will be stored as a ValueExpression.
+   * Otherwise, it will parsed as a whitespace-separated series
+   * of strings.
+   * Null values are ignored.
+   */
+  protected void setStringSetProperty(
+    FacesBean       bean,
+    PropertyKey     key,
+    ValueExpression expression)
+  {
+    if (expression == null)
+      return;
+
+    if (expression.isLiteralText())
+    {
+      bean.setProperty(key, 
+                       _parseNameTokensAsSet(expression.getValue(null)));
+    }
+    else
+    {
+      bean.setValueExpression(key, expression);
+    }
+  }
 
   /**
    * Set a property of type java.lang.Number.  If the value
@@ -438,6 +465,15 @@
     return list;
   }
 
+  static private final Set<String> _parseNameTokensAsSet (Object o)
+  {
+    List<String> list = _parseNameTokensAsList(o);
+
+    if (list == null)
+      return null;
+    else
+      return new HashSet(list);
+  }
 
   private static final TrinidadLogger _LOG = 
     TrinidadLogger.createTrinidadLogger(UIXComponentELTag.class);

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java?rev=781895&r1=781894&r2=781895&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/expl/Coercions.java
Fri Jun  5 02:29:11 2009
@@ -27,6 +27,7 @@
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
 import org.apache.myfaces.trinidadinternal.share.text.ColorFormat;
@@ -137,7 +138,11 @@
       }
       else if (type == List.class)
       {
-        return Arrays.asList(XMLUtils.parseNameTokens(text));
+        return XMLUtils.parseNameTokensAsList(text);
+      }
+      else if (type == Set.class)
+      {
+        return XMLUtils.parseNameTokensAsSet(text);
       }
       // For Dates, try to parse it as an ISO 8601 Date.
       // If that fails, simply let the string pass through;  for

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/xml/XMLUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/xml/XMLUtils.java?rev=781895&r1=781894&r2=781895&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/xml/XMLUtils.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/xml/XMLUtils.java
Fri Jun  5 02:29:11 2009
@@ -23,6 +23,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -340,6 +343,41 @@
    */
   static public String[] parseNameTokens(String stringValue)
   {
+    List<String> list = parseNameTokensAsList(stringValue);
+
+    if (list == null)
+      return null;
+    else
+      return list.toArray(new String[list.size()]);
+
+  }
+
+  /**
+   * Parses a whitespace separated series of name tokens.
+   * @param stringValue the full string
+   * @return a set of each constituent value, or null
+   *  if there are no tokens (that is, the string is empty or
+   *  all whitespace)
+   */
+  static public Set<String> parseNameTokensAsSet(String stringValue)
+  {
+    List<String> list = parseNameTokensAsList(stringValue);
+
+    if (list == null)
+      return null;
+    else
+      return new HashSet(list);
+  }
+
+  /**
+   * Parses a whitespace separated series of name tokens.
+   * @param stringValue the full string
+   * @return a list of each constituent value, or null
+   *  if there are no tokens (that is, the string is empty or
+   *  all whitespace)
+   */
+  static public List<String> parseNameTokensAsList(String stringValue)
+  {
     if (stringValue == null)
       return null;
 
@@ -384,7 +422,7 @@
     if (list.isEmpty())
       return null;
 
-    return list.toArray(new String[list.size()]);
+    return list;
   }
 
   /**



Mime
View raw message