1 2 /* 3 This Java source file was generated by test-to-java.xsl 4 and is a derived work from the source document. 5 The source document contained the following notice: 6 7 8 9 Copyright (c) 2001-2004 World Wide Web Consortium, 10 (Massachusetts Institute of Technology, Institut National de 11 Recherche en Informatique et en Automatique, Keio University). All 12 Rights Reserved. This program is distributed under the W3C's Software 13 Intellectual Property License. This program is distributed in the 14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 PURPOSE. 17 18 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21 */ 22 23 package org.w3c.domts.level2.core; 24 25 import org.w3c.dom.*; 26 27 28 import org.w3c.domts.DOMTestCase; 29 import org.w3c.domts.DOMTestDocumentBuilderFactory; 30 31 32 33 /** 34 * The "setAttributeNode(newAttr)" method raises an 35 * "INUSE_ATTRIBUTE_ERR DOMException if the "newAttr" 36 * is already an attribute of another element. 37 * 38 * Retrieve the first emp:address and append 39 * a newly created element. The "createAttributeNS(namespaceURI,qualifiedName)" 40 * and "setAttributeNodeNS(newAttr)" methods are invoked 41 * to create and add a new attribute to the newly created 42 * Element. The "setAttributeNodeNS(newAttr)" method is 43 * once again called to add the new attribute causing an 44 * exception to be raised since the attribute is already 45 * an attribute of another element. 46 * @author NIST 47 * @author Mary Brady 48 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])</a> 49 * @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> 50 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAtNodeNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAtNodeNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])</a> 51 */ 52 public final class setAttributeNodeNS01 extends DOMTestCase { 53 54 /** 55 * Constructor. 56 * @param factory document factory, may not be null 57 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 58 */ 59 public setAttributeNodeNS01(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 60 super(factory); 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 String namespaceURI = "http://www.newattr.com"; 75 String qualifiedName = "emp:newAttr"; 76 Document doc; 77 Element newElement; 78 Attr newAttr; 79 NodeList elementList; 80 Node testAddr; 81 Node appendedChild; 82 Attr setAttr1; 83 Attr setAttr2; 84 doc = (Document) load("staffNS", true); 85 elementList = doc.getElementsByTagName("emp:address"); 86 testAddr = elementList.item(0); 87 assertNotNull("empAddrNotNull", testAddr); 88 newElement = doc.createElement("newElement"); 89 appendedChild = testAddr.appendChild(newElement); 90 newAttr = doc.createAttributeNS(namespaceURI, qualifiedName); 91 setAttr1 = newElement.setAttributeNodeNS(newAttr); 92 93 { 94 boolean success = false; 95 try { 96 setAttr2 = ((Element) /*Node */testAddr).setAttributeNodeNS(newAttr); 97 } catch (DOMException ex) { 98 success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR); 99 } 100 assertTrue("throw_INUSE_ATTRIBUTE_ERR", success); 101 } 102 } 103 /** 104 * Gets URI that identifies the test. 105 * @return uri identifier of test 106 */ 107 public String getTargetURI() { 108 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNodeNS01"; 109 } 110 /** 111 * Runs this test from the command line. 112 * @param args command line arguments 113 */ 114 public static void main(final String[] args) { 115 DOMTestCase.doMain(setAttributeNodeNS01.class, args); 116 } 117 } 118 119