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 8Copyright (c) 2001-2003 World Wide Web Consortium, 9(Massachusetts Institute of Technology, Institut National de 10Recherche en Informatique et en Automatique, Keio University). All 11Rights Reserved. This program is distributed under the W3C's Software 12Intellectual Property License. This program is distributed in the 13hope that it will be useful, but WITHOUT ANY WARRANTY; without even 14the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15PURPOSE. 16See W3C License http://www.w3.org/Consortium/Legal/ for more details. 17 18*/ 19 20package org.w3c.domts.level1.core; 21 22import org.w3c.dom.*; 23 24 25import org.w3c.domts.DOMTestCase; 26import org.w3c.domts.DOMTestDocumentBuilderFactory; 27 28 29 30/** 31 * The "setNamedItem(arg)" method raises a 32 * WRONG_DOCUMENT_ERR DOMException if "arg" was created 33 * from a different document than the one that created 34 * the NamedNodeMap. 35 * 36 * Create a NamedNodeMap object from the attributes of the 37 * last child of the third employee and attempt to add 38 * another Attr node to it that was created from a 39 * different DOM document. This should raise the desired 40 * exception. This method uses the "createAttribute(name)" 41 * method from the Document interface. 42* @author NIST 43* @author Mary Brady 44* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])</a> 45* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788</a> 46* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-1025163788')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-1025163788')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])</a> 47* @see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=249">http://www.w3.org/Bugs/Public/show_bug.cgi?id=249</a> 48*/ 49public final class namednodemapwrongdocumenterr extends DOMTestCase { 50 51 /** 52 * Constructor. 53 * @param factory document factory, may not be null 54 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 55 */ 56 public namednodemapwrongdocumenterr(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 57 super(factory); 58 59 // 60 // check if loaded documents are supported for content type 61 // 62 String contentType = getContentType(); 63 preload(contentType, "staff", true); 64 preload(contentType, "staff", true); 65 } 66 67 /** 68 * Runs the test case. 69 * @throws Throwable Any uncaught exception causes test to fail 70 */ 71 public void runTest() throws Throwable { 72 Document doc1; 73 Document doc2; 74 NodeList elementList; 75 Node testAddress; 76 NamedNodeMap attributes; 77 Node newAttribute; 78 Node setNode; 79 doc1 = (Document) load("staff", true); 80 doc2 = (Document) load("staff", true); 81 elementList = doc1.getElementsByTagName("address"); 82 testAddress = elementList.item(2); 83 newAttribute = doc2.createAttribute("newAttribute"); 84 attributes = testAddress.getAttributes(); 85 86 { 87 boolean success = false; 88 try { 89 setNode = attributes.setNamedItem(newAttribute); 90 } catch (DOMException ex) { 91 success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); 92 } 93 assertTrue("throw_WRONG_DOCUMENT_ERR", success); 94 } 95} 96 /** 97 * Gets URI that identifies the test. 98 * @return uri identifier of test 99 */ 100 public String getTargetURI() { 101 return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapwrongdocumenterr"; 102 } 103 /** 104 * Runs this test from the command line. 105 * @param args command line arguments 106 */ 107 public static void main(final String[] args) { 108 DOMTestCase.doMain(namednodemapwrongdocumenterr.class, args); 109 } 110} 111 112