1 2/* 3This Java source file was generated by test-to-java.xsl 4and is a derived work from the source document. 5The source document contained the following notice: 6 7 8 9Copyright (c) 2001-2003 World Wide Web Consortium, 10(Massachusetts Institute of Technology, Institut National de 11Recherche en Informatique et en Automatique, Keio University). All 12Rights Reserved. This program is distributed under the W3C's Software 13Intellectual Property License. This program is distributed in the 14hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16PURPOSE. 17 18See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21*/ 22 23package org.w3c.domts.level2.core; 24 25import org.w3c.dom.*; 26 27 28import org.w3c.domts.DOMTestCase; 29import org.w3c.domts.DOMTestDocumentBuilderFactory; 30 31 32 33/** 34 * The method setAttributeNodeNS adds a new attribute and raises the 35 * INUSE_ATTRIBUTE_ERR exception if the newAttr is already an attribute of 36 * another Element object. 37 * 38 * Retreive an attribute node of an existing element node. Attempt to add it to an another 39 * element node. Check if the INUSE_ATTRIBUTE_ERR exception is thrown. 40 * 41* @author IBM 42* @author Neil Delima 43* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS</a> 44*/ 45public final class elementsetattributenodens03 extends DOMTestCase { 46 47 /** 48 * Constructor. 49 * @param factory document factory, may not be null 50 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 51 */ 52 public elementsetattributenodens03(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 53 54 org.w3c.domts.DocumentBuilderSetting[] settings = 55 new org.w3c.domts.DocumentBuilderSetting[] { 56org.w3c.domts.DocumentBuilderSetting.namespaceAware, 57org.w3c.domts.DocumentBuilderSetting.namespaceAware 58 }; 59 DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings); 60 setFactory(testFactory); 61 62 // 63 // check if loaded documents are supported for content type 64 // 65 String contentType = getContentType(); 66 preload(contentType, "staffNS", true); 67 } 68 69 /** 70 * Runs the test case. 71 * @throws Throwable Any uncaught exception causes test to fail 72 */ 73 public void runTest() throws Throwable { 74 Document doc; 75 Element element1; 76 Element element2; 77 Attr attribute; 78 Attr newAttribute; 79 NodeList elementList; 80 String nullNS = null; 81 82 doc = (Document) load("staffNS", true); 83 elementList = doc.getElementsByTagNameNS("http://www.nist.gov", "address"); 84 element1 = (Element) elementList.item(1); 85 attribute = element1.getAttributeNodeNS(nullNS, "street"); 86 element2 = (Element) elementList.item(2); 87 88 { 89 boolean success = false; 90 try { 91 newAttribute = element2.setAttributeNodeNS(attribute); 92 } catch (DOMException ex) { 93 success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR); 94 } 95 assertTrue("elementsetattributenodens03", success); 96 } 97} 98 /** 99 * Gets URI that identifies the test. 100 * @return uri identifier of test 101 */ 102 public String getTargetURI() { 103 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/elementsetattributenodens03"; 104 } 105 /** 106 * Runs this test from the command line. 107 * @param args command line arguments 108 */ 109 public static void main(final String[] args) { 110 DOMTestCase.doMain(elementsetattributenodens03.class, args); 111 } 112} 113 114