org.osgi.resource.Requirement Java Examples
The following examples show how to use
org.osgi.resource.Requirement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NsToHtmlPackage.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String pkgName = Util.getFilterValue(filter, BundleRevision.PACKAGE_NAMESPACE); if (pkgName != null) { sb.append(pkgName); appendVersionAndResolutionDirective(sb, requirement); } else { sb.append(filter); } return sb.toString(); }
Example #2
Source File: Resources.java From concierge with Eclipse Public License 1.0 | 6 votes |
void addWire(final BundleWire wire) { final Capability cap = wire.getCapability(); final Requirement req = wire.getRequirement(); if (wire.getProvider() == revision) { providedWires.insert(cap.getNamespace(), wire); inUseSet.add(wire.getRequirer()); ((ConciergeBundleWire) wire).providerWiring = this; } else { requiredWires.insert(req.getNamespace(), wire); if (HostNamespace.HOST_NAMESPACE.equals(wire.getRequirement() .getNamespace())) { inUseSet.add(wire.getProvider()); } ((ConciergeBundleWire) wire).requirerWiring = this; } }
Example #3
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Get Fragments matching a host bundle. * * @param hostBundle * , the host bundle, for which fragments should be found * @return an array of fragments, which should be attached to the host * bundle */ List<Revision> getFragments(final BundleRevision hostBundle) { final List<Revision> candidates = new ArrayList<Revision>( fragmentIndex.lookup(hostBundle.getSymbolicName())); if (!candidates.isEmpty()) { final Capability cap = hostBundle .getCapabilities(HostNamespace.HOST_NAMESPACE).get(0); for (final Iterator<Revision> iter = candidates.iterator(); iter .hasNext();) { final Requirement req = iter.next() .getRequirements(HostNamespace.HOST_NAMESPACE).get(0); if (!matches(req, cap)) { iter.remove(); } } } return candidates; }
Example #4
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
public synchronized Map<Resource, List<Wire>> resolve( final ResolveContext context) throws ResolutionException { if (context == null) { throw new IllegalArgumentException("context is null"); } final MultiMap<Resource, Wire> solution = new MultiMap<Resource, Wire>(); final ArrayList<Requirement> unresolvedRequirements = new ArrayList<Requirement>(); final ArrayList<Resource> unresolvedResources = new ArrayList<Resource>(); resolve0(context, solution, unresolvedRequirements, unresolvedResources, true); if (!unresolvedRequirements.isEmpty() || !unresolvedResources.isEmpty()) { throw new ResolutionException("Could not resolve.", null, unresolvedRequirements); } return solution.getFlatMap(); }
Example #5
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
protected List<Capability> findProviders(Requirement requirement){ final String filterStr = requirement.getDirectives() .get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); final List<Capability> providers; if (filterStr == null) { providers = capabilityRegistry .getAll(requirement.getNamespace()); } else { try { providers = RFC1960Filter.filterWithIndex( requirement, filterStr, capabilityRegistry); } catch (final InvalidSyntaxException ise) { // TODO: debug output ise.printStackTrace(); return Collections.emptyList(); } } return providers; }
Example #6
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
static boolean matches0(final String namespace, final Requirement req, final Capability cap, final String filterStr) { if (!namespace.startsWith("osgi.wiring.")) { return true; } final String mandatory = cap.getDirectives() .get(Namespace.RESOLUTION_MANDATORY); if (mandatory == null) { return true; } final Set<String> mandatoryAttributes = new HashSet<String>( Arrays.asList(Utils.splitString( Utils.unQuote(mandatory).toLowerCase(), ','))); final Matcher matcher = FILTER_ASSERT_MATCHER .matcher(filterStr == null ? "" : filterStr); while (matcher.find()) { mandatoryAttributes.remove(matcher.group(1)); } return mandatoryAttributes.isEmpty(); }
Example #7
Source File: ResolveContextImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addToProvidersIfMatching(Resource res, List<Capability> providers, Requirement req) { String f = req.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); Filter filter = null; if(f != null) { try { filter = bc.createFilter(f); } catch (InvalidSyntaxException e) { // TODO log filter failure, skip System.err.println("Failed, " + f + ". " + e); return; } } for(Capability c : res.getCapabilities(req.getNamespace())) { if(filter != null && !filter.matches(c.getAttributes())) { continue; } providers.add(c); } }
Example #8
Source File: NsToHtmlBundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String bundleName = Util.getFilterValue(filter, BundleRevision.BUNDLE_NAMESPACE); if (bundleName != null) { sb.append(bundleName); Util.appendVersion(sb, filter, Constants.BUNDLE_VERSION_ATTRIBUTE); } else { // Filter too complex to extract info from... sb.append(filter); } return sb.toString(); }
Example #9
Source File: NsToHtmlContent.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(100); sb.append("<table border='0'>\n"); for (final Entry<String, String> dir : requirement.getDirectives() .entrySet()) { Util.toHTMLtr13_3(sb, ":=", dir.getKey(), dir.getValue()); } for (final Entry<String, Object> attr : requirement.getAttributes() .entrySet()) { Util.toHTMLtr13_3(sb, "=", attr.getKey(), attr.getValue()); } sb.append("</table>\n"); return sb.toString(); }
Example #10
Source File: NsToHtmlGeneric.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(100); sb.append("<table border='0'>\n"); for (final Entry<String, String> dir : requirement.getDirectives() .entrySet()) { Util.toHTMLtr13_3(sb, ":=", dir.getKey(), dir.getValue()); } for (final Entry<String, Object> attr : requirement.getAttributes() .entrySet()) { Util.toHTMLtr13_3(sb, "=", attr.getKey(), attr.getValue()); } sb.append("</table>\n"); return sb.toString(); }
Example #11
Source File: NsToHtmlHost.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String hostName = Util.getFilterValue(filter, BundleRevision.HOST_NAMESPACE); if (hostName != null) { sb.append(hostName); Util.appendVersion(sb, filter, Constants.BUNDLE_VERSION_ATTRIBUTE); } else { // Filter too complex to extract info from... sb.append(filter); } return sb.toString(); }
Example #12
Source File: NsToHtmlEE.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toHTML(Requirement requirement) { final StringBuffer sb = new StringBuffer(50); final String filter = requirement.getDirectives().get("filter"); final String eeName = Util.getFilterValue(filter, ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE); if (eeName != null) { sb.append(eeName); Util.appendVersion(sb, filter, Constants.VERSION_ATTRIBUTE); } else { // Filter too complex to extract info from... sb.append(filter); } return sb.toString(); }
Example #13
Source File: ResourceImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<Requirement> getRequirements(String namespace) { List<Requirement> result = rs; if (namespace != null) { result = new ArrayList<Requirement>(); for (Requirement r : rs) { if (namespace.equalsIgnoreCase(r.getNamespace())) { result.add(r); } } } return Collections.unmodifiableList(result); }
Example #14
Source File: ResourceImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Resource[\n"); for (Capability c : cs) { sb.append(c.toString()); } for (Requirement r : rs) { sb.append(r.toString()); } sb.append("]\n"); return sb.toString(); }
Example #15
Source File: ExpressionResolver.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Collection<Resource> getResources(Requirement req) { Collection<Capability> cs = repository.findProviders(Collections.singleton(req)).get(req); Collection<Resource> res = new ArrayList<Resource>(cs.size()); for (Capability c : cs) { // TODO could resource be null? res.add(c.getResource()); } return res; }
Example #16
Source File: Resources.java From concierge with Eclipse Public License 1.0 | 5 votes |
private void addWire(final Wire wire) { if (wire.getProvider() == resource) { final Capability cap = wire.getCapability(); capabilities.insertUnique(cap.getNamespace(), cap); providedWires.insert(cap.getNamespace(), wire); } else { final Requirement req = wire.getRequirement(); requirements.insertUnique(req.getNamespace(), req); requiredWires.insert(req.getNamespace(), wire); } }
Example #17
Source File: FrameworkWiringImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("unchecked") public Collection<BundleCapability> findProviders(Requirement requirement) { final String namespace = requirement.getNamespace(); final String filterStr = requirement.getDirectives().get("filter"); Filter filter; if (filterStr != null) { try { filter = FrameworkUtil.createFilter(filterStr); } catch (InvalidSyntaxException ise) { final String msg = "Invalid filter directive '" + filterStr + "': " + ise; throw new IllegalArgumentException(msg, ise); } } else { filter = null; } HashSet<BundleCapability> res = new HashSet<BundleCapability>(); for (BundleGeneration bg : fwCtx.bundles.getBundleGenerations(null)) { BundleRevisionImpl bri = bg.bundleRevision; if (bri != null) { for (BundleCapability bc : bri.getDeclaredCapabilities(namespace)) { if (null == filter || filter.matches(bc.getAttributes())) { res.add(bc); } } } } return res; }
Example #18
Source File: RequirementImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean equals(Object other) { if (this == other) return true; if (other == null) return false; if (!(other instanceof Requirement)) return false; Requirement r = (Requirement) other; return getNamespace().equals(r.getNamespace()) && getDirectives().equals(r.getDirectives()) && getAttributes().equals(r.getAttributes()) && getResource() == r.getResource(); // getResource().equals(r.getResource()); }
Example #19
Source File: NsToHtmlPackage.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void appendVersionAndResolutionDirective(final StringBuffer sb, final Requirement requirement) { final String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE); Util.appendVersion(sb, filter, Constants.VERSION_ATTRIBUTE); Util.appendResolution(sb, requirement); }
Example #20
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the resolution directive from a requirement and convert it to a HTML * string. * * @param sb * The buffer to append the resulting interval to. * @param requirement * The rquirement to extract and present the resolution directiv * from. */ public static void appendResolution(final StringBuffer sb, final Requirement requirement) { final String resolution = requirement.getDirectives().get(Constants.RESOLUTION_DIRECTIVE); if (resolution != null && resolution.length() > 0) { if (resolution.equals(Constants.RESOLUTION_MANDATORY)) { // Default, don't print } else { sb.append(" "); sb.append(resolution); } } }
Example #21
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
static boolean matches(final Requirement req, final Capability cap) { final String reqNamespace = req.getNamespace(); final String capNamespace = cap.getNamespace(); if (!reqNamespace.equals(capNamespace)) { return false; } /* * final String effective = req.getDirectives().get( * Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE); if (!(effective == null * || effective .equals(Namespace.EFFECTIVE_RESOLVE))) { return false; } */ final String filter = req.getDirectives() .get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); try { if (!(filter == null || RFC1960Filter.fromString(filter) .matches(cap.getAttributes()))) { return false; } return matches0(capNamespace, req, cap, filter); } catch (final InvalidSyntaxException e) { // TODO: to log e.printStackTrace(); return false; } }
Example #22
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
private void hostFragment(final ResolveContext context, final BundleRevision fragment, final BundleRevision host, final MultiMap<Resource, Wire> solution) { // host the capabilities for (final Capability cap : fragment.getCapabilities(null)) { if (!IdentityNamespace.IDENTITY_NAMESPACE .equals(cap.getNamespace())) { final HostedBundleCapability hostedCap = new HostedBundleCapability( host, cap); context.insertHostedCapability( new ArrayList<Capability>(host.getCapabilities( PackageNamespace.PACKAGE_NAMESPACE)), hostedCap); } } // create host wire final Capability hostCapability = host .getCapabilities(HostNamespace.HOST_NAMESPACE).get(0); final Requirement hostRequirement = fragment .getRequirements(HostNamespace.HOST_NAMESPACE).get(0); final Wire wire = Resources.createWire(hostCapability, hostRequirement); solution.insert(fragment, wire); solution.insert(host, wire); }
Example #23
Source File: AbstractBundle.java From concierge with Eclipse Public License 1.0 | 5 votes |
protected final BundleRevisionDTO getBundleRevisionDTO(BundleRevision revision){ BundleRevisionDTO dto = new BundleRevisionDTO(); dto.bundle = revision.getBundle().getBundleId(); dto.id = revision.hashCode(); dto.symbolicName = revision.getSymbolicName(); dto.type = revision.getTypes(); dto.version = getVersion().toString(); // add requirement/capabilities List<Capability> caps = revision.getCapabilities(null); dto.capabilities = new ArrayList<CapabilityDTO>(caps.size()); for(Capability c : caps){ CapabilityDTO capDTO = new CapabilityDTO(); capDTO.id = c.hashCode(); capDTO.namespace = c.getNamespace(); capDTO.resource = c.getResource().hashCode(); capDTO.attributes = getDTOMap(c.getAttributes()); capDTO.directives = new HashMap<String, String>(c.getDirectives()); dto.capabilities.add(capDTO); } List<Requirement> reqs = revision.getRequirements(null); dto.requirements = new ArrayList<RequirementDTO>(reqs.size()); for(Requirement r : reqs){ RequirementDTO reqDTO = new RequirementDTO(); reqDTO.id = r.hashCode(); reqDTO.namespace = r.getNamespace(); reqDTO.resource = r.getResource().hashCode(); reqDTO.attributes = getDTOMap(r.getAttributes()); reqDTO.directives = new HashMap<String, String>(r.getDirectives()); dto.requirements.add(reqDTO); } return dto; }
Example #24
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * @see org.osgi.framework.wiring.FrameworkWiring#findProviders(Requirement requirement) */ public Collection<BundleCapability> findProviders(Requirement requirement) { final List<Capability> providers = resolver.findProviders(requirement); final List<BundleCapability> result = new ArrayList<BundleCapability>(providers.size()); for(int i=0;i<providers.size();i++){ Capability cap = providers.get(i); if(cap instanceof BundleCapability){ result.add((BundleCapability) cap); } } return result; }
Example #25
Source File: RepositoryManagerImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public List<Capability> findProviders(Requirement requirement) { ArrayList<Capability> res = new ArrayList<Capability>(); for (RepositoryInfo ri : myRepos != null ? myRepos.keySet() : repos.getAll()) { Repository r = repos.getRepository(ri); if (r != null) { res.addAll(r.findProviders(Collections.singleton(requirement)).get(requirement)); } } return res; }
Example #26
Source File: NPEfix8_eigth_t.java From coming with MIT License | 4 votes |
public List<Requirement> getRequirements(String namespace) { return asRequirementList(getDeclaredRequirements(namespace)); }
Example #27
Source File: NPEfix8_eigth_s.java From coming with MIT License | 4 votes |
static List<Requirement> asRequirementList(List reqs) { return (List<Requirement>) reqs; }
Example #28
Source File: NPEfix8_eigth_s.java From coming with MIT License | 4 votes |
public List<Requirement> getRequirements(String namespace) { return asRequirementList(getDeclaredRequirements(namespace)); }
Example #29
Source File: TestBundle.java From vespa with Apache License 2.0 | 4 votes |
@Override public List<Requirement> getRequirements(String namespace) { throw new UnsupportedOperationException(); }
Example #30
Source File: BundleWiringImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
@SuppressWarnings("unchecked") @Override public List<Requirement> getResourceRequirements(String namespace) { return (List<Requirement>)(List<?>)getRequirements(namespace); }