Author: rickhall
Date: Thu Jan 21 21:53:32 2010
New Revision: 901874

URL: http://svn.apache.org/viewvc?rev=901874&view=rev
Log:
More fixes and improvements.

Modified:
    
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
    
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java

Modified: 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=901874&r1=901873&r2=901874&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
 (original)
+++ 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
 Thu Jan 21 21:53:32 2010
@@ -18,6 +18,9 @@
  */
 package org.apache.felix.framework.capabilityset;
 
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -53,6 +56,10 @@
                 Map<Object, Set<Capability>> index = entry.getValue();
                 Set<Capability> caps = index.get(
                     cap.getAttribute(entry.getKey()).getValue());
+if (cap.getAttribute(entry.getKey()).getValue().getClass().isArray())
+{
+    System.out.println("!!! ARRAY VALUE " + cap);
+}
                 if (caps == null)
                 {
                     caps = new HashSet<Capability>();
@@ -311,32 +318,18 @@
                         "Unknown comparison operator: " + op);
             }
         }
+
         // If the LHS is not a comparable or boolean, check if it is an
-        // array. If so, call compare() on each element of the array until
-        // a match is found.
-        else if (lhs.getClass().isArray())
+        // array. If so, convert it to a list so we can treat it as a
+        // collection.
+        if (lhs.getClass().isArray())
         {
-            // If this is an array of primitives, then convert
-            // the entire array to an array of the associated
-            // primitive wrapper class instances.
-            if (lhs.getClass().getComponentType().isPrimitive())
-            {
-                lhs = convertPrimitiveArray(lhs);
-            }
-
-            // Now call compare on each element of array.
-            Object[] array = (Object[]) lhs;
-            for (int i = 0; i < array.length; i++)
-            {
-                if (compare(array[i], rhsString, op))
-                {
-                    return true;
-                }
-            }
+            lhs = convertArrayToList(lhs);
         }
+
         // If LHS is a collection, then call compare() on each element
         // of the collection until a match is found.
-        else if (lhs instanceof Collection)
+        if (lhs instanceof Collection)
         {
             for (Iterator iter = ((Collection) lhs).iterator(); 
iter.hasNext(); )
             {
@@ -345,6 +338,8 @@
                     return true;
                 }
             }
+
+            return false;
         }
 
         // Since we cannot identify the LHS type, then we can only perform
@@ -399,83 +394,14 @@
      * @param array An array of primitive types.
      * @return An corresponding array using pritive wrapper objects.
     **/
-    private static Object[] convertPrimitiveArray(Object array)
+    private static List convertArrayToList(Object array)
     {
-        Class clazz = array.getClass().getComponentType();
-
-        if (clazz == Boolean.TYPE)
-        {
-            boolean[] src = (boolean[]) array;
-            array = new Boolean[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = (src[i] ? Boolean.TRUE : 
Boolean.FALSE);
-            }
-        }
-        else if (clazz == Character.TYPE)
-        {
-            char[] src = (char[]) array;
-            array = new Character[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Character(src[i]);
-            }
-        }
-        else if (clazz == Byte.TYPE)
-        {
-            byte[] src = (byte[]) array;
-            array = new Byte[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Byte(src[i]);
-            }
-        }
-        else if (clazz == Short.TYPE)
-        {
-            byte[] src = (byte[]) array;
-            array = new Byte[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Byte(src[i]);
-            }
-        }
-        else if (clazz == Integer.TYPE)
-        {
-            int[] src = (int[]) array;
-            array = new Integer[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Integer(src[i]);
-            }
-        }
-        else if (clazz == Long.TYPE)
+        List list = new ArrayList(Array.getLength(array));
+        int len = Array.getLength(array);
+        for (int i = 0; i < len; i++)
         {
-            long[] src = (long[]) array;
-            array = new Long[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Long(src[i]);
-            }
-        }
-        else if (clazz == Float.TYPE)
-        {
-            float[] src = (float[]) array;
-            array = new Float[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Float(src[i]);
-            }
+            list.add(Array.get(array, i));
         }
-        else if (clazz == Double.TYPE)
-        {
-            double[] src = (double[]) array;
-            array = new Double[src.length];
-            for (int i = 0; i < src.length; i++)
-            {
-                ((Object[]) array)[i] = new Double(src[i]);
-            }
-        }
-
-        return (Object[]) array;
+        return list;
     }
 }
\ No newline at end of file

Modified: 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java?rev=901874&r1=901873&r2=901874&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
 (original)
+++ 
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
 Thu Jan 21 21:53:32 2010
@@ -161,7 +161,8 @@
         // Get exported packages from bundle manifest.
         List<ParsedHeaderClause> exportClauses =
             parseStandardHeader((String) 
headerMap.get(Constants.EXPORT_PACKAGE));
-        exportClauses = normalizeExportClauses(logger, exportClauses, 
getManifestVersion());
+        exportClauses = normalizeExportClauses(logger, exportClauses,
+            getManifestVersion(), m_bundleSymbolicName, m_bundleVersion);
         List<Capability> exportCaps = convertExports(exportClauses, owner);
 
         //
@@ -516,7 +517,8 @@
     }
 
     private static List<ParsedHeaderClause> normalizeExportClauses(
-        Logger logger, List<ParsedHeaderClause> clauses, String mv)
+        Logger logger, List<ParsedHeaderClause> clauses,
+        String mv, String bsn, Version bv)
         throws BundleException
     {
         // Verify that "java.*" packages are not exported.
@@ -595,7 +597,35 @@
             }
         }
 
-        if (!mv.equals("2"))
+        // If this is an R4 bundle, then make sure it doesn't specify
+        // bundle symbolic name or bundle version attributes.
+        if (mv.equals("2"))
+        {
+            for (int clauseIdx = 0; clauseIdx < clauses.size(); clauseIdx++)
+            {
+                // R3 package capabilities should only have a version 
attribute.
+                List<Attribute> attrs = clauses.get(clauseIdx).m_attrs;
+                for (int attrIdx = 0; attrIdx < attrs.size(); attrIdx++)
+                {
+                    // Find symbolic name and version attribute, if present.
+                    if 
(attrs.get(attrIdx).getName().equals(Constants.BUNDLE_VERSION_ATTRIBUTE) ||
+                        
attrs.get(attrIdx).getName().equals(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE))
+                    {
+                        throw new BundleException(
+                            "Exports must not specify bundle symbolic name or 
bundle version.");
+                    }
+                }
+
+                // Now that we know that there are no bundle symbolic name and 
version
+                // attributes, add them since the spec says they are there 
implicitly.
+                attrs.add(new Attribute(
+                    Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, bsn, false));
+                attrs.add(new Attribute(
+                    Constants.BUNDLE_VERSION_ATTRIBUTE, bv, false));
+                ((ArrayList) attrs).trimToSize();
+            }
+        }
+        else if (!mv.equals("2"))
         {
             // Check to make sure that R3 bundles have only specified
             // the 'specification-version' attribute and no directives
@@ -1163,7 +1193,7 @@
         try
         {
             List<ParsedHeaderClause> exportClauses = 
parseStandardHeader(header);
-            exportClauses = normalizeExportClauses(logger, exportClauses, "2");
+            exportClauses = normalizeExportClauses(logger, exportClauses, "2", 
bsn, bv);
             caps = convertExports(exportClauses, owner);
         }
         catch (BundleException ex)


Reply via email to