Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4915693

UserDataHandler is not called during import of element node

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b51
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: eaR10174 Date: 09/02/2003


        The UserDataHandler handler is not called during import of an element node (see
      test.java below). According to the method javadoc
        
          public Node importNode(Node importedNode,
                             boolean deep)
                      throws DOMException

                     
             ...
             However, if any UserDataHandlers has been specified along with the associated data
             these handlers will be called with the appropriate parameters before this method
             returns.


      the handler should be called.

        The bug appears in jdk1.5.0beta-b17 and affects a new JCK1.5 test:
        
          api/org_w3c/dom/Document/index.html#ImportNode[ImportNode018]

      ------------------------------------test.java-----------------------------
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.w3c.dom.UserDataHandler;

      public class test {
            
          DocumentBuilder docBuilder = null;

          public static void main(String argv[]) {
              new test().run();
          }
          
          public void run() {
              try {
                  DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                  docBuilder = docBF.newDocumentBuilder();
                  
                  Document doc1 = docBuilder.newDocument();
                  Document doc2 = docBuilder.newDocument();
                  
                  Element importedElem = doc1.createElement("root");
                  
                  final StringBuffer strBuffer = new StringBuffer();
                  UserDataHandler handler = new UserDataHandler() {
                          public void handle(short operation, String key, Object data,
                                  Node src, Node dst) {
                              strBuffer.append("Method handle invoked.");
                              System.out.println("Operation: " + operation);
                              System.out.println("Key : " + key);
                              System.out.println("Data : " + data);
                              System.out.println("Src node : " + src);
                              System.out.println("Dst node : " + dst);
                          }
                  };

                  importedElem.setUserData("Key1", "Data1", handler);
          
                  Element elem = (Element)doc2.importNode(importedElem, true);
                  
                  System.out.println(strBuffer.toString());
              } catch (Exception e) {
                  e.printStackTrace();
                  return;
              }

          }
      }
      --------------------------------------------------------------------------
      % java -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b17)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b17, mixed mode)

      --------------------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            vkorcl Venugopal K (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: