示例#1
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!");
    }
  }
  /**
   * Intialize from a portion of a structured document.
   *
   * @param root the element
   */
  protected void initialize(Element root) {

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

    TextElement doc = (TextElement) root;

    String typedoctype = "";

    if (root instanceof Attributable) {
      Attribute itsType = ((Attributable) root).getAttribute("type");

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

    String doctype = doc.getName();

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

    Enumeration elements = doc.getChildren();

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

      if (!handleElement(elem)) {
        Logging.logCheckedWarning(
            LOG, "Unhandleded element \'", elem.getName(), "\' in ", doc.getName());
      }
    }

    // sanity check time!

    // FIXME [email protected] 20030409 check things
  }
示例#3
0
文件: HTTPAdv.java 项目: sisbell/jxta
  /**
   * Private constructor for xml serialized instances. Use the instantiator.
   *
   * @param doc The XML serialization of the advertisement.
   */
  private HTTPAdv(XMLElement doc) {
    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());
    }

    Attribute attr = doc.getAttribute(FlagsTag);

    if (attr != null) {
      String options = attr.getValue();

      publicAddressOnly = (options.indexOf(PublicAddressOnlyAttr) != -1);
    }

    Enumeration elements = doc.getChildren();

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

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

    // Sanity Check!!!

    // For consistency we force the flags to "disabled" for items we do not
    // have data for. However, the flags truely matter only when there is
    // data.
    if (proxy == null) {
      proxyEnabled = false;
    }

    if (serverEnabled && (0 == listenPort)) {
      throw new IllegalArgumentException(
          "Dynmaic port selection not supported with incoming connections.");
    }

    if ((listenPort < -1) || (listenPort > 65535)) {
      throw new IllegalArgumentException("Illegal Listen Port Value");
    }

    if (!Arrays.asList(CONFIGMODES).contains(configMode)) {
      throw new IllegalArgumentException("Unsupported configuration mode.");
    }

    // XXX 20050118 bondolo Some versions apparently don't initialize this field. Eventually make it
    // required.
    if (null == getProtocol()) {
      setProtocol("http");
    }
  }