コード例 #1
0
  /**
   * {@inheritDoc}
   *
   * @param raw Description of the Parameter
   * @return Description of the Return Value
   */
  protected boolean handleElement(Element raw) {

    if (super.handleElement(raw)) {
      return true;
    }

    XMLElement elem = (XMLElement) raw;

    if (DEST_PID_TAG.equals(elem.getName())) {
      try {
        URI pID = new URI(elem.getTextValue());

        setDestPeerID((PeerID) IDFactory.fromURI(pID));
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Bad PeerID in advertisement");
      } catch (ClassCastException badID) {
        throw new IllegalArgumentException("ID in advertisement is not a peer id");
      }
      return true;
    }

    if (elem.getName().equals("Dst")) {
      for (Enumeration eachXpt = elem.getChildren(); eachXpt.hasMoreElements(); ) {
        TextElement aXpt = (TextElement) eachXpt.nextElement();

        AccessPointAdvertisement xptAdv =
            (AccessPointAdvertisement) AdvertisementFactory.newAdvertisement(aXpt);

        setDest(xptAdv);
      }
      return true;
    }

    if (elem.getName().equals("Hops")) {
      Vector hops = new Vector();

      for (Enumeration eachXpt = elem.getChildren(); eachXpt.hasMoreElements(); ) {
        TextElement aXpt = (TextElement) eachXpt.nextElement();

        AccessPointAdvertisement xptAdv =
            (AccessPointAdvertisement) AdvertisementFactory.newAdvertisement(aXpt);

        hops.addElement(xptAdv);
      }
      setHops(hops);
      return true;
    }

    return false;
  }
コード例 #2
0
ファイル: DiscoveryQuery.java プロジェクト: haruo31/langrid
  /**
   * 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.");
    }
  }
コード例 #3
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!");
    }
  }
コード例 #4
0
  public void fromXML(XMLElement inXML) {
    String[] infoTags = getTags();
    Iterator<XMLElement> infoFields = inXML.getChildren();

    while (infoFields.hasNext()) {
      XMLElement fieldStep = infoFields.next();
      String curField = fieldStep.getTagName();

      for (int i = 0; i < infoTags.length; i++) {
        if (infoTags[i].equals(curField)) {

          handleTag(i, fieldStep);
          break;
        }
      }
    }
  }
コード例 #5
0
 /**
  * Writes the figures to the specified output stream.
  * This method applies the specified drawingTransform to the drawing, and draws
  * it on an image of the specified getChildCount.
  * 
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures,
         AffineTransform drawingTransform, Dimension imageSize) throws IOException {
     
     this.drawingTransform = (drawingTransform == null) ? new AffineTransform() : drawingTransform;
     this.bounds = (imageSize == null) ? 
         new Rectangle(0,0,Integer.MAX_VALUE,Integer.MAX_VALUE) :
         new Rectangle(0, 0, imageSize.width, imageSize.height);
     
     XMLElement document = new XMLElement("map");
     
     // Note: Image map elements need to be written from front to back
     for (Figure f: new ReversedList<Figure>(figures)) {
         writeElement(document, f);
     }
     
     // Strip AREA elements with "nohref" attributes from the end of the
     // map
     if (! isIncludeNohref) {
         for (int i=document.getChildrenCount() - 1; i >= 0; i--) {
             XMLElement child = (XMLElement) document.getChildAtIndex(i);
             if (child.hasAttribute("nohref")) {
                 document.removeChildAtIndex(i);
             }
         }
     }
     
     
     // Write XML content
     PrintWriter writer = new PrintWriter(
             new OutputStreamWriter(out, "UTF-8")
             );
     //new XMLWriter(writer).write(document);
     for (Object o : document.getChildren()) {
         XMLElement child = (XMLElement) o;
         new XMLWriter(writer).write(child);
     }
     
     // Flush writer
     writer.flush();
 }