public ServiceRegistrationImpl( BundleImpl bundle, long serviceId, String[] classNames, Object service, Dictionary<String, ?> properties) { this.bundle = bundle; this.serviceId = serviceId; this.classNames = classNames; this.service = service; if ((properties == null) || properties.isEmpty()) this.properties = EMPTY_PROPERTIES; else { Enumeration<String> keys = properties.keys(); Map<String, Object> thisProperties = newCaseInsensitiveMapInstance(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (Constants.OBJECTCLASS.equalsIgnoreCase(key) || Constants.SERVICE_ID.equalsIgnoreCase(key)) continue; else if (thisProperties.containsKey(key)) throw new IllegalArgumentException(key); else thisProperties.put(key, properties.get(key)); } this.properties = thisProperties.isEmpty() ? EMPTY_PROPERTIES : thisProperties; } }
private static ServiceReferenceDTO getServiceReferenceDTO(ServiceReference<?> ref) { if (ref == null) { return null; } Bundle b = ref.getBundle(); if (b == null) { // service has been unregistered return null; } ServiceReferenceDTO dto = new ServiceReferenceDTO(); dto.bundle = b.getBundleId(); String[] keys = ref.getPropertyKeys(); Map<String, Object> properties = newMap(keys.length); for (String k : keys) { Object v = ref.getProperty(k); if (Constants.SERVICE_ID.equals(k)) { dto.id = ((Long) v).longValue(); } properties.put(k, mapValue(v)); } dto.properties = properties; Bundle[] using = ref.getUsingBundles(); final int length = (using == null) ? 0 : using.length; long[] usingBundles = new long[length]; for (int i = 0; i < length; i++) { usingBundles[i] = using[i].getBundleId(); } dto.usingBundles = usingBundles; return dto; }
public Object getProperty(String key) { Object value; if (Constants.OBJECTCLASS.equalsIgnoreCase(key)) value = classNames; else if (Constants.SERVICE_ID.equalsIgnoreCase(key)) value = serviceId; else synchronized (properties) { value = properties.get(key); } return value; }