You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/01/15 15:25:37 UTC

svn commit: r899641 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: CapabilityImpl.java RequirementImpl.java VersionRange.java cs/Attribute.java cs/Capability.java cs/Directive.java manifestparser/Main.java

Author: rickhall
Date: Fri Jan 15 14:25:36 2010
New Revision: 899641

URL: http://svn.apache.org/viewvc?rev=899641&view=rev
Log:
Add directives and a few other changes.

Added:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Directive.java
Modified:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/VersionRange.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Capability.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java Fri Jan 15 14:25:36 2010
@@ -24,6 +24,7 @@
 import java.util.StringTokenizer;
 import org.apache.felix.resolver.cs.Attribute;
 import org.apache.felix.resolver.cs.Capability;
+import org.apache.felix.resolver.cs.Directive;
 import org.apache.felix.resolver.manifestparser.Constants;
 
 public class CapabilityImpl implements Capability
@@ -31,6 +32,8 @@
     private final Module m_module;
     private final String m_namespace;
     private final List m_uses;
+    private final List<Directive> m_dirs;
+    private final List<Directive> m_dirsConst;
     private final List<Attribute> m_attrs;
     private final List<Attribute> m_attrsConst;
 
@@ -39,6 +42,8 @@
         m_namespace = namespace;
         m_module = module;
         m_uses = new ArrayList<String>();
+        m_dirs = new ArrayList<Directive>();
+        m_dirsConst = Collections.unmodifiableList(m_dirs);
         m_attrs = new ArrayList<Attribute>();
         m_attrsConst = Collections.unmodifiableList(m_attrs);
     }
@@ -109,6 +114,23 @@
         return this;
     }
 
+    public Directive getDirective(String name)
+    {
+        for (int i = 0; i < m_dirs.size(); i++)
+        {
+            if (m_dirs.get(i).getName().equals(name))
+            {
+                return m_dirs.get(i);
+            }
+        }
+        return null;
+    }
+
+    public List<Directive> getDirectives()
+    {
+        return m_dirsConst;
+    }
+
     public Attribute getAttribute(String name)
     {
         for (int i = 0; i < m_attrs.size(); i++)

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/RequirementImpl.java Fri Jan 15 14:25:36 2010
@@ -18,9 +18,11 @@
  */
 package org.apache.felix.resolver;
 
+import java.util.ArrayList;
 import org.apache.felix.resolver.cs.Attribute;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.apache.felix.resolver.cs.Capability;
@@ -40,6 +42,8 @@
     {
         m_namespace = namespace;
         m_attrs = new HashMap<String, Attribute>();
+// TODO: PROTO3 RESOLVER - Maybe we don't need to get the filter now since we no
+//       longer need to parse it; check timing difference.
         getFilter();
     }
 
@@ -52,7 +56,7 @@
     {
         if (m_filter == null)
         {
-            m_filter = SimpleFilter.parse(convertToFilter());
+            m_filter = convertToFilter(m_attrs);
         }
         return m_filter;
     }
@@ -124,75 +128,85 @@
 
     public String toString()
     {
-        return m_namespace + "; " + convertToFilter();
+        return m_namespace + "; " + getFilter().toString();
     }
 
-    private String convertToFilter()
+    private static SimpleFilter convertToFilter(Map<String, Attribute> attrs)
     {
-        StringBuffer sb = new StringBuffer();
-        if ((m_attrs != null) && (m_attrs.size() > 1))
-        {
-            sb.append("(&");
-        }
+        // Rather than building a filter string to be parsed into a SimpleFilter,
+        // we will just create the parsed SimpleFilter directly.
+
+        List<SimpleFilter> filters = new ArrayList<SimpleFilter>();
 
-        for (Iterator<Entry<String, Attribute>> it = m_attrs.entrySet().iterator(); it.hasNext(); )
+        for (Entry<String, Attribute> entry : attrs.entrySet())
         {
-            Entry<String, Attribute> entry = it.next();
             if (entry.getValue().getValue() instanceof VersionRange)
             {
                 VersionRange vr = (VersionRange) entry.getValue().getValue();
-                if (vr.isLowInclusive())
+                if (vr.isFloorInclusive())
                 {
-                    sb.append("(");
-                    sb.append(entry.getValue().getName());
-                    sb.append(">=");
-                    sb.append(vr.getLow().toString());
-                    sb.append(")");
+                    filters.add(
+                        new SimpleFilter(
+                            entry.getValue().getName(),
+                            vr.getFloor().toString(),
+                            SimpleFilter.GTE));
                 }
                 else
                 {
-                    sb.append("(!(");
-                    sb.append(entry.getValue().getName());
-                    sb.append("<=");
-                    sb.append(vr.getLow().toString());
-                    sb.append("))");
+                    SimpleFilter not =
+                        new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
+                    ((List) not.getValue()).add(
+                        new SimpleFilter(
+                            entry.getValue().getName(),
+                            vr.getFloor().toString(),
+                            SimpleFilter.LTE));
+                    filters.add(not);
                 }
 
-                if (vr.getHigh() != null)
+                if (vr.getCeiling() != null)
                 {
-                    if (vr.isHighInclusive())
+                    if (vr.isCeilingInclusive())
                     {
-                        sb.append("(");
-                        sb.append(entry.getValue().getName());
-                        sb.append("<=");
-                        sb.append(vr.getHigh().toString());
-                        sb.append(")");
+                        filters.add(
+                            new SimpleFilter(
+                                entry.getValue().getName(),
+                                vr.getCeiling().toString(),
+                                SimpleFilter.LTE));
                     }
                     else
                     {
-                        sb.append("(!(");
-                        sb.append(entry.getValue().getName());
-                        sb.append(">=");
-                        sb.append(vr.getHigh().toString());
-                        sb.append("))");
+                        SimpleFilter not =
+                            new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
+                        ((List) not.getValue()).add(
+                            new SimpleFilter(
+                                entry.getValue().getName(),
+                                vr.getCeiling().toString(),
+                                SimpleFilter.GTE));
+                        filters.add(not);
                     }
                 }
             }
             else
             {
-                sb.append("(");
-                sb.append(entry.getValue().getName());
-                sb.append("=");
-                sb.append(entry.getValue().getValue().toString());
-                sb.append(")");
+                filters.add(
+                    new SimpleFilter(
+                        entry.getValue().getName(),
+                        entry.getValue().getValue().toString(),
+                        SimpleFilter.EQ));
             }
         }
 
-        if ((m_attrs != null) && (m_attrs.size() > 1))
+        SimpleFilter sf = null;
+
+        if (filters.size() == 1)
+        {
+            sf = filters.get(0);
+        }
+        else if (attrs.size() > 1)
         {
-            sb.append(")");
+            sf = new SimpleFilter(null, filters, SimpleFilter.AND);
         }
 
-        return sb.toString();
+        return sf;
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/VersionRange.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/VersionRange.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/VersionRange.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/VersionRange.java Fri Jan 15 14:25:36 2010
@@ -20,62 +20,63 @@
 
 public class VersionRange
 {
-    private Version m_low = null;
-    private boolean m_isLowInclusive = false;
-    private Version m_high = null;
-    private boolean m_isHighInclusive = false;
+    private Version m_floor = null;
+    private boolean m_isFloorInclusive = false;
+    private Version m_ceiling = null;
+    private boolean m_isCeilingInclusive = false;
     private String m_toString = null;
-    public static final VersionRange infiniteRange = new VersionRange(Version.emptyVersion, true, null, true);
+    public static final VersionRange infiniteRange =
+        new VersionRange(Version.emptyVersion, true, null, true);
 
     public VersionRange(Version low, boolean isLowInclusive,
         Version high, boolean isHighInclusive)
     {
-        m_low = low;
-        m_isLowInclusive = isLowInclusive;
-        m_high = high;
-        m_isHighInclusive = isHighInclusive;
+        m_floor = low;
+        m_isFloorInclusive = isLowInclusive;
+        m_ceiling = high;
+        m_isCeilingInclusive = isHighInclusive;
     }
 
-    public Version getLow()
+    public Version getFloor()
     {
-        return m_low;
+        return m_floor;
     }
 
-    public boolean isLowInclusive()
+    public boolean isFloorInclusive()
     {
-        return m_isLowInclusive;
+        return m_isFloorInclusive;
     }
 
-    public Version getHigh()
+    public Version getCeiling()
     {
-        return m_high;
+        return m_ceiling;
     }
 
-    public boolean isHighInclusive()
+    public boolean isCeilingInclusive()
     {
-        return m_isHighInclusive;
+        return m_isCeilingInclusive;
     }
 
     public boolean isInRange(Version version)
     {
         // We might not have an upper end to the range.
-        if (m_high == null)
+        if (m_ceiling == null)
         {
-            return (version.compareTo(m_low) >= 0);
+            return (version.compareTo(m_floor) >= 0);
         }
-        else if (isLowInclusive() && isHighInclusive())
+        else if (isFloorInclusive() && isCeilingInclusive())
         {
-            return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) <= 0);
+            return (version.compareTo(m_floor) >= 0) && (version.compareTo(m_ceiling) <= 0);
         }
-        else if (isHighInclusive())
+        else if (isCeilingInclusive())
         {
-            return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) <= 0);
+            return (version.compareTo(m_floor) > 0) && (version.compareTo(m_ceiling) <= 0);
         }
-        else if (isLowInclusive())
+        else if (isFloorInclusive())
         {
-            return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) < 0);
+            return (version.compareTo(m_floor) >= 0) && (version.compareTo(m_ceiling) < 0);
         }
-        return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 0);
+        return (version.compareTo(m_floor) > 0) && (version.compareTo(m_ceiling) < 0);
     }
 
     public static VersionRange parse(String range)
@@ -107,19 +108,20 @@
             return false;
         }
         final VersionRange other = (VersionRange) obj;
-        if (m_low != other.m_low && (m_low == null || !m_low.equals(other.m_low)))
+        if (m_floor != other.m_floor && (m_floor == null || !m_floor.equals(other.m_floor)))
         {
             return false;
         }
-        if (m_isLowInclusive != other.m_isLowInclusive)
+        if (m_isFloorInclusive != other.m_isFloorInclusive)
         {
             return false;
         }
-        if (m_high != other.m_high && (m_high == null || !m_high.equals(other.m_high)))
+        if (m_ceiling != other.m_ceiling
+            && (m_ceiling == null || !m_ceiling.equals(other.m_ceiling)))
         {
             return false;
         }
-        if (m_isHighInclusive != other.m_isHighInclusive)
+        if (m_isCeilingInclusive != other.m_isCeilingInclusive)
         {
             return false;
         }
@@ -129,10 +131,10 @@
     public int hashCode()
     {
         int hash = 5;
-        hash = 97 * hash + (m_low != null ? m_low.hashCode() : 0);
-        hash = 97 * hash + (m_isLowInclusive ? 1 : 0);
-        hash = 97 * hash + (m_high != null ? m_high.hashCode() : 0);
-        hash = 97 * hash + (m_isHighInclusive ? 1 : 0);
+        hash = 97 * hash + (m_floor != null ? m_floor.hashCode() : 0);
+        hash = 97 * hash + (m_isFloorInclusive ? 1 : 0);
+        hash = 97 * hash + (m_ceiling != null ? m_ceiling.hashCode() : 0);
+        hash = 97 * hash + (m_isCeilingInclusive ? 1 : 0);
         return hash;
     }
 
@@ -140,19 +142,19 @@
     {
         if (m_toString == null)
         {
-            if (m_high != null)
+            if (m_ceiling != null)
             {
                 StringBuffer sb = new StringBuffer();
-                sb.append(m_isLowInclusive ? '[' : '(');
-                sb.append(m_low.toString());
+                sb.append(m_isFloorInclusive ? '[' : '(');
+                sb.append(m_floor.toString());
                 sb.append(',');
-                sb.append(m_high.toString());
-                sb.append(m_isHighInclusive ? ']' : ')');
+                sb.append(m_ceiling.toString());
+                sb.append(m_isCeilingInclusive ? ']' : ')');
                 m_toString = sb.toString();
             }
             else
             {
-                m_toString = m_low.toString();
+                m_toString = m_floor.toString();
             }
         }
         return m_toString;

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Attribute.java Fri Jan 15 14:25:36 2010
@@ -21,7 +21,7 @@
 public class Attribute
 {
     private final String m_name;
-    private final Object m_value; // Always comparable except VersionRange
+    private final Object m_value;
     private final boolean m_isMandatory;
 
     public Attribute(String name, Object value, boolean isMandatory)

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Capability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Capability.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Capability.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Capability.java Fri Jan 15 14:25:36 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.resolver.cs;
 
-import java.util.Iterator;
 import java.util.List;
 import org.apache.felix.resolver.Module;
 
@@ -33,6 +32,8 @@
 
     Module getModule();
     String getNamespace();
+    Directive getDirective(String name);
+    List<Directive> getDirectives();
     Attribute getAttribute(String name);
     List<Attribute> getAttributes();
     List<String> getUses();

Added: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Directive.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Directive.java?rev=899641&view=auto
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Directive.java (added)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/Directive.java Fri Jan 15 14:25:36 2010
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.felix.resolver.cs;
+
+public class Directive
+{
+    private final String m_name;
+    private final Object m_value;
+
+    public Directive(String name, Object value)
+    {
+        m_name = name;
+        m_value = value;
+    }
+
+    public String getName()
+    {
+        return m_name;
+    }
+
+    public Object getValue()
+    {
+        return m_value;
+    }
+
+    public String toString()
+    {
+        return m_name + "=" + m_value;
+    }
+}
\ No newline at end of file

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java?rev=899641&r1=899640&r2=899641&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/manifestparser/Main.java Fri Jan 15 14:25:36 2010
@@ -389,7 +389,8 @@
     private static Module getTarget(List<Module> modules)
     {
 //        return getTargetByOrder(modules);
-        return getTargetByUnresolved(modules);
+//        return getTargetByUnresolved(modules);
+        return getTargetBySymbolicName(modules, "com.sun.xml.ws");
 //        return getTargetBySymbolicName(modules, "org.springframework.faces");
 //        return getTargetBySymbolicName(modules, "bundle1");
     }