Esempio n. 1
0
  /**
   * Intialize a Discovery Query from a portion of a structured document.
   *
   * @param root document to intialize from
   */
  protected void initialize(Element root) {

    if (!XMLElement.class.isInstance(root)) {
      throw new IllegalArgumentException(getClass().getName() + " only supports XMLElement");
    }

    XMLElement doc = (XMLElement) root;

    if (!doc.getName().equals(getAdvertisementType())) {
      throw new IllegalArgumentException(
          "Could not construct : "
              + getClass().getName()
              + "from doc containing a "
              + doc.getName());
    }

    setDiscoveryType(-1); // force illegal value;

    Enumeration<XMLElement> elements = doc.getChildren();

    while (elements.hasMoreElements()) {
      XMLElement elem = elements.nextElement();

      if (!handleElement(elem)) {
        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {
          LOG.fine("Unhandled Element : " + elem.toString());
        }
      }
    }

    // sanity check time!

    if ((DiscoveryService.PEER != getDiscoveryType())
        && (DiscoveryService.GROUP != getDiscoveryType())
        && (DiscoveryService.ADV != getDiscoveryType())) {
      throw new IllegalArgumentException("Type is not one of the required values.");
    }
    if (getThreshold() < 0) {
      throw new IllegalArgumentException("Threshold must not be less than zero.");
    }
    if ((getDiscoveryType() != DiscoveryService.PEER) && (getThreshold() == 0)) {
      throw new IllegalArgumentException("Threshold may not be zero.");
    }
    if ((null == getAttr()) && (null != getValue())) {
      throw new IllegalArgumentException("Value specified without attribute.");
    }
  }
Esempio n. 2
0
  /**
   * Private constructor. Use instantiator
   *
   * @param root Description of the Parameter
   */
  private RouteAdv(Element root) {
    if (!XMLElement.class.isInstance(root)) {
      throw new IllegalArgumentException(getClass().getName() + " only supports XLMElement");
    }

    XMLElement doc = (XMLElement) root;

    String doctype = doc.getName();

    String typedoctype = "";
    Attribute itsType = doc.getAttribute("type");

    if (null != itsType) {
      typedoctype = itsType.getValue();
    }

    if (!doctype.equals(getAdvertisementType()) && !getAdvertisementType().equals(typedoctype)) {
      throw new IllegalArgumentException(
          "Could not construct : "
              + getClass().getName()
              + "from doc containing a "
              + doc.getName());
    }

    Enumeration elements = doc.getChildren();

    while (elements.hasMoreElements()) {
      XMLElement elem = (XMLElement) elements.nextElement();

      if (!handleElement(elem)) {
        if (LOG.isEnabledFor(Level.DEBUG)) {
          LOG.debug("Unhandled Element: " + elem.toString());
        }
      }
    }

    // HACK Compatibility

    setDestPeerID(getDestPeerID());

    // Sanity Check!!!

    if (hasALoop()) {
      throw new IllegalArgumentException("Route contains a loop!");
    }
  }