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;
 }
 private static Object mapValue(Object v) {
   if ((v == null)
       || v instanceof Number
       || v instanceof Boolean
       || v instanceof Character
       || v instanceof String
       || v instanceof DTO) {
     return v;
   }
   if (v instanceof Map) {
     Map<?, ?> m = (Map<?, ?>) v;
     Map<Object, Object> map = newMap(m.size());
     for (Map.Entry<?, ?> e : m.entrySet()) {
       map.put(mapValue(e.getKey()), mapValue(e.getValue()));
     }
     return map;
   }
   if (v instanceof List) {
     List<?> c = (List<?>) v;
     List<Object> list = newList(c.size());
     for (Object o : c) {
       list.add(mapValue(o));
     }
     return list;
   }
   if (v instanceof Set) {
     Set<?> c = (Set<?>) v;
     Set<Object> set = newSet(c.size());
     for (Object o : c) {
       set.add(mapValue(o));
     }
     return set;
   }
   if (v.getClass().isArray()) {
     final int length = Array.getLength(v);
     final Class<?> componentType = mapComponentType(v.getClass().getComponentType());
     Object array = Array.newInstance(componentType, length);
     for (int i = 0; i < length; i++) {
       Array.set(array, i, mapValue(Array.get(v, i)));
     }
     return array;
   }
   return String.valueOf(v);
 }
 private BundleRevisionDTO getBundleRevisionDTO(BundleRevision revision) {
   if (revision == null) {
     return null;
   }
   BundleRevisionDTO dto = resources.get(revision);
   if (dto != null) {
     return dto;
   }
   dto = new BundleRevisionDTO();
   dto.id = identifier(revision);
   resources.put(revision, dto);
   dto.bundle = revision.getBundle().getBundleId();
   dto.symbolicName = revision.getSymbolicName();
   dto.type = revision.getTypes();
   dto.version = revision.getVersion().toString();
   dto.capabilities = getListCapabilityDTO(revision.getDeclaredCapabilities(null));
   dto.requirements = getListRequirementDTO(revision.getDeclaredRequirements(null));
   return dto;
 }
 private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(BundleWiring wiring) {
   if (wiring == null) {
     return null;
   }
   BundleWiringDTO.NodeDTO dto = wiringnodes.get(wiring);
   if (dto != null) {
     return dto;
   }
   dto = new BundleWiringDTO.NodeDTO();
   dto.id = identifier(wiring);
   wiringnodes.put(wiring, dto);
   dto.current = wiring.isCurrent();
   dto.inUse = wiring.isInUse();
   dto.resource = getResourceId(wiring.getRevision());
   dto.capabilities = getListCapabilityRefDTO(wiring.getCapabilities(null));
   dto.requirements = getListRequirementRefDTO(wiring.getRequirements(null));
   dto.providedWires = getListBundleWireDTO(wiring.getProvidedWires(null));
   dto.requiredWires = getListBundleWireDTO(wiring.getRequiredWires(null));
   return dto;
 }