Home | History | Annotate | Download | only in dom
      1 /*
      2  This Java source file was generated by test-to-java.xsl
      3  and is a derived work from the source document.
      4  The source document contained the following notice:
      5 
      6 
      7 
      8  Copyright (c) 2001-2003 World Wide Web Consortium,
      9  (Massachusetts Institute of Technology, Institut National de
     10  Recherche en Informatique et en Automatique, Keio University).  All
     11  Rights Reserved.  This program is distributed under the W3C's Software
     12  Intellectual Property License.  This program is distributed in the
     13  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     15  PURPOSE.
     16 
     17  See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     18 
     19 
     20  */
     21 
     22 package tests.org.w3c.dom;
     23 
     24 import org.w3c.dom.Node;
     25 import org.w3c.dom.Document;
     26 import org.w3c.dom.DocumentType;
     27 import org.w3c.dom.DOMImplementation;
     28 import org.w3c.dom.Element;
     29 
     30 import javax.xml.parsers.DocumentBuilder;
     31 
     32 /**
     33  * The method getOwnerDocument returns the Document object associated with this
     34  * node
     35  *
     36  * Create a new DocumentType node. Since this node is not used with any Document
     37  * yet verify if the ownerDocument is null.
     38  *
     39  * @author IBM
     40  * @author Neil Delima
     41  * @see <a
     42  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#node-ownerDoc">http://www.w3.org/TR/DOM-Level-2-Core/core#node-ownerDoc</a>
     43  * @see <a
     44  *      href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a>
     45  */
     46 public final class NodeGetOwnerDocument extends DOMTestCase {
     47 
     48     DOMDocumentBuilderFactory factory;
     49 
     50     DocumentBuilder builder;
     51 
     52     protected void setUp() throws Exception {
     53         super.setUp();
     54         try {
     55             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     56                     .getConfiguration1());
     57             builder = factory.getBuilder();
     58         } catch (Exception e) {
     59             fail("Unexpected exception" + e.getMessage());
     60         }
     61     }
     62 
     63     protected void tearDown() throws Exception {
     64         factory = null;
     65         builder = null;
     66         super.tearDown();
     67     }
     68 
     69     /**
     70      * Runs the test case.
     71      *
     72      * @throws Throwable
     73      *             Any uncaught exception causes test to fail
     74      */
     75     public void testGetOwnerDocument1() throws Throwable {
     76         Document doc;
     77         Document ownerDoc;
     78         DOMImplementation domImpl;
     79         DocumentType docType;
     80         String nullID = null;
     81 
     82         doc = (Document) load("staff", builder);
     83         domImpl = doc.getImplementation();
     84         docType = domImpl.createDocumentType("mydoc", nullID, nullID);
     85         ownerDoc = docType.getOwnerDocument();
     86         assertNull("nodegetownerdocument01", ownerDoc);
     87     }
     88     public void testGetOwnerDocument2() throws Throwable {
     89         Document doc;
     90         Document newDoc;
     91         Element newElem;
     92         Document ownerDocDoc;
     93         Document ownerDocElem;
     94         DOMImplementation domImpl;
     95         DocumentType docType;
     96         String nullNS = null;
     97 
     98         doc = (Document) load("staff", builder);
     99         domImpl = doc.getImplementation();
    100         docType = domImpl.createDocumentType("mydoc", nullNS, nullNS);
    101         newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "mydoc",
    102                 docType);
    103         ownerDocDoc = newDoc.getOwnerDocument();
    104         assertNull("nodegetownerdocument02_1", ownerDocDoc);
    105         newElem = newDoc
    106                 .createElementNS("http://www.w3.org/DOM/Test", "myelem");
    107         ownerDocElem = newElem.getOwnerDocument();
    108         assertNotNull("nodegetownerdocument02_2", ownerDocElem);
    109     }
    110 }
    111