felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r900957 [1/2] - in /felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework: candidateset/ util/ util/manifestparser/
Date Tue, 19 Jan 2010 21:07:28 GMT
Author: rickhall
Date: Tue Jan 19 21:07:27 2010
New Revision: 900957

URL: http://svn.apache.org/viewvc?rev=900957&view=rev
Log:
Manifest parser is now compiling, but everything is still broken.

Modified:
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/VersionRange.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/CapabilityImpl.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java?rev=900957&r1=900956&r2=900957&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
(original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
Tue Jan 19 21:07:27 2010
@@ -18,9 +18,13 @@
  */
 package org.apache.felix.framework.candidateset;
 
+import java.util.List;
+
 public interface Requirement
 {
     String getNamespace();
     SimpleFilter getFilter();
     boolean isOptional();
+    Directive getDirective(String name);
+    List<Directive> getDirectives();
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/VersionRange.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/VersionRange.java?rev=900957&r1=900956&r2=900957&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/VersionRange.java
(original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/VersionRange.java
Tue Jan 19 21:07:27 2010
@@ -22,62 +22,63 @@
 
 public class VersionRange
 {
-    private final Version m_low;
-    private final boolean m_isLowInclusive;
-    private final Version m_high;
-    private final boolean m_isHighInclusive;
-    public static final VersionRange infiniteRange = new VersionRange(Version.emptyVersion,
true, null, true);
+    private final Version m_floor;
+    private final boolean m_isFloorInclusive;
+    private final Version m_ceiling;
+    private final boolean m_isCeilingInclusive;
+    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)
@@ -109,19 +110,19 @@
             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;
         }
@@ -131,28 +132,28 @@
     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;
     }
 
     public String toString()
     {
-        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 ? ']' : ')');
             return sb.toString();
         }
         else
         {
-            return m_low.toString();
+            return m_floor.toString();
         }
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/CapabilityImpl.java?rev=900957&r1=900956&r2=900957&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/CapabilityImpl.java
(original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/util/manifestparser/CapabilityImpl.java
Tue Jan 19 21:07:27 2010
@@ -21,30 +21,120 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.StringTokenizer;
 import org.apache.felix.framework.candidateset.Attribute;
 import org.apache.felix.framework.candidateset.Capability;
 import org.apache.felix.framework.candidateset.Directive;
 import org.apache.felix.framework.candidateset.Module;
+import org.apache.felix.framework.util.Util;
+import org.osgi.framework.Constants;
 
 public class CapabilityImpl implements Capability
 {
     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;
+    private final List<String> m_uses;
+    private final List<List<String>> m_includeFilter;
+    private final List<List<String>> m_excludeFilter;
 
-    public CapabilityImpl(Module module, String namespace)
+    public CapabilityImpl(Module module, String namespace,
+        List<Directive> dirs, List<Attribute> attrs)
     {
         m_namespace = namespace;
         m_module = module;
-        m_uses = new ArrayList<String>();
-        m_dirs = new ArrayList<Directive>();
+        m_dirs = dirs;
         m_dirsConst = Collections.unmodifiableList(m_dirs);
-        m_attrs = new ArrayList<Attribute>();
+        m_attrs = attrs;
         m_attrsConst = Collections.unmodifiableList(m_attrs);
+
+        // Find all export directives: uses, mandatory, include, and exclude.
+        String mandatory = "";
+        List<String> uses = null;
+        List<List<String>> includeFilter = null, excludeFilter = null;
+        for (int dirIdx = 0; dirIdx < m_dirs.size(); dirIdx++)
+        {
+            if (m_dirs.get(dirIdx).getName().equals(Constants.USES_DIRECTIVE))
+            {
+                // Parse these uses directive.
+                StringTokenizer tok = new StringTokenizer(
+                    (String) m_dirs.get(dirIdx).getValue(), ",");
+                uses = new ArrayList<String>(tok.countTokens());
+                while (tok.hasMoreTokens())
+                {
+                    uses.add(tok.nextToken().trim());
+                }
+            }
+            else if (m_dirs.get(dirIdx).getName().equals(Constants.MANDATORY_DIRECTIVE))
+            {
+                mandatory = (String) m_dirs.get(dirIdx).getValue();
+            }
+            else if (m_dirs.get(dirIdx).getName().equals(Constants.INCLUDE_DIRECTIVE)
+                || m_dirs.get(dirIdx).getName().equals(Constants.EXCLUDE_DIRECTIVE))
+            {
+                List<List<String>> filterList = null;
+
+                List<String> filters = ManifestParser.parseDelimitedString(
+                    (String) m_dirs.get(dirIdx).getValue(), ",");
+                filterList = new ArrayList<List<String>>(filters.size());
+
+                for (int filterIdx = 0; filterIdx < filters.size(); filterIdx++)
+                {
+                    String[] substrings = Util.parseSubstring(filters.get(filterIdx));
+                    List<String> l = new ArrayList<String>(substrings.length);
+                    for (int subIdx = 0; subIdx < substrings.length; subIdx++)
+                    {
+                        l.add(substrings[subIdx]);
+                    }
+                    filterList.add(l);
+                }
+
+                if (m_dirs.get(dirIdx).getName().equals(Constants.INCLUDE_DIRECTIVE))
+                {
+                    includeFilter = filterList;
+                }
+                else
+                {
+                    excludeFilter = filterList;
+                }
+            }
+        }
+
+        // Set final values.
+        m_uses = uses;
+        m_includeFilter = includeFilter;
+        m_excludeFilter = excludeFilter;
+
+        // Parse mandatory directive and mark specified
+        // attributes as mandatory.
+        StringTokenizer tok = new StringTokenizer(mandatory, ", ");
+        while (tok.hasMoreTokens())
+        {
+            // Get attribute name.
+            String attrName = tok.nextToken().trim();
+            // Find attribute and mark it as mandatory.
+            boolean found = false;
+            for (int i = 0; (!found) && (i < m_attrs.size()); i++)
+            {
+                if (m_attrs.get(i).getName().equals(attrName))
+                {
+                    m_attrs.set(i, new Attribute(
+                        m_attrs.get(i).getName(),
+                        m_attrs.get(i).getValue(), true));
+                    found = true;
+                }
+            }
+            // If a specified mandatory attribute was not found,
+            // then error.
+            if (!found)
+            {
+                throw new IllegalArgumentException(
+                    "Mandatory attribute '" + attrName + "' does not exist.");
+            }
+        }
     }
 
     public Module getModule()



Mime
View raw message