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 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 setNamedItemNS adds a node using its namespaceURI and localName and
35 *  raises a INUSE_ATTRIBUTE_ERR Raised if arg is an Attr that is already an
36 *  attribute of another Element object.
37 *
38 *  Retreieve the attributes of first element whose localName is address into a named node map.
39 *  Retreive the attribute whose namespaceURI=http://www.usa.com and localName=domestic
40 *  from the NamedNodeMap.  Retreieve the attributes of second element whose localName is address
41 *  into a named node map.  Call the setNamedItemNS method on the second nodemap with the domestic
42 *  attribute that was retreived and removed from the first nodeMap as an argument.
43 *  Assuming that when an attribute is removed from a nodemap, it still remains in the domtree
44 *  his should raise an INUSE_ATTRIBIUTE_ERR.
45* @author IBM
46* @author Neil Delima
47* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS</a>
48*/
49public final class namednodemapsetnameditemns07 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 namednodemapsetnameditemns07(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
57
58      org.w3c.domts.DocumentBuilderSetting[] settings =
59          new org.w3c.domts.DocumentBuilderSetting[] {
60org.w3c.domts.DocumentBuilderSetting.namespaceAware
61        };
62        DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
63        setFactory(testFactory);
64
65    //
66    //   check if loaded documents are supported for content type
67    //
68    String contentType = getContentType();
69    preload(contentType, "staffNS", true);
70    }
71
72   /**
73    * Runs the test case.
74    * @throws Throwable Any uncaught exception causes test to fail
75    */
76   public void runTest() throws Throwable {
77      Document doc;
78      NamedNodeMap attributes;
79      NodeList elementList;
80      Element element;
81      Attr attr;
82      Node newNode;
83      doc = (Document) load("staffNS", true);
84      elementList = doc.getElementsByTagNameNS("*", "address");
85      element = (Element) elementList.item(0);
86      attributes = element.getAttributes();
87      attr = (Attr) attributes.getNamedItemNS("http://www.usa.com", "domestic");
88      element = (Element) elementList.item(1);
89      attributes = element.getAttributes();
90
91      {
92         boolean success = false;
93         try {
94            newNode = attributes.setNamedItemNS(attr);
95          } catch (DOMException ex) {
96            success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR);
97         }
98         assertTrue("namednodemapsetnameditemns07", success);
99      }
100}
101   /**
102    *  Gets URI that identifies the test.
103    *  @return uri identifier of test
104    */
105   public String getTargetURI() {
106      return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/namednodemapsetnameditemns07";
107   }
108   /**
109    * Runs this test from the command line.
110    * @param args command line arguments
111    */
112   public static void main(final String[] args) {
113        DOMTestCase.doMain(namednodemapsetnameditemns07.class, args);
114   }
115}
116
117