public static FrameworkDTO newFrameworkDTO(
     BundleContext systemBundleContext, Map<String, String> configuration) {
   FrameworkDTO dto = new FrameworkDTO();
   dto.properties = asProperties(configuration);
   if (systemBundleContext == null) {
     dto.bundles = newList(0);
     dto.services = newList(0);
     return dto;
   }
   Bundle[] bundles = systemBundleContext.getBundles();
   int size = bundles == null ? 0 : bundles.length;
   List<BundleDTO> bundleDTOs = newList(size);
   for (int i = 0; i < size; i++) {
     bundleDTOs.add(newBundleDTO(bundles[i]));
   }
   dto.bundles = bundleDTOs;
   try {
     ServiceReference<?>[] references = systemBundleContext.getAllServiceReferences(null, null);
     size = references == null ? 0 : references.length;
     List<ServiceReferenceDTO> refDTOs = newList(size);
     for (int i = 0; i < size; i++) {
       ServiceReferenceDTO serviceRefDTO = getServiceReferenceDTO(references[i]);
       if (serviceRefDTO != null) {
         refDTOs.add(serviceRefDTO);
       }
     }
     dto.services = refDTOs;
   } catch (InvalidSyntaxException e) {
     dto.services = newList(0);
   }
   return dto;
 }
  @Override
  public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
    SignedContentFactory factory = equinoxContainer.getSignedContentFactory();
    if (factory == null) {
      return Collections.emptyMap();
    }

    try {
      SignerInfo[] infos = signerInfos;
      if (infos == null) {
        SignedContent signedContent = factory.getSignedContent(this);
        infos = signedContent.getSignerInfos();
        signerInfos = infos;
      }
      if (infos.length == 0) return Collections.emptyMap();
      Map<X509Certificate, List<X509Certificate>> results =
          new HashMap<X509Certificate, List<X509Certificate>>(infos.length);
      for (int i = 0; i < infos.length; i++) {
        if (signersType == SIGNERS_TRUSTED && !infos[i].isTrusted()) continue;
        Certificate[] certs = infos[i].getCertificateChain();
        if (certs == null || certs.length == 0) continue;
        List<X509Certificate> certChain = new ArrayList<X509Certificate>();
        for (int j = 0; j < certs.length; j++) certChain.add((X509Certificate) certs[j]);
        results.put((X509Certificate) certs[0], certChain);
      }
      return results;
    } catch (Exception e) {
      return Collections.emptyMap();
    }
  }
 private List<CapabilityDTO> getListCapabilityDTO(List<BundleCapability> caps) {
   if (caps == null) {
     return null;
   }
   List<CapabilityDTO> dtos = newList(caps.size());
   for (BundleCapability cap : caps) {
     dtos.add(getCapabilityDTO(cap));
   }
   return dtos;
 }
 private List<WireDTO> getListBundleWireDTO(List<BundleWire> wires) {
   if (wires == null) {
     return null;
   }
   List<WireDTO> dtos = newList(wires.size());
   for (BundleWire wire : wires) {
     dtos.add(getBundleWireDTO(wire));
   }
   return dtos;
 }
 private List<RequirementRefDTO> getListRequirementRefDTO(List<BundleRequirement> reqs) {
   if (reqs == null) {
     return null;
   }
   List<RequirementRefDTO> dtos = newList(reqs.size());
   for (BundleRequirement req : reqs) {
     dtos.add(getRequirementRefDTO(req));
   }
   return dtos;
 }
 public static ServiceReferenceDTO[] newArrayServiceReferenceDTO(
     ServiceReference<?>[] references) {
   final int length = (references == null) ? 0 : references.length;
   List<ServiceReferenceDTO> refDTOs = new ArrayList<ServiceReferenceDTO>(length);
   for (int i = 0; i < length; i++) {
     ServiceReferenceDTO dto = getServiceReferenceDTO(references[i]);
     if (dto != null) {
       refDTOs.add(dto);
     }
   }
   return refDTOs.toArray(new ServiceReferenceDTO[refDTOs.size()]);
 }
 public static BundleRevisionDTO[] newArrayBundleRevisionDTO(BundleRevisions revisions) {
   if (revisions == null) {
     return null;
   }
   List<BundleRevision> revs = revisions.getRevisions();
   final int size = revs.size();
   BundleRevisionDTO[] dtos = new BundleRevisionDTO[size];
   for (int i = 0; i < size; i++) {
     dtos[i] = new DTOBuilder().getBundleRevisionDTO(revs.get(i));
   }
   return dtos;
 }
 List<Generation> getGenerations() {
   List<Generation> result = new ArrayList<Generation>();
   ModuleRevision current = getModule().getCurrentRevision();
   result.add((Generation) current.getRevisionInfo());
   ModuleWiring wiring = current.getWiring();
   if (wiring != null) {
     List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
     if (hostWires != null) {
       for (ModuleWire hostWire : hostWires) {
         result.add((Generation) hostWire.getRequirer().getRevisionInfo());
       }
     }
   }
   return result;
 }
 void removeInitListeners() {
   BundleContext context = createBundleContext(false);
   for (FrameworkListener initListener : initListeners) {
     context.removeFrameworkListener(initListener);
   }
   initListeners.clear();
 }
 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);
 }
 public void init(FrameworkListener... listeners) throws BundleException {
   if (listeners != null) {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println(
           "Initializing framework with framework listeners: " + listeners); // $NON-NLS-1$
     }
     initListeners.addAll(Arrays.asList(listeners));
   } else {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println("Initializing framework with framework no listeners"); // $NON-NLS-1$
     }
   }
   try {
     ((SystemModule) getModule()).init();
   } finally {
     if (!initListeners.isEmpty()) {
       getEquinoxContainer().getEventPublisher().flushFrameworkEvents();
       removeInitListeners();
     }
   }
 }
 /**
  * Assumes the input map always has String keys and the values are of types: String, Version,
  * Long, Double or List of the previous types. Lists are copied and Version objects are converted
  * to String objects.
  */
 private static Map<String, Object> newAttributesMapDTO(Map<String, Object> map) {
   Map<String, Object> dto = new HashMap<String, Object>(map);
   /* Lists are copied and Version objects are converted to String objects. */
   for (Map.Entry<String, Object> entry : dto.entrySet()) {
     Object value = entry.getValue();
     if (value instanceof Version) {
       entry.setValue(String.valueOf(value));
       continue;
     }
     if (value instanceof List) {
       List<Object> newList = new ArrayList<Object>((List<?>) value);
       for (ListIterator<Object> iter = newList.listIterator(); iter.hasNext(); ) {
         Object element = iter.next();
         if (element instanceof Version) {
           iter.set(String.valueOf(element));
         }
       }
       entry.setValue(newList);
       continue;
     }
   }
   return dto;
 }
 public static BundleWiringDTO[] newArrayBundleWiringDTO(BundleRevisions revisions) {
   if (revisions == null) {
     return null;
   }
   List<BundleRevision> revs = revisions.getRevisions();
   final int size = revs.size();
   List<BundleWiringDTO> dtos = new ArrayList<BundleWiringDTO>(size);
   for (int i = 0; i < size; i++) {
     BundleWiring wiring = revs.get(i).getWiring();
     if (wiring != null) {
       dtos.add(
           new DTOBuilder().getBundleWiringDTO(wiring)); // use new DTOBuilder for each wiring dto
     }
   }
   return dtos.toArray(new BundleWiringDTO[dtos.size()]);
 }