Java Code Examples for org.osgi.framework.ServiceReference#getPropertyKeys()

The following examples show how to use org.osgi.framework.ServiceReference#getPropertyKeys() . 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: ServicePojo.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
public ServicePojo(final ServiceReference<?> sref) {
	id = ((Long) sref.getProperty(Constants.SERVICE_ID)).longValue();
	final Map<String, Object> props = new HashMap<String, Object>();
	for (final String key : sref.getPropertyKeys()) {
		props.put(key, sref.getProperty(key));
	}
	setProperties(props);

	setBundle(getBundleUri(sref.getBundle()));
	final List<String> usingBundlesList = new ArrayList<String>();

	if (sref.getUsingBundles() != null) {
		for (final Bundle using : sref.getUsingBundles()) {
			usingBundlesList.add(getBundleUri(using));
		}
	}
	setUsingBundles(usingBundlesList.toArray(new String[usingBundlesList.size()]));
}
 
Example 2
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
protected final ServiceReferenceDTO getServiceReferenceDTO(ServiceReference ref){
	ServiceReferenceDTO dto = new ServiceReferenceDTO();
	dto.bundle = bundleId;
	dto.id = (Long) ref.getProperty(Constants.SERVICE_ID);
	dto.properties = new HashMap<String, Object>();
	for(String key : ref.getPropertyKeys()){
		Object val = ref.getProperty(key);
		dto.properties.put(key, getDTOValue(val));
	}
	Bundle[] usingBundles = ref.getUsingBundles();
	if(usingBundles == null){
		dto.usingBundles = new long[0];
	} else {
		dto.usingBundles = new long[usingBundles.length];
		for(int j=0;j<usingBundles.length;j++){
			dto.usingBundles[j] = usingBundles[j].getBundleId();
		}
	}
	return dto;
}
 
Example 3
Source File: RFC1960Filter.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * check, if the filter matches a service reference.
 * 
 * @param reference
 *            the service reference.
 * @return true, iff it matches.
 * @see org.osgi.framework.Filter#match(org.osgi.framework.ServiceReference)
 * @category Filter
 */
public boolean match(final ServiceReference<?> reference) {
	try {
		return matches(
				((ServiceReferenceImpl<?>) reference).properties);
	} catch (final ClassCastException e) {
		// so this was not instance of ServiceReferenceImpl. Someone
		// must have created an own implementation.
		final Map<String, Object> dict = new HashMap<String, Object>();
		final String[] keys = reference.getPropertyKeys();
		for (int i = 0; i < keys.length; i++) {
			dict.put(keys[i], reference.getProperty(keys[i]));
		}
		return matches(dict);
	}
}
 
Example 4
Source File: ServiceComponentRuntimeImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ServiceReferenceDTO getServiceReferenceDTO(ServiceReference<?> sr) {
  ServiceReferenceDTO res = new ServiceReferenceDTO();
  res.properties = new HashMap<String, Object>();
  for (String key : sr.getPropertyKeys()) {
    Object val = safeDTOObject(sr.getProperty(key));
    res.properties.put(key, val);
  }
  res.id = ((Long)sr.getProperty(Constants.SERVICE_ID)).longValue();
  Bundle [] using = sr.getUsingBundles();
  if (using != null) {
    res.usingBundles = new long [using.length];
    for (int i = 0; i < using.length; i++) {
      res.usingBundles[i] = using[i].getBundleId();
    }
  } else {
    res.usingBundles = new long [0];
  }
  Bundle b = sr.getBundle();
  if (b == null) {
    return null;
  }
  res.bundle = b.getBundleId();
  return res;
}
 
Example 5
Source File: Utils.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> getProperties(ServiceReference<?> sref) {
    String[] propertyKeys = sref.getPropertyKeys();
    Map<String, Object> properties = new HashMap<>(propertyKeys.length);

    for (String key : propertyKeys) {
        properties.put(key, sref.getProperty(key));
    }

    return properties;
}
 
Example 6
Source File: RFC1960Filter.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * check if the filter matches a service reference.
 * 
 * @param reference
 *            the service reference.
 * @return true if the filter matches, false otherwise.
 * @see org.osgi.framework.Filter#match(org.osgi.framework.ServiceReference)
 * @category Filter
 */
public boolean match(final ServiceReference<?> reference) {
	try {
		return matches(((ServiceReferenceImpl<?>) reference).properties);
	} catch (final ClassCastException ce) {
		// so this was not instance of ServiceReferenceImpl. Someone
		// must have created an own implementation.
		final HashMap<String, Object> dict = new HashMap<String, Object>();
		final String[] keys = reference.getPropertyKeys();
		for (int i = 0; i < keys.length; i++) {
			dict.put(keys[i], reference.getProperty(keys[i]));
		}
		return matches(dict);
	}
}
 
Example 7
Source File: FrameworkCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void showLongService(ServiceReference<?> s, String pad, PrintWriter out) {
  out.print(Util.showServiceClasses(s));
  final String[] k = s.getPropertyKeys();
  for (final String element : k) {
    out.print("\n  " + pad + element + " = "
              + Util.showObject(s.getProperty(element)));
  }
}
 
Example 8
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Dictionary<String, Object> collectProperties(ServiceReference<?> sr)
{
  final Dictionary<String, Object> props = new Hashtable<String, Object>();
  final String[] keys = sr.getPropertyKeys();
  if (keys != null) {
    for (final String key : keys) {
      props.put(key, sr.getProperty(key));
    }
  }
  return props;
}
 
Example 9
Source File: PropertyDictionary.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
PropertyDictionary(ServiceReference<?> sr) {
  props = new Hashtable<String,Object>();
  for (String key : sr.getPropertyKeys()) {
    props.put(key, sr.getProperty(key));
  }
}
 
Example 10
Source File: RFC1960Filter.java    From AtlasForAndroid with MIT License 5 votes vote down vote up
public boolean match(ServiceReference serviceReference) {
    try {
        return match(((ServiceReferenceImpl) serviceReference).properties);
    } catch (Exception e) {
        Dictionary hashtable = new Hashtable();
        String[] propertyKeys = serviceReference.getPropertyKeys();
        for (int i = RFC1960Filter.EQUALS; i < propertyKeys.length; i += RFC1960Filter.PRESENT) {
            hashtable.put(propertyKeys[i], serviceReference.getProperty(propertyKeys[i]));
        }
        return match(hashtable);
    }
}
 
Example 11
Source File: RFC1960Filter.java    From AtlasForAndroid with MIT License 5 votes vote down vote up
public boolean match(ServiceReference serviceReference) {
    try {
        return match(((ServiceReferenceImpl) serviceReference).properties);
    } catch (Exception e) {
        Dictionary hashtable = new Hashtable();
        String[] propertyKeys = serviceReference.getPropertyKeys();
        for (int i = EQUALS; i < propertyKeys.length; i += PRESENT) {
            hashtable.put(propertyKeys[i], serviceReference.getProperty(propertyKeys[i]));
        }
        return match(hashtable);
    }
}
 
Example 12
Source File: LinkerBinderManager.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the information of the declarationBinderRef to update the BinderDescriptor.
 * information.
 *
 * @param declarationBinderRef the ServiceReference<DeclarationBinder> of the DeclarationBinder
 * @throws InvalidFilterException
 */
private void update(ServiceReference<S> declarationBinderRef) throws InvalidFilterException {
    properties.clear();
    for (String key : declarationBinderRef.getPropertyKeys()) {
        properties.put(key, declarationBinderRef.getProperty(key));
    }
    match = binderServiceFilter.matches(properties);
    targetFilter = getFilter(properties.get(TARGET_FILTER_PROPERTY));
}
 
Example 13
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String toHTML(ExtLogEntry e) {
    final StringBuffer sb = new StringBuffer();

    sb.append("<html>");

    sb.append("<table border=0 width=\"100%\">");
    sb.append("<tr bgcolor=\"#eeeeee\">");

    sb.append("<td width=50 valign=top align=left bgcolor=\"#eeeeee\">" +
              fontify(e.getId() +
                      ", "+ shortName(e.getBundle())) + "</td>")
      ;

    sb.append("<td  valign=top  align=left bgcolor=\"#eeeeee\">" +
              fontify(tf.format(new Date(e.getTime()))) + "</td>")
;

    sb.append("<td valign=top align=right bgcolor=\"#eeeeee\">" +
              fontify(levelString(e.getLevel())) + "</td>");


    sb.append("</tr>");

    sb.append("<tr>");
    sb.append("<td width=\"100%\" colspan=3>");
    sb.append(fontify(quoteHtml(e.getMessage())));
    sb.append("</td>");
    sb.append("</tr>");

    final ServiceReference<?> sr = e.getServiceReference();
    if (null!=sr) {
      sb.append("<tr bgcolor=\"#eeeeee\">");
      sb.append("<td width=\"100%\" colspan=\"3\">");
      sb.append(fontify("Service Properties"));
      sb.append("</td>");
      sb.append("</tr>");
      final String[] propKeys = sr.getPropertyKeys();
      for (final String propKey : propKeys) {
        // Reuse service reference properties presentation form the
        // services tab.
        final StringWriter sw = new StringWriter();
        final PrintWriter  pr = new PrintWriter(sw);
        try {
          org.knopflerfish.bundle.desktop.swing.Util
            .printObject(pr, sr.getProperty(propKey));
        } catch (final IOException ioe) {
        }

        sb.append("<tr>");
        sb.append("<td valign=top align=left>" +fontify(propKey) +"</td>");
        sb.append("<td valign=top align=left colspan=\"2\">"
                  +fontify(sw.toString())
                  +"</td>");
        sb.append("</tr>");
      }
    }

    final Throwable t = e.getException();
    if(t != null) {
      sb.append("<tr bgcolor=\"#eeeeee\">");

      sb.append("<td colspan=3 align=left bgcolor=\"#eeeeee\">" +
                fontify("Exception"));
      sb.append("</td>");
      sb.append("</tr>");

      sb.append("<tr>");
      sb.append("<td colspan=3>");

      final StringWriter w = new StringWriter();
      t.printStackTrace(new PrintWriter(w));
      sb.append(fontify(Text.replace(w.toString(), "\n", "<br>")));
      sb.append("</td>");
      sb.append("</tr>");
    }

    sb.append("</table>");

    sb.append("</font>\n");
    sb.append("</html>");

    return sb.toString();
  }