// 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;
    public void begin(Collection<? extends Resource> mandatory, Collection<? extends Resource> optional) {

        // Set the thread association
        processorAssociation.set(this);

        // Get the initial set of trigger bundles
        Collection<BundleRevision> triggers = new ArrayList<BundleRevision>();
        addTriggers(mandatory, triggers);
        addTriggers(optional, triggers);
        triggers = new RemoveOnlyCollection<BundleRevision>(triggers);

        // Create a {@link ResolverHook} for each factory
        if (registrations != null) {
            for (ResolverHookRegistration hookreg : registrations) {
                try {
                    ResolverHookFactory hookFactory = syscontext.getService(hookreg.sref);
                    if (hookreg.isRegistered()) {
                        hookreg.hook = hookFactory.begin(triggers);
                    }
                } catch (RuntimeException ex) {
                    hookreg.lastException = ex;
                    throw new ResolverHookException(ex);
                }
            }
        }
    }

    private void addTriggers(Collection<? extends Resource> resources, Collection<BundleRevision> triggers) {
        if (resources != null) {
            for (Resource res : resources) {
// 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;

    public void begin(Collection<? extends Resource> mandatory, Collection<? extends Resource> optional) {

        // Set the thread association
        processorAssociation.set(this);

        // Get the initial set of trigger bundles
        Collection<BundleRevision> triggers = new ArrayList<BundleRevision>();
        addTriggers(mandatory, triggers);
        addTriggers(optional, triggers);
        triggers = new RemoveOnlyCollection<BundleRevision>(triggers);

        // Create a {@link ResolverHook} for each factory
        if (registrations != null) {
            for (ResolverHookRegistration hookreg : registrations) {
                try {
                    ResolverHookFactory hookFactory = syscontext.getService(hookreg.sref);
                    if (hookreg.isRegistered()) {
                        hookreg.hook = hookFactory.begin(triggers);
                    }
                } catch (RuntimeException ex) {
                    hookreg.lastException = ex;
                    throw new ResolverHookException(ex);
                }
            }
        }
    }

    private void addTriggers(Collection<? extends Resource> resources, Collection<BundleRevision> triggers) {
        if (resources != null) {
            for (Resource res : resources) {
                XBundleRevision brev = (XBundleRevision) res;