Java Code Examples for org.osgi.resource.Resource#getCapabilities()
The following examples show how to use
org.osgi.resource.Resource#getCapabilities() .
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: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the MIME-type of a repository resource. * * @param resource * The resource to get the MIME type for. * * @return Resource MIME type or {@code null} if no MIME-type available. */ public static String getResourceMime(Resource resource) { String res = null; for (final Capability cap : resource .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); final String mime = (String) attrs.get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); if (mime != null) { res = mime; break; } } return res; }
Example 2
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the location to use when installing this resource. * * If available, the resource URL will be used as the location. Otherwise we * simply use the hash code of the resource. * * @param resource * the resource to determine the installation location for. * @return location to use when installing this resource or {@code null} if * location is available for this resource. */ public static String getLocation(Resource resource) { for (final Capability cap : resource .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); if (supportedMimeTypes.contains(attrs .get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE))) { final String url = (String) attrs.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); if (url != null) { return url; } } } return null; }
Example 3
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 4
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the name of a repository resource from the identity name space." */ public static String getResourceName(Resource resource) { final List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE); if (idCaps.size() != 1) { Activator.log.error("Found " + idCaps.size() + " identity capabilites expected one: " + idCaps); return resource.toString(); } final Capability idCap = idCaps.get(0); return idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE) .toString(); }
Example 5
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get version of a repository resource form the identity name space. */ public static Version getResourceVersion(Resource resource) { final List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE); if (idCaps.size() != 1) { Activator.log.error("Found " + idCaps.size() + " identity capabilites expected one: " + idCaps); return Version.emptyVersion; } final Capability idCap = idCaps.get(0); return (Version) idCap.getAttributes() .get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); }
Example 6
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the type of a repository resource from the identity name space." * * @param resource * The resource to get the type for. * * @return Type as a string, one of {@link IdentityNamespace#TYPE_BUNDLE}, * {@link IdentityNamespace#TYPE_FRAGMENT}, and * {@link IdentityNamespace#TYPE_UNKNOWN}. */ public static String getResourceType(Resource resource) { final List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE); for (final Capability idCap : idCaps) { final String type = (String) idCap.getAttributes() .get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE); if (type != null) { return type; } } return "—"; }
Example 7
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the size in bytes of a repository resource. * * @param resource * The resource to get the size of. * * @return Resource size in byte or {@code -1} if no size available. */ public static long getResourceSize(Resource resource) { long res = -1; for (final Capability cap : resource .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); final Long size = (Long) attrs.get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE); if (size != null) { res = size.longValue(); } } return res; }
Example 8
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the category of a repository resource. * * The category is specified as the value of the bundle manifest entry named * {@link Constants#BUNDLE_CATEGORY}. * * @param resource * The resource to get the category for. * * @return Resource category or {@code "[no category]"} if no category is available. */ public static String getResourceCategory(Resource resource) { for (final Capability cap : resource .getCapabilities(KF_EXTRAS_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); final Object val = attrs.get("category"); if (val != null) { return (String) val; } } return "[no category]"; }
Example 9
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the vendor of a repository resource. * * The vendor is specified as the value of the bundle manifest entry named * {@link Constants#BUNDLE_VENDOR}. * * @param resource * The resource to get the vendor for. * * @return Resource vendor or {@code "[no vendor]"} if vendor information is * not available. */ public static String getResourceVendor(Resource resource) { for (final Capability cap : resource .getCapabilities(KF_EXTRAS_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); final Object val = attrs.get("vendor"); if (val != null) { return (String) val; } } return "[no vendor]"; }
Example 10
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the icon for a repository resource. * * The icon is specified as the value of the bundle manifest entry named * {@code Bundle-Icon}. * * @param resource * The resource to get the icon for. * * @return Resource icon string or {@code null} if icon information is * not available. */ public static String getResourceIcon(Resource resource) { for (final Capability cap : resource .getCapabilities(KF_EXTRAS_NAMESPACE)) { final Map<String, Object> attrs = cap.getAttributes(); final Object val = attrs.get("icon"); if (val != null) { return (String) val; } } return null; }
Example 11
Source File: RepositoryXmlParser.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void ensureOsgiContentUrlsAreAbsolute(URL repositoryUrl, Collection<Resource> rs) throws Exception { for(Resource r : rs) { for(Capability c : r.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) { String url = (String)c.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); url = new URL(repositoryUrl, url).toExternalForm(); c.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url); } } }
Example 12
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 4 votes |
void addAll(final Resource res) { for (final Capability cap : res.getCapabilities(null)) { add(cap); } }
Example 13
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 4 votes |
void removeAll(final Resource res) { for (final Capability cap : res.getCapabilities(null)) { remove(cap); } }