Beispiel #1
0
  /**
   * Merge two hashtables of servcices, overwriting old with new if they have the same base class
   * id.
   *
   * @oldServices --service table of a parent group
   * @newServices --services to be added or substituted
   * @return --merged table
   */
  private static Map mergeTables(Map oldServices, Map newServices) {
    // just use brute force; we won't be doing it that often
    Map mergedServices = new HashMap(oldServices);
    Iterator newKeys = newServices.keySet().iterator();

    while (newKeys.hasNext()) {
      ModuleClassID key = (ModuleClassID) newKeys.next();
      Iterator oldKeys = oldServices.keySet().iterator();

      while (oldKeys.hasNext()) {
        ModuleClassID oldkey = (ModuleClassID) oldKeys.next();

        if (oldkey.isOfSameBaseClass(key)) {
          mergedServices.remove(oldkey);
        }
      }
      mergedServices.put(key, newServices.get(key));
    }
    return mergedServices;
  }
  /** {@inheritDoc} */
  public void serializeTo(Element element) throws DocumentSerializationException {
    for (Iterator i = transportMetrics.iterator(); i.hasNext(); ) {
      TransportMetric transportMetric = (TransportMetric) i.next();

      DocumentSerializableUtilities.addDocumentSerializable(
          element, "transportMetric", transportMetric);
    }
    if (moduleClassID != null) {
      DocumentSerializableUtilities.addString(element, "moduleClassID", moduleClassID.toString());
    }
  }
  private void outputModules(
      StructuredTextDocument doc, Hashtable modulesTable, String mainTag, MimeMediaType encodeAs) {

    Enumeration allClasses = modulesTable.keys();
    while (allClasses.hasMoreElements()) {
      ModuleClassID mcid = (ModuleClassID) allClasses.nextElement();
      Object val = modulesTable.get(mcid);

      // For applications, we ignore the role ID. It is not meaningfull,
      // and a new one is assigned on the fly when loading this adv.

      if (val instanceof Advertisement) {
        TextElement m = doc.createElement(mainTag);
        doc.appendChild(m);

        if (!(modulesTable == appsTable || mcid.equals(mcid.getBaseClass()))) {
          // It is not an app and there is a role ID. Output it.

          TextElement i = doc.createElement(mcidTag, mcid.toString());
          m.appendChild(i);
        }

        StructuredTextDocument advdoc =
            (StructuredTextDocument) ((Advertisement) val).getDocument(encodeAs);

        StructuredDocumentUtils.copyElements(doc, m, advdoc);

      } else if (val instanceof ModuleSpecID) {
        TextElement m;

        if (modulesTable == appsTable || mcid.equals(mcid.getBaseClass())) {

          // Either it is an app or there is no role ID.
          // So the specId is good enough.
          m = doc.createElement(mainTag, ((ModuleSpecID) val).toString());
          doc.appendChild(m);
        } else {
          // The role ID matters, so the classId must be separate.
          m = doc.createElement(mainTag);
          doc.appendChild(m);

          TextElement i;
          i = doc.createElement(mcidTag, mcid.toString());
          m.appendChild(i);

          i = doc.createElement(msidTag, ((ModuleSpecID) val).toString());
          m.appendChild(i);
        }
      } else {
        if (LOG.isEnabledFor(Level.WARN)) LOG.warn("unsupported class in modules table");
      }
    }
  }