You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2010/02/04 23:06:44 UTC

svn commit: r906678 - in /myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad: bean/FacesBeanImpl.java bean/util/ValueMap.java component/UIXFacesBeanImpl.java util/CollectionUtils.java

Author: bsullivan
Date: Thu Feb  4 22:06:44 2010
New Revision: 906678

URL: http://svn.apache.org/viewvc?rev=906678&view=rev
Log:
Make sure that the ID_KEY is present in the UIXFacesBeanImpl.java key set when the UIXFacesBeanImpl is delegating the storageof the ID property back to the UIXComponentBase.

Modified:
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBeanImpl.java
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ValueMap.java
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXFacesBeanImpl.java
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBeanImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBeanImpl.java?rev=906678&r1=906677&r2=906678&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBeanImpl.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBeanImpl.java Thu Feb  4 22:06:44 2010
@@ -31,8 +31,6 @@
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 
-
-
 import org.apache.myfaces.trinidad.bean.util.FlaggedPropertyMap;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
@@ -46,12 +44,6 @@
   {
   }
 
-  /**
-   * Get the type of a FacesBean
-   */
-  // TODO Use auto "TYPE" detection?
-  abstract public Type getType();
-
   final public Object getProperty(PropertyKey key)
   {
     Object o = getLocalProperty(key);
@@ -301,12 +293,12 @@
     }
   }
 
-  final public Set<PropertyKey> keySet()
+  public Set<PropertyKey> keySet()
   {
     if (_properties == null)
       return Collections.emptySet();
-
-    return _properties.keySet();
+    else
+      return _properties.keySet();
   }
 
   @SuppressWarnings("unchecked")

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ValueMap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ValueMap.java?rev=906678&r1=906677&r2=906678&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ValueMap.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ValueMap.java Thu Feb  4 22:06:44 2010
@@ -257,6 +257,6 @@
     throw new ClassCastException();
   }
 
-  private FacesBean    _bean;
-  private MakeEntries  _entries;
+  private final FacesBean    _bean;
+  private transient MakeEntries  _entries;
 }

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXFacesBeanImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXFacesBeanImpl.java?rev=906678&r1=906677&r2=906678&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXFacesBeanImpl.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXFacesBeanImpl.java Thu Feb  4 22:06:44 2010
@@ -18,10 +18,14 @@
  */
 package org.apache.myfaces.trinidad.component;
 
+import java.util.Collections;
+import java.util.Set;
+
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.bean.FacesBeanImpl;
 import org.apache.myfaces.trinidad.bean.PropertyKey;
+import org.apache.myfaces.trinidad.util.CollectionUtils;
 
 /**
  * FacesBeanImpl subclass that implements UIXFacesBean.  UIXComponentBase subclasses that want to
@@ -87,6 +91,17 @@
     _component = component;
   }  
 
+  @Override
+  public Set<PropertyKey> keySet()
+  {
+    // override to make sure that the id key is in the returned set.
+    Set<PropertyKey> baseSet = super.keySet();
+    
+    if (baseSet.isEmpty())
+      return _ID_KEY_SET;
+    else
+      return CollectionUtils.compositeSet(baseSet, _ID_KEY_SET);
+  }
 
   @Override
   public void setPropertyImpl(PropertyKey key, Object value)
@@ -138,6 +153,8 @@
     super.restoreState(context, addIdState[1]);
   }
   
+  // Set containing the ID Key
+  private static final Set<PropertyKey> _ID_KEY_SET =Collections.singleton(UIXComponentBase.ID_KEY);
   
   private Type _type;
   private UIXComponent _component;

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java?rev=906678&r1=906677&r2=906678&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/CollectionUtils.java Thu Feb  4 22:06:44 2010
@@ -26,11 +26,13 @@
 import java.lang.reflect.Array;
 
 import java.util.AbstractQueue;
+import java.util.AbstractSet;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.ConcurrentModificationException;
+import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -42,6 +44,7 @@
 import java.util.RandomAccess;
 import java.util.Set;
 
+import org.apache.myfaces.trinidad.component.CompositeIterator;
 import org.apache.myfaces.trinidad.context.Version;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
@@ -145,6 +148,28 @@
     return _asSet(a, true);
   }
 
+  /**
+   * Returns an unmodifiable versions of the Set of Enums.  If the contents of the set are known
+   * to be unmodifiable by the caller in any way, the set itself will be retured, otherwise an
+   * unmodifiable copy of the Set will be returned.
+   * @param s Set to get the tamper-proof version of
+   * @return An unmodifiable tamper-proof version of the set
+   */
+  public static <E extends Enum<E>> Set<E> unmodifiableCopyOfEnumSet(Set<E> s)
+  {
+    Class<? extends Set> copyClass = s.getClass();
+    
+    if ((_EMPTY_SET == copyClass) || (_SINGLETON_SET == copyClass))
+    {
+      // these classes are already unmodifiable, so just return
+      return s;
+    }
+    else
+    {
+      return Collections.unmodifiableSet(EnumSet.copyOf(s));
+    }
+  }
+
   private static <T> Set<T> _asSet(T[] a, boolean makeImmutable)
   {
     int count = (a != null) ? a.length : 0;
@@ -184,6 +209,23 @@
     return outSet;
   }
 
+  /**
+   * Given two disjoint sets, returns a live composition of the two Sets that maintains
+   * the disjoint invariant.  If both Sets are Serializable, the returned
+   * implementation will be Serializable as well.  The returned Set implementation is
+   * not thread safe.
+   * @param primarySet The Set that adds will be applied to
+   * @param secondarySet The other Set
+   * @return The composition of the two disjoint Sets
+   * @throws NullPointerException of primarySet or secondarySet are <code>null</code>
+   */
+  public static <T> Set<T> compositeSet(Set<T> primarySet, Set<T> secondarySet)
+  {
+    if ((primarySet instanceof Serializable) && (secondarySet instanceof Serializable))
+      return new SerializableFixedCompositeSet(primarySet, secondarySet);
+    else
+      return new FixedCompositeSet(primarySet, secondarySet);
+  }
 
   /**
    * Returns a Collection based on the passed in Collection <code>c</code>,
@@ -412,7 +454,286 @@
       return getDelegate().toString();
     }
   }
+
+  /**
+   * Note: Requires contents to be disjoint!
+   * @param <E>
+   */
+  protected abstract static class CompositeCollection<E> implements Collection<E>
+  {
+    protected abstract Collection<E> getPrimaryDelegate();
+    protected abstract Collection<E> getSecondaryDelegate();
+
+    @Override
+    public int size()
+    {
+      return getPrimaryDelegate().size() + getSecondaryDelegate().size();
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+      return getPrimaryDelegate().isEmpty() || getSecondaryDelegate().isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o)
+    {
+      return getPrimaryDelegate().contains(o) || getSecondaryDelegate().contains(o);
+    }
+
+    @Override
+    public Iterator<E> iterator()
+    {
+      return new CompositeIterator(getPrimaryDelegate().iterator(),
+                                   getSecondaryDelegate().iterator());
+    }
+
+    @Override
+    public Object[] toArray()
+    {
+      int size = size();
+      
+      Object[] out = new Object[size];
+      
+      int i = 0;
+      for (Object currObject : this)
+      {
+        out[i] = currObject;
+        
+        i++;
+        
+        if (i == size)
+          break;
+      }
+      
+      return out;
+    }
+
+    @Override
+    public <T> T[] toArray(T[] outArray)
+    {
+      int collectionSize = size();
+      int arraySize = outArray.length;
+      
+      // size isn't big enough, so need a new array
+      if (collectionSize > arraySize)
+      {
+        outArray = (T[])Array.newInstance(outArray.getClass().getComponentType(),
+                                          collectionSize);
+      }
+
+      Iterator<E> iterator = this.iterator();
+      
+      for (int i = 0; i < collectionSize; i++)
+      {
+        if (!iterator.hasNext())
+          break;
+        
+        outArray[i] = (T)iterator.next();
+      }
+      
+      return outArray;
+    }
+
+    @Override
+    public boolean add(E e)
+    {
+      return getPrimaryDelegate().add(e);
+    }
+
+    @Override
+    public boolean remove(Object o)
+    {
+      boolean removed = getPrimaryDelegate().remove(0);
+      
+      if (!removed)
+        removed = getSecondaryDelegate().remove(0);
+      
+      return removed;
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c)
+    {
+      // find all of the items in both the collection and the primary delegate
+      
+      Set<Object> intersection = new HashSet<Object>(getPrimaryDelegate());
+      intersection.retainAll(c);
+            
+      if (intersection.size() == c.size())
+      {
+        // the primary delegate contained all of the items, so we're done
+        return true;
+      }
+      else
+      {
+        // compute the set of items we still haven't match in order to check against the
+        // secondary delegate
+        Set<Object> remainder = new HashSet<Object>(c);
+        remainder.removeAll(intersection);
+        
+        return getSecondaryDelegate().containsAll(remainder);
+      }
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends E> c)
+    {
+      // determine the result ahead of time
+      boolean changed = !containsAll(c);
+      
+      // make sure that the collections maintain disjointness
+      getSecondaryDelegate().removeAll(c);
+      getPrimaryDelegate().addAll(c);
+      
+      return changed;
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c)
+    {
+      return getPrimaryDelegate().removeAll(c) || getSecondaryDelegate().removeAll(c);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c)
+    {
+      return getPrimaryDelegate().retainAll(c) || getSecondaryDelegate().retainAll(c);
+    }
+
+    @Override
+    public void clear()
+    {
+      getPrimaryDelegate().clear();
+      getSecondaryDelegate().clear();
+    }
+    
+    @Override
+    public String toString()
+    {
+      return super.toString() + 
+             "[primary:" + 
+             getPrimaryDelegate() +
+             ", secondary:" +
+             getSecondaryDelegate() +
+             "]";
+    }
+  }
+  
+  /**
+   * Note: Requires contents to be disjoint!
+   * @param <E>
+   */
+  protected abstract static class CompositeSet<E> extends CompositeCollection<E> implements Set<E>
+  {
+    @Override
+    protected abstract Set<E> getPrimaryDelegate();
     
+    @Override
+    protected abstract Set<E> getSecondaryDelegate();
+
+    /**
+     * Implement Set-defined equals behavior 
+     */
+    @Override
+    public boolean equals(Object o)
+    {
+      if (o == this)
+        return true;
+      else if (!(o instanceof Set))
+        return false;
+      else
+      {
+        Collection other = (Collection) o;
+
+        if (other.size() != size())
+        {
+          return false;
+        }
+        else
+        {
+          // since the sizes are the same, if we contain all of the other collection's
+          // elements, we are identical
+          try
+          {
+            return containsAll(other);
+          }
+          catch(NullPointerException npe)
+          {
+            // optional NullPointerException that containsAll is allowed to throw
+            return false;
+          }
+          catch(ClassCastException npe)
+          {
+            // optional ClassCastException that containsAll is allowed to throw
+            return false;
+          }
+        }
+      }
+    }
+
+    /**
+     * Implement Set-defined equals behavior 
+     */
+    @Override
+    public int hashCode()
+    {
+      // Set defines hashCode() as additive based on the contents
+      return getPrimaryDelegate().hashCode() + getSecondaryDelegate().hashCode();
+    }
+  }
+  
+  /**
+   * Concrete Composite Set that takes the two sets to compose
+   */
+  private static class FixedCompositeSet<E> extends CompositeSet<E>
+  {
+    FixedCompositeSet(Set<E> primarySet, Set<E> secondarySet)
+    {
+      if (primarySet == null)
+        throw new NullPointerException();
+
+      if (secondarySet == null)
+        throw new NullPointerException();
+      
+      assert Collections.disjoint(primarySet, secondarySet) : "Composed Sets not disjoint";
+      
+      _primarySet   = primarySet;
+      _secondarySet = secondarySet;
+    }
+
+    @Override
+    protected Set<E> getPrimaryDelegate()
+    {
+      return _primarySet;
+    }
+    
+    @Override
+    protected Set<E> getSecondaryDelegate()
+    {
+      return _secondarySet;
+    }
+    
+    private final Set<E> _primarySet;
+    private final Set<E> _secondarySet;
+  }
+
+  /**
+   * Serializable version of FixedCompositeSet
+   * @param <E>
+   */
+  private static final class SerializableFixedCompositeSet<E> extends FixedCompositeSet<E>
+                                                              implements Serializable
+  {
+    SerializableFixedCompositeSet(Set<E> primarySet, Set<E> secondarySet)
+    {
+      super(primarySet, secondarySet);
+    }
+    
+    private static final long serialVersionUID = 0L;    
+  }
+  
   private static class SerializableCollection<E> extends DelegatingCollection<E>
                                                  implements Serializable
   {
@@ -965,6 +1286,10 @@
   private static final Class<? extends List> _CHECKED_LIST;
   private static final Class<? extends List> _UNMODIFIABLE_LIST;
   private static final Class<? extends List> _SYNCHRONIZED_LIST;
+  private static final Class<? extends Set> _EMPTY_SET = Collections.emptySet().getClass();
+  private static final Class<? extends Set> _SINGLETON_SET = Collections.singleton(null).getClass();
+  
+
   private static final Queue _EMPTY_QUEUE = new EmptyQueue();
   private static final Iterator _EMPTY_ITERATOR = new EmptyIterator();
   private static final Iterator _EMPTY_LIST_ITERATOR = new EmptyListIterator();