// Path: api/src/main/java/org/jboss/osgi/resolver/XCapability.java
// public interface XCapability extends XElement, XAttributeSupport, XDirectiveSupport, Capability {
// 
//     /**
//      * Get the resource declaring this capability.
//      */
//     XResource getResource();
//     
//     /**
//      * Validate the capability
//      */
//     void validate();
// 
//     /**
//      * Adapt this capability to another type
//      */
//     <T extends XCapability> T adapt(Class<T> clazz);
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XPackageRequirement.java
// public interface XPackageRequirement extends XRequirement {
// 
//     /**
//      * The package name
//      */
//     String getPackageName();
// 
//     /**
//      * A flag indicating that this is a dynamic package requirement
//      */
//     boolean isDynamic();
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XResource.java
// public interface XResource extends XElement, XAttributeSupport, Resource {
// 
//     /** The id attachment key */
//     AttachmentKey<Long> RESOURCE_IDENTIFIER_KEY = AttachmentKey.create(Long.class);
// 
//     /**
//      * Artifact coordinates may be defined by the simple groupId:artifactId:version form,
//      * or the fully qualified form groupId:artifactId:type:version[:classifier]
//      */
//     String MAVEN_IDENTITY_NAMESPACE = "maven.identity";
// 
//     /**
//      * Artifact coordinates are defined by {@link org.jboss.modules.ModuleIdentifier}
//      */
//     String MODULE_IDENTITY_NAMESPACE = "module.identity";
// 
//     /**
//      * The attribute on the {@link XIdentityCapability} for the below types
//      */
//     String CAPABILITY_TYPE_ATTRIBUTE = IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE;
// 
//     /**
//      * Some predefined resource types
//      */
//     String TYPE_BUNDLE = IdentityNamespace.TYPE_BUNDLE;
//     String TYPE_FRAGMENT = IdentityNamespace.TYPE_FRAGMENT;
//     String TYPE_UNKNOWN = IdentityNamespace.TYPE_UNKNOWN;
//     String TYPE_ABSTRACT = "abstract";
//     String TYPE_MODULE = "module";
//     String TYPE_MAVEN = "maven";
// 
//     /**
//      * Get the identity capability for this resource
//      */
//     XIdentityCapability getIdentityCapability();
// 
//     /**
//      * Validate the resource
//      */
//     void validate();
// 
//     /**
//      * Get the current resource state
//      */
//     State getState();
// 
//     /**
//      * True if the resource is mutable
//      */
//     boolean isMutable();
// 
//     /**
//      * True if the resource is abstract
//      */
//     boolean isAbstract();
// 
//     /**
//      * Make the resource immutable
//      */
//     void setMutable(boolean mutable);
// 
//     /**
//      * Get the {@link XWiringSupport} associated with this resource
//      */
//     XWiringSupport getWiringSupport();
// 
//     /**
//      * Get the {@link XWiring} associated with this resource
//      */
//     XWiring getWiring(boolean checkEffective);
// 
//     /**
//      * The resource state in the {@link XEnvironment}
//      */
//     enum State {
//         INSTALLED, UNINSTALLED
//     }
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XWire.java
// public interface XWire extends Wire {
// 
//     Wiring getProviderWiring();
// 
//     void setProviderWiring(Wiring providerWiring);
// 
//     Wiring getRequirerWiring();
// 
//     void setRequirerWiring(Wiring requirerWiring);
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XWiring.java
// public interface XWiring extends Wiring {
// 
//     boolean isEffective();
//     
//     void addRequiredWire(Wire wire);
// 
//     void addProvidedWire(Wire wire);
// }


import static org.jboss.osgi.resolver.ResolverMessages.MESSAGES;
import static org.osgi.framework.namespace.IdentityNamespace.IDENTITY_NAMESPACE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.osgi.resolver.XCapability;
import org.jboss.osgi.resolver.XPackageRequirement;
import org.jboss.osgi.resolver.XResource;
import org.jboss.osgi.resolver.XWire;
import org.jboss.osgi.resolver.XWiring;
import org.osgi.framework.namespace.HostNamespace;
import org.osgi.resource.Capability;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
import org.osgi.resource.Wire;
import org.osgi.resource.Wiring;
import org.osgi.service.resolver.HostedCapability;
        synchronized (this) {
            // Necessary to guard collections post-construction

            if (reqwires != null) {
                for (Wire wire : reqwires) {
                    addRequiredWire(wire);
                }
            }
            if (provwires != null) {
                for (Wire wire : provwires) {
                    addProvidedWire(wire);
                }
            }
        }
    }

    @Override
    public XResource getResource() {
        return resource;
    }

    @Override
    public boolean isEffective() {
        return resource.getWiringSupport().isEffective();
    }

    @Override
    public void addRequiredWire(Wire wire) {
        synchronized (required) {
            if (wire instanceof AbstractWire) {
// Path: api/src/main/java/org/jboss/osgi/resolver/XCapability.java
// public interface XCapability extends XElement, XAttributeSupport, XDirectiveSupport, Capability {
// 
//     /**
//      * Get the resource declaring this capability.
//      */
//     XResource getResource();
//     
//     /**
//      * Validate the capability
//      */
//     void validate();
// 
//     /**
//      * Adapt this capability to another type
//      */
//     <T extends XCapability> T adapt(Class<T> clazz);
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XPackageRequirement.java
// public interface XPackageRequirement extends XRequirement {
// 
//     /**
//      * The package name
//      */
//     String getPackageName();
// 
//     /**
//      * A flag indicating that this is a dynamic package requirement
//      */
//     boolean isDynamic();
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XResource.java
// public interface XResource extends XElement, XAttributeSupport, Resource {
// 
//     /** The id attachment key */
//     AttachmentKey<Long> RESOURCE_IDENTIFIER_KEY = AttachmentKey.create(Long.class);
// 
//     /**
//      * Artifact coordinates may be defined by the simple groupId:artifactId:version form,
//      * or the fully qualified form groupId:artifactId:type:version[:classifier]
//      */
//     String MAVEN_IDENTITY_NAMESPACE = "maven.identity";
// 
//     /**
//      * Artifact coordinates are defined by {@link org.jboss.modules.ModuleIdentifier}
//      */
//     String MODULE_IDENTITY_NAMESPACE = "module.identity";
// 
//     /**
//      * The attribute on the {@link XIdentityCapability} for the below types
//      */
//     String CAPABILITY_TYPE_ATTRIBUTE = IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE;
// 
//     /**
//      * Some predefined resource types
//      */
//     String TYPE_BUNDLE = IdentityNamespace.TYPE_BUNDLE;
//     String TYPE_FRAGMENT = IdentityNamespace.TYPE_FRAGMENT;
//     String TYPE_UNKNOWN = IdentityNamespace.TYPE_UNKNOWN;
//     String TYPE_ABSTRACT = "abstract";
//     String TYPE_MODULE = "module";
//     String TYPE_MAVEN = "maven";
// 
//     /**
//      * Get the identity capability for this resource
//      */
//     XIdentityCapability getIdentityCapability();
// 
//     /**
//      * Validate the resource
//      */
//     void validate();
// 
//     /**
//      * Get the current resource state
//      */
//     State getState();
// 
//     /**
//      * True if the resource is mutable
//      */
//     boolean isMutable();
// 
//     /**
//      * True if the resource is abstract
//      */
//     boolean isAbstract();
// 
//     /**
//      * Make the resource immutable
//      */
//     void setMutable(boolean mutable);
// 
//     /**
//      * Get the {@link XWiringSupport} associated with this resource
//      */
//     XWiringSupport getWiringSupport();
// 
//     /**
//      * Get the {@link XWiring} associated with this resource
//      */
//     XWiring getWiring(boolean checkEffective);
// 
//     /**
//      * The resource state in the {@link XEnvironment}
//      */
//     enum State {
//         INSTALLED, UNINSTALLED
//     }
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XWire.java
// public interface XWire extends Wire {
// 
//     Wiring getProviderWiring();
// 
//     void setProviderWiring(Wiring providerWiring);
// 
//     Wiring getRequirerWiring();
// 
//     void setRequirerWiring(Wiring requirerWiring);
// }
// 
// Path: api/src/main/java/org/jboss/osgi/resolver/XWiring.java
// public interface XWiring extends Wiring {
// 
//     boolean isEffective();
//     
//     void addRequiredWire(Wire wire);
// 
//     void addProvidedWire(Wire wire);
// }


// Path: api/src/main/java/org/jboss/osgi/resolver/spi/AbstractWiring.java
import static org.jboss.osgi.resolver.ResolverMessages.MESSAGES;
import static org.osgi.framework.namespace.IdentityNamespace.IDENTITY_NAMESPACE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.osgi.resolver.XCapability;
import org.jboss.osgi.resolver.XPackageRequirement;
import org.jboss.osgi.resolver.XResource;
import org.jboss.osgi.resolver.XWire;
import org.jboss.osgi.resolver.XWiring;
import org.osgi.framework.namespace.HostNamespace;
import org.osgi.resource.Capability;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
import org.osgi.resource.Wire;
import org.osgi.resource.Wiring;
import org.osgi.service.resolver.HostedCapability;

        synchronized (this) {
            // Necessary to guard collections post-construction

            if (reqwires != null) {
                for (Wire wire : reqwires) {
                    addRequiredWire(wire);
                }
            }
            if (provwires != null) {
                for (Wire wire : provwires) {
                    addProvidedWire(wire);
                }
            }
        }
    }

    @Override
    public XResource getResource() {
        return resource;
    }

    @Override
    public boolean isEffective() {
        return resource.getWiringSupport().isEffective();
    }

    @Override
    public void addRequiredWire(Wire wire) {
        synchronized (required) {
            if (wire instanceof AbstractWire) {
                ((XWire) wire).setRequirerWiring(this);