Author: rickhall
Date: Fri Jan 15 19:19:30 2010
New Revision: 899767
URL: http://svn.apache.org/viewvc?rev=899767&view=rev
Log:
Add candidate set.
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Attribute.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Capability.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/CapabilitySet.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Directive.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
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/candidateset/SimpleFilter.java
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
Modified:
felix/sandbox/rickhall/framework-proto/pom.xml
Modified: felix/sandbox/rickhall/framework-proto/pom.xml
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/pom.xml?rev=899767&r1=899766&r2=899767&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/pom.xml (original)
+++ felix/sandbox/rickhall/framework-proto/pom.xml Fri Jan 15 19:19:30 2010
@@ -46,6 +46,15 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <target>1.5</target>
+ <source>1.5</source>
+ </configuration>
+ </plugin>
+
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
@@ -59,7 +68,7 @@
<Export-Package>org.osgi.framework;-split-package:=merge-first,org.osgi.framework.launch,org.osgi.framework.hooks.service,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker</Export-Package>
<Private-Package>org.apache.felix.moduleloader.*,org.apache.felix.framework.*</Private-Package>
<Import-Package>!*</Import-Package>
-
<Include-Resource>META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,{src/main/resources/}</Include-Resource>
+
<Include-Resource>META-INF/LICENSE=LICENSE,META-INF/NOTICE=NOTICE,{src/main/resources/}</Include-Resource>
</instructions>
</configuration>
</plugin>
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Attribute.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Attribute.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Attribute.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Attribute.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.candidateset;
+
+public class Attribute
+{
+ private final String m_name;
+ private final Object m_value;
+ private final boolean m_isMandatory;
+
+ public Attribute(String name, Object value, boolean isMandatory)
+ {
+ m_name = name;
+ m_value = value;
+ m_isMandatory = isMandatory;
+ }
+
+ public String getName()
+ {
+ return m_name;
+ }
+
+ public Object getValue()
+ {
+ return m_value;
+ }
+
+ public boolean isMandatory()
+ {
+ return m_isMandatory;
+ }
+
+ public String toString()
+ {
+ return m_name + "=" + m_value;
+ }
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Capability.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Capability.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Capability.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Capability.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,39 @@
+/*
+ * 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.candidateset;
+
+import java.util.List;
+
+public interface Capability
+{
+ static final String MODULE_NAMESPACE = "module";
+ static final String HOST_NAMESPACE = "host";
+ static final String PACKAGE_NAMESPACE = "package";
+
+ public static final String PACKAGE_ATTR = "package";
+ public static final String VERSION_ATTR = "version";
+
+ Module getModule();
+ String getNamespace();
+ Directive getDirective(String name);
+ List<Directive> getDirectives();
+ Attribute getAttribute(String name);
+ List<Attribute> getAttributes();
+ List<String> getUses();
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/CapabilitySet.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/CapabilitySet.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/CapabilitySet.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/CapabilitySet.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,481 @@
+/*
+ * 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.candidateset;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class CapabilitySet
+{
+ private final Map<String, Map<Object, Set<Capability>>> m_indices =
+ new HashMap<String, Map<Object, Set<Capability>>>();
+ private final Set<Capability> m_capList = new HashSet<Capability>();
+
+ public CapabilitySet(List<String> indexProps)
+ {
+ for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
+ {
+ m_indices.put(indexProps.get(i), new HashMap<Object,
Set<Capability>>());
+ }
+ }
+
+ public void addCapability(Capability cap)
+ {
+ m_capList.add(cap);
+
+ // Index capability.
+ for (Entry<String, Map<Object, Set<Capability>>> entry :
m_indices.entrySet())
+ {
+ if (cap.getAttribute(entry.getKey()) != null)
+ {
+ Map<Object, Set<Capability>> index = entry.getValue();
+ Set<Capability> caps = index.get(
+ cap.getAttribute(entry.getKey()).getValue());
+ if (caps == null)
+ {
+ caps = new HashSet<Capability>();
+ index.put(cap.getAttribute(entry.getKey()).getValue(),
caps);
+ }
+ caps.add(cap);
+ }
+ }
+
+// System.out.println("+++ INDICES " + m_indices);
+ }
+
+ public void removeCapability(Capability cap)
+ {
+ if (m_capList.remove(cap))
+ {
+ for (Iterator<Map.Entry<String, Map<Object, Set<Capability>>>>
+ it = m_indices.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry<String, Map<Object, Set<Capability>>> entry =
it.next();
+ if (cap.getAttribute(entry.getKey()) != null)
+ {
+ Map<Object, Set<Capability>> index = entry.getValue();
+ Set<Capability> caps =
index.get(cap.getAttribute(entry.getKey()).getValue());
+ caps.remove(cap);
+ if (caps.size() == 0)
+ {
+ it.remove();
+ }
+ }
+ }
+
+ System.out.println("+++ INDICES " + m_indices);
+ }
+ }
+
+ public Set<Capability> match(SimpleFilter sf)
+ {
+ return matchMandatory(match(m_capList, sf), sf);
+ }
+
+ private Set<Capability> match(Set<Capability> caps, SimpleFilter sf)
+ {
+//System.out.println("+++ SF " + sf);
+ Set<Capability> matches = new HashSet<Capability>();
+
+ if (sf.getOperation() == SimpleFilter.AND)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For AND we calculate the intersection of each subfilter.
+ // We can short-circuit the AND operation if there are no
+ // remaining capabilities.
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; (caps.size() > 0) && (i < sfs.size()); i++)
+ {
+//System.out.println("+++ REMAINING " + caps);
+ matches = match(caps, sfs.get(i));
+//System.out.println("+++ CURRENT " + matches);
+ caps = matches;
+ }
+ }
+ else if (sf.getOperation() == SimpleFilter.OR)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For OR we calculate the union of each subfilter.
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; i < sfs.size(); i++)
+ {
+ matches.addAll(match(caps, sfs.get(i)));
+ }
+ }
+ else if (sf.getOperation() == SimpleFilter.NOT)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For OR we calculate the union of each subfilter.
+ matches.addAll(caps);
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; i < sfs.size(); i++)
+ {
+ matches.removeAll(match(caps, sfs.get(i)));
+ }
+ }
+ else
+ {
+ Map<Object, Set<Capability>> index = m_indices.get(sf.getName());
+ if ((sf.getOperation() == SimpleFilter.EQ) && (index != null))
+ {
+ Set<Capability> existingCaps = index.get(sf.getValue());
+ if (existingCaps != null)
+ {
+ matches.addAll(existingCaps);
+//System.out.println("NARROWED " + caps.size() + " TO " + existingCaps.size());
+ matches.retainAll(caps);
+ }
+ }
+ else
+ {
+// System.out.println("+++ SEARCHING " + caps.size() + "
CAPABILITIES");
+ for (Iterator<Capability> it = caps.iterator(); it.hasNext(); )
+ {
+ Capability cap = it.next();
+ Attribute attr = cap.getAttribute(sf.getName());
+ if (attr != null)
+ {
+ Object lhs = attr.getValue();
+ if (compare(lhs, (String) sf.getValue(),
sf.getOperation()))
+ {
+ matches.add(cap);
+ }
+ }
+ }
+ }
+ }
+
+ return matches;
+ }
+
+ public static boolean matches(Capability cap, SimpleFilter sf)
+ {
+ boolean matched = true;
+
+ if (sf.getOperation() == SimpleFilter.AND)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For AND we calculate the intersection of each subfilter.
+ // We can short-circuit the AND operation if there are no
+ // remaining capabilities.
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; matched && (i < sfs.size()); i++)
+ {
+ matched = matches(cap, sfs.get(i));
+ }
+ }
+ else if (sf.getOperation() == SimpleFilter.OR)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For OR we calculate the union of each subfilter.
+ matched = false;
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; !matched && (i < sfs.size()); i++)
+ {
+ matched = matches(cap, sfs.get(i));
+ }
+ }
+ else if (sf.getOperation() == SimpleFilter.NOT)
+ {
+ // Evaluate each subfilter against the remaining capabilities.
+ // For OR we calculate the union of each subfilter.
+ List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
+ for (int i = 0; i < sfs.size(); i++)
+ {
+ matched = !(matches(cap, sfs.get(i)));
+ }
+ }
+ else
+ {
+ matched = false;
+ Attribute attr = cap.getAttribute(sf.getName());
+ if (attr != null)
+ {
+ Object lhs = attr.getValue();
+ matched = compare(lhs, (String) sf.getValue(),
sf.getOperation());
+ }
+ }
+
+ return matched && matchMandatory(cap, sf);
+ }
+
+ private static Set<Capability> matchMandatory(Set<Capability> caps,
SimpleFilter sf)
+ {
+ for (Iterator<Capability> it = caps.iterator(); it.hasNext(); )
+ {
+ Capability cap = it.next();
+ if (!matchMandatory(cap, sf))
+ {
+ it.remove();
+ }
+ }
+ return caps;
+ }
+
+ private static boolean matchMandatory(Capability cap, SimpleFilter sf)
+ {
+ List<Attribute> attrs = cap.getAttributes();
+ for (int attrIdx = 0; attrIdx < attrs.size(); attrIdx++)
+ {
+ if (attrs.get(attrIdx).isMandatory()
+ && !matchMandatory(attrs.get(attrIdx), sf))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean matchMandatory(Attribute attr, SimpleFilter sf)
+ {
+ if ((sf.getOperation() == SimpleFilter.EQ)
+ && sf.getName().equals(attr.getName()))
+ {
+ return true;
+ }
+ else if ((sf.getOperation() == SimpleFilter.AND))
+ {
+ List list = (List) sf.getValue();
+ for (int i = 0; i < list.size(); i++)
+ {
+ SimpleFilter sf2 = (SimpleFilter) list.get(i);
+ if ((sf2.getOperation() == SimpleFilter.EQ)
+ && sf2.getName().equals(attr.getName()))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static final Class[] STRING_CLASS = new Class[] { String.class };
+
+ private static boolean compare(Object lhs, String rhsString, int op)
+ {
+ // If the type is comparable, then we can just return the
+ // result immediately.
+ if (lhs instanceof Comparable)
+ {
+ Object rhs = coerceType(lhs, rhsString);
+ switch (op)
+ {
+ case SimpleFilter.EQ :
+ return (((Comparable) lhs).compareTo(rhs) == 0);
+ case SimpleFilter.GTE :
+ return (((Comparable) lhs).compareTo(rhs) >= 0);
+ case SimpleFilter.LTE :
+ return (((Comparable) lhs).compareTo(rhs) <= 0);
+// case SimpleFilter.APPROX :
+// return compareToApprox(((Comparable) lhs), rhs);
+ default:
+ throw new RuntimeException(
+ "Unknown comparison operator: " + op);
+ }
+ }
+ // Booleans do not implement comparable, so special case them.
+ else if (lhs instanceof Boolean)
+ {
+ Object rhs = coerceType(lhs, rhsString);
+ switch (op)
+ {
+ case SimpleFilter.EQ :
+ case SimpleFilter.GTE :
+ case SimpleFilter.LTE :
+// case SimpleFilter.APPROX:
+ return (lhs.equals(rhs));
+ default:
+ throw new RuntimeException(
+ "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())
+ {
+ // 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;
+ }
+ }
+ }
+ // If LHS is a collection, then call compare() on each element
+ // of the collection until a match is found.
+ else if (lhs instanceof Collection)
+ {
+ for (Iterator iter = ((Collection) lhs).iterator();
iter.hasNext(); )
+ {
+ if (compare(iter.next(), rhsString, op))
+ {
+ return true;
+ }
+ }
+ }
+
+ // Since we cannot identify the LHS type, then we can only perform
+ // equality comparison.
+ return lhs.equals(coerceType(lhs, rhsString));
+ }
+
+ private static Object coerceType(Object lhs, String rhsString)
+ {
+ // If the LHS expects a string, then we can just return
+ // the RHS since it is a string.
+ if (lhs.getClass() == rhsString.getClass())
+ {
+ return rhsString;
+ }
+
+ // Try to convert the RHS type to the LHS type by using
+ // the string constructor of the LHS class, if it has one.
+ Object rhs = null;
+ try
+ {
+ // The Character class is a special case, since its constructor
+ // does not take a string, so handle it separately.
+ if (lhs instanceof Character)
+ {
+ rhs = new Character(rhsString.charAt(0));
+ }
+ else
+ {
+ rhs = lhs.getClass()
+ .getConstructor(STRING_CLASS)
+ .newInstance(new Object[] { rhsString });
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(
+ "Could not instantiate class "
+ + lhs.getClass().getName()
+ + " using string constructor with argument '"
+ + rhsString + "' because " + ex);
+ }
+
+ return rhs;
+ }
+
+ /**
+ * This is an ugly utility method to convert an array of primitives
+ * to an array of primitive wrapper objects. This method simplifies
+ * processing LDAP filters since the special case of primitive arrays
+ * can be ignored.
+ * @param array An array of primitive types.
+ * @return An corresponding array using pritive wrapper objects.
+ **/
+ private static Object[] convertPrimitiveArray(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)
+ {
+ 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]);
+ }
+ }
+ 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;
+ }
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Directive.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Directive.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Directive.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Directive.java
Fri Jan 15 19:19:30 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.framework.candidateset;
+
+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
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Module.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.candidateset;
+
+import java.util.List;
+
+public interface Module
+{
+ String getName();
+ List<Capability> getCapabilities();
+ List<Requirement> getRequirements();
+ boolean isResolved();
+ List<Wire> getWires();
+}
\ No newline at end of file
Added:
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=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Requirement.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,26 @@
+/*
+ * 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.candidateset;
+
+public interface Requirement
+{
+ String getNamespace();
+ SimpleFilter getFilter();
+ boolean isOptional();
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/SimpleFilter.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/SimpleFilter.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/SimpleFilter.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/SimpleFilter.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,217 @@
+/*
+ * 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.candidateset;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SimpleFilter
+{
+ public static final int AND = 1;
+ public static final int OR = 2;
+ public static final int NOT = 3;
+ public static final int EQ = 4;
+ public static final int LTE = 5;
+ public static final int GTE = 6;
+
+ private final String m_name;
+ private final Object m_value;
+ private final int m_op;
+
+ public SimpleFilter(String attr, Object value, int op)
+ {
+ m_name = attr;
+ m_value = value;
+ m_op = op;
+ }
+
+ public String getName()
+ {
+ return m_name;
+ }
+
+ public Object getValue()
+ {
+ return m_value;
+ }
+
+ public int getOperation()
+ {
+ return m_op;
+ }
+
+ public String toString()
+ {
+ String s = null;
+ switch (m_op)
+ {
+ case AND:
+ s = "(&" + toString((List) m_value) + ")";
+ break;
+ case OR:
+ s = "(|" + toString((List) m_value) + ")";
+ break;
+ case NOT:
+ s = "(!" + toString((List) m_value) + ")";
+ break;
+ case EQ:
+ s = "(" + m_name + "=" + m_value + ")";
+ break;
+ case LTE:
+ s = "(" + m_name + "<=" + m_value + ")";
+ break;
+ case GTE:
+ s = "(" + m_name + ">=" + m_value + ")";
+ break;
+ }
+ return s;
+ }
+
+ private String toString(List list)
+ {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < list.size(); i++)
+ {
+ sb.append(list.get(i).toString());
+ }
+ return sb.toString();
+ }
+
+ public static SimpleFilter parse(String filter)
+ {
+ filter = filter.trim();
+
+ if ((filter == null) || (filter.length() == 0))
+ {
+ throw new IllegalArgumentException("Null or empty filter.");
+ }
+ else if (filter.charAt(0) != '(')
+ {
+ throw new IllegalArgumentException("Missing opening parenthesis: "
+ filter);
+ }
+
+ SimpleFilter sf = null;
+ List stack = new ArrayList();
+ for (int i = 0; i < filter.length(); i++)
+ {
+ if (sf != null)
+ {
+ throw new IllegalArgumentException(
+ "Only one top-level operation allowed: " + filter);
+ }
+ if (filter.charAt(i) == '(')
+ {
+ if (filter.charAt(i+1) == '&')
+ {
+ stack.add(0, new SimpleFilter(null, new ArrayList(),
SimpleFilter.AND));
+ }
+ else if (filter.charAt(i+1) == '|')
+ {
+ stack.add(0, new SimpleFilter(null, new ArrayList(),
SimpleFilter.OR));
+ }
+ else if (filter.charAt(i+1) == '!')
+ {
+ stack.add(0, new SimpleFilter(null, new ArrayList(),
SimpleFilter.NOT));
+ }
+ else
+ {
+ stack.add(0, new Integer(i));
+ }
+ }
+ else if (filter.charAt(i) == ')')
+ {
+ Object top = stack.remove(0);
+ if (top instanceof SimpleFilter)
+ {
+ if (!stack.isEmpty() && (stack.get(0) instanceof
SimpleFilter))
+ {
+ ((List) ((SimpleFilter)
stack.get(0)).m_value).add(top);
+ }
+ else
+ {
+ sf = (SimpleFilter) top;
+ }
+ }
+ else if (!stack.isEmpty() && (stack.get(0) instanceof
SimpleFilter))
+ {
+ ((List) ((SimpleFilter) stack.get(0)).m_value).add(
+ SimpleFilter.subfilter(filter, ((Integer)
top).intValue() + 1, i));
+ }
+ else
+ {
+ sf = SimpleFilter.subfilter(filter, ((Integer)
top).intValue() + 1, i);
+ }
+ }
+ }
+
+ if (sf == null)
+ {
+ throw new IllegalArgumentException("Missing closing parenthesis: "
+ filter);
+ }
+
+ return sf;
+ }
+
+ private static SimpleFilter subfilter(String filter, int startIdx, int
endIdx)
+ {
+ final String opChars = "=<>";
+ String attr = null, value = null;
+ int op = -1;
+ for (int i = 0; i < (endIdx - startIdx); i++)
+ {
+ if (opChars.indexOf(filter.charAt(startIdx + i)) >= 0)
+ {
+ switch (filter.charAt(startIdx + i))
+ {
+ case '=':
+ attr = filter.substring(startIdx, startIdx + i);
+ op = EQ;
+ value = filter.substring(startIdx + i + 1, endIdx);
+ break;
+ case '<':
+ if (filter.charAt(startIdx + i + 1) != '=')
+ {
+ throw new IllegalArgumentException(
+ "Unknown operator: " +
filter.substring(startIdx, endIdx));
+ }
+ attr = filter.substring(startIdx, startIdx + i);
+ op = LTE;
+ value = filter.substring(startIdx + i + 2, endIdx);
+ break;
+ case '>':
+ if (filter.charAt(startIdx + i + 1) != '=')
+ {
+ throw new IllegalArgumentException(
+ "Unknown operator: " +
filter.substring(startIdx, endIdx));
+ }
+ attr = filter.substring(startIdx, startIdx + i);
+ op = GTE;
+ value = filter.substring(startIdx + i + 2, endIdx);
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Unknown operator: " + filter.substring(startIdx,
endIdx));
+ }
+ break;
+ }
+ }
+
+ return new SimpleFilter(attr, value, op);
+ }
+}
\ No newline at end of file
Added:
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java?rev=899767&view=auto
==============================================================================
---
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
(added)
+++
felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/candidateset/Wire.java
Fri Jan 15 19:19:30 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.candidateset;
+
+public interface Wire
+{
+ Module getImporter();
+ Requirement getRequirement();
+ Module getExporter();
+ Capability getCapability();
+}
\ No newline at end of file