// Path: api/src/main/java/org/jboss/osgi/resolver/XBundle.java
// public interface XBundle extends Attachable, Bundle {
// 
//     /**
//      * Get the current {@link XBundleRevision}
//      */
//     XBundleRevision getBundleRevision();
// 
//     /**
//      * Get the bundle canonical name
//      *
//      * [symbolicName:version]
//      */
//     String getCanonicalName();
// 
//     /**
//      * True if the bundle is resolved.
//      */
//     boolean isResolved();
// 
//     /**
//      * True if the bundle is a fragment.
//      */
//     boolean isFragment();
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XBundleRevision.java
// public interface XBundleRevision extends XResource, BundleRevision {
// 
//     /**
//      * Get the associated {@link XBundle}
//      */
//     XBundle getBundle();
// 
//     /**
//      * Get the {@link XBundleWiringSupport} associated with this resource
//      */
//     XBundleWiringSupport getWiringSupport();
// 
//     /**
//      * Get the bundle canonical name
//      *
//      * [symbolicName:version]
//      */
//     String getCanonicalName();
// 
//     /**
//      * Get the associated {@link ModuleIdentifier}
//      * or null if the revision is not resolved
//      */
//     ModuleIdentifier getModuleIdentifier();
// 
//     /**
//      * Get the associated {@link ModuleIdentifier}
//      * or null if the revision is not resolved
//      */
//     ModuleClassLoader getModuleClassLoader();
// 
//     /**
//      * @see {@link Bundle#getResource(String)}
//      */
//     URL getResource(String name);
// 
//     /**
//      * @see {@link Bundle#getResources(String)}
//      */
//     Enumeration<URL> getResources(String name) throws IOException;
// 
//     /**
//      * @see {@link Bundle#findEntries(String, String, boolean)}
//      */
//     Enumeration<URL> findEntries(String path, String filePattern, boolean recursive);
// 
//     /**
//      * @see {@link Bundle#getEntry(String)}
//      */
//     URL getEntry(String path);
// 
//     /**
//      * @see {@link Bundle#getEntryPaths(String)}
//      */
//     Enumeration<String> getEntryPaths(String path);
// 
//     /**
//      * True if this revision is a fragment
//      */
//     boolean isFragment();
// }


import static org.jboss.osgi.resolver.ResolverLogger.LOGGER;
import static org.jboss.osgi.resolver.ResolverMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.osgi.resolver.XBundle;
import org.jboss.osgi.resolver.XBundleRevision;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.resource.Resource;
/*
 * #%L
 * JBossOSGi Resolver API
 * %%
 * Copyright (C) 2010 - 2012 JBoss by Red Hat
 * %%
 * 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.
 * #L%
 */
package org.jboss.osgi.resolver.spi;




/**
 * The default implementation for {@link ResolverHook} functionality.
 *
 * @author thomas.diesler@jboss.com
 * @since 01-Feb-2013
 */
public class ResolverHookProcessor {

    private static ThreadLocal<ResolverHookProcessor> processorAssociation = new ThreadLocal<ResolverHookProcessor>();
    
    private final BundleContext syscontext;
    private List<ResolverHookRegistration> registrations;
    private Collection<BundleRevision> candidates;

    public interface SingletonLocator {
        Collection<BundleCapability> findCollisionCandidates(BundleCapability icap);
    }

// Path: api/src/main/java/org/jboss/osgi/resolver/XBundle.java
// public interface XBundle extends Attachable, Bundle {
// 
//     /**
//      * Get the current {@link XBundleRevision}
//      */
//     XBundleRevision getBundleRevision();
// 
//     /**
//      * Get the bundle canonical name
//      *
//      * [symbolicName:version]
//      */
//     String getCanonicalName();
// 
//     /**
//      * True if the bundle is resolved.
//      */
//     boolean isResolved();
// 
//     /**
//      * True if the bundle is a fragment.
//      */
//     boolean isFragment();
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XBundleRevision.java
// public interface XBundleRevision extends XResource, BundleRevision {
// 
//     /**
//      * Get the associated {@link XBundle}
//      */
//     XBundle getBundle();
// 
//     /**
//      * Get the {@link XBundleWiringSupport} associated with this resource
//      */
//     XBundleWiringSupport getWiringSupport();
// 
//     /**
//      * Get the bundle canonical name
//      *
//      * [symbolicName:version]
//      */
//     String getCanonicalName();
// 
//     /**
//      * Get the associated {@link ModuleIdentifier}
//      * or null if the revision is not resolved
//      */
//     ModuleIdentifier getModuleIdentifier();
// 
//     /**
//      * Get the associated {@link ModuleIdentifier}
//      * or null if the revision is not resolved
//      */
//     ModuleClassLoader getModuleClassLoader();
// 
//     /**
//      * @see {@link Bundle#getResource(String)}
//      */
//     URL getResource(String name);
// 
//     /**
//      * @see {@link Bundle#getResources(String)}
//      */
//     Enumeration<URL> getResources(String name) throws IOException;
// 
//     /**
//      * @see {@link Bundle#findEntries(String, String, boolean)}
//      */
//     Enumeration<URL> findEntries(String path, String filePattern, boolean recursive);
// 
//     /**
//      * @see {@link Bundle#getEntry(String)}
//      */
//     URL getEntry(String path);
// 
//     /**
//      * @see {@link Bundle#getEntryPaths(String)}
//      */
//     Enumeration<String> getEntryPaths(String path);
// 
//     /**
//      * True if this revision is a fragment
//      */
//     boolean isFragment();
// }


// Path: api/src/main/java/org/jboss/osgi/resolver/spi/ResolverHookProcessor.java
import static org.jboss.osgi.resolver.ResolverLogger.LOGGER;
import static org.jboss.osgi.resolver.ResolverMessages.MESSAGES;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.osgi.resolver.XBundle;
import org.jboss.osgi.resolver.XBundleRevision;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.resource.Resource;

/*
 * #%L
 * JBossOSGi Resolver API
 * %%
 * Copyright (C) 2010 - 2012 JBoss by Red Hat
 * %%
 * 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.
 * #L%
 */
package org.jboss.osgi.resolver.spi;




/**
 * The default implementation for {@link ResolverHook} functionality.
 *
 * @author thomas.diesler@jboss.com
 * @since 01-Feb-2013
 */
public class ResolverHookProcessor {

    private static ThreadLocal<ResolverHookProcessor> processorAssociation = new ThreadLocal<ResolverHookProcessor>();
    
    private final BundleContext syscontext;
    private List<ResolverHookRegistration> registrations;
    private Collection<BundleRevision> candidates;

    public interface SingletonLocator {
        Collection<BundleCapability> findCollisionCandidates(BundleCapability icap);
    }

    public ResolverHookProcessor(BundleContext syscontext, Collection<XBundle> unresolved) {