Home | History | Annotate | Download | only in core
      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 "setPrefix(prefix)" method causes the
     35  *   DOMException NO_MODIFICATION_ALLOWED_ERR to be raised
     36  *   if the node is readonly.
     37  *
     38  *   Obtain the children of the THIRD "gender" element.  The elements
     39  *   content is an entity reference.  Get the FIRST item
     40  *   from the entity reference and execute the "setPrefix(prefix)" method.
     41  *   This causes a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
     42 * @author NIST
     43 * @author Mary Brady
     44 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])</a>
     45 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSPrefix">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSPrefix</a>
     46 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-NodeNSPrefix')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-NodeNSPrefix')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
     47 */
     48 public final class prefix08 extends DOMTestCase {
     49 
     50    /**
     51     * Constructor.
     52     * @param factory document factory, may not be null
     53     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     54     */
     55    public prefix08(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     56 
     57       org.w3c.domts.DocumentBuilderSetting[] settings =
     58           new org.w3c.domts.DocumentBuilderSetting[] {
     59 org.w3c.domts.DocumentBuilderSetting.namespaceAware
     60         };
     61         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     62         setFactory(testFactory);
     63 
     64     //
     65     //   check if loaded documents are supported for content type
     66     //
     67     String contentType = getContentType();
     68     preload(contentType, "staff", true);
     69     }
     70 
     71    /**
     72     * Runs the test case.
     73     * @throws Throwable Any uncaught exception causes test to fail
     74     */
     75    public void runTest() throws Throwable {
     76       Document doc;
     77       NodeList genderList;
     78       Node genderNode;
     79       Node entRef;
     80       Node entElement;
     81       Node createdNode;
     82       int nodeType;
     83       doc = (Document) load("staff", true);
     84       genderList = doc.getElementsByTagName("gender");
     85       genderNode = genderList.item(2);
     86       entRef = genderNode.getFirstChild();
     87       nodeType = (int) entRef.getNodeType();
     88 
     89       if (equals(1, nodeType)) {
     90           entRef = doc.createEntityReference("ent4");
     91       assertNotNull("createdEntRefNotNull", entRef);
     92       }
     93     entElement = entRef.getFirstChild();
     94       assertNotNull("entElement", entElement);
     95       createdNode = doc.createElement("text3");
     96 
     97       {
     98          boolean success = false;
     99          try {
    100             entElement.setPrefix("newPrefix");
    101           } catch (DOMException ex) {
    102             success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
    103          }
    104          assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
    105       }
    106 }
    107    /**
    108     *  Gets URI that identifies the test.
    109     *  @return uri identifier of test
    110     */
    111    public String getTargetURI() {
    112       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix08";
    113    }
    114    /**
    115     * Runs this test from the command line.
    116     * @param args command line arguments
    117     */
    118    public static void main(final String[] args) {
    119         DOMTestCase.doMain(prefix08.class, args);
    120    }
    121 }
    122 
    123