incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r425276 [3/12] - in /incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src: main/java/org/apache/myfaces/adfinternal/agent/ main/java/org/apache/myfaces/adfinternal/agent/parse/ main/java/org/apache/myfaces/adfi...
Date Tue, 25 Jul 2006 04:42:46 GMT
Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityKey.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityKey.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityKey.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityKey.java Mon Jul 24 21:42:41 2006
@@ -13,130 +13,130 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent;
-
-import java.util.HashMap;
-
-/**
- * Key for capability
- * Pretty much an impl similar to uix of AgentCapabilityKey
- * -- added method getKeyAt (and required storage units)
- * -- remove getKeyCount as ...
- *
- */
-public final class CapabilityKey
-{
-
-  private CapabilityKey(String capabilityName,
-                        int index)
-  {
-    if (capabilityName == null)
-      throw new NullPointerException();
-
-    if (index < 0)
-      throw new IllegalArgumentException();
-
-    _capName = capabilityName.intern();
-    _capIndex = index;
-    _capKeyNames.put(_capName, this);
-
-    if (_keys.length < _capIndex)
-    {
-      CapabilityKey[] newKeys = new CapabilityKey[_keys.length + DEFAULT_SIZE];
-      System.arraycopy(_keys, 0, newKeys, 0, _keys.length);
-    }
-
-    _keys[_capIndex] = this;
-  }
-
-  /**
-   * Create a new CapabilityKey. If an key with name already exists returns the
-   * pre-created CapabilityKey
-   * @param capabilityName
-   */
-  public static CapabilityKey getCapabilityKey(String capabilityName, boolean createIfNull)
-  {
-    if (capabilityName == null)
-      return null;
-
-    Object key = _capKeyNames.get(capabilityName);
-    if ((createIfNull) && (key == null))
-      key = _createKey(capabilityName);
-
-    return ((CapabilityKey) key);
-  }
-
-  /**
-   *
-   * @param capabilityName
-   * @return CapabilityKey for the capability name
-   */
-  public static CapabilityKey getCapabilityKey(String capabilityName)
-  {
-    return getCapabilityKey (capabilityName, false);
-  }
-
-  /**
-   * @return capability name
-   */
-  public String getCapabilityName()
-  {
-    return _capName;
-  }
-
-  /**
-   * @return capability key index
-   */
-  public int getIndex()
-  {
-    return _capIndex;
-  }
-
-
-  /**
-   * @param index
-   * @return CapabilityKey with the specified index
-   */
-  public static CapabilityKey getKeyAt(int index)
-  {
-    if (index >= 0 && index <= _count)
-      return _keys[index];
-
-    //just return null if out of range
-    return null;
-  }
-
-  public boolean equals(Object obj)
-  {
-    return this == obj;
-  }
-
-  public int hashCode()
-  {
-    return _capIndex;
-  }
-
-  synchronized private static Object _createKey(String capabilityName)
-  {
-    Object key = _capKeyNames.get(capabilityName);
-    if (key == null)
-    {
-      key = new CapabilityKey(capabilityName, _count++);
-    }
-    return key;
-  }
-
-  public String toString()
-  {
-    return _capName;
-  }
-
-  private String _capName;
-  private int _capIndex = 0;
-
-  static final private int DEFAULT_SIZE = 50;
-
-  static private HashMap _capKeyNames = new HashMap();
-  static private CapabilityKey[] _keys = new CapabilityKey[DEFAULT_SIZE];
-  private static int _count = 0;
-}
+package org.apache.myfaces.adfinternal.agent;
+
+import java.util.HashMap;
+
+/**
+ * Key for capability
+ * Pretty much an impl similar to uix of AgentCapabilityKey
+ * -- added method getKeyAt (and required storage units)
+ * -- remove getKeyCount as ...
+ *
+ */
+public final class CapabilityKey
+{
+
+  private CapabilityKey(String capabilityName,
+                        int index)
+  {
+    if (capabilityName == null)
+      throw new NullPointerException();
+
+    if (index < 0)
+      throw new IllegalArgumentException();
+
+    _capName = capabilityName.intern();
+    _capIndex = index;
+    _capKeyNames.put(_capName, this);
+
+    if (_keys.length < _capIndex)
+    {
+      CapabilityKey[] newKeys = new CapabilityKey[_keys.length + DEFAULT_SIZE];
+      System.arraycopy(_keys, 0, newKeys, 0, _keys.length);
+    }
+
+    _keys[_capIndex] = this;
+  }
+
+  /**
+   * Create a new CapabilityKey. If an key with name already exists returns the
+   * pre-created CapabilityKey
+   * @param capabilityName
+   */
+  public static CapabilityKey getCapabilityKey(String capabilityName, boolean createIfNull)
+  {
+    if (capabilityName == null)
+      return null;
+
+    Object key = _capKeyNames.get(capabilityName);
+    if ((createIfNull) && (key == null))
+      key = _createKey(capabilityName);
+
+    return ((CapabilityKey) key);
+  }
+
+  /**
+   *
+   * @param capabilityName
+   * @return CapabilityKey for the capability name
+   */
+  public static CapabilityKey getCapabilityKey(String capabilityName)
+  {
+    return getCapabilityKey (capabilityName, false);
+  }
+
+  /**
+   * @return capability name
+   */
+  public String getCapabilityName()
+  {
+    return _capName;
+  }
+
+  /**
+   * @return capability key index
+   */
+  public int getIndex()
+  {
+    return _capIndex;
+  }
+
+
+  /**
+   * @param index
+   * @return CapabilityKey with the specified index
+   */
+  public static CapabilityKey getKeyAt(int index)
+  {
+    if (index >= 0 && index <= _count)
+      return _keys[index];
+
+    //just return null if out of range
+    return null;
+  }
+
+  public boolean equals(Object obj)
+  {
+    return this == obj;
+  }
+
+  public int hashCode()
+  {
+    return _capIndex;
+  }
+
+  synchronized private static Object _createKey(String capabilityName)
+  {
+    Object key = _capKeyNames.get(capabilityName);
+    if (key == null)
+    {
+      key = new CapabilityKey(capabilityName, _count++);
+    }
+    return key;
+  }
+
+  public String toString()
+  {
+    return _capName;
+  }
+
+  private String _capName;
+  private int _capIndex = 0;
+
+  static final private int DEFAULT_SIZE = 50;
+
+  static private HashMap _capKeyNames = new HashMap();
+  static private CapabilityKey[] _keys = new CapabilityKey[DEFAULT_SIZE];
+  private static int _count = 0;
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityMap.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityMap.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityMap.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityMap.java Mon Jul 24 21:42:41 2006
@@ -13,355 +13,355 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent;
-
-import java.util.Set;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.AbstractMap;
-import java.util.HashSet;
-import java.util.Collections;
-
-/**
- * Pretty much the same Impl of UIX CapabilityMap, with following changes
- * -- Actually a map implementation now
- * -- added support to get Entries (To support a map interface)
- * -- Also this impl assumes that the number of keys **will** change (increase) after init.
- *
- */
-public class CapabilityMap extends AbstractMap implements Cloneable
-{
-
-  private CapabilityMap()
-  {
-  }
-
-  CapabilityMap(Object[][] keyValuesArr)
-  {
-
-    int arrayCount = keyValuesArr.length;
-    CapabilityKey[][] keyArrays = new CapabilityKey[arrayCount][];
-
-    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
-    {
-      keyArrays[arrayIndex] = new CapabilityKey[
-              keyValuesArr[arrayIndex] == null ? 0 : (keyValuesArr[arrayIndex].length >> 1)];
-    }
-
-    //Get All the Keys
-    //determine how many keys we need. The keys list/count could change hence
-    //need to find max key index.
-    int maxKeyIndex = 0;
-    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
-    {
-      Object[] keyValues = keyValuesArr[arrayIndex];
-      CapabilityKey[] keys = keyArrays[arrayIndex];
-      int keyCount = keys.length;
-
-      for (int i = 0; i < keyCount; i++)
-      {
-        keys[i] = (CapabilityKey) keyValues[i << 1];
-        maxKeyIndex = _max(keys[i].getIndex(), maxKeyIndex);
-      }
-    }
-
-    _indexedValues = new Object[maxKeyIndex + 1];
-    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
-    {
-      Object[] keyValues = keyValuesArr[arrayIndex];
-      CapabilityKey[] keys = keyArrays[arrayIndex];
-      int keyCount = keys.length;
-
-      for (int i = 0; i < keyCount; i++)
-      {
-        _indexedValues[keys[i].getIndex()] = keyValues[(i << 1) + 1];
-      }
-    }
-  }
-
-
-  /**
-   * @param capKey
-   * @return value object for the capability
-   */
-  public Object getCapability(CapabilityKey capKey)
-  {
-    int keyIndex = capKey.getIndex();
-
-    if (keyIndex < _indexedValues.length)
-      return _indexedValues[keyIndex];
-
-    return null;
-  }
-
-  /**
-   * @param capabilities
-   * @return  returns a new capability map that merges key/values of the provided map
-   */
-  public CapabilityMap merge(Map capabilities)
-  {
-    if ((capabilities == null) || (capabilities.isEmpty()))
-      return this;
-
-    return merge(_getMapAsArray(capabilities));
-  }
-
-
-  /**
-   * @param capabilities
-   * @return
-   */
-  //Doing this as current Impl. uses this method
-  public CapabilityMap merge(Object[] capabilities)
-  {
-    // could simply do this but .....
-    // new CapabilitiesImpl (new Object[][] {_getCapabilitiesAsArray(),
-    //                                       capabilities});
-
-    if ((capabilities == null) || (capabilities.length <= 0))
-      return this;
-
-    int maxKeyIndex = _indexedValues.length;
-    Object[] capKeys = new Object[capabilities.length >> 1];
-    Object[] capValues = new Object[capabilities.length >> 1];
-    for (int i = 0, j = 0; i < capabilities.length - 1; i++)
-    {
-      CapabilityKey capKey = (CapabilityKey) capabilities[i++];
-      capKeys[j] = capKey;
-      capValues[j++] = capabilities[i];
-      maxKeyIndex = _max(capKey.getIndex(), maxKeyIndex);
-    }
-
-    //new structures
-    Object[] indexedValues = new Object[maxKeyIndex + 1];
-
-    //Copy the values
-    System.arraycopy(_indexedValues, 0, indexedValues, 0, _indexedValues.length);
-    for (int i = 0; i < capKeys.length; i++)
-    {
-      CapabilityKey capKey = (CapabilityKey) capKeys[i];
-      int keyIndex = capKey.getIndex();
-      indexedValues[keyIndex] = capValues[i];
-    }
-
-    CapabilityMap newImpl = new CapabilityMap();
-    newImpl._indexedValues = indexedValues;
-    return newImpl;
-  }
-
-  //Implementation of Map Methods
-  /**
-   * @param key
-   * @return
-   */
-  public Object get(Object key)
-  {
-    if (key == null)
-      return null;
-
-    if (key instanceof CapabilityKey)
-      return getCapability((CapabilityKey) key);
-
-    return _get(key.toString());
-  }
-
-  /**
-   * @param key
-   * @param value
-   * @return
-   */
-  public Object put(Object key, Object value)
-  {
-    return new UnsupportedOperationException();
-  }
-
-  /**
-   * @return
-   */
-  public Set entrySet()
-  {
-    if (_entrySet == null)
-      _createEntrySet();
-
-    return _entrySet;
-  }
-
-  public Object clone()
-  {
-    try
-    {
-      CapabilityMap that = (CapabilityMap) super.clone();
-      that._indexedValues = (Object[]) _indexedValues.clone();
-      that._entrySet = null;
-      return that;
-    }
-    catch (CloneNotSupportedException cnse)
-    {
-      assert false;
-      return null;
-    }
-  }
-
-  private Object _get(String key)
-  {
-    //key == null should be done before
-    CapabilityKey key0 = null;
-    Object value = null;
-    key0 = CapabilityKey.getCapabilityKey(key);
-    if (key0 != null)
-      value = getCapability(key0);
-
-    return value;
-  }
-
-
-  synchronized private void _createEntrySet()
-  {
-    if (_entrySet == null)
-    {
-      HashSet hs = new HashSet();
-      Iterator iter = new KeyIterator();
-      while (iter.hasNext())
-      {
-        CapabilityKey capKey = (CapabilityKey) iter.next();
-        Object value = getCapability(capKey);
-        CEntry ce = new CEntry(capKey.getCapabilityName(), value);
-        hs.add(ce);
-      }
-      //Don't allow clear(), remove(), etc etc on the map
-      _entrySet = Collections.unmodifiableSet(hs);
-    }
-  }
-
-
-  private int _max(int value1, int value2)
-  {
-    return (value1 > value2 ? value1 : value2);
-  }
-
-
-  private Object[] _getMapAsArray(Map capabilities)
-  {
-    Iterator iter = capabilities.keySet().iterator();
-    Object[] caps = new Object[capabilities.size() * 2];
-    int i = 0;
-    while (iter.hasNext())
-    {
-      Object key = iter.next();
-      CapabilityKey capKey = key instanceof CapabilityKey
-                             ? (CapabilityKey) key
-                             : CapabilityKey.getCapabilityKey((String) key);
-      caps[i++] = capKey;
-      caps[i++] = capabilities.get(key);
-    }
-    return caps;
-  }
-
-
-  //KeyIterator
-  private class KeyIterator implements Iterator
-  {
-    public KeyIterator()
-    {
-      _setNext();
-    }
-
-    public void remove()
-    {
-      throw new UnsupportedOperationException();
-    }
-
-    public boolean hasNext()
-    {
-      if (_next != null)
-        return true;
-      return false;
-    }
-
-    public Object next()
-    {
-      if (_next == null)
-        _setNext();
-
-      if (_next != null)
-      {
-        CapabilityKey next = _next;
-        _setNext();
-        return next;
-      }
-
-      throw new NoSuchElementException();
-    }
-
-    private void _setNext()
-    {
-      _next = null;
-      for (int i = _current; i < _indexedValues.length; i++)
-      {
-        if (_indexedValues[i] != null)
-        {
-          _next = CapabilityKey.getKeyAt(i);
-          _current = ++i;
-          break;
-        }
-      }
-    }
-
-    private int _current = 0;
-    private CapabilityKey _next = null;
-
-  }
-
-
-  //Map Entry
-  private class CEntry implements Entry
-  {
-
-    private Object key;
-    private Object value;
-
-    CEntry(Object key, Object value)
-    {
-      this.key = key;
-      this.value = value;
-    }
-
-    public boolean equals(Object o)
-    {
-      if (this == o)
-        return true;
-
-      if (!(o instanceof CEntry))
-        return false;
-
-      CEntry ce = (CEntry) o;
-      return ((ce.key == key || ce.key.equals(key)) &&
-              (value == null ? ce.value == null : ce.value.equals(value)));
-    }
-
-    public Object getKey()
-    {
-      return key;
-    }
-
-    public Object getValue()
-    {
-      return value;
-    }
-
-    public Object setValue(Object newValue)
-    {
-      throw new UnsupportedOperationException();
-    }
-
-    public int hashCode()
-    {
-      return key.hashCode() ^ (value == null ? 0 : value.hashCode());
-    }
-  }
-
-
-  private Object[] _indexedValues;
-  private Set _entrySet;
+package org.apache.myfaces.adfinternal.agent;
+
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.AbstractMap;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * Pretty much the same Impl of UIX CapabilityMap, with following changes
+ * -- Actually a map implementation now
+ * -- added support to get Entries (To support a map interface)
+ * -- Also this impl assumes that the number of keys **will** change (increase) after init.
+ *
+ */
+public class CapabilityMap extends AbstractMap implements Cloneable
+{
+
+  private CapabilityMap()
+  {
+  }
+
+  CapabilityMap(Object[][] keyValuesArr)
+  {
+
+    int arrayCount = keyValuesArr.length;
+    CapabilityKey[][] keyArrays = new CapabilityKey[arrayCount][];
+
+    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
+    {
+      keyArrays[arrayIndex] = new CapabilityKey[
+              keyValuesArr[arrayIndex] == null ? 0 : (keyValuesArr[arrayIndex].length >> 1)];
+    }
+
+    //Get All the Keys
+    //determine how many keys we need. The keys list/count could change hence
+    //need to find max key index.
+    int maxKeyIndex = 0;
+    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
+    {
+      Object[] keyValues = keyValuesArr[arrayIndex];
+      CapabilityKey[] keys = keyArrays[arrayIndex];
+      int keyCount = keys.length;
+
+      for (int i = 0; i < keyCount; i++)
+      {
+        keys[i] = (CapabilityKey) keyValues[i << 1];
+        maxKeyIndex = _max(keys[i].getIndex(), maxKeyIndex);
+      }
+    }
+
+    _indexedValues = new Object[maxKeyIndex + 1];
+    for (int arrayIndex = 0; arrayIndex < arrayCount; arrayIndex++)
+    {
+      Object[] keyValues = keyValuesArr[arrayIndex];
+      CapabilityKey[] keys = keyArrays[arrayIndex];
+      int keyCount = keys.length;
+
+      for (int i = 0; i < keyCount; i++)
+      {
+        _indexedValues[keys[i].getIndex()] = keyValues[(i << 1) + 1];
+      }
+    }
+  }
+
+
+  /**
+   * @param capKey
+   * @return value object for the capability
+   */
+  public Object getCapability(CapabilityKey capKey)
+  {
+    int keyIndex = capKey.getIndex();
+
+    if (keyIndex < _indexedValues.length)
+      return _indexedValues[keyIndex];
+
+    return null;
+  }
+
+  /**
+   * @param capabilities
+   * @return  returns a new capability map that merges key/values of the provided map
+   */
+  public CapabilityMap merge(Map capabilities)
+  {
+    if ((capabilities == null) || (capabilities.isEmpty()))
+      return this;
+
+    return merge(_getMapAsArray(capabilities));
+  }
+
+
+  /**
+   * @param capabilities
+   * @return
+   */
+  //Doing this as current Impl. uses this method
+  public CapabilityMap merge(Object[] capabilities)
+  {
+    // could simply do this but .....
+    // new CapabilitiesImpl (new Object[][] {_getCapabilitiesAsArray(),
+    //                                       capabilities});
+
+    if ((capabilities == null) || (capabilities.length <= 0))
+      return this;
+
+    int maxKeyIndex = _indexedValues.length;
+    Object[] capKeys = new Object[capabilities.length >> 1];
+    Object[] capValues = new Object[capabilities.length >> 1];
+    for (int i = 0, j = 0; i < capabilities.length - 1; i++)
+    {
+      CapabilityKey capKey = (CapabilityKey) capabilities[i++];
+      capKeys[j] = capKey;
+      capValues[j++] = capabilities[i];
+      maxKeyIndex = _max(capKey.getIndex(), maxKeyIndex);
+    }
+
+    //new structures
+    Object[] indexedValues = new Object[maxKeyIndex + 1];
+
+    //Copy the values
+    System.arraycopy(_indexedValues, 0, indexedValues, 0, _indexedValues.length);
+    for (int i = 0; i < capKeys.length; i++)
+    {
+      CapabilityKey capKey = (CapabilityKey) capKeys[i];
+      int keyIndex = capKey.getIndex();
+      indexedValues[keyIndex] = capValues[i];
+    }
+
+    CapabilityMap newImpl = new CapabilityMap();
+    newImpl._indexedValues = indexedValues;
+    return newImpl;
+  }
+
+  //Implementation of Map Methods
+  /**
+   * @param key
+   * @return
+   */
+  public Object get(Object key)
+  {
+    if (key == null)
+      return null;
+
+    if (key instanceof CapabilityKey)
+      return getCapability((CapabilityKey) key);
+
+    return _get(key.toString());
+  }
+
+  /**
+   * @param key
+   * @param value
+   * @return
+   */
+  public Object put(Object key, Object value)
+  {
+    return new UnsupportedOperationException();
+  }
+
+  /**
+   * @return
+   */
+  public Set entrySet()
+  {
+    if (_entrySet == null)
+      _createEntrySet();
+
+    return _entrySet;
+  }
+
+  public Object clone()
+  {
+    try
+    {
+      CapabilityMap that = (CapabilityMap) super.clone();
+      that._indexedValues = (Object[]) _indexedValues.clone();
+      that._entrySet = null;
+      return that;
+    }
+    catch (CloneNotSupportedException cnse)
+    {
+      assert false;
+      return null;
+    }
+  }
+
+  private Object _get(String key)
+  {
+    //key == null should be done before
+    CapabilityKey key0 = null;
+    Object value = null;
+    key0 = CapabilityKey.getCapabilityKey(key);
+    if (key0 != null)
+      value = getCapability(key0);
+
+    return value;
+  }
+
+
+  synchronized private void _createEntrySet()
+  {
+    if (_entrySet == null)
+    {
+      HashSet hs = new HashSet();
+      Iterator iter = new KeyIterator();
+      while (iter.hasNext())
+      {
+        CapabilityKey capKey = (CapabilityKey) iter.next();
+        Object value = getCapability(capKey);
+        CEntry ce = new CEntry(capKey.getCapabilityName(), value);
+        hs.add(ce);
+      }
+      //Don't allow clear(), remove(), etc etc on the map
+      _entrySet = Collections.unmodifiableSet(hs);
+    }
+  }
+
+
+  private int _max(int value1, int value2)
+  {
+    return (value1 > value2 ? value1 : value2);
+  }
+
+
+  private Object[] _getMapAsArray(Map capabilities)
+  {
+    Iterator iter = capabilities.keySet().iterator();
+    Object[] caps = new Object[capabilities.size() * 2];
+    int i = 0;
+    while (iter.hasNext())
+    {
+      Object key = iter.next();
+      CapabilityKey capKey = key instanceof CapabilityKey
+                             ? (CapabilityKey) key
+                             : CapabilityKey.getCapabilityKey((String) key);
+      caps[i++] = capKey;
+      caps[i++] = capabilities.get(key);
+    }
+    return caps;
+  }
+
+
+  //KeyIterator
+  private class KeyIterator implements Iterator
+  {
+    public KeyIterator()
+    {
+      _setNext();
+    }
+
+    public void remove()
+    {
+      throw new UnsupportedOperationException();
+    }
+
+    public boolean hasNext()
+    {
+      if (_next != null)
+        return true;
+      return false;
+    }
+
+    public Object next()
+    {
+      if (_next == null)
+        _setNext();
+
+      if (_next != null)
+      {
+        CapabilityKey next = _next;
+        _setNext();
+        return next;
+      }
+
+      throw new NoSuchElementException();
+    }
+
+    private void _setNext()
+    {
+      _next = null;
+      for (int i = _current; i < _indexedValues.length; i++)
+      {
+        if (_indexedValues[i] != null)
+        {
+          _next = CapabilityKey.getKeyAt(i);
+          _current = ++i;
+          break;
+        }
+      }
+    }
+
+    private int _current = 0;
+    private CapabilityKey _next = null;
+
+  }
+
+
+  //Map Entry
+  private class CEntry implements Entry
+  {
+
+    private Object key;
+    private Object value;
+
+    CEntry(Object key, Object value)
+    {
+      this.key = key;
+      this.value = value;
+    }
+
+    public boolean equals(Object o)
+    {
+      if (this == o)
+        return true;
+
+      if (!(o instanceof CEntry))
+        return false;
+
+      CEntry ce = (CEntry) o;
+      return ((ce.key == key || ce.key.equals(key)) &&
+              (value == null ? ce.value == null : ce.value.equals(value)));
+    }
+
+    public Object getKey()
+    {
+      return key;
+    }
+
+    public Object getValue()
+    {
+      return value;
+    }
+
+    public Object setValue(Object newValue)
+    {
+      throw new UnsupportedOperationException();
+    }
+
+    public int hashCode()
+    {
+      return key.hashCode() ^ (value == null ? 0 : value.hashCode());
+    }
+  }
+
+
+  private Object[] _indexedValues;
+  private Set _entrySet;
 }

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityValue.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityValue.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityValue.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityValue.java Mon Jul 24 21:42:41 2006
@@ -13,64 +13,64 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent;
-
-import java.util.HashMap;
-
-public class CapabilityValue
-{
-  //AdfFacesAgent (the old Agent) uses Objects constants for 
-  //capability values, and the code base uses identity comaprison
-  //to check for a capability value.
- 
-  //With the new Agent, the values are in a file and are string objects.
-  //So one way of making the identity comparison still work is to perform
-  //an string.intern() on the values read from the file.
- 
-  //Also string values need to be retained, as need to support
-  //clients accessing the Agent Api (AdfFacesContext object constants 
-  //are internal impl)
-  
-  //This is a poor man's quick substitute for string.intern().
-  //Later, need to refine this properly.
-  //Based on key, can know the value type object. Need metadata info on key
-  public final static Object getCapabilityValue (CapabilityKey key,
-                                                 Object value)
-  {
-    if (value instanceof String)
-    {
-      String stringValue = (String) value;
-      if (stringValue.length() == 0)
-        return null;
-      if (Character.isDigit(stringValue.charAt(0)))
-      {
-        try
-        {
-          return Integer.valueOf(stringValue);
-        }
-        catch (NumberFormatException nfe)
-        {
-        }
-      }
-      
-      if ("true".equals(value))
-        return Boolean.TRUE;
-      else if ("false".equals(value))
-        return Boolean.FALSE;
-    }
-    
-    return _getValue(value);
-  }
-  
-  synchronized static private Object _getValue(Object value)
-  {
-    Object cValue =  _values.get(value);
-    if (cValue != null)
-      return cValue;
-
-    _values.put(value, value);
-    return value;
-  }
-  
-  private static HashMap _values = new HashMap(32);
+package org.apache.myfaces.adfinternal.agent;
+
+import java.util.HashMap;
+
+public class CapabilityValue
+{
+  //AdfFacesAgent (the old Agent) uses Objects constants for 
+  //capability values, and the code base uses identity comaprison
+  //to check for a capability value.
+ 
+  //With the new Agent, the values are in a file and are string objects.
+  //So one way of making the identity comparison still work is to perform
+  //an string.intern() on the values read from the file.
+ 
+  //Also string values need to be retained, as need to support
+  //clients accessing the Agent Api (AdfFacesContext object constants 
+  //are internal impl)
+  
+  //This is a poor man's quick substitute for string.intern().
+  //Later, need to refine this properly.
+  //Based on key, can know the value type object. Need metadata info on key
+  public final static Object getCapabilityValue (CapabilityKey key,
+                                                 Object value)
+  {
+    if (value instanceof String)
+    {
+      String stringValue = (String) value;
+      if (stringValue.length() == 0)
+        return null;
+      if (Character.isDigit(stringValue.charAt(0)))
+      {
+        try
+        {
+          return Integer.valueOf(stringValue);
+        }
+        catch (NumberFormatException nfe)
+        {
+        }
+      }
+      
+      if ("true".equals(value))
+        return Boolean.TRUE;
+      else if ("false".equals(value))
+        return Boolean.FALSE;
+    }
+    
+    return _getValue(value);
+  }
+  
+  synchronized static private Object _getValue(Object value)
+  {
+    Object cValue =  _values.get(value);
+    if (cValue != null)
+      return cValue;
+
+    _values.put(value, value);
+    return value;
+  }
+  
+  private static HashMap _values = new HashMap(32);
 }

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/CapabilityValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DefaultAgent.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DefaultAgent.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DefaultAgent.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DefaultAgent.java Mon Jul 24 21:42:41 2006
@@ -13,87 +13,87 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent;
-
-import org.apache.myfaces.adf.context.Agent;
-
-import java.util.Map;
-
-
-/**
- * Default base class for Agent
- */
-public class DefaultAgent implements Agent
-{
-  /**
-   *
-   * @return return the Type of Agent. Returns <code>TYPE_UNKNOWN</code> if not available.
-   * <br>E.g. desktop, pda, phone
-   *
-   */
-  public Object getType() {
-     return TYPE_UNKNOWN;
-  }
-  /**
-   *
-   * @return return the canonical name of the Agent. Returns <code>null</code> if not available.
-   * <br>E.g. gecko, ie, opera, pocketie
-   *
-   */
-  public String getAgentName()
-  {
-    return null;
-  }
-
-  /**
-   *
-   * @return return the version number of the Agent. Return <code>null</code> if not available.
-   *
-   */
-  public String getAgentVersion()
-  {
-    return null;
-  }
-
-  /**
-   *
-   * @return return the canonical name for the platform. Returns <code>null</code> if not available.
-   *  <br>E.g ppc, series60, windows, mac, linux, solaris
-   */
-  public String getPlatformName()
-  {
-    return null;
-  }
-
-
-  /**
-   *
-   * @return return the version number for the platform. Returns <code>null</code> if not available.
-   */
-  public String getPlatformVersion()
-  {
-    return null;
-  }
-
-
-  /**
-   *
-   * @return return a canonical name for the Hardware make and Model. Returns <code>null</code> if not available.
-   * <br>E.g nokia6600, sonyericssonP900, nokai3650i
-   */
-  public String getHardwareMakeModel()
-  {
-    return null;
-  }
-
-
-  /**
-   *
-   * @return Map of capability name and value for the current Agent.
-   */
-  public Map getCapabilities ()
-  {
-    return null;
-  }  
-
-}
+package org.apache.myfaces.adfinternal.agent;
+
+import org.apache.myfaces.adf.context.Agent;
+
+import java.util.Map;
+
+
+/**
+ * Default base class for Agent
+ */
+public class DefaultAgent implements Agent
+{
+  /**
+   *
+   * @return return the Type of Agent. Returns <code>TYPE_UNKNOWN</code> if not available.
+   * <br>E.g. desktop, pda, phone
+   *
+   */
+  public Object getType() {
+     return TYPE_UNKNOWN;
+  }
+  /**
+   *
+   * @return return the canonical name of the Agent. Returns <code>null</code> if not available.
+   * <br>E.g. gecko, ie, opera, pocketie
+   *
+   */
+  public String getAgentName()
+  {
+    return null;
+  }
+
+  /**
+   *
+   * @return return the version number of the Agent. Return <code>null</code> if not available.
+   *
+   */
+  public String getAgentVersion()
+  {
+    return null;
+  }
+
+  /**
+   *
+   * @return return the canonical name for the platform. Returns <code>null</code> if not available.
+   *  <br>E.g ppc, series60, windows, mac, linux, solaris
+   */
+  public String getPlatformName()
+  {
+    return null;
+  }
+
+
+  /**
+   *
+   * @return return the version number for the platform. Returns <code>null</code> if not available.
+   */
+  public String getPlatformVersion()
+  {
+    return null;
+  }
+
+
+  /**
+   *
+   * @return return a canonical name for the Hardware make and Model. Returns <code>null</code> if not available.
+   * <br>E.g nokia6600, sonyericssonP900, nokai3650i
+   */
+  public String getHardwareMakeModel()
+  {
+    return null;
+  }
+
+
+  /**
+   *
+   * @return Map of capability name and value for the current Agent.
+   */
+  public Map getCapabilities ()
+  {
+    return null;
+  }  
+
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DefaultAgent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DeviceRepository.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DeviceRepository.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DeviceRepository.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DeviceRepository.java Mon Jul 24 21:42:41 2006
@@ -13,14 +13,14 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent;
-
-import javax.faces.context.FacesContext;
-import org.apache.myfaces.adf.context.Agent;
-
-public abstract class DeviceRepository
-{
-  public abstract CapabilityMap getCapabilityMap(
-    FacesContext context,
-    Agent        agent);
-}
+package org.apache.myfaces.adfinternal.agent;
+
+import javax.faces.context.FacesContext;
+import org.apache.myfaces.adf.context.Agent;
+
+public abstract class DeviceRepository
+{
+  public abstract CapabilityMap getCapabilityMap(
+    FacesContext context,
+    Agent        agent);
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/DeviceRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocument.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocument.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocument.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocument.java Mon Jul 24 21:42:41 2006
@@ -13,346 +13,346 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent.parse;
-
-import org.apache.myfaces.adf.logging.ADFLogger;
-import org.apache.myfaces.adf.context.Agent;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-import java.net.URL;
-
-
-/**
- * implementation of Capabilities document
- * only the capabilities provider needs to know about the document.
- */
-public class CapabilitiesDocument
-{
-
-  CapabilitiesDocument(CapabilitiesNode[] agents, DeviceNode[] devices)
-  {
-    _agents = agents;
-    _devices = devices;
-    _defaultAgentCapabilities = _getDefaultAgentCapabilities(_agents);
-  }
-
-
-  private CapabilitiesDocument()
-  {
-    this(null, null);
-  }
-
-  /**
-   * @param agent
-   * @return An array of Capabilities {name, value, name, value}.
-   * The array may have duplicates and is ordered in ascending order (priority)
-   */
-  public Object[][] getCapabilities(Agent agent)
-  {
-    Object[][] agentCaps = null;
-    //TODO: Right now we go by best match. But May be we should
-    //get all that nodes that matched (sort by match score) and merge
-    //This way the xml file would be simpler (--or more cryptic??)
-    CapabilitiesNode agentMatchedNode = _getAgentCapabiltiesNode(agent);
-    if (agentMatchedNode != null)
-      agentCaps = _getCapabilities(agent, _agents, null, agentMatchedNode);
-
-
-
-    //Now get the capabilities of the device, if it is known
-    // - Match the correct device node
-    // - Get the components in the device
-    // - resolve the capabilities of the components
-    // - If agent name is aavailable and is not "UNKNOWN" then
-    //   use the capabilities of the agent (instead of the capabilities of the
-    //   browser component). We need to do this as request could be from a agent
-    //   like opera, but the device default browser may be something else.
-    //TODO: Need to support a "extends" mechanism for devices, so that one device
-    //can extend capabilities from a similar device.
-    DeviceNode dNode = _getDeviceNode(agent);
-    if (dNode != null)
-    {
-      DeviceComponentNode[] cNodes = dNode.__getComponents();
-      if (cNodes == null)
-        return agentCaps;
-
-      Object[][][] deviceCaps = new Object[cNodes.length][][];
-      for (int i = 0; i < cNodes.length; i++)
-      {
-        if ((cNodes[i].__getType() == DeviceComponentNode.TYPE_BROWSER) &&
-            (agent.getAgentName() != null))
-        {
-          deviceCaps[i] = agentCaps;
-        }
-        else
-        {
-          deviceCaps[i] = _getCapabilities(agent, _agents, cNodes[i]);
-        }
-      }
-
-      return _mergeCaps(deviceCaps, null);
-    }
-
-    //if device is null return agentCaps
-    //if agentName is also null then return
-    //default agentCaps
-    if (agentCaps != null)
-      return agentCaps;
-
-    return _defaultAgentCapabilities;
-  }
-
-
-  private Object[][] _getDefaultAgentCapabilities(CapabilitiesNode[] agents)
-  {
-    if (_agents == null)
-      return null;
-
-    for (int i = 0; i < _agents.length; i++)
-    {
-      if (agents[i].__isDefault())
-      {
-        return _getCapabilities(null, _agents, null, _agents[i]);
-      }
-    }
-
-    return null;
-  }
-
-  /**
-   * @param agent
-   * @return the capabilities node that best matches for current Agent
-   */
-  private CapabilitiesNode _getAgentCapabiltiesNode(Agent agent)
-  {
-    if (_agents == null)
-      return null;
-    //get the best match node
-    double maxScore = 0;
-    CapabilitiesNode agentMatchedNode = null;
-    for (int i = 0; i < _agents.length; i++)
-    {
-      double score = _agents[i].__matches(agent);
-      if ((score > 0) && (score > maxScore))
-      {
-        maxScore = score;
-        agentMatchedNode = _agents[i];
-      }
-    }
-    return agentMatchedNode;
-  }
-
-
-  /**
-   * @param agent
-   * @return device node that best matches the current Agent
-   */
-  private DeviceNode _getDeviceNode(Agent agent)
-  {
-    if (_devices == null)
-       return null;
-
-    double maxScore = 0;
-    DeviceNode deviceNode = null;
-    for (int i = 0; i < _devices.length; i++)
-    {
-      double score = _devices[i].__matches(agent);
-      if ((score > 0) && (score > maxScore))
-      {
-        maxScore = score;
-        deviceNode = _devices[i];
-      }
-    }
-    return deviceNode;
-  }
-
-
-  /**
-   * Get/resolve the capabilities for for a give capabilitiesNode
-   */
-  private Object[][] _getCapabilities(Agent agent,
-                                      CapabilitiesNode[] capNodes,
-                                      List includedByRefs,
-                                      CapabilitiesNode matchNode)
-  {
-    assert (matchNode != null);
-
-    if (capNodes == null)
-      return new Object[0][0];
-
-    //--do we need to bother about caching (a resolved state)
-    //for each node? Not until this becomes a problem
-
-    //check for circular dependecy
-    if (includedByRefs == null)
-      includedByRefs = new ArrayList();
-
-    if (matchNode.__getId() != null)
-    {
-      if (includedByRefs.contains(matchNode.__getId()))
-      {
-        _LOG.warning("Invalid dependency found in include by reference");
-        return new Object[0][0];
-      }
-
-      includedByRefs.add(matchNode.__getId());
-    }
-
-    //process node that includes by reference
-    IncludeNode[] refIncludes = matchNode.__getIncludesByRef();
-    Object[][][] refCaps = null;
-    if (refIncludes != null)
-    {
-      refCaps = new Object[refIncludes.length][][];
-      for (int i = 0; i < refIncludes.length; i++)
-      {
-        assert (refIncludes[i].__getRefId() != null);
-        refCaps[i] = _getCapabilities(agent, capNodes,
-                                      includedByRefs, refIncludes[i].__getRefId());
-      }
-    }
-
-    //process nodes the includes a external file
-    IncludeNode[] uriIncludes = matchNode.__getIncludesByUri();
-    Object[][] uriCaps = null;
-    if (uriIncludes != null)
-    {
-      uriCaps = new Object[uriIncludes.length][];
-      for (int i = 0; i < uriIncludes.length; i++)
-      {
-        assert (uriIncludes[i].__getSrcUrl() != null);
-        uriCaps[i] = _getCapabilities(uriIncludes[i].__getSrcUrl());
-        assert (uriCaps[i] != null);
-      }
-    }
-
-    return _mergeCaps(refCaps, uriCaps);
-  }
-
-
-  private Object[][] _getCapabilities(Agent agent,
-                                      CapabilitiesNode[] capNodes,
-                                      DeviceComponentNode dcNode)
-  {
-
-    assert (capNodes != null);
-    assert (dcNode != null);
-
-    ArrayList includedByRefs = new ArrayList();
-
-    //process node that includes by reference
-    IncludeNode[] refIncludes = dcNode.__getIncludesByRef();
-    Object[][][] refCaps = null;
-    if (refIncludes != null)
-    {
-      refCaps = new Object[refIncludes.length][][];
-      for (int i = 0; i < refIncludes.length; i++)
-      {
-        assert (refIncludes[i].__getRefId() != null);
-        refCaps[i] = _getCapabilities(agent, capNodes,
-                                      includedByRefs, refIncludes[i].__getRefId());
-      }
-    }
-
-    //process nodes the includes a external file
-    IncludeNode[] uriIncludes = dcNode.__getIncludesByUri();
-    Object[][] uriCaps = null;
-    if (uriIncludes != null)
-    {
-      uriCaps = new Object[uriIncludes.length][];
-      for (int i = 0; i < uriIncludes.length; i++)
-      {
-        assert (uriIncludes[i].__getSrcUrl() != null);
-        uriCaps[i] = _getCapabilities(uriIncludes[i].__getSrcUrl());
-        assert (uriCaps[i] != null);
-      }
-    }
-
-    return _mergeCaps(refCaps, uriCaps);
-  }
-
-
-  /**
-   * get capabilties of node using a node refid
-   */
-  private Object[][] _getCapabilities(Agent agent,
-                                      CapabilitiesNode[] capNodes,
-                                      List includedByRefs,
-                                      String refId)
-  {
-    assert (capNodes != null);
-    assert (refId != null);
-    assert (includedByRefs != null);
-
-    for (int i = 0; i < capNodes.length; i++)
-    {
-      if (refId.equals(capNodes[i].__getId()))
-      {
-        Object[][] caps = _getCapabilities(agent, capNodes, includedByRefs, capNodes[i]);
-        return caps;
-      }
-    }
-
-    _LOG.warning("Reference to id: " + refId + " not found");
-    return new Object[0][0];
-  }
-
-
-  /**
-   * capabilities from parsed and cached capability data documents
-   */
-  private Object[] _getCapabilities(URL srcUrl)
-  {
-    Object o = includeNodeBySrcCaps.get(srcUrl);
-    if (o != null)
-      return (Object[]) o;
-
-    Object[] caps = null;
-    synchronized (includeNodeBySrcCaps)
-    {
-      caps = CapabilityDataDocumentParser.parse(srcUrl);
-      includeNodeBySrcCaps.put(srcUrl, caps);
-    }
-
-    return caps;
-  }
-
-  //merge capabilities array
-  private Object[][] _mergeCaps(Object[][][] caps1, Object[][] caps2)
-  {
-    if (caps1 == null)
-      return caps2;
-
-    int len = 0;
-    for (int i = 0; i < caps1.length; i++)
-    {
-      len += caps1[i].length;
-    }
-
-    Object[][] merged = new Object[len + (caps2 == null ? 0 : caps2.length)][];
-    len = 0;
-    for (int i = 0; i < caps1.length; i++)
-    {
-      System.arraycopy(caps1[i], 0, merged, len, caps1[i].length);
-      len += caps1[i].length;
-    }
-
-    if (caps2 != null)
-      System.arraycopy(caps2, 0, merged, len, caps2.length);
-
-    return merged;
-  }
-
-
-  private CapabilitiesNode[] _agents;
-  private DeviceNode[] _devices;
-  private HashMap includeNodeBySrcCaps = new HashMap();
-  private Object[][] _defaultAgentCapabilities;
-
-  static final CapabilitiesDocument EMPTY_DOCUMENT = new CapabilitiesDocument();
-
-  private static ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesDocument.class);
-
-}
+package org.apache.myfaces.adfinternal.agent.parse;
+
+import org.apache.myfaces.adf.logging.ADFLogger;
+import org.apache.myfaces.adf.context.Agent;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.net.URL;
+
+
+/**
+ * implementation of Capabilities document
+ * only the capabilities provider needs to know about the document.
+ */
+public class CapabilitiesDocument
+{
+
+  CapabilitiesDocument(CapabilitiesNode[] agents, DeviceNode[] devices)
+  {
+    _agents = agents;
+    _devices = devices;
+    _defaultAgentCapabilities = _getDefaultAgentCapabilities(_agents);
+  }
+
+
+  private CapabilitiesDocument()
+  {
+    this(null, null);
+  }
+
+  /**
+   * @param agent
+   * @return An array of Capabilities {name, value, name, value}.
+   * The array may have duplicates and is ordered in ascending order (priority)
+   */
+  public Object[][] getCapabilities(Agent agent)
+  {
+    Object[][] agentCaps = null;
+    //TODO: Right now we go by best match. But May be we should
+    //get all that nodes that matched (sort by match score) and merge
+    //This way the xml file would be simpler (--or more cryptic??)
+    CapabilitiesNode agentMatchedNode = _getAgentCapabiltiesNode(agent);
+    if (agentMatchedNode != null)
+      agentCaps = _getCapabilities(agent, _agents, null, agentMatchedNode);
+
+
+
+    //Now get the capabilities of the device, if it is known
+    // - Match the correct device node
+    // - Get the components in the device
+    // - resolve the capabilities of the components
+    // - If agent name is aavailable and is not "UNKNOWN" then
+    //   use the capabilities of the agent (instead of the capabilities of the
+    //   browser component). We need to do this as request could be from a agent
+    //   like opera, but the device default browser may be something else.
+    //TODO: Need to support a "extends" mechanism for devices, so that one device
+    //can extend capabilities from a similar device.
+    DeviceNode dNode = _getDeviceNode(agent);
+    if (dNode != null)
+    {
+      DeviceComponentNode[] cNodes = dNode.__getComponents();
+      if (cNodes == null)
+        return agentCaps;
+
+      Object[][][] deviceCaps = new Object[cNodes.length][][];
+      for (int i = 0; i < cNodes.length; i++)
+      {
+        if ((cNodes[i].__getType() == DeviceComponentNode.TYPE_BROWSER) &&
+            (agent.getAgentName() != null))
+        {
+          deviceCaps[i] = agentCaps;
+        }
+        else
+        {
+          deviceCaps[i] = _getCapabilities(agent, _agents, cNodes[i]);
+        }
+      }
+
+      return _mergeCaps(deviceCaps, null);
+    }
+
+    //if device is null return agentCaps
+    //if agentName is also null then return
+    //default agentCaps
+    if (agentCaps != null)
+      return agentCaps;
+
+    return _defaultAgentCapabilities;
+  }
+
+
+  private Object[][] _getDefaultAgentCapabilities(CapabilitiesNode[] agents)
+  {
+    if (_agents == null)
+      return null;
+
+    for (int i = 0; i < _agents.length; i++)
+    {
+      if (agents[i].__isDefault())
+      {
+        return _getCapabilities(null, _agents, null, _agents[i]);
+      }
+    }
+
+    return null;
+  }
+
+  /**
+   * @param agent
+   * @return the capabilities node that best matches for current Agent
+   */
+  private CapabilitiesNode _getAgentCapabiltiesNode(Agent agent)
+  {
+    if (_agents == null)
+      return null;
+    //get the best match node
+    double maxScore = 0;
+    CapabilitiesNode agentMatchedNode = null;
+    for (int i = 0; i < _agents.length; i++)
+    {
+      double score = _agents[i].__matches(agent);
+      if ((score > 0) && (score > maxScore))
+      {
+        maxScore = score;
+        agentMatchedNode = _agents[i];
+      }
+    }
+    return agentMatchedNode;
+  }
+
+
+  /**
+   * @param agent
+   * @return device node that best matches the current Agent
+   */
+  private DeviceNode _getDeviceNode(Agent agent)
+  {
+    if (_devices == null)
+       return null;
+
+    double maxScore = 0;
+    DeviceNode deviceNode = null;
+    for (int i = 0; i < _devices.length; i++)
+    {
+      double score = _devices[i].__matches(agent);
+      if ((score > 0) && (score > maxScore))
+      {
+        maxScore = score;
+        deviceNode = _devices[i];
+      }
+    }
+    return deviceNode;
+  }
+
+
+  /**
+   * Get/resolve the capabilities for for a give capabilitiesNode
+   */
+  private Object[][] _getCapabilities(Agent agent,
+                                      CapabilitiesNode[] capNodes,
+                                      List includedByRefs,
+                                      CapabilitiesNode matchNode)
+  {
+    assert (matchNode != null);
+
+    if (capNodes == null)
+      return new Object[0][0];
+
+    //--do we need to bother about caching (a resolved state)
+    //for each node? Not until this becomes a problem
+
+    //check for circular dependecy
+    if (includedByRefs == null)
+      includedByRefs = new ArrayList();
+
+    if (matchNode.__getId() != null)
+    {
+      if (includedByRefs.contains(matchNode.__getId()))
+      {
+        _LOG.warning("Invalid dependency found in include by reference");
+        return new Object[0][0];
+      }
+
+      includedByRefs.add(matchNode.__getId());
+    }
+
+    //process node that includes by reference
+    IncludeNode[] refIncludes = matchNode.__getIncludesByRef();
+    Object[][][] refCaps = null;
+    if (refIncludes != null)
+    {
+      refCaps = new Object[refIncludes.length][][];
+      for (int i = 0; i < refIncludes.length; i++)
+      {
+        assert (refIncludes[i].__getRefId() != null);
+        refCaps[i] = _getCapabilities(agent, capNodes,
+                                      includedByRefs, refIncludes[i].__getRefId());
+      }
+    }
+
+    //process nodes the includes a external file
+    IncludeNode[] uriIncludes = matchNode.__getIncludesByUri();
+    Object[][] uriCaps = null;
+    if (uriIncludes != null)
+    {
+      uriCaps = new Object[uriIncludes.length][];
+      for (int i = 0; i < uriIncludes.length; i++)
+      {
+        assert (uriIncludes[i].__getSrcUrl() != null);
+        uriCaps[i] = _getCapabilities(uriIncludes[i].__getSrcUrl());
+        assert (uriCaps[i] != null);
+      }
+    }
+
+    return _mergeCaps(refCaps, uriCaps);
+  }
+
+
+  private Object[][] _getCapabilities(Agent agent,
+                                      CapabilitiesNode[] capNodes,
+                                      DeviceComponentNode dcNode)
+  {
+
+    assert (capNodes != null);
+    assert (dcNode != null);
+
+    ArrayList includedByRefs = new ArrayList();
+
+    //process node that includes by reference
+    IncludeNode[] refIncludes = dcNode.__getIncludesByRef();
+    Object[][][] refCaps = null;
+    if (refIncludes != null)
+    {
+      refCaps = new Object[refIncludes.length][][];
+      for (int i = 0; i < refIncludes.length; i++)
+      {
+        assert (refIncludes[i].__getRefId() != null);
+        refCaps[i] = _getCapabilities(agent, capNodes,
+                                      includedByRefs, refIncludes[i].__getRefId());
+      }
+    }
+
+    //process nodes the includes a external file
+    IncludeNode[] uriIncludes = dcNode.__getIncludesByUri();
+    Object[][] uriCaps = null;
+    if (uriIncludes != null)
+    {
+      uriCaps = new Object[uriIncludes.length][];
+      for (int i = 0; i < uriIncludes.length; i++)
+      {
+        assert (uriIncludes[i].__getSrcUrl() != null);
+        uriCaps[i] = _getCapabilities(uriIncludes[i].__getSrcUrl());
+        assert (uriCaps[i] != null);
+      }
+    }
+
+    return _mergeCaps(refCaps, uriCaps);
+  }
+
+
+  /**
+   * get capabilties of node using a node refid
+   */
+  private Object[][] _getCapabilities(Agent agent,
+                                      CapabilitiesNode[] capNodes,
+                                      List includedByRefs,
+                                      String refId)
+  {
+    assert (capNodes != null);
+    assert (refId != null);
+    assert (includedByRefs != null);
+
+    for (int i = 0; i < capNodes.length; i++)
+    {
+      if (refId.equals(capNodes[i].__getId()))
+      {
+        Object[][] caps = _getCapabilities(agent, capNodes, includedByRefs, capNodes[i]);
+        return caps;
+      }
+    }
+
+    _LOG.warning("Reference to id: " + refId + " not found");
+    return new Object[0][0];
+  }
+
+
+  /**
+   * capabilities from parsed and cached capability data documents
+   */
+  private Object[] _getCapabilities(URL srcUrl)
+  {
+    Object o = includeNodeBySrcCaps.get(srcUrl);
+    if (o != null)
+      return (Object[]) o;
+
+    Object[] caps = null;
+    synchronized (includeNodeBySrcCaps)
+    {
+      caps = CapabilityDataDocumentParser.parse(srcUrl);
+      includeNodeBySrcCaps.put(srcUrl, caps);
+    }
+
+    return caps;
+  }
+
+  //merge capabilities array
+  private Object[][] _mergeCaps(Object[][][] caps1, Object[][] caps2)
+  {
+    if (caps1 == null)
+      return caps2;
+
+    int len = 0;
+    for (int i = 0; i < caps1.length; i++)
+    {
+      len += caps1[i].length;
+    }
+
+    Object[][] merged = new Object[len + (caps2 == null ? 0 : caps2.length)][];
+    len = 0;
+    for (int i = 0; i < caps1.length; i++)
+    {
+      System.arraycopy(caps1[i], 0, merged, len, caps1[i].length);
+      len += caps1[i].length;
+    }
+
+    if (caps2 != null)
+      System.arraycopy(caps2, 0, merged, len, caps2.length);
+
+    return merged;
+  }
+
+
+  private CapabilitiesNode[] _agents;
+  private DeviceNode[] _devices;
+  private HashMap includeNodeBySrcCaps = new HashMap();
+  private Object[][] _defaultAgentCapabilities;
+
+  static final CapabilitiesDocument EMPTY_DOCUMENT = new CapabilitiesDocument();
+
+  private static ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesDocument.class);
+
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocument.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocumentParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocumentParser.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocumentParser.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocumentParser.java Mon Jul 24 21:42:41 2006
@@ -13,182 +13,182 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent.parse;
-
-import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXParseException;
-
-import org.apache.myfaces.adf.logging.ADFLogger;
-import org.apache.myfaces.adfinternal.share.xml.ParseContextImpl;
-
-import org.apache.myfaces.adfinternal.share.xml.TreeBuilder;
-import org.apache.myfaces.adfinternal.share.xml.BaseNodeParser;
-import org.apache.myfaces.adfinternal.share.xml.ParseContext;
-import org.apache.myfaces.adfinternal.share.xml.NodeParser;
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Parser for parsing capabilities document
- */
-public class CapabilitiesDocumentParser extends BaseNodeParser
-        implements XMLConstants
-{
-
-  private CapabilitiesDocumentParser() {}
-
-  static public CapabilitiesDocument createInstance (URL capUrl)
-  {
-    //if URL is null return empty documen
-    if (capUrl == null)
-      return CapabilitiesDocument.EMPTY_DOCUMENT;
-
-    CapabilitiesDocumentParser parser = new CapabilitiesDocumentParser();
-    InputStream stream = null;
-    try
-    {
-      URLConnection connection = capUrl.openConnection();
-      stream = connection.getInputStream();
-
-      InputSource source = new InputSource(stream);
-      source.setSystemId(capUrl.toExternalForm());
-
-      ParseContextImpl pc = new ParseContextImpl ();
-      pc.setProperty(NS_URI, __BASE_URL, capUrl);
-      TreeBuilder builder =  new  TreeBuilder();
-      return (CapabilitiesDocument) builder.parse(null, source, pc, parser);
-
-    }
-    catch (SAXException saxe)
-    {
-      //Logging handled by tree builder
-      //_LOG.severe("Failed to parse capabilities document", saxe);
-      ;
-    }
-    catch (IOException ioe)
-    {
-      _LOG.severe("Failed to parse capabilities document", ioe);
-    }
-    finally
-    {
-      try
-      {
-        if (stream != null)
-          stream.close();
-      }
-      catch (IOException e)
-      {
-        //do nothing
-        ;
-      }
-    }
-
-    return CapabilitiesDocument.EMPTY_DOCUMENT;
-  }
-
-
-  public void startElement (ParseContext context,
-                            String       namespaceURI,
-                            String       localName,
-                            Attributes   attrs )
-          throws SAXParseException
-  {
-    if (!NS_URI.equals(namespaceURI))
-    {
-      throw new SAXParseException("Invalid Namespace: " +
-                                  namespaceURI, context.getLocator());
-    }
-
-    if (!ELEMENT_ROOT.equals(localName))
-    {
-      throw new SAXParseException("Invalid Root Element: " +
-                                  localName, context.getLocator());
-    }
-  }
-
-
-  public NodeParser startChildElement(ParseContext context,
-                                      String       namespaceURI,
-                                      String       localName,
-                                      Attributes   attrs)
-          throws SAXParseException
-  {
-    if (ELEMENT_AGENT_CAPABILITIES.equals(localName))
-    {
-      return this;
-    }
-    else if (ELEMENT_DEVICES.equals(localName))
-    {
-      return this;
-    }
-    else if (ELEMENT_CAPABILITIES.equals(localName))
-    {
-      return new CapabilitiesNodeParser();
-    }
-    else if (ELEMENT_DEVICE.equals(localName))
-    {
-      return new DeviceNodeParser();
-    }
-
-    //return null, if not a known element
-    return null;
-  }
-
-
-  public void addCompletedChild (ParseContext context,
-                                 String       namespaceURI,
-                                 String       localName,
-                                 Object       child)
-          throws SAXParseException
-  {
-    if (child == null)
-      return;
-
-    if (ELEMENT_CAPABILITIES.equals(localName))
-      _capabilitiesNodes.add(child);
-
-    if (ELEMENT_DEVICE.equals(localName))
-      _deviceNodes.add(child);
-  }
-
-
-  public Object endElement (ParseContext context,
-                            String       namespaceURI,
-                            String       localName)
-  {
-    if (!ELEMENT_ROOT.equals(localName))
-      return null;
-
-    CapabilitiesNode[] agents = null;
-    if (_capabilitiesNodes.size() > 0)
-    {
-      agents = (CapabilitiesNode[]) _capabilitiesNodes.toArray
-              (new CapabilitiesNode[_capabilitiesNodes.size()]);
-    }
-
-    DeviceNode[] devices = null;
-    if (_deviceNodes.size() > 0)
-    {
-      devices = (DeviceNode[]) _deviceNodes.toArray
-              (new DeviceNode[_deviceNodes.size()]);
-    }
-
-    CapabilitiesDocument document = new CapabilitiesDocument(agents, devices);
-    return document;
-  }
-
-  private List _capabilitiesNodes = new ArrayList();
-  private List _deviceNodes = new ArrayList();
-
-  static final String __BASE_URL = "baseURL";
-
-  static private final ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesDocumentParser.class);
-}
+package org.apache.myfaces.adfinternal.agent.parse;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXParseException;
+
+import org.apache.myfaces.adf.logging.ADFLogger;
+import org.apache.myfaces.adfinternal.share.xml.ParseContextImpl;
+
+import org.apache.myfaces.adfinternal.share.xml.TreeBuilder;
+import org.apache.myfaces.adfinternal.share.xml.BaseNodeParser;
+import org.apache.myfaces.adfinternal.share.xml.ParseContext;
+import org.apache.myfaces.adfinternal.share.xml.NodeParser;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Parser for parsing capabilities document
+ */
+public class CapabilitiesDocumentParser extends BaseNodeParser
+        implements XMLConstants
+{
+
+  private CapabilitiesDocumentParser() {}
+
+  static public CapabilitiesDocument createInstance (URL capUrl)
+  {
+    //if URL is null return empty documen
+    if (capUrl == null)
+      return CapabilitiesDocument.EMPTY_DOCUMENT;
+
+    CapabilitiesDocumentParser parser = new CapabilitiesDocumentParser();
+    InputStream stream = null;
+    try
+    {
+      URLConnection connection = capUrl.openConnection();
+      stream = connection.getInputStream();
+
+      InputSource source = new InputSource(stream);
+      source.setSystemId(capUrl.toExternalForm());
+
+      ParseContextImpl pc = new ParseContextImpl ();
+      pc.setProperty(NS_URI, __BASE_URL, capUrl);
+      TreeBuilder builder =  new  TreeBuilder();
+      return (CapabilitiesDocument) builder.parse(null, source, pc, parser);
+
+    }
+    catch (SAXException saxe)
+    {
+      //Logging handled by tree builder
+      //_LOG.severe("Failed to parse capabilities document", saxe);
+      ;
+    }
+    catch (IOException ioe)
+    {
+      _LOG.severe("Failed to parse capabilities document", ioe);
+    }
+    finally
+    {
+      try
+      {
+        if (stream != null)
+          stream.close();
+      }
+      catch (IOException e)
+      {
+        //do nothing
+        ;
+      }
+    }
+
+    return CapabilitiesDocument.EMPTY_DOCUMENT;
+  }
+
+
+  public void startElement (ParseContext context,
+                            String       namespaceURI,
+                            String       localName,
+                            Attributes   attrs )
+          throws SAXParseException
+  {
+    if (!NS_URI.equals(namespaceURI))
+    {
+      throw new SAXParseException("Invalid Namespace: " +
+                                  namespaceURI, context.getLocator());
+    }
+
+    if (!ELEMENT_ROOT.equals(localName))
+    {
+      throw new SAXParseException("Invalid Root Element: " +
+                                  localName, context.getLocator());
+    }
+  }
+
+
+  public NodeParser startChildElement(ParseContext context,
+                                      String       namespaceURI,
+                                      String       localName,
+                                      Attributes   attrs)
+          throws SAXParseException
+  {
+    if (ELEMENT_AGENT_CAPABILITIES.equals(localName))
+    {
+      return this;
+    }
+    else if (ELEMENT_DEVICES.equals(localName))
+    {
+      return this;
+    }
+    else if (ELEMENT_CAPABILITIES.equals(localName))
+    {
+      return new CapabilitiesNodeParser();
+    }
+    else if (ELEMENT_DEVICE.equals(localName))
+    {
+      return new DeviceNodeParser();
+    }
+
+    //return null, if not a known element
+    return null;
+  }
+
+
+  public void addCompletedChild (ParseContext context,
+                                 String       namespaceURI,
+                                 String       localName,
+                                 Object       child)
+          throws SAXParseException
+  {
+    if (child == null)
+      return;
+
+    if (ELEMENT_CAPABILITIES.equals(localName))
+      _capabilitiesNodes.add(child);
+
+    if (ELEMENT_DEVICE.equals(localName))
+      _deviceNodes.add(child);
+  }
+
+
+  public Object endElement (ParseContext context,
+                            String       namespaceURI,
+                            String       localName)
+  {
+    if (!ELEMENT_ROOT.equals(localName))
+      return null;
+
+    CapabilitiesNode[] agents = null;
+    if (_capabilitiesNodes.size() > 0)
+    {
+      agents = (CapabilitiesNode[]) _capabilitiesNodes.toArray
+              (new CapabilitiesNode[_capabilitiesNodes.size()]);
+    }
+
+    DeviceNode[] devices = null;
+    if (_deviceNodes.size() > 0)
+    {
+      devices = (DeviceNode[]) _deviceNodes.toArray
+              (new DeviceNode[_deviceNodes.size()]);
+    }
+
+    CapabilitiesDocument document = new CapabilitiesDocument(agents, devices);
+    return document;
+  }
+
+  private List _capabilitiesNodes = new ArrayList();
+  private List _deviceNodes = new ArrayList();
+
+  static final String __BASE_URL = "baseURL";
+
+  static private final ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesDocumentParser.class);
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesDocumentParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNode.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNode.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNode.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNode.java Mon Jul 24 21:42:41 2006
@@ -13,117 +13,117 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent.parse;
-import org.apache.myfaces.adf.context.Agent;
-
-/**
- * Object for Capabilities node
- */
-class CapabilitiesNode
-{
-
-  public CapabilitiesNode(String id,
-                          boolean isDefault,
-                          NameVersion agent,
-                          NameVersion platform,
-                          IncludeNode[] nodesWithRef,
-                          IncludeNode[] nodesWithSrc)
-  {
-    _id = id;
-    _isDefault = isDefault;
-    _agent = agent;
-    _platform = platform;
-    _nodesWithRef = nodesWithRef;
-    _nodesWithSrc = nodesWithSrc;
-  }
-
-  String __getId()
-  {
-    return _id;
-  }
-
-  boolean __isDefault()
-  {
-    return _isDefault;
-  }
-
-  void setNodesWithRef(IncludeNode[] nodesWithRef)
-  {
-    _nodesWithRef = nodesWithRef;
-  }
-
-  void __setNodesWithSrc(IncludeNode[] nodesWithSrc)
-  {
-    _nodesWithSrc = nodesWithSrc;
-  }
-
-  IncludeNode[] __getIncludesByUri()
-  {
-    return _nodesWithSrc;
-  }
-
-  IncludeNode[] __getIncludesByRef()
-  {
-    return _nodesWithRef;
-  }
-
-  double __matches(Agent agent)
-  {
-
-    double agentScore = 0;  //TODO: use the NO_MATCH constant
-    if (_agent != null) {
-      agentScore = _getAgentMatch(agent);
-      if (agentScore <= 0)
-        return 0;
-    }
-
-    double platformScore = 0; //TODO: use the NO_MATCH constant
-    if (_platform != null) {
-      platformScore = _getPlatformMatch(agent);
-
-      if (platformScore <= 0)
-        return 0;
-    }
-
-    //provide heavy weightage for agent
-    return (agentScore * 10000 + platformScore);
-  }
-
-  private double _getPlatformMatch(Agent agent)
-  {
-    String platName = agent.getPlatformName();
-    String version = agent.getPlatformVersion();
-    VersionId platVersionId = null;
-    if (version != null)
-      platVersionId = new VersionId(version);
-
-    return _platform.match(platName, platVersionId);
-  }
-
-  private double _getAgentMatch(Agent agent)
-  {
-    String agentName = agent.getAgentName();
-    String version = agent.getAgentVersion();
-    VersionId agentVersionId = null;
-    if (version != null)
-      agentVersionId = new VersionId(version);
-
-    return _agent.match(agentName, agentVersionId);
-  }
-
-
-  NameVersion _agent;
-  NameVersion _platform;
-  private String _id;
-  private boolean _isDefault = false;
-  private IncludeNode[] _nodesWithRef;
-  private IncludeNode[] _nodesWithSrc;
-
-
-/*
-  private static String _AGENT_VERSIONID_KEY =
-          "org.apache.myfaces.adfinternal.agent.parse.AGENT_VERSIONID";
-  private static String _PLATFORM_VERSIONID_KEY =
-          "org.apache.myfaces.adfinternal.agent.parse.PLATFORM_VERSIONID";
-*/
-}
+package org.apache.myfaces.adfinternal.agent.parse;
+import org.apache.myfaces.adf.context.Agent;
+
+/**
+ * Object for Capabilities node
+ */
+class CapabilitiesNode
+{
+
+  public CapabilitiesNode(String id,
+                          boolean isDefault,
+                          NameVersion agent,
+                          NameVersion platform,
+                          IncludeNode[] nodesWithRef,
+                          IncludeNode[] nodesWithSrc)
+  {
+    _id = id;
+    _isDefault = isDefault;
+    _agent = agent;
+    _platform = platform;
+    _nodesWithRef = nodesWithRef;
+    _nodesWithSrc = nodesWithSrc;
+  }
+
+  String __getId()
+  {
+    return _id;
+  }
+
+  boolean __isDefault()
+  {
+    return _isDefault;
+  }
+
+  void setNodesWithRef(IncludeNode[] nodesWithRef)
+  {
+    _nodesWithRef = nodesWithRef;
+  }
+
+  void __setNodesWithSrc(IncludeNode[] nodesWithSrc)
+  {
+    _nodesWithSrc = nodesWithSrc;
+  }
+
+  IncludeNode[] __getIncludesByUri()
+  {
+    return _nodesWithSrc;
+  }
+
+  IncludeNode[] __getIncludesByRef()
+  {
+    return _nodesWithRef;
+  }
+
+  double __matches(Agent agent)
+  {
+
+    double agentScore = 0;  //TODO: use the NO_MATCH constant
+    if (_agent != null) {
+      agentScore = _getAgentMatch(agent);
+      if (agentScore <= 0)
+        return 0;
+    }
+
+    double platformScore = 0; //TODO: use the NO_MATCH constant
+    if (_platform != null) {
+      platformScore = _getPlatformMatch(agent);
+
+      if (platformScore <= 0)
+        return 0;
+    }
+
+    //provide heavy weightage for agent
+    return (agentScore * 10000 + platformScore);
+  }
+
+  private double _getPlatformMatch(Agent agent)
+  {
+    String platName = agent.getPlatformName();
+    String version = agent.getPlatformVersion();
+    VersionId platVersionId = null;
+    if (version != null)
+      platVersionId = new VersionId(version);
+
+    return _platform.match(platName, platVersionId);
+  }
+
+  private double _getAgentMatch(Agent agent)
+  {
+    String agentName = agent.getAgentName();
+    String version = agent.getAgentVersion();
+    VersionId agentVersionId = null;
+    if (version != null)
+      agentVersionId = new VersionId(version);
+
+    return _agent.match(agentName, agentVersionId);
+  }
+
+
+  NameVersion _agent;
+  NameVersion _platform;
+  private String _id;
+  private boolean _isDefault = false;
+  private IncludeNode[] _nodesWithRef;
+  private IncludeNode[] _nodesWithSrc;
+
+
+/*
+  private static String _AGENT_VERSIONID_KEY =
+          "org.apache.myfaces.adfinternal.agent.parse.AGENT_VERSIONID";
+  private static String _PLATFORM_VERSIONID_KEY =
+          "org.apache.myfaces.adfinternal.agent.parse.PLATFORM_VERSIONID";
+*/
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNodeParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNodeParser.java?rev=425276&r1=425275&r2=425276&view=diff
==============================================================================
--- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNodeParser.java (original)
+++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNodeParser.java Mon Jul 24 21:42:41 2006
@@ -13,137 +13,137 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.myfaces.adfinternal.agent.parse;
-
-
-import org.apache.myfaces.adfinternal.share.xml.BaseNodeParser;
-import org.apache.myfaces.adfinternal.share.xml.NodeParser;
-import org.apache.myfaces.adfinternal.share.xml.ParseContext;
-import org.apache.myfaces.adf.logging.ADFLogger;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXParseException;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.text.ParseException;
-
-
-/**
- * Node parser for capabilities node of capabilities file
- */
-class CapabilitiesNodeParser extends BaseNodeParser implements XMLConstants
-{
-
-  public void startElement (ParseContext context,
-                            String       namespaceURI,
-                            String       localName,
-                            Attributes   attrs )
-          throws SAXParseException
-  {
-    if (!NS_URI.equals(namespaceURI))
-    {
-      throw new SAXParseException("Invalid Namespace: " +
-                                  namespaceURI, context.getLocator());
-    }
-
-    _id = attrs.getValue(ATTRIBUTE_ID);
-    String isDefault = attrs.getValue(ATTRIBUTE_DEFAULT);
-    if ("true".equals(isDefault))
-      _isDefault = true;
-
-    String agent = attrs.getValue(ATTRIBUTE_AGENTS);
-    if (agent != null)
-    {
-      try
-      {
-        _agent = new NameVersion(agent);
-      }
-      catch (ParseException pe)
-      {
-        _LOG.warning("Unable to parse agent string");
-      }
-    }
-
-    String platform = attrs.getValue(ATTRIBUTE_PLATFORMS);
-    if (platform != null)
-    {
-      try
-      {
-        _platform = new NameVersion(platform);
-      }
-      catch (ParseException pe)
-      {
-        _LOG.warning("Unable to parse agent string");
-      }
-    }
-
-    if ((_id == null) && (_agent == null))
-      _LOG.warning("Element " + ELEMENT_CAPABILITIES +
-                   " has missing (or empty) attributes");
-
-  }
-
-
-  public NodeParser startChildElement(ParseContext context,
-                                      String       namespaceURI,
-                                      String       localName,
-                                      Attributes   attrs)
-          throws SAXParseException
-  {
-    if (ELEMENT_INCLUDE.equals(localName))
-      return new IncludeNodeParser();
-
-    //return null; if unknown element
-    return null;
-  }
-
-
-  public void addCompletedChild (ParseContext context,
-                                 String       namespaceURI,
-                                 String       localName,
-                                 Object       child)
-          throws SAXParseException
-  {
-    if (child == null)
-      return;
-
-    if (ELEMENT_INCLUDE.equals(localName))
-      _includeNodes.add(child);
-  }
-
-  public Object endElement (ParseContext context,
-                            String       namespaceURI,
-                            String       localName)
-  {
-    if ((_id == null) && (_agent == null))
-      return null;
-
-    ArrayList nodesWithRefList = new ArrayList(_includeNodes.size());
-    ArrayList nodesWithSrcList = new ArrayList(_includeNodes.size());
-    for (int i = 0; i < _includeNodes.size(); i++)
-    {
-      IncludeNode node = (IncludeNode) _includeNodes.get(i);
-      if (node.__getRefId() != null)
-        nodesWithRefList.add(node);
-      else
-        nodesWithSrcList.add(node);
-    }
-    IncludeNode[] nodesWithRef = (IncludeNode[])
-            nodesWithRefList.toArray(new IncludeNode[nodesWithRefList.size()]);
-    IncludeNode[] nodesWithSrc = (IncludeNode[])
-            nodesWithSrcList.toArray(new IncludeNode[nodesWithSrcList.size()]);
-
-    return new CapabilitiesNode(_id, _isDefault, _agent,
-                                _platform, nodesWithRef, nodesWithSrc);
-  }
-
-
-
-  private String _id;
-  private boolean _isDefault;
-  private NameVersion _agent;
-  private NameVersion _platform;
-  private List _includeNodes = new ArrayList();
-
-  static private final ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesNodeParser.class);
-}
+package org.apache.myfaces.adfinternal.agent.parse;
+
+
+import org.apache.myfaces.adfinternal.share.xml.BaseNodeParser;
+import org.apache.myfaces.adfinternal.share.xml.NodeParser;
+import org.apache.myfaces.adfinternal.share.xml.ParseContext;
+import org.apache.myfaces.adf.logging.ADFLogger;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXParseException;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.text.ParseException;
+
+
+/**
+ * Node parser for capabilities node of capabilities file
+ */
+class CapabilitiesNodeParser extends BaseNodeParser implements XMLConstants
+{
+
+  public void startElement (ParseContext context,
+                            String       namespaceURI,
+                            String       localName,
+                            Attributes   attrs )
+          throws SAXParseException
+  {
+    if (!NS_URI.equals(namespaceURI))
+    {
+      throw new SAXParseException("Invalid Namespace: " +
+                                  namespaceURI, context.getLocator());
+    }
+
+    _id = attrs.getValue(ATTRIBUTE_ID);
+    String isDefault = attrs.getValue(ATTRIBUTE_DEFAULT);
+    if ("true".equals(isDefault))
+      _isDefault = true;
+
+    String agent = attrs.getValue(ATTRIBUTE_AGENTS);
+    if (agent != null)
+    {
+      try
+      {
+        _agent = new NameVersion(agent);
+      }
+      catch (ParseException pe)
+      {
+        _LOG.warning("Unable to parse agent string");
+      }
+    }
+
+    String platform = attrs.getValue(ATTRIBUTE_PLATFORMS);
+    if (platform != null)
+    {
+      try
+      {
+        _platform = new NameVersion(platform);
+      }
+      catch (ParseException pe)
+      {
+        _LOG.warning("Unable to parse agent string");
+      }
+    }
+
+    if ((_id == null) && (_agent == null))
+      _LOG.warning("Element " + ELEMENT_CAPABILITIES +
+                   " has missing (or empty) attributes");
+
+  }
+
+
+  public NodeParser startChildElement(ParseContext context,
+                                      String       namespaceURI,
+                                      String       localName,
+                                      Attributes   attrs)
+          throws SAXParseException
+  {
+    if (ELEMENT_INCLUDE.equals(localName))
+      return new IncludeNodeParser();
+
+    //return null; if unknown element
+    return null;
+  }
+
+
+  public void addCompletedChild (ParseContext context,
+                                 String       namespaceURI,
+                                 String       localName,
+                                 Object       child)
+          throws SAXParseException
+  {
+    if (child == null)
+      return;
+
+    if (ELEMENT_INCLUDE.equals(localName))
+      _includeNodes.add(child);
+  }
+
+  public Object endElement (ParseContext context,
+                            String       namespaceURI,
+                            String       localName)
+  {
+    if ((_id == null) && (_agent == null))
+      return null;
+
+    ArrayList nodesWithRefList = new ArrayList(_includeNodes.size());
+    ArrayList nodesWithSrcList = new ArrayList(_includeNodes.size());
+    for (int i = 0; i < _includeNodes.size(); i++)
+    {
+      IncludeNode node = (IncludeNode) _includeNodes.get(i);
+      if (node.__getRefId() != null)
+        nodesWithRefList.add(node);
+      else
+        nodesWithSrcList.add(node);
+    }
+    IncludeNode[] nodesWithRef = (IncludeNode[])
+            nodesWithRefList.toArray(new IncludeNode[nodesWithRefList.size()]);
+    IncludeNode[] nodesWithSrc = (IncludeNode[])
+            nodesWithSrcList.toArray(new IncludeNode[nodesWithSrcList.size()]);
+
+    return new CapabilitiesNode(_id, _isDefault, _agent,
+                                _platform, nodesWithRef, nodesWithSrc);
+  }
+
+
+
+  private String _id;
+  private boolean _isDefault;
+  private NameVersion _agent;
+  private NameVersion _platform;
+  private List _includeNodes = new ArrayList();
+
+  static private final ADFLogger _LOG = ADFLogger.createADFLogger(CapabilitiesNodeParser.class);
+}

Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/adfinternal/agent/parse/CapabilitiesNodeParser.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message