felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r918498 [3/3] - in /felix/trunk/framework/src/main/java/org/apache/felix: framework/capabilityset/ framework/util/manifestparser/ moduleloader/
Date Wed, 03 Mar 2010 14:58:22 GMT
Added: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ParsedHeaderClause.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ParsedHeaderClause.java?rev=918498&view=auto
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ParsedHeaderClause.java
(added)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ParsedHeaderClause.java
Wed Mar  3 14:58:21 2010
@@ -0,0 +1,37 @@
+/*
+ *  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.framework.util.manifestparser;
+
+import java.util.List;
+import org.apache.felix.framework.capabilityset.Attribute;
+import org.apache.felix.framework.capabilityset.Directive;
+
+public class ParsedHeaderClause
+{
+    public final List<String> m_paths;
+    public final List<Directive> m_dirs;
+    public final List<Attribute> m_attrs;
+
+    public ParsedHeaderClause(List<String> paths, List<Directive> dirs, List<Attribute>
attrs)
+    {
+        m_paths = paths;
+        m_dirs = dirs;
+        m_attrs = attrs;
+    }
+}
\ No newline at end of file

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java?rev=918498&r1=918497&r2=918498&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
Wed Mar  3 14:58:21 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework.util.manifestparser;
 
+import java.util.List;
 import java.util.Map;
 import org.osgi.framework.Constants;
 
@@ -84,7 +85,7 @@
     public boolean match(Map configMap, String name)
     {
         String libname = System.mapLibraryName(name);
-        String[] exts = ManifestParser.parseDelimitedString(
+        List<String> exts = ManifestParser.parseDelimitedString(
             (String) configMap.get(Constants.FRAMEWORK_LIBRARY_EXTENSIONS), ",");
         int extIdx = 0;
 
@@ -111,15 +112,15 @@
 
             // If we have other native library extensions to try, then
             // calculate the new native library name.
-            if ((exts != null) && (extIdx < exts.length))
+            if ((exts != null) && (extIdx < exts.size()))
             {
                 int idx = libname.lastIndexOf(".");
                 libname = (idx < 0)
-                    ? libname + "." + exts[extIdx++]
-                    : libname.substring(0, idx) + "." + exts[extIdx++];
+                    ? libname + "." + exts.get(extIdx++)
+                    : libname.substring(0, idx) + "." + exts.get(extIdx++);
             }
         }
-        while ((exts != null) && (extIdx < exts.length));
+        while ((exts != null) && (extIdx < exts.size()));
 
         return false;
     }

Copied: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java
(from r915677, felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/Requirement.java)
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java?p2=felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java&p1=felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/Requirement.java&r1=915677&r2=918498&rev=918498&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/Requirement.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java
Wed Mar  3 14:58:21 2010
@@ -1,109 +1,60 @@
 /*
- * 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
+ *  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
+ *    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.
+ *  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.framework.util.manifestparser;
 
-import org.apache.felix.framework.util.MapToDictionary;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.felix.framework.capabilityset.Attribute;
+import org.apache.felix.framework.capabilityset.Directive;
+import org.apache.felix.framework.capabilityset.Requirement;
+import org.apache.felix.framework.capabilityset.SimpleFilter;
 import org.apache.felix.framework.util.VersionRange;
-import org.apache.felix.moduleloader.ICapability;
-import org.apache.felix.moduleloader.IRequirement;
-import org.osgi.framework.*;
+import org.osgi.framework.Constants;
 
-public class Requirement implements IRequirement
+public class RequirementImpl implements Requirement
 {
     private final String m_namespace;
-    private final R4Directive[] m_directives;
-    private final R4Attribute[] m_attributes;
-    private final boolean m_isOptional;
-
-    private final String m_targetName;
-    private final VersionRange m_targetVersionRange;
-    private volatile Filter m_filter;
-
-    public Requirement(String namespace, String filterStr) throws InvalidSyntaxException
+    private final SimpleFilter m_filter;
+    private final boolean m_optional;
+    private final List<Directive> m_dirs;
+    private final List<Directive> m_dirsConst;
+
+// TODO: FELIX3 - Get rid of dynamic argument.
+    public RequirementImpl(
+        String namespace, List<Directive> dirs, List<Attribute> attrs)
     {
         m_namespace = namespace;
-        m_filter = FrameworkUtil.createFilter(filterStr);
-        m_directives = null;
-        m_attributes = null;
-        m_isOptional = false;
-        m_targetName = null;
-        m_targetVersionRange = null;
-    }
+        m_dirs = dirs;
+        m_dirsConst = Collections.unmodifiableList(m_dirs);
+        m_filter = convertToFilter(attrs);
 
-    public Requirement(String namespace, R4Directive[] directives, R4Attribute[] attributes)
-    {
-        m_namespace = namespace;
-        m_directives = directives;
-        m_attributes = attributes;
-        m_filter = null;
-
-        // Find all import directives: resolution.
+        // Find resolution import directives.
         boolean optional = false;
-        for (int i = 0; (m_directives != null) && (i < m_directives.length); i++)
+        for (int dirIdx = 0; dirIdx < m_dirs.size(); dirIdx++)
         {
-            if (m_directives[i].getName().equals(Constants.RESOLUTION_DIRECTIVE))
-            {
-                optional = m_directives[i].getValue().equals(Constants.RESOLUTION_OPTIONAL);
-            }
-        }
-        m_isOptional = optional;
-
-        String targetName = null;
-        VersionRange targetVersionRange = VersionRange.infiniteRange;
-        for (int i = 0; i < m_attributes.length; i++)
-        {
-            if (m_namespace.equals(ICapability.MODULE_NAMESPACE))
-            {
-                if (m_attributes[i].getName().equals(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE))
-                {
-                    targetName = (String) m_attributes[i].getValue();
-                }
-                else if (m_attributes[i].getName().equals(Constants.BUNDLE_VERSION_ATTRIBUTE))
-                {
-                    targetVersionRange = (VersionRange) m_attributes[i].getValue();
-                }
-            }
-            else if (m_namespace.equals(ICapability.PACKAGE_NAMESPACE))
+            if (m_dirs.get(dirIdx).getName().equals(Constants.RESOLUTION_DIRECTIVE))
             {
-                if (m_attributes[i].getName().equals(ICapability.PACKAGE_PROPERTY))
-                {
-                    targetName = (String) m_attributes[i].getValue();
-                }
-                else if (m_attributes[i].getName().equals(ICapability.VERSION_PROPERTY))
-                {
-                    targetVersionRange = (VersionRange) m_attributes[i].getValue();
-                }
-            }
-            else if (m_namespace.equals(ICapability.HOST_NAMESPACE))
-            {
-                if (m_attributes[i].getName().equals(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE))
-                {
-                    targetName = (String) m_attributes[i].getValue();
-                }
-                else if (m_attributes[i].getName().equals(Constants.BUNDLE_VERSION_ATTRIBUTE))
-                {
-                    targetVersionRange = (VersionRange) m_attributes[i].getValue();
-                }
+                optional = m_dirs.get(dirIdx).getValue().equals(Constants.RESOLUTION_OPTIONAL);
             }
         }
-        m_targetName = targetName;
-        m_targetVersionRange = targetVersionRange;
+        m_optional = optional;
     }
 
     public String getNamespace()
@@ -111,268 +62,126 @@
         return m_namespace;
     }
 
-    public Filter getFilter()
+    public SimpleFilter getFilter()
     {
-        if (m_filter == null)
-        {
-            m_filter = convertToFilter();
-        }
         return m_filter;
     }
 
-// TODO: RB - We need to verify that the resolver code does not
-// touch these implementation-specific methods.
-
-    public String getTargetName()
-    {
-        return m_targetName;
-    }
-
-    public VersionRange getTargetVersionRange()
+    public boolean isOptional()
     {
-        return m_targetVersionRange;
+        return m_optional;
     }
 
-    public R4Directive[] getDirectives()
+    public Directive getDirective(String name)
     {
-        // TODO: RB - We should return copies of the arrays probably.
-        return m_directives;
+        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 R4Attribute[] getAttributes()
+    public List<Directive> getDirectives()
     {
-        // TODO: RB - We should return copies of the arrays probably.
-        return m_attributes;
+        return m_dirsConst;
     }
 
-    public boolean isMultiple()
+    public String toString()
     {
-        return false;
+        return m_namespace + "; " + getFilter().toString();
     }
 
-    public boolean isOptional()
+    private static SimpleFilter convertToFilter(List<Attribute> attrs)
     {
-        return m_isOptional;
-    }
+        // Rather than building a filter string to be parsed into a SimpleFilter,
+        // we will just create the parsed SimpleFilter directly.
 
-    public String getComment()
-    {
-        return "Comment for " + toString();
-    }
+        List<SimpleFilter> filters = new ArrayList<SimpleFilter>();
 
-    public boolean isSatisfied(ICapability capability)
-    {
-        // If the requirement was constructed with a filter, then
-        // we must use that filter for evaluation.
-        if ((m_attributes == null) && (m_filter != null))
-        {
-            return m_namespace.equals(capability.getNamespace()) &&
-                getFilter().match(new MapToDictionary(capability.getProperties()));
-        }
-        // Otherwise, if the requirement was constructed with attributes, then
-        // perform the evaluation manually instead of using the filter for
-        // performance reasons.
-        else if (m_attributes != null)
+        for (Attribute attr : attrs)
         {
-            return capability.getNamespace().equals(getNamespace()) &&
-                doAttributesMatch((Capability) capability);
-        }
-
-        return false;
-    }
-
-    private boolean doAttributesMatch(Capability ec)
-    {
-        // Grab the capability's attributes.
-        R4Attribute[] capAttrs = ec.getAttributes();
-
-        // Cycle through all attributes of this import package
-        // and make sure its values match the attribute values
-        // of the specified export package.
-        for (int reqAttrIdx = 0; reqAttrIdx < m_attributes.length; reqAttrIdx++)
-        {
-            // Get current attribute from this import package.
-            R4Attribute reqAttr = m_attributes[reqAttrIdx];
-
-            // Check if the export package has the same attribute.
-            boolean found = false;
-            for (int capAttrIdx = 0;
-                (!found) && (capAttrIdx < capAttrs.length);
-                capAttrIdx++)
+            if (attr.getValue() instanceof VersionRange)
             {
-                // Get current attribute for the export package.
-                R4Attribute capAttr = capAttrs[capAttrIdx];
-                // Check if the attribute names are equal.
-                if (reqAttr.getName().equals(capAttr.getName()))
+                VersionRange vr = (VersionRange) attr.getValue();
+                if (vr.isFloorInclusive())
                 {
-                    // We only recognize version types. If the value of the
-                    // attribute is a version/version range, then we use the
-                    // "in range" comparison, otherwise we simply use equals().
-                    if (capAttr.getValue() instanceof Version)
-                    {
-                        if (!((VersionRange) reqAttr.getValue()).isInRange((Version) capAttr.getValue()))
-                        {
-                            return false;
-                        }
-                    }
-                    else if (capAttr.getValue() instanceof Object[])
-                    {
-                        Object[] values = (Object[]) capAttr.getValue();
-                        boolean matched = false;
-                        for (int valIdx = 0; !matched && (valIdx < values.length);
valIdx++)
-                        {
-                            if (reqAttr.getValue().equals(values[valIdx]))
-                            {
-                                matched = true;
-                            }
-                        }
-                        if (!matched)
-                        {
-                            return false;
-                        }
-                    }
-                    else if (!reqAttr.getValue().equals(capAttr.getValue()))
-                    {
-                        return false;
-                    }
-                    found = true;
+                    filters.add(
+                        new SimpleFilter(
+                            attr.getName(),
+                            vr.getFloor().toString(),
+                            SimpleFilter.GTE));
                 }
-            }
-            // If the attribute was not found, then return false.
-            if (!found)
-            {
-                return false;
-            }
-        }
-
-        // Now, cycle through all attributes of the export package and verify that
-        // all mandatory attributes are present in this import package.
-        for (int capAttrIdx = 0; capAttrIdx < capAttrs.length; capAttrIdx++)
-        {
-            // Get current attribute for this package.
-            R4Attribute capAttr = capAttrs[capAttrIdx];
-
-            // If the export attribute is mandatory, then make sure
-            // this import package has the attribute.
-            if (capAttr.isMandatory())
-            {
-                boolean found = false;
-                for (int reqAttrIdx = 0;
-                    (!found) && (reqAttrIdx < m_attributes.length);
-                    reqAttrIdx++)
+                else
                 {
-                    // Get current attribute from specified package.
-                    R4Attribute reqAttr = m_attributes[reqAttrIdx];
-
-                    // Check if the attribute names are equal
-                    // and set found flag.
-                    if (capAttr.getName().equals(reqAttr.getName()))
+                    SimpleFilter not =
+                        new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
+                    ((List) not.getValue()).add(
+                        new SimpleFilter(
+                            attr.getName(),
+                            vr.getFloor().toString(),
+                            SimpleFilter.LTE));
+                    filters.add(not);
+                }
+
+                if (vr.getCeiling() != null)
+                {
+                    if (vr.isCeilingInclusive())
+                    {
+                        filters.add(
+                            new SimpleFilter(
+                                attr.getName(),
+                                vr.getCeiling().toString(),
+                                SimpleFilter.LTE));
+                    }
+                    else
                     {
-                        found = true;
+                        SimpleFilter not =
+                            new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
+                        ((List) not.getValue()).add(
+                            new SimpleFilter(
+                                attr.getName(),
+                                vr.getCeiling().toString(),
+                                SimpleFilter.GTE));
+                        filters.add(not);
                     }
                 }
-                // If not found, then return false.
-                if (!found)
-                {
-                    return false;
-                }
             }
-        }
-
-        return true;
-    }
-
-    private Filter convertToFilter()
-    {
-        StringBuffer sb = new StringBuffer();
-        if ((m_attributes != null) && (m_attributes.length > 1))
-        {
-            sb.append("(&");
-        }
-        for (int i = 0; (m_attributes != null) && (i < m_attributes.length); i++)
-        {
-            // If this is a package import, then convert wild-carded
-            // dynamically imported package names to an OR comparison.
-            if (m_namespace.equals(ICapability.PACKAGE_NAMESPACE) &&
-                m_attributes[i].getName().equals(ICapability.PACKAGE_PROPERTY) &&
-                m_attributes[i].getValue().toString().endsWith(".*"))
-            {
-                int idx = m_attributes[i].getValue().toString().indexOf(".*");
-                sb.append("(|(package=");
-                sb.append(m_attributes[i].getValue().toString().substring(0, idx));
-                sb.append(")(package=");
-                sb.append(m_attributes[i].getValue().toString());
-                sb.append("))");
-            }
-            else if (m_attributes[i].getValue() instanceof VersionRange)
+            else
             {
-                VersionRange vr = (VersionRange) m_attributes[i].getValue();
-                if (vr.isLowInclusive())
+                List<String> values = SimpleFilter.parseSubstring(attr.getValue().toString());
+                if (values.size() > 1)
                 {
-                    sb.append("(");
-                    sb.append(m_attributes[i].getName());
-                    sb.append(">=");
-                    sb.append(vr.getLow().toString());
-                    sb.append(")");
+                    filters.add(
+                        new SimpleFilter(
+                            attr.getName(),
+                            values,
+                            SimpleFilter.SUBSTRING));
                 }
                 else
                 {
-                    sb.append("(!(");
-                    sb.append(m_attributes[i].getName());
-                    sb.append("<=");
-                    sb.append(vr.getLow().toString());
-                    sb.append("))");
+                    filters.add(
+                        new SimpleFilter(
+                            attr.getName(),
+                            values.get(0),
+                            SimpleFilter.EQ));
                 }
-
-                if (vr.getHigh() != null)
-                {
-                    if (vr.isHighInclusive())
-                    {
-                        sb.append("(");
-                        sb.append(m_attributes[i].getName());
-                        sb.append("<=");
-                        sb.append(vr.getHigh().toString());
-                        sb.append(")");
-                    }
-                    else
-                    {
-                        sb.append("(!(");
-                        sb.append(m_attributes[i].getName());
-                        sb.append(">=");
-                        sb.append(vr.getHigh().toString());
-                        sb.append("))");
-                    }
-                }
-            }
-            else
-            {
-                sb.append("(");
-                sb.append(m_attributes[i].getName());
-                sb.append("=");
-                sb.append(m_attributes[i].getValue().toString());
-                sb.append(")");
             }
         }
 
-        if ((m_attributes != null) && (m_attributes.length > 1))
-        {
-            sb.append(")");
-        }
+        SimpleFilter sf = null;
 
-        try
+        if (filters.size() == 1)
         {
-            return FrameworkUtil.createFilter(sb.toString());
+            sf = filters.get(0);
         }
-        catch (InvalidSyntaxException ex)
+        else if (attrs.size() > 1)
         {
-            // This should never happen, so we can safely ignore.
+            sf = new SimpleFilter(null, filters, SimpleFilter.AND);
         }
 
-        return null;
-    }
-
-    public String toString()
-    {
-        return getNamespace() + "; " + getFilter().toString();
+        return sf;
     }
 }
\ No newline at end of file



Mime
View raw message