felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1305488 [3/3] - in /felix/sandbox/rickhall/rfc-112: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/resolver/ src/main/java/org/apache/felix/resol...
Date Mon, 26 Mar 2012 18:47:21 GMT
Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WireImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WireImpl.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WireImpl.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WireImpl.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+
+class WireImpl implements Wire
+{
+    private final Resource m_requirer;
+    private final Requirement m_req;
+    private final Resource m_provider;
+    private final Capability m_cap;
+
+    public WireImpl(
+        Resource requirer, Requirement req,
+        Resource provider, Capability cap)
+    {
+        m_requirer = requirer;
+        m_req = req;
+        m_provider = provider;
+        m_cap = cap;
+    }
+
+    public Resource getRequirer()
+    {
+        return m_requirer;
+    }
+
+    public Requirement getRequirement()
+    {
+        return m_req;
+    }
+
+    public Resource getProvider()
+    {
+        return m_provider;
+    }
+
+    public Capability getCapability()
+    {
+        return m_cap;
+    }
+
+    @Override
+    public String toString()
+    {
+        return m_req
+            + " -> "
+            + "[" + m_provider + "]";
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedCapability.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedCapability.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedCapability.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ *
+ * Licensed 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;
+
+import java.util.Map;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+import org.osgi.service.resolver.HostedCapability;
+
+public class WrappedCapability implements HostedCapability
+{
+    private final Resource m_host;
+    private final Capability m_cap;
+
+    public WrappedCapability(Resource host, Capability cap)
+    {
+        m_host = host;
+        m_cap = cap;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final WrappedCapability other = (WrappedCapability) obj;
+        if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+        {
+            return false;
+        }
+        if (m_cap != other.m_cap && (m_cap == null || !m_cap.equals(other.m_cap)))
+        {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+        hash = 37 * hash + (m_cap != null ? m_cap.hashCode() : 0);
+        return hash;
+    }
+
+    public Capability getDeclaredCapability()
+    {
+        return m_cap;
+    }
+
+    public Resource getResource()
+    {
+        return m_host;
+    }
+
+    public String getNamespace()
+    {
+        return m_cap.getNamespace();
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_cap.getDirectives();
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_cap.getAttributes();
+    }
+
+// TODO: RFC-112 - Need impl-specific type.
+//    public List<String> getUses()
+//    {
+//        return m_cap.getUses();
+//    }
+
+    @Override
+    public String toString()
+    {
+        if (m_host == null)
+        {
+            return getAttributes().toString();
+        }
+        if (getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE))
+        {
+            return "[" + m_host + "] "
+                + getNamespace()
+                + "; "
+                + getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+        }
+        return "[" + m_host + "] " + getNamespace() + "; " + getAttributes();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedRequirement.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedRequirement.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedRequirement.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedRequirement.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,102 @@
+/*
+ * 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;
+
+import java.util.Map;
+import org.osgi.resource.Namespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+public class WrappedRequirement implements Requirement
+{
+    private final Resource m_host;
+    private final Requirement m_req;
+
+    public WrappedRequirement(Resource host, Requirement req)
+    {
+        m_host = host;
+        m_req = req;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final WrappedRequirement other = (WrappedRequirement) obj;
+        if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+        {
+            return false;
+        }
+        if (m_req != other.m_req && (m_req == null || !m_req.equals(other.m_req)))
+        {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+        hash = 37 * hash + (m_req != null ? m_req.hashCode() : 0);
+        return hash;
+    }
+
+    public Requirement getDeclaredRequirement()
+    {
+        return m_req;
+    }
+
+    public Resource getResource()
+    {
+        return m_host;
+    }
+
+    public String getNamespace()
+    {
+        return m_req.getNamespace();
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_req.getDirectives();
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_req.getAttributes();
+    }
+
+    @Override
+    public String toString()
+    {
+        return "[" + m_host + "] "
+            + getNamespace()
+            + "; "
+            + getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedResource.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedResource.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedResource.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/WrappedResource.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+class WrappedResource implements Resource
+{
+    private final Resource m_host;
+    private final List<Resource> m_fragments;
+    private List<Capability> m_cachedCapabilities = null;
+    private List<Requirement> m_cachedRequirements = null;
+
+    public WrappedResource(Resource host, List<Resource> fragments)
+    {
+        m_host = host;
+        m_fragments = fragments;
+    }
+
+    public Resource getDeclaredResource()
+    {
+        return m_host;
+    }
+
+    public List<Resource> getFragments()
+    {
+        return m_fragments;
+    }
+
+    public List<Capability> getCapabilities(String namespace)
+    {
+        if (m_cachedCapabilities == null)
+        {
+            List<Capability> caps = new ArrayList<Capability>();
+
+            // Wrap host capabilities.
+            for (Capability cap : m_host.getCapabilities(null))
+            {
+                caps.add(new WrappedCapability(this, cap));
+            }
+
+            // Wrap fragment capabilities.
+            if (m_fragments != null)
+            {
+                for (Resource fragment : m_fragments)
+                {
+                    for (Capability cap : fragment.getCapabilities(null))
+                    {
+                        // Filter out identity capabilities, since they
+                        // are not part of the fragment payload.
+                        if (!cap.getNamespace()
+                            .equals(IdentityNamespace.IDENTITY_NAMESPACE))
+                        {
+                            caps.add(new WrappedCapability(this,  cap));
+                        }
+                    }
+                }
+            }
+            m_cachedCapabilities = Collections.unmodifiableList(caps);
+        }
+        return m_cachedCapabilities;
+    }
+
+    public List<Requirement> getRequirements(String namespace)
+    {
+        if (m_cachedRequirements == null)
+        {
+            List<Requirement> reqs = new ArrayList<Requirement>();
+
+            // Wrap host requirements.
+            for (Requirement req : m_host.getRequirements(null))
+            {
+                reqs.add(new WrappedRequirement(this, req));
+            }
+
+            // Wrap fragment requirements.
+            if (m_fragments != null)
+            {
+                for (Resource fragment : m_fragments)
+                {
+                    for (Requirement req : fragment.getRequirements(null))
+                    {
+                        // Filter out host and execution environment requirements,
+                        // since they are not part of the fragment payload.
+                        if (!req.getNamespace().equals(HostNamespace.HOST_NAMESPACE)
+                            && !req.getNamespace().equals(
+                                ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))
+                        {
+                            reqs.add(new WrappedRequirement(this, req));
+                        }
+                    }
+                }
+            }
+            m_cachedRequirements = Collections.unmodifiableList(reqs);
+        }
+        return m_cachedRequirements;
+    }
+
+    public String toString()
+    {
+        return m_host.toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleCapability.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleCapability.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleCapability.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,79 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+
+class BundleCapability implements Capability
+{
+    private final Resource m_resource;
+    private final Map<String, String> m_dirs;
+    private final Map<String, Object> m_attrs;
+
+    public BundleCapability(Resource resource, String name)
+    {
+        m_resource = resource;
+        m_dirs = new HashMap<String, String>();
+        m_attrs = new HashMap<String, Object>();
+        m_attrs.put(BundleNamespace.BUNDLE_NAMESPACE, name);
+    }
+
+    public String getNamespace()
+    {
+        return BundleNamespace.BUNDLE_NAMESPACE;
+    }
+
+    public void addDirective(String name, String value)
+    {
+        m_dirs.put(name, value);
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_dirs;
+    }
+
+    public void addAttribute(String name, Object value)
+    {
+        m_attrs.put(name, value);
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_attrs;
+    }
+
+    public Resource getResource()
+    {
+        return m_resource;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getNamespace() + "; "
+            + getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleRequirement.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleRequirement.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleRequirement.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/BundleRequirement.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+class BundleRequirement implements Requirement
+{
+    private final Resource m_resource;
+    private final Map<String, String> m_dirs;
+    private final Map<String, Object> m_attrs;
+
+    public BundleRequirement(Resource resource, String name)
+    {
+        m_resource = resource;
+        m_dirs = new HashMap<String, String>();
+        m_dirs.put(
+            BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE,
+            "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + name + ")");
+        m_attrs = new HashMap<String, Object>();
+    }
+
+    public String getNamespace()
+    {
+        return BundleNamespace.BUNDLE_NAMESPACE;
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_dirs;
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_attrs;
+    }
+
+    public Resource getResource()
+    {
+        return m_resource;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getNamespace() + "; "
+            + getDirectives().get(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/IdentityCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/IdentityCapability.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/IdentityCapability.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/IdentityCapability.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+
+class IdentityCapability implements Capability
+{
+    private final Resource m_resource;
+    private final Map<String, String> m_dirs;
+    private final Map<String, Object> m_attrs;
+
+    public IdentityCapability(Resource resource, String name)
+    {
+        m_resource = resource;
+        m_dirs = new HashMap<String, String>();
+        m_attrs = new HashMap<String, Object>();
+        m_attrs.put(IdentityNamespace.IDENTITY_NAMESPACE, name);
+    }
+
+    public String getNamespace()
+    {
+        return IdentityNamespace.IDENTITY_NAMESPACE;
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_dirs;
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_attrs;
+    }
+
+    public Resource getResource()
+    {
+        return m_resource;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getNamespace() + "; "
+            + getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/Main.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/Main.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/Main.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,180 @@
+/*
+ * 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.test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.felix.resolver.Logger;
+import org.apache.felix.resolver.ResolverImpl;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Namespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+import org.osgi.resource.Wiring;
+import org.osgi.service.resolver.ResolutionException;
+import org.osgi.service.resolver.Resolver;
+
+public class Main
+{
+    public static void main(String[] args) throws ResolutionException
+    {
+        Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
+
+        Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
+        Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
+
+        System.out.println("\nSCENARIO 1\n");
+        List<Resource> mandatory = populateScenario1(wirings, candMap);
+        ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
+        Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
+        System.out.println("RESULT " + wireMap);
+
+        System.out.println("\nSCENARIO 2\n");
+        mandatory = populateScenario2(wirings, candMap);
+        rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
+        wireMap = resolver.resolve(rci);
+        System.out.println("RESULT " + wireMap);
+
+        System.out.println("\nSCENARIO 3\n");
+        mandatory = populateScenario3(wirings, candMap);
+        rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
+        wireMap = resolver.resolve(rci);
+        System.out.println("RESULT " + wireMap);
+    }
+
+    private static List<Resource> populateScenario1(
+        Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap)
+    {
+        wirings.clear();
+        candMap.clear();
+
+        ResourceImpl exporter = new ResourceImpl("A");
+        exporter.addCapability(new PackageCapability(exporter, "foo"));
+        ResourceImpl importer = new ResourceImpl("B");
+        importer.addRequirement(new PackageRequirement(importer, "foo"));
+        candMap.put(
+            importer.getRequirements(null).get(0),
+            exporter.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE));
+        List<Resource> resources = new ArrayList<Resource>();
+        resources.add(importer);
+        return resources;
+    }
+
+    private static List<Resource> populateScenario2(
+        Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap)
+    {
+        wirings.clear();
+        candMap.clear();
+
+        List<Capability> fooCands = new ArrayList<Capability>();
+        List<Capability> barCands = new ArrayList<Capability>();
+
+        // A
+        ResourceImpl a = new ResourceImpl("A");
+        PackageCapability p = new PackageCapability(a, "foo");
+        a.addCapability(p);
+        fooCands.add(p);
+
+        // B
+        ResourceImpl b = new ResourceImpl("B");
+        p = new PackageCapability(b, "foo");
+        b.addCapability(p);
+        fooCands.add(p);
+
+        p = new PackageCapability(b, "bar");
+        p.addDirective(PackageNamespace.CAPABILITY_USES_DIRECTIVE, "foo");
+        b.addCapability(p);
+        barCands.add(p);
+
+        // C
+        ResourceImpl c = new ResourceImpl("C");
+        Requirement r = new PackageRequirement(c, "foo");
+        c.addRequirement(r);
+        candMap.put(r, fooCands);
+
+        r = new PackageRequirement(c, "bar");
+        c.addRequirement(r);
+        candMap.put(r, barCands);
+
+        // Mandatory resources
+        List<Resource> resources = new ArrayList<Resource>();
+        resources.add(c);
+        return resources;
+    }
+
+    private static List<Resource> populateScenario3(
+        Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap)
+    {
+        wirings.clear();
+        candMap.clear();
+
+        List<Capability> resourcesCands = new ArrayList<Capability>();
+        List<Capability> dResourcesCands = new ArrayList<Capability>();
+        List<Capability> eBundleDCands = new ArrayList<Capability>();
+        List<Capability> eResourcesCands = new ArrayList<Capability>();
+
+        // B
+        ResourceImpl b = new ResourceImpl("B");
+        PackageCapability pc = new PackageCapability(b, "resources");
+        b.addCapability(pc);
+        eResourcesCands.add(pc);
+
+        // C
+        ResourceImpl c = new ResourceImpl("C");
+        pc = new PackageCapability(c, "resources");
+        c.addCapability(pc);
+        eResourcesCands.add(pc);
+        dResourcesCands.add(pc);
+
+        // D
+        ResourceImpl d = new ResourceImpl("D");
+        pc = new PackageCapability(d, "export");
+        pc.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "resources");
+        d.addCapability(pc);
+
+        BundleCapability bc = new BundleCapability(d, "D");
+        bc.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "resources");
+        d.addCapability(bc);
+        eBundleDCands.add(bc);
+
+        Requirement r = new PackageRequirement(d, "resources");
+        d.addRequirement(r);
+        candMap.put(r, dResourcesCands);
+
+        // E
+        ResourceImpl e = new ResourceImpl("E");
+        r = new BundleRequirement(e, "D");
+        e.addRequirement(r);
+        candMap.put(r, eBundleDCands);
+
+        r = new PackageRequirement(e, "resources");
+        e.addRequirement(r);
+        candMap.put(r, eResourcesCands);
+
+        // Mandatory resources
+        List<Resource> resources = new ArrayList<Resource>();
+        resources.add(e);
+        return resources;
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageCapability.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageCapability.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageCapability.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,78 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+
+class PackageCapability implements Capability
+{
+    private final Resource m_resource;
+    private final Map<String, String> m_dirs;
+    private final Map<String, Object> m_attrs;
+
+    public PackageCapability(Resource resource, String name)
+    {
+        m_resource = resource;
+        m_dirs = new HashMap<String, String>();
+        m_attrs = new HashMap<String, Object>();
+        m_attrs.put(PackageNamespace.PACKAGE_NAMESPACE, name);
+    }
+
+    public String getNamespace()
+    {
+        return PackageNamespace.PACKAGE_NAMESPACE;
+    }
+
+    public void addDirective(String name, String value)
+    {
+        m_dirs.put(name, value);
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_dirs;
+    }
+
+    public void addAttribute(String name, Object value)
+    {
+        m_attrs.put(name, value);
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_attrs;
+    }
+
+    public Resource getResource()
+    {
+        return m_resource;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getNamespace() + "; "
+            + getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageRequirement.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageRequirement.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageRequirement.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/PackageRequirement.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+class PackageRequirement implements Requirement
+{
+    private final Resource m_resource;
+    private final Map<String, String> m_dirs;
+    private final Map<String, Object> m_attrs;
+
+    public PackageRequirement(Resource resource, String name)
+    {
+        m_resource = resource;
+        m_dirs = new HashMap<String, String>();
+        m_dirs.put(
+            PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE,
+            "(" + PackageNamespace.PACKAGE_NAMESPACE + "=" + name + ")");
+        m_attrs = new HashMap<String, Object>();
+    }
+
+    public String getNamespace()
+    {
+        return PackageNamespace.PACKAGE_NAMESPACE;
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_dirs;
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_attrs;
+    }
+
+    public Resource getResource()
+    {
+        return m_resource;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getNamespace() + "; "
+            + getDirectives().get(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResolveContextImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResolveContextImpl.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResolveContextImpl.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResolveContextImpl.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,86 @@
+/*
+ * 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.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wiring;
+import org.osgi.service.resolver.HostedCapability;
+import org.osgi.service.resolver.ResolveContext;
+
+class ResolveContextImpl extends ResolveContext
+{
+    private final Map<Resource, Wiring> m_wirings;
+    private final Map<Requirement, List<Capability>> m_candMap;
+    private final Collection<Resource> m_mandatory;
+    private final Collection<Resource> m_optional;
+
+    public ResolveContextImpl(
+        Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap,
+        Collection<Resource> mandatory, Collection<Resource> optional)
+    {
+        m_wirings = wirings;
+        m_candMap = candMap;
+        m_mandatory = mandatory;
+        m_optional = optional;
+    }
+
+    @Override
+    public Collection<Resource> getMandatoryResources()
+    {
+        return new ArrayList<Resource>(m_mandatory);
+    }
+
+    @Override
+    public Collection<Resource> getOptionalResources()
+    {
+        return new ArrayList<Resource>(m_optional);
+    }
+
+    @Override
+    public List<Capability> findProviders(Requirement r)
+    {
+        return new ArrayList<Capability>(m_candMap.get(r));
+    }
+
+    @Override
+    public int insertHostedCapability(List<Capability> capabilities, HostedCapability hostedCapability)
+    {
+        int idx = 0;
+        capabilities.add(idx, hostedCapability);
+        return idx;
+    }
+
+    @Override
+    public boolean isEffective(Requirement requirement)
+    {
+        return true;
+    }
+
+    @Override
+    public Map<Resource, Wiring> getWirings()
+    {
+        return m_wirings;
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResourceImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResourceImpl.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResourceImpl.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/apache/felix/resolver/test/ResourceImpl.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,89 @@
+/*
+ * 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.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+public class ResourceImpl implements Resource
+{
+    private final List<Capability> m_caps;
+    private final List<Requirement> m_reqs;
+
+    public ResourceImpl(String name)
+    {
+        m_caps = new ArrayList<Capability>();
+        m_caps.add(0, new IdentityCapability(this, name));
+        m_reqs = new ArrayList<Requirement>();
+    }
+
+    public void addCapability(Capability cap)
+    {
+        m_caps.add(cap);
+    }
+
+    public List<Capability> getCapabilities(String namespace)
+    {
+        List<Capability> result = m_caps;
+        if (namespace != null)
+        {
+            result = new ArrayList<Capability>();
+            for (Capability cap : m_caps)
+            {
+                if (cap.getNamespace().equals(namespace))
+                {
+                    result.add(cap);
+                }
+            }
+        }
+        return result;
+    }
+
+    public void addRequirement(Requirement req)
+    {
+        m_reqs.add(req);
+    }
+
+    public List<Requirement> getRequirements(String namespace)
+    {
+        List<Requirement> result = m_reqs;
+        if (namespace != null)
+        {
+            result = new ArrayList<Requirement>();
+            for (Requirement req : m_reqs)
+            {
+                if (req.getNamespace().equals(namespace))
+                {
+                    result.add(req);
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0).toString();
+    }
+}
\ No newline at end of file

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/HostedCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/HostedCapability.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/HostedCapability.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/HostedCapability.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ * 
+ * Licensed 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.osgi.service.resolver;
+
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+
+/**
+ * A capability hosted by a resource.
+ * 
+ * <p>
+ * A HostedCapability is a Capability where the {@link #getResource()} method
+ * returns a Resource that hosts this Capability instead of declaring it. This
+ * is necessary for cases where the declaring Resource of a Capability does not
+ * match the runtime state. For example, this is the case for fragments attached
+ * to a host. Most fragment declared capabilities and requirements become hosted
+ * by the host resource. Since a fragment can attach to multiple hosts, a single
+ * capability can actually be hosted multiple times.
+ * 
+ * @ThreadSafe
+ * @noimplement
+ * @version $Id: db698baa07e2ee8b5467871239adb5f0806dc183 $
+ */
+public interface HostedCapability extends Capability {
+
+	/**
+	 * Return the Resource that hosts this Capability.
+	 * 
+	 * @return The Resource that hosts this Capability.
+	 */
+	Resource getResource();
+
+	/**
+	 * Return the Capability hosted by the Resource.
+	 * 
+	 * @return The Capability hosted by the Resource.
+	 */
+	Capability getDeclaredCapability();
+}

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolutionException.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolutionException.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolutionException.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolutionException.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) OSGi Alliance (2011, 2012). All Rights Reserved.
+ * 
+ * Licensed 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.osgi.service.resolver;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import org.osgi.resource.Requirement;
+
+/**
+ * Indicates failure to resolve a set of requirements.
+ * 
+ * <p>
+ * If a resolution failure is caused by a missing mandatory dependency a
+ * resolver may include any requirements it has considered in the resolution
+ * exception. Clients may access this set of dependencies via the
+ * {@link #getUnresolvedRequirements()} method.
+ * 
+ * <p>
+ * Resolver implementations may extend this class to provide extra state
+ * information about the reason for the resolution failure.
+ * 
+ * @version $Id: 42e5773e3b7e240673874329e5d9e705d0b698c5 $
+ */
+public class ResolutionException extends Exception {
+
+	private static final long				serialVersionUID	= 1L;
+
+	private final Collection<Requirement>	unresolvedRequirements;
+
+	/**
+	 * Create a {@code ResolutionException} with the specified message, cause
+	 * and unresolved requirements.
+	 * 
+	 * @param message The message.
+	 * @param cause The cause of this exception.
+	 * @param unresolvedRequirements The unresolved mandatory requirements from
+	 *        mandatory resources or {@code null} if no unresolved requirements
+	 *        information is provided.
+	 */
+	public ResolutionException(String message, Throwable cause, Collection<Requirement> unresolvedRequirements) {
+		super(message, cause);
+		if ((unresolvedRequirements == null) || unresolvedRequirements.isEmpty()) {
+			this.unresolvedRequirements = emptyCollection();
+		} else {
+			this.unresolvedRequirements = Collections.unmodifiableCollection(new ArrayList<Requirement>(unresolvedRequirements));
+		}
+	}
+
+	/**
+	 * Create a {@code ResolutionException} with the specified message.
+	 * 
+	 * @param message The message.
+	 */
+	public ResolutionException(String message) {
+		super(message);
+		unresolvedRequirements = emptyCollection();
+	}
+
+	/**
+	 * Create a {@code ResolutionException} with the specified cause.
+	 * 
+	 * @param cause The cause of this exception.
+	 */
+	public ResolutionException(Throwable cause) {
+		super(cause);
+		unresolvedRequirements = emptyCollection();
+	}
+
+	private static <T> Collection<T> emptyCollection() {
+		return Collections.EMPTY_LIST;
+	}
+
+	/**
+	 * Return the unresolved requirements, if any, for this exception.
+	 * 
+	 * <p>
+	 * The unresolved requirements are provided for informational purposes and
+	 * the specific set of unresolved requirements that are provided after a
+	 * resolve failure is not defined.
+	 * 
+	 * @return A collection of the unresolved requirements for this exception.
+	 *         The returned collection may be empty if no unresolved
+	 *         requirements information is provided.
+	 */
+	public Collection<Requirement> getUnresolvedRequirements() {
+		return unresolvedRequirements;
+	}
+}

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolveContext.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolveContext.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolveContext.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/ResolveContext.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) OSGi Alliance (2011, 2012). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.resolver;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wiring;
+
+/**
+ * A resolve context provides resources, options and constraints to the
+ * potential solution of a {@link Resolver#resolve(ResolveContext) resolve}
+ * operation.
+ * 
+ * <p>
+ * Resolve Contexts:
+ * <ul>
+ * <li>Specify the mandatory and optional resources to resolve. The mandatory
+ * and optional resources must be consistent and correct. For example, they must
+ * not violate the singleton policy of the implementer.</li>
+ * <li>Provide {@link Capability capabilities} that the Resolver can use to
+ * satisfy {@link Requirement requirements} via the
+ * {@link #findProviders(Requirement)} method</li>
+ * <li>Constrain solutions via the {@link #getWirings()} method. A wiring
+ * consists of a map of existing {@link Resource resources} to {@link Wiring
+ * wiring}.</li>
+ * <li>Filter requirements that are part of a resolve operation via the
+ * {@link #isEffective(Requirement)}.</li>
+ * </ul>
+ * 
+ * <p>
+ * A resolver may call the methods on the resolve context any number of times
+ * during a resolve operation using any thread. Implementors should ensure that
+ * this class is properly thread safe.
+ * 
+ * <p>
+ * Except for {@link #insertHostedCapability(List, HostedCapability)}, the
+ * resolve context methods must be <i>idempotent</i>. This means that resources
+ * must have constant capabilities and requirements and the resolve context must
+ * return a consistent set of capabilities, wires and effective requirements.
+ * 
+ * @ThreadSafe
+ * @version $Id: f92eae32ab6fadb25e13d226458d6af50e8dcbba $
+ */
+public abstract class ResolveContext {
+	/**
+	 * Return the resources that must be resolved for this resolve context.
+	 * 
+	 * <p>
+	 * The default implementation returns an empty collection.
+	 * 
+	 * @return The resources that must be resolved for this resolve context. May
+	 *         be empty if there are no mandatory resources.
+	 */
+	public Collection<Resource> getMandatoryResources() {
+		return emptyCollection();
+	}
+
+	/**
+	 * Return the resources that the resolver should attempt to resolve for this
+	 * resolve context. Inability to resolve one of the specified resources will
+	 * not result in a resolution exception.
+	 * 
+	 * <p>
+	 * The default implementation returns an empty collection.
+	 * 
+	 * @return The resources that the resolver should attempt to resolve for
+	 *         this resolve context. May be empty if there are no mandatory
+	 *         resources.
+	 */
+	public Collection<Resource> getOptionalResources() {
+		return emptyCollection();
+	}
+
+	private static <T> Collection<T> emptyCollection() {
+		return Collections.EMPTY_LIST;
+	}
+
+	/**
+	 * Find Capabilities that match the given Requirement.
+	 * <p>
+	 * The returned list contains {@link Capability} objects where the Resource
+	 * must be the declared Resource of the Capability. The Resolver can then
+	 * add additional {@link HostedCapability} objects with the
+	 * {@link #insertHostedCapability(List, HostedCapability)} method when it,
+	 * for example, attaches fragments. Those {@link HostedCapability} objects
+	 * will then use the host's Resource which likely differs from the declared
+	 * Resource of the corresponding Capability.
+	 * 
+	 * <p>
+	 * The returned list is in priority order such that the Capabilities with a
+	 * lower index have a preference over those with a higher index. The
+	 * resolver must use the
+	 * {@link #insertHostedCapability(List, HostedCapability)} method to add
+	 * additional Capabilities to maintain priority order. In general, this is
+	 * necessary when the Resolver uses Capabilities declared in a Resource but
+	 * that must originate from an attached host.
+	 * 
+	 * <p>
+	 * Each returned Capability must match the given Requirement. This implies
+	 * that the filter in the Requirement must match as well as any namespace
+	 * specific directives. For example, the mandatory attributes for the
+	 * {@code osgi.wiring.package} namespace.
+	 * 
+	 * @param requirement The requirement that a resolver is attempting to
+	 *        satisfy. Must not be {@code null}.
+	 * @return A list of {@link Capability} objects that match the specified
+	 *         requirement.
+	 */
+	public abstract List<Capability> findProviders(Requirement requirement);
+
+	/**
+	 * Add a {@link HostedCapability} to the list of capabilities returned from
+	 * {@link #findProviders(Requirement)}.
+	 * 
+	 * <p>
+	 * This method is used by the {@link Resolver} to add Capabilities that are
+	 * hosted by another Resource to the list of Capabilities returned from
+	 * {@link #findProviders(Requirement)}. This function is necessary to allow
+	 * fragments to attach to hosts, thereby changing the origin of a
+	 * Capability. This method must insert the specified HostedCapability in a
+	 * place that makes the list maintain the preference order. It must return
+	 * the index in the list of the inserted {@link HostedCapability}.
+	 * 
+	 * @param capabilities The list returned from
+	 *        {@link #findProviders(Requirement)}. Must not be {@code null}.
+	 * @param hostedCapability The HostedCapability to insert in the specified
+	 *        list. Must not be {@code null}.
+	 * @return The index in the list of the inserted HostedCapability.
+	 * 
+	 */
+	public abstract int insertHostedCapability(List<Capability> capabilities, HostedCapability hostedCapability);
+
+	/**
+	 * Test if a given requirement should be wired in the resolve operation. If
+	 * this method returns {@code false}, then the resolver should ignore this
+	 * requirement during the resolve operation.
+	 * 
+	 * <p>
+	 * The primary use case for this is to test the {@code effective} directive
+	 * on the requirement, though implementations are free to use any effective
+	 * test.
+	 * 
+	 * @param requirement The Requirement to test. Must not be {@code null}.
+	 * @return {@code true} if the requirement should be considered as part of
+	 *         the resolve operation.
+	 */
+	public abstract boolean isEffective(Requirement requirement);
+
+	/**
+	 * Returns the wirings for existing resolved resources.
+	 * 
+	 * <p>
+	 * For example, if this resolve context is for an OSGi framework, then the
+	 * result would contain all the currently resolved bundles with each
+	 * bundle's current wiring.
+	 * 
+	 * <p>
+	 * Multiple calls to this method for this resolve context must return the
+	 * same result.
+	 * 
+	 * @return The wirings for existing resolved resources. The returned map is
+	 *         unmodifiable.
+	 */
+	public abstract Map<Resource, Wiring> getWirings();
+}

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/Resolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/Resolver.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/Resolver.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/Resolver.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) OSGi Alliance (2006, 2012). All Rights Reserved.
+ *
+ * Licensed 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.
+ */
+
+// This document is an experimental draft to enable interoperability
+// between bundle repositories. There is currently no commitment to
+// turn this draft into an official specification.
+
+package org.osgi.service.resolver;
+
+import java.util.List;
+import java.util.Map;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+
+/**
+ * A resolver service resolves the specified resources in the context supplied
+ * by the caller.
+ * 
+ * @ThreadSafe
+ * @noimplement
+ * @version $Id: dfb89b8d09af62ecf62321b80d7e2310512f27a1 $
+ */
+public interface Resolver {
+	/**
+	 * Resolve the specified resolve context and return any new resources and
+	 * wires to the caller.
+	 * 
+	 * <p>
+	 * The resolver considers two groups of resources:
+	 * <ul>
+	 * <li>Mandatory - any resource in the
+	 * {@link ResolveContext#getMandatoryResources() mandatory group} must be
+	 * resolved. A failure to satisfy any mandatory requirement for these
+	 * resources will result in throwing a {@link ResolutionException}</li>
+	 * <li>Optional - any resource in the
+	 * {@link ResolveContext#getOptionalResources() optional group} may be
+	 * resolved. A failure to satisfy a mandatory requirement for a resource in
+	 * this group will not fail the overall resolution but no resources or wires
+	 * will be returned for that resource.</li>
+	 * </ul>
+	 * 
+	 * <p>
+	 * The resolve method returns the delta between the start state defined by
+	 * {@link ResolveContext#getWirings()} and the end resolved state. That is,
+	 * only new resources and wires are included.
+	 * 
+	 * <p>
+	 * The behavior of the resolver is not defined if the specified resolve
+	 * context supplies inconsistent information.
+	 * 
+	 * @param context The resolve context for the resolve operation. Must not be
+	 *        {@code null}.
+	 * @return The new resources and wires required to satisfy the specified
+	 *         resolve context. The returned map is the property of the caller
+	 *         and can be modified by the caller.
+	 * @throws ResolutionException If the resolution cannot be satisfied.
+	 */
+	Map<Resource, List<Wire>> resolve(ResolveContext context) throws ResolutionException;
+}

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/package-info.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/package-info.java?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/package-info.java (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/package-info.java Mon Mar 26 18:47:20 2012
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) OSGi Alliance (2010, 2012). All Rights Reserved.
+ * 
+ * Licensed 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.
+ */
+
+/**
+ * Resolver Service Package Version 1.0.
+ * 
+ * <p>
+ * Bundles wishing to use this package must list the package in the
+ * Import-Package header of the bundle's manifest. This package has two types of
+ * users: the consumers that use the API in this package and the providers that
+ * implement the API in this package.
+ * 
+ * <p>
+ * Example import for consumers using the API in this package:
+ * <p>
+ * {@code  Import-Package: org.osgi.service.resolver; version="[1.0,2.0)"}
+ * <p>
+ * Example import for providers implementing the API in this package:
+ * <p>
+ * {@code  Import-Package: org.osgi.service.resolver; version="[1.0,1.1)"}
+ * 
+ * @version $Id: db1706d83ca104187f77cb1feb7cf52b92b3740d $
+ */
+
+package org.osgi.service.resolver;
+

Added: felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/packageinfo
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/packageinfo?rev=1305488&view=auto
==============================================================================
--- felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/packageinfo (added)
+++ felix/sandbox/rickhall/rfc-112/src/main/java/org/osgi/service/resolver/packageinfo Mon Mar 26 18:47:20 2012
@@ -0,0 +1 @@
+version 1.0



Mime
View raw message