Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82DB8905E for ; Mon, 26 Mar 2012 18:47:47 +0000 (UTC) Received: (qmail 2967 invoked by uid 500); 26 Mar 2012 18:47:47 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 2937 invoked by uid 500); 26 Mar 2012 18:47:47 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 2930 invoked by uid 99); 26 Mar 2012 18:47:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2012 18:47:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2012 18:47:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D2BE223889FD for ; Mon, 26 Mar 2012 18:47:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@felix.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120326184722.D2BE223889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 getDirectives() + { + return m_cap.getDirectives(); + } + + public Map getAttributes() + { + return m_cap.getAttributes(); + } + +// TODO: RFC-112 - Need impl-specific type. +// public List 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 getDirectives() + { + return m_req.getDirectives(); + } + + public Map 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 m_fragments; + private List m_cachedCapabilities = null; + private List m_cachedRequirements = null; + + public WrappedResource(Resource host, List fragments) + { + m_host = host; + m_fragments = fragments; + } + + public Resource getDeclaredResource() + { + return m_host; + } + + public List getFragments() + { + return m_fragments; + } + + public List getCapabilities(String namespace) + { + if (m_cachedCapabilities == null) + { + List caps = new ArrayList(); + + // 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 getRequirements(String namespace) + { + if (m_cachedRequirements == null) + { + List reqs = new ArrayList(); + + // 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 m_dirs; + private final Map m_attrs; + + public BundleCapability(Resource resource, String name) + { + m_resource = resource; + m_dirs = new HashMap(); + m_attrs = new HashMap(); + 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 getDirectives() + { + return m_dirs; + } + + public void addAttribute(String name, Object value) + { + m_attrs.put(name, value); + } + + public Map 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 m_dirs; + private final Map m_attrs; + + public BundleRequirement(Resource resource, String name) + { + m_resource = resource; + m_dirs = new HashMap(); + m_dirs.put( + BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, + "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + name + ")"); + m_attrs = new HashMap(); + } + + public String getNamespace() + { + return BundleNamespace.BUNDLE_NAMESPACE; + } + + public Map getDirectives() + { + return m_dirs; + } + + public Map 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 m_dirs; + private final Map m_attrs; + + public IdentityCapability(Resource resource, String name) + { + m_resource = resource; + m_dirs = new HashMap(); + m_attrs = new HashMap(); + m_attrs.put(IdentityNamespace.IDENTITY_NAMESPACE, name); + } + + public String getNamespace() + { + return IdentityNamespace.IDENTITY_NAMESPACE; + } + + public Map getDirectives() + { + return m_dirs; + } + + public Map 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 wirings = new HashMap(); + Map> candMap = new HashMap>(); + + System.out.println("\nSCENARIO 1\n"); + List mandatory = populateScenario1(wirings, candMap); + ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST); + Map> 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 populateScenario1( + Map wirings, Map> 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 resources = new ArrayList(); + resources.add(importer); + return resources; + } + + private static List populateScenario2( + Map wirings, Map> candMap) + { + wirings.clear(); + candMap.clear(); + + List fooCands = new ArrayList(); + List barCands = new ArrayList(); + + // 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 resources = new ArrayList(); + resources.add(c); + return resources; + } + + private static List populateScenario3( + Map wirings, Map> candMap) + { + wirings.clear(); + candMap.clear(); + + List resourcesCands = new ArrayList(); + List dResourcesCands = new ArrayList(); + List eBundleDCands = new ArrayList(); + List eResourcesCands = new ArrayList(); + + // 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 resources = new ArrayList(); + 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 m_dirs; + private final Map m_attrs; + + public PackageCapability(Resource resource, String name) + { + m_resource = resource; + m_dirs = new HashMap(); + m_attrs = new HashMap(); + 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 getDirectives() + { + return m_dirs; + } + + public void addAttribute(String name, Object value) + { + m_attrs.put(name, value); + } + + public Map 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 m_dirs; + private final Map m_attrs; + + public PackageRequirement(Resource resource, String name) + { + m_resource = resource; + m_dirs = new HashMap(); + m_dirs.put( + PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, + "(" + PackageNamespace.PACKAGE_NAMESPACE + "=" + name + ")"); + m_attrs = new HashMap(); + } + + public String getNamespace() + { + return PackageNamespace.PACKAGE_NAMESPACE; + } + + public Map getDirectives() + { + return m_dirs; + } + + public Map 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 m_wirings; + private final Map> m_candMap; + private final Collection m_mandatory; + private final Collection m_optional; + + public ResolveContextImpl( + Map wirings, Map> candMap, + Collection mandatory, Collection optional) + { + m_wirings = wirings; + m_candMap = candMap; + m_mandatory = mandatory; + m_optional = optional; + } + + @Override + public Collection getMandatoryResources() + { + return new ArrayList(m_mandatory); + } + + @Override + public Collection getOptionalResources() + { + return new ArrayList(m_optional); + } + + @Override + public List findProviders(Requirement r) + { + return new ArrayList(m_candMap.get(r)); + } + + @Override + public int insertHostedCapability(List capabilities, HostedCapability hostedCapability) + { + int idx = 0; + capabilities.add(idx, hostedCapability); + return idx; + } + + @Override + public boolean isEffective(Requirement requirement) + { + return true; + } + + @Override + public Map 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 m_caps; + private final List m_reqs; + + public ResourceImpl(String name) + { + m_caps = new ArrayList(); + m_caps.add(0, new IdentityCapability(this, name)); + m_reqs = new ArrayList(); + } + + public void addCapability(Capability cap) + { + m_caps.add(cap); + } + + public List getCapabilities(String namespace) + { + List result = m_caps; + if (namespace != null) + { + result = new ArrayList(); + 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 getRequirements(String namespace) + { + List result = m_reqs; + if (namespace != null) + { + result = new ArrayList(); + 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. + * + *

+ * 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. + * + *

+ * 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. + * + *

+ * 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 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 unresolvedRequirements) { + super(message, cause); + if ((unresolvedRequirements == null) || unresolvedRequirements.isEmpty()) { + this.unresolvedRequirements = emptyCollection(); + } else { + this.unresolvedRequirements = Collections.unmodifiableCollection(new ArrayList(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 Collection emptyCollection() { + return Collections.EMPTY_LIST; + } + + /** + * Return the unresolved requirements, if any, for this exception. + * + *

+ * 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 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. + * + *

+ * Resolve Contexts: + *

    + *
  • 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.
  • + *
  • Provide {@link Capability capabilities} that the Resolver can use to + * satisfy {@link Requirement requirements} via the + * {@link #findProviders(Requirement)} method
  • + *
  • Constrain solutions via the {@link #getWirings()} method. A wiring + * consists of a map of existing {@link Resource resources} to {@link Wiring + * wiring}.
  • + *
  • Filter requirements that are part of a resolve operation via the + * {@link #isEffective(Requirement)}.
  • + *
+ * + *

+ * 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. + * + *

+ * Except for {@link #insertHostedCapability(List, HostedCapability)}, the + * resolve context methods must be idempotent. 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. + * + *

+ * 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 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. + * + *

+ * 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 getOptionalResources() { + return emptyCollection(); + } + + private static Collection emptyCollection() { + return Collections.EMPTY_LIST; + } + + /** + * Find Capabilities that match the given Requirement. + *

+ * 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. + * + *

+ * 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. + * + *

+ * 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 findProviders(Requirement requirement); + + /** + * Add a {@link HostedCapability} to the list of capabilities returned from + * {@link #findProviders(Requirement)}. + * + *

+ * 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 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. + * + *

+ * 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. + * + *

+ * 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. + * + *

+ * 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 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. + * + *

+ * The resolver considers two groups of resources: + *

    + *
  • 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}
  • + *
  • 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.
  • + *
+ * + *

+ * 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. + * + *

+ * 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> 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. + * + *

+ * 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. + * + *

+ * Example import for consumers using the API in this package: + *

+ * {@code Import-Package: org.osgi.service.resolver; version="[1.0,2.0)"} + *

+ * Example import for providers implementing the API in this package: + *

+ * {@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