@Override public Capability getCapability() { return wire.getCapability(); }
private static Wire findMatchingWire(SimpleFilter filter, Collection<Wire> wires) { for (Wire wire : wires) { Capability cap = wire.getCapability(); if (CapabilitySet.matches(cap, filter)) { return wire; } } return null; }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private static void writeWire(ModuleWire wire, DataOutputStream out, Map<Object, Integer> objectTable) throws IOException { Wire w = wire; Integer capability = objectTable.get(w.getCapability()); Integer provider = objectTable.get(w.getProvider()); Integer requirement = objectTable.get(w.getRequirement()); Integer requirer = objectTable.get(w.getRequirer()); if (capability == null || provider == null || requirement == null || requirer == null) throw new NullPointerException("Could not find the expected indexes"); //$NON-NLS-1$ out.writeInt(addToWriteTable(wire, objectTable)); out.writeInt(capability); out.writeInt(provider); out.writeInt(requirement); out.writeInt(requirer); }
private void propagateState(Map<Resource, FeatureState> states, Resource resource, FeatureState state, SubsystemResolver resolver) { if (!isSubsystem(resource)) { FeatureState reqState = mergeStates(state, states.get(resource)); if (reqState != states.get(resource)) { states.put(resource, reqState); for (Wire wire : resolver.getWiring().get(resource)) { if (IDENTITY_NAMESPACE.equals(wire.getCapability().getNamespace())) { propagateState(states, wire.getProvider(), reqState, resolver); } } } } }
private static Object toJson(Map<Resource, List<Wire>> wiring) { Map<String, List<Map<String, Object>>> wires = new HashMap<>(); for (Map.Entry<Resource, List<Wire>> reswiring : wiring.entrySet()) { Resource resource = reswiring.getKey(); String id = toString(resource); List<Map<String, Object>> reswires = new ArrayList<>(); for (Wire w : reswiring.getValue()) { Map<String, Object> rw = new LinkedHashMap<>(); rw.put("requirement", toString(w.getRequirement())); rw.put("capability", toString(w.getCapability())); rw.put("requirer", toString(w.getRequirer())); rw.put("provider", toString(w.getProvider())); reswires.add(rw); } wires.put(id, reswires); } return wires; }
/** * Returns a mapping for resources that match given filter, to a subsystem that represents region or scoped feature. * @param resourceFilter * @return map from resource to region name */ private Map<Resource, String> getResourceMapping(SimpleFilter resourceFilter) { Map<String, String> flats = getFlatSubsystemsMap(); Map<Resource, List<Wire>> wiring = getWiring(); Map<Resource, String> resources = new HashMap<>(); SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM); if (wiring != null) { for (Resource resource : wiring.keySet()) { if (findMatchingCapability(resourceFilter, resource.getCapabilities(null)) != null) { // Find the subsystem where this feature is installed Wire wire = findMatchingWire(sf, wiring.get(resource)); if (wire != null) { String region = (String) wire.getCapability().getAttributes().get(IDENTITY_NAMESPACE); region = flats.get(region); resources.put(resource, region); } } } } return resources; }
private static Resource findResolvedProvider(Wire wire, Set<Resource> resources, AbstractResolveContext rc) { // Make sure not to add new resources into the result. The resolver // already created the closure of all the needed resources. We need to // find the key in the result that already provides the capability // defined by this wire. Capability capability = wire.getCapability(); Resource resource = capability.getResource(); if (rc.isSystemResource(resource) || (ResourceUtils.isFragment(resource) && resources.contains(resource))) { return resource; } for (Resource resolved : resources) { for (Capability resolvedCap : resolved.getCapabilities(capability.getNamespace())) { if (ResourceUtils.matches(wire.getRequirement(), resolvedCap)) { return resolved; } } } // It shouldn't be possible to arrive here! throw new IllegalStateException( Strings.format("The capability for wire %s was not associated with a resource in the resolution", wire)); }
private static Resource findResolvedProvider(Wire wire, Set<Resource> resources, AbstractResolveContext rc) { // Make sure not to add new resources into the result. The resolver // already created the closure of all the needed resources. We need to // find the key in the result that already provides the capability // defined by this wire. Capability capability = wire.getCapability(); Resource resource = capability.getResource(); if (rc.isSystemResource(resource) || (ResourceUtils.isFragment(resource) && resources.contains(resource))) { return resource; } for (Resource resolved : resources) { for (Capability resolvedCap : resolved.getCapabilities(capability.getNamespace())) { if (ResourceUtils.matches(wire.getRequirement(), resolvedCap)) { return resolved; } } } // It shouldn't be possible to arrive here! throw new IllegalStateException( Strings.format("The capability for wire %s was not associated with a resource in the resolution", wire)); }
private Capability getSatisfyingCapability(Requirement req) { // If the requiring revision is not resolved, then check in the // candidate map for its matching candidate. Capability cap = m_allCandidates.getFirstCandidate(req); // Otherwise, if the requiring revision is resolved then check // in its wires for the capability satisfying the requirement. if (cap == null && m_context.getWirings().containsKey(req.getResource())) { List<Wire> wires = m_context.getWirings().get(req.getResource()).getRequiredResourceWires(null); req = getDeclaredRequirement(req); for (Wire w : wires) { if (w.getRequirement().equals(req)) { // TODO: RESOLVER - This is not 100% correct, since requirements for // dynamic imports with wildcards will reside on many wires and // this code only finds the first one, not necessarily the correct // one. This is only used for the diagnostic message, but it still // could confuse the user. cap = w.getCapability(); break; } } } return cap; }
private Capability getSatisfyingCapability(Requirement req) { // If the requiring revision is not resolved, then check in the // candidate map for its matching candidate. Capability cap = m_allCandidates.getFirstCandidate(req); // Otherwise, if the requiring revision is resolved then check // in its wires for the capability satisfying the requirement. if (cap == null && m_context.getWirings().containsKey(req.getResource())) { List<Wire> wires = m_context.getWirings().get(req.getResource()).getRequiredResourceWires(null); req = getDeclaredRequirement(req); for (Wire w : wires) { if (w.getRequirement().equals(req)) { // TODO: RESOLVER - This is not 100% correct, since requirements for // dynamic imports with wildcards will reside on many wires and // this code only finds the first one, not necessarily the correct // one. This is only used for the diagnostic message, but it still // could confuse the user. cap = w.getCapability(); break; } } } return cap; }
private Capability getSatisfyingCapability(Requirement req) { // If the requiring revision is not resolved, then check in the // candidate map for its matching candidate. Capability cap = m_allCandidates.getFirstCandidate(req); // Otherwise, if the requiring revision is resolved then check // in its wires for the capability satisfying the requirement. if (cap == null && m_context.getWirings().containsKey(req.getResource())) { List<Wire> wires = m_context.getWirings().get(req.getResource()).getRequiredResourceWires(null); req = getDeclaredRequirement(req); for (Wire w : wires) { if (w.getRequirement().equals(req)) { // TODO: RESOLVER - This is not 100% correct, since requirements for // dynamic imports with wildcards will reside on many wires and // this code only finds the first one, not necessarily the correct // one. This is only used for the diagnostic message, but it still // could confuse the user. cap = w.getCapability(); break; } } } return cap; } }
private Capability getSatisfyingCapability(Requirement req) { // If the requiring revision is not resolved, then check in the // candidate map for its matching candidate. Capability cap = m_allCandidates.getFirstCandidate(req); // Otherwise, if the requiring revision is resolved then check // in its wires for the capability satisfying the requirement. if (cap == null && m_context.getWirings().containsKey(req.getResource())) { List<Wire> wires = m_context.getWirings().get(req.getResource()).getRequiredResourceWires(null); req = getDeclaredRequirement(req); for (Wire w : wires) { if (w.getRequirement().equals(req)) { // TODO: RESOLVER - This is not 100% correct, since requirements for // dynamic imports with wildcards will reside on many wires and // this code only finds the first one, not necessarily the correct // one. This is only used for the diagnostic message, but it still // could confuse the user. cap = w.getCapability(); break; } } } return cap; } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Wire) { Wire w = (Wire) obj; if (capability.equals(w.getCapability()) && requirement.equals(w.getRequirement())) { Resource provider = getProvider(); Resource requirer = getRequirer(); return (provider == null ? w.getProvider() == null : provider.equals(w.getProvider())) && (requirer == null ? w.getRequirer() == null : requirer.equals(w.getRequirer())); } } return false; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Wire) { Wire w = (Wire) obj; if (capability.equals(w.getCapability()) && requirement.equals(w.getRequirement())) { Resource provider = getProvider(); Resource requirer = getRequirer(); return (provider == null ? w.getProvider() == null : provider.equals(w.getProvider())) && (requirer == null ? w.getRequirer() == null : requirer.equals(w.getRequirer())); } } return false; }
private static BundleWireDTO createBundleWireDTO(Wire wire, Set<BundleRevisionDTO> resources, Set<NodeDTO> nodes) { BundleWireDTO wdto = new BundleWireDTO(); if (wire instanceof BundleWire) { BundleWire w = (BundleWire) wire; BundleWiring pw = w.getProviderWiring(); addWiringNodeIfNotPresent(pw, resources, nodes); wdto.providerWiring = getWiringID(pw); BundleWiring rw = w.getRequirerWiring(); addWiringNodeIfNotPresent(rw, resources, nodes); wdto.requirerWiring = getWiringID(rw); } wdto.provider = getResourceIDAndAdd(wire.getProvider(), resources); wdto.requirer = getResourceIDAndAdd(wire.getRequirer(), resources); wdto.capability = new CapabilityRefDTO(); wdto.capability.capability = getCapabilityID(wire.getCapability()); wdto.capability.resource = getResourceIDAndAdd(wire.getCapability().getResource(), resources); wdto.requirement = new RequirementRefDTO(); wdto.requirement.requirement = getRequirementID(wire.getRequirement()); wdto.requirement.resource = getResourceIDAndAdd(wire.getRequirement().getResource(), resources); return wdto; }