Java Code Examples for org.osgi.framework.Constants#SERVICE_ID
The following examples show how to use
org.osgi.framework.Constants#SERVICE_ID .
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: PropertiesDictionary.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object get(Object key) { if (key == Constants.OBJECTCLASS) { return (ocIndex >= 0) ? values[ocIndex] : null; } else if (key == Constants.SERVICE_ID) { return (sidIndex >= 0) ? values[sidIndex] : null; } else if (key == Constants.SERVICE_BUNDLEID) { return (sidIndex >= 0) ? values[sbidIndex] : null; } else if (key == Constants.SERVICE_SCOPE) { return (sidIndex >= 0) ? values[ssIndex] : null; } for (int i = size - 1; i >= 0; i--) { if (((String)key).equalsIgnoreCase(keys[i])) { return values[i]; } } return null; }
Example 2
Source File: PropertiesDictionary.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
PropertiesDictionary(@SuppressWarnings("rawtypes") Dictionary in, String[] classes, Long sid, Long bid, String scope) { final int max_size = (in != null ? in.size() : 0) + size; keys = new String[max_size]; values = new Object[max_size]; keys[ocIndex] = Constants.OBJECTCLASS; values[ocIndex] = classes; keys[sidIndex] = Constants.SERVICE_ID; values[sidIndex] = sid != null ? sid : new Long(nextServiceID++); keys[sbidIndex] = Constants.SERVICE_BUNDLEID; values[sbidIndex] = bid; keys[ssIndex] = Constants.SERVICE_SCOPE; values[ssIndex] = scope; if (in != null) { try { for (@SuppressWarnings("rawtypes") final Enumeration e = in.keys(); e.hasMoreElements();) { final String key = (String) e.nextElement(); if (!key.equalsIgnoreCase(Constants.OBJECTCLASS) && !key.equalsIgnoreCase(Constants.SERVICE_ID) && !key.equalsIgnoreCase(Constants.SERVICE_BUNDLEID) && !key.equalsIgnoreCase(Constants.SERVICE_SCOPE)) { for (int i = size - 1; i >= 0; i--) { if (key.equalsIgnoreCase(keys[i])) { throw new IllegalArgumentException( "Several entries for property: " + key); } } keys[size] = key; values[size++] = in.get(key); } } } catch (final ClassCastException ignore) { throw new IllegalArgumentException( "Properties contains key that is not of type java.lang.String"); } } }
Example 3
Source File: ServiceReferenceImpl.java From AtlasForAndroid with MIT License | 5 votes |
ServiceReferenceImpl(Bundle bundle, Object obj, Dictionary<String, ?> dictionary, String[] strArr) { this.useCounters = new HashMap(0); this.cachedServices = null; if (obj instanceof ServiceFactory) { this.isServiceFactory = true; } else { this.isServiceFactory = false; checkService(obj, strArr); } this.bundle = bundle; this.service = obj; this.properties = dictionary == null ? new Hashtable() : new Hashtable(dictionary.size()); if (dictionary != null) { Enumeration keys = dictionary.keys(); while (keys.hasMoreElements()) { String str = (String) keys.nextElement(); this.properties.put(str, dictionary.get(str)); } } this.properties.put(Constants.OBJECTCLASS, strArr); Dictionary dictionary2 = this.properties; String str2 = Constants.SERVICE_ID; long j = nextServiceID + 1; nextServiceID = j; dictionary2.put(str2, Long.valueOf(j)); Integer num = dictionary == null ? null : (Integer) dictionary.get(Constants.SERVICE_RANKING); this.properties.put(Constants.SERVICE_RANKING, Integer.valueOf(num == null ? 0 : num.intValue())); this.registration = new ServiceRegistrationImpl(); }
Example 4
Source File: ServiceTracker.java From concierge with Eclipse Public License 1.0 | 4 votes |
/** * Create a {@code ServiceTracker} on the specified {@code ServiceReference} * . * * <p> * The service referenced by the specified {@code ServiceReference} will be * tracked by this {@code ServiceTracker}. * * @param context The {@code BundleContext} against which the tracking is * done. * @param reference The {@code ServiceReference} for the service to be * tracked. * @param customizer The customizer object to call when services are added, * modified, or removed in this {@code ServiceTracker}. If customizer * is {@code null}, then this {@code ServiceTracker} will be used as * the {@code ServiceTrackerCustomizer} and this * {@code ServiceTracker} will call the * {@code ServiceTrackerCustomizer} methods on itself. */ public ServiceTracker(final BundleContext context, final ServiceReference<S> reference, final ServiceTrackerCustomizer<S, T> customizer) { this.context = context; this.trackReference = reference; this.trackClass = null; this.customizer = (customizer == null) ? this : customizer; this.listenerFilter = "(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID).toString() + ")"; try { this.filter = context.createFilter(listenerFilter); } catch (InvalidSyntaxException e) { /* * we could only get this exception if the ServiceReference was * invalid */ IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage()); iae.initCause(e); throw iae; } }
Example 5
Source File: ServiceHTMLDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void appendServiceHTML(final StringBuffer sb, final long sid) { try { final String filter = "(" + Constants.SERVICE_ID + "=" + sid + ")"; final ServiceReference<?>[] srl = Activator.getTargetBC_getServiceReferences(null, filter); if (srl != null && srl.length == 1) { sb.append("<html>"); sb.append("<table border=0>"); sb.append("<tr><td width=\"100%\" bgcolor=\"#eeeeee\">"); JHTMLBundle.startFont(sb, "-1"); sb.append("Service #" + sid); sb.append(", "); Util.bundleLink(sb, srl[0].getBundle()); JHTMLBundle.stopFont(sb); sb.append("</td>\n"); sb.append("</tr>\n"); sb.append("</table>"); JHTMLBundle.startFont(sb); sb.append("<b>Properties</b>"); JHTMLBundle.stopFont(sb); sb.append("<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\">"); final String[] keys = srl[0].getPropertyKeys(); for (int i = 0; keys != null && i < keys.length; i++) { final StringWriter sw = new StringWriter(); final PrintWriter pr = new PrintWriter(sw); Util.printObject(pr, srl[0].getProperty(keys[i])); sb.append("<tr>"); sb.append("<td valign=\"top\">"); JHTMLBundle.startFont(sb); sb.append(keys[i]); JHTMLBundle.stopFont(sb); sb.append("</td>"); sb.append("<td valign=\"top\">"); sb.append(sw.toString()); sb.append("</td>"); sb.append("</tr>"); } sb.append("</table>"); try { formatServiceObject(sb, srl[0]); } catch (final Exception e) { sb.append("Failed to format service object: " + e); Activator.log .warn("Failed to format service object: " + e, srl[0], e); } sb.append("</html>"); } else { sb.append("No service with sid=" + sid); } } catch (final Exception e2) { e2.printStackTrace(); } }
Example 6
Source File: ServiceListenerTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void serviceChanged(ServiceEvent evt) { events.add(evt); out.println("ServiceEvent: " +toString(evt) ); if (ServiceEvent.UNREGISTERING==evt.getType()) { ServiceReference sr = evt.getServiceReference(); // Validate that no bundle is marked as using the service Bundle[] usingBundles = sr.getUsingBundles(); if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg) should be null " +"but is: "); } // Check if the service can be fetched Object service = bc.getService(sr); usingBundles = sr.getUsingBundles(); if (UNREGISTERSERVICE_VALID_DURING_UNREGISTERING) { // In this mode the service shall be obtainable during // unregistration. if (null==service) { teststatus = false; out.print("*** Service should be available to ServiceListener " +"while handling unregistering event."); } out.println("Service (unreg): " +service); if (checkUsingBundles && usingBundles.length!=1) { teststatus = false; printUsingBundles(sr, "*** One using bundle expected " +"(unreg, after getService), found: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): "); } } else { // In this mode the service shall NOT be obtainable during // unregistration. if (null!=service) { teststatus = false; out.print("*** Service should not be available to ServiceListener " +"while handling unregistering event."); } if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg, after getService), " +"should be null but is: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): null"); } } bc.ungetService(sr); // Check that the UNREGISTERING service can not be looked up // using the service registry. try { Long sid = (Long)sr.getProperty(Constants.SERVICE_ID); String sidFilter = "(" +Constants.SERVICE_ID +"=" +sid +")"; ServiceReference[] srs = bc.getServiceReferences((String)null, sidFilter); if (null==srs || 0==srs.length) { out.println("ServiceReference for UNREGISTERING service is not" +" found in the service registry; ok."); } else { teststatus = false; out.println("*** ServiceReference for UNREGISTERING" +" service, " + sr +", not found in the service registry; fail."); out.print("Found the following Service references: "); for (int i=0; null!=srs && i<srs.length; i++) { if (i>0) out.print(", "); out.print(srs[i]); } out.println(); } } catch (Throwable t) { teststatus = false; out.println("*** Unexpected excpetion when trying to lookup a" +" service while it is in state UNREGISTERING; " +t); t.printStackTrace(out); } } }
Example 7
Source File: ServiceTracker.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create a {@code ServiceTracker} on the specified {@code ServiceReference} * . * * <p> * The service referenced by the specified {@code ServiceReference} will be * tracked by this {@code ServiceTracker}. * * @param context The {@code BundleContext} against which the tracking is * done. * @param reference The {@code ServiceReference} for the service to be * tracked. * @param customizer The customizer object to call when services are added, * modified, or removed in this {@code ServiceTracker}. If customizer * is {@code null}, then this {@code ServiceTracker} will be used as * the {@code ServiceTrackerCustomizer} and this * {@code ServiceTracker} will call the * {@code ServiceTrackerCustomizer} methods on itself. */ public ServiceTracker(final BundleContext context, final ServiceReference<S> reference, final ServiceTrackerCustomizer<S, T> customizer) { this.context = context; this.trackReference = reference; this.trackClass = null; this.customizer = (customizer == null) ? this : customizer; this.listenerFilter = "(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID).toString() + ")"; try { this.filter = context.createFilter(listenerFilter); } catch (InvalidSyntaxException e) { /* * we could only get this exception if the ServiceReference was * invalid */ IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage()); iae.initCause(e); throw iae; } }