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 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.Attr; 26 import org.w3c.dom.Document; 27 import org.w3c.dom.NodeList; 28 import org.w3c.dom.NamedNodeMap; 29 import org.w3c.dom.Element; 30 31 import javax.xml.parsers.DocumentBuilder; 32 33 /** 34 * The "getOwnerElement()" will return the Element node this attribute is 35 * attached to or null if this attribute is not in use. Get the "domestic" 36 * attribute from the first "address" node. Apply the "getOwnerElement()" method 37 * to get the Element associated with the attribute. The value returned should 38 * be "address". 39 * 40 * @author NIST 41 * @author Mary Brady 42 * @see <a 43 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-F68D095">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-F68D095</a> 44 */ 45 public final class OwnerElement extends DOMTestCase { 46 47 DOMDocumentBuilderFactory factory; 48 49 DocumentBuilder builder; 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 try { 54 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 55 .getConfiguration1()); 56 builder = factory.getBuilder(); 57 } catch (Exception e) { 58 fail("Unexpected exception" + e.getMessage()); 59 } 60 } 61 62 protected void tearDown() throws Exception { 63 factory = null; 64 builder = null; 65 super.tearDown(); 66 } 67 68 /** 69 * Runs the test case. 70 * 71 * @throws Throwable 72 * Any uncaught exception causes test to fail 73 */ 74 public void testGetOwnerElement1() throws Throwable { 75 Document doc; 76 NodeList addressList; 77 Node testNode; 78 NamedNodeMap attributes; 79 Attr domesticAttr; 80 Element elementNode; 81 String name; 82 doc = (Document) load("staff", builder); 83 addressList = doc.getElementsByTagName("address"); 84 testNode = addressList.item(0); 85 attributes = testNode.getAttributes(); 86 domesticAttr = (Attr) attributes.getNamedItem("domestic"); 87 elementNode = domesticAttr.getOwnerElement(); 88 name = elementNode.getNodeName(); 89 assertEquals("throw_Equals", "address", name); 90 } 91 public void testGetOwnerElement2() throws Throwable { 92 Document doc; 93 Attr newAttr; 94 Element elementNode; 95 doc = (Document) load("staff", builder); 96 newAttr = doc.createAttribute("newAttribute"); 97 elementNode = newAttr.getOwnerElement(); 98 assertNull("throw_Null", elementNode); 99 } 100 } 101