/**
   * Get the named properties for this resource and (potentially) its children.
   *
   * @param names an arrary of property names to retrieve
   * @return a MultiStatus of PropertyResponses
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getProperties(PropertyName[] names) throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    MultiStatus newMultiStatus = new MultiStatus();

    Enumeration responses = multiStatus.getResponses();

    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      PropertyResponse newResponse = new PropertyResponse(response.getResource());
      newResponse.setDescription(response.getDescription());
      newMultiStatus.addResponse(newResponse);

      Hashtable properties = (Hashtable) response.getPropertiesByPropName();

      // Hashtable newProperties = (Hashtable) newResponse.getProperties();
      for (int i = 0; i < names.length; i++) {
        if (properties.containsKey(names[i])) {
          PropertyValue srcval = response.getProperty(names[i]);
          newResponse.setProperty(names[i], srcval);

          // newProperties.put(names[i], properties.get(names[i]));
        } else {
          Document factory = null;

          try {
            factory = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
          } catch (Exception e) {
            throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
          }

          // we'll create an xml element with no value because that's
          //    what webdav will need to return for most methods... even if the
          //    property doesn't exist.   That's because the
          //    distinction between a propertyname and propertyvalue
          //    is fuzzy in WebDAV xml. A property name is
          //    essentially an empty property value because
          //    all property values have their property
          //    name stuck on.
          // if we decide to set reviewStatus to null instead (as
          //    we did previously, then the code for MultiStatus.asXML()
          //    needs to be updated to expect null values.
          // (jlc 990520)
          Element elTm = factory.createElementNS("X", "X:" + names[i].getLocal());

          elTm.setAttribute("xmlns:X", names[i].getNamespace());

          newResponse.addProperty(names[i], elTm, WebDAVStatus.SC_NOT_FOUND);
        }
      }
    }

    return newMultiStatus;
  }
Exemplo n.º 2
0
  /**
   * XML Circuit constructor
   *
   * @param file the file that contains the XML description of the circuit
   * @param g the graphics that will paint the node
   * @throws CircuitLoadingException if the internal circuit can not be loaded
   */
  public CircuitUI(File file, Graphics g) throws CircuitLoadingException {
    this("");

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    Document doc;
    Element root;

    Hashtable<Integer, Link> linkstable = new Hashtable<Integer, Link>();

    try {
      builder = factory.newDocumentBuilder();
      doc = builder.parse(file);
    } catch (SAXException sxe) {
      throw new CircuitLoadingException("SAX exception raised, invalid XML file.");
    } catch (ParserConfigurationException pce) {
      throw new CircuitLoadingException(
          "Parser exception raised, parser configuration is invalid.");
    } catch (IOException ioe) {
      throw new CircuitLoadingException("I/O exception, file cannot be loaded.");
    }

    root = (Element) doc.getElementsByTagName("Circuit").item(0);
    this.setName(root.getAttribute("name"));

    NodeList nl = root.getElementsByTagName("Node");
    Element e;
    Node n;
    Class cl;

    for (int i = 0; i < nl.getLength(); ++i) {
      e = (Element) nl.item(i);

      try {
        cl = Class.forName(e.getAttribute("class"));
      } catch (Exception exc) {
        System.err.println(exc.getMessage());
        throw new RuntimeException("Circuit creation from xml.");
      }

      try {
        n = ((Node) cl.newInstance());
      } catch (Exception exc) {
        System.err.println(exc.getMessage());
        throw new RuntimeException("Circuit creation from xml.");
      }

      this.nodes.add(n);
      n.setLocation(new Integer(e.getAttribute("x")), new Integer(e.getAttribute("y")));

      if (n instanceof giraffe.ui.Nameable) ((Nameable) n).setNodeName(e.getAttribute("node_name"));

      if (n instanceof giraffe.ui.CompositeNode) {
        try {
          ((CompositeNode) n)
              .load(new File(file.getParent() + "/" + e.getAttribute("file_name")), g);
        } catch (Exception exc) {
          /* try to load from the lib */
          ((CompositeNode) n)
              .load(new File(giraffe.Giraffe.PATH + "/lib/" + e.getAttribute("file_name")), g);
        }
      }

      NodeList nlist = e.getElementsByTagName("Anchor");
      Element el;

      for (int j = 0; j < nlist.getLength(); ++j) {
        el = (Element) nlist.item(j);

        Anchor a = n.getAnchor(new Integer(el.getAttribute("id")));
        NodeList linklist = el.getElementsByTagName("Link");
        Element link;
        Link l;

        for (int k = 0; k < linklist.getLength(); ++k) {
          link = (Element) linklist.item(k);
          int id = new Integer(link.getAttribute("id"));
          int index = new Integer(link.getAttribute("index"));

          if (id >= this.linkID) linkID = id + 1;

          if (linkstable.containsKey(id)) {
            l = linkstable.get(id);
            l.addLinkedAnchorAt(a, index);
            a.addLink(l);
          } else {
            l = new Link(id);
            l.addLinkedAnchorAt(a, index);
            this.links.add(l);
            linkstable.put(id, l);
            a.addLink(l);
          }
        }
      }
    }
  }