src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/DOMResultBuilder.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xerces.internal.jaxp.validation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xerces.internal.dom.AttrImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xerces.internal.dom.DocumentTypeImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xerces.internal.dom.ElementImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xerces.internal.dom.EntityImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xerces.internal.dom.NotationImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xerces.internal.impl.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xerces.internal.xni.Augmentations;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xerces.internal.xni.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xerces.internal.xni.XMLLocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xerces.internal.xni.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xerces.internal.xni.XNIException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xerces.internal.xs.AttributePSVI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xerces.internal.xs.ElementPSVI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    49
import java.util.ArrayList;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    50
import java.util.List;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    51
import javax.xml.transform.dom.DOMResult;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import org.w3c.dom.CDATASection;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import org.w3c.dom.Comment;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import org.w3c.dom.DocumentType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
import org.w3c.dom.Element;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
import org.w3c.dom.Entity;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
import org.w3c.dom.NamedNodeMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
import org.w3c.dom.Notation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import org.w3c.dom.ProcessingInstruction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import org.w3c.dom.Text;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * <p>DOM result builder.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * @author Michael Glavassevich, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
final class DOMResultBuilder implements DOMDocumentHandler {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    /** Table for quick check of child insertion. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private final static int[] kidOK;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    static {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        kidOK = new int[13];
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        kidOK[Node.DOCUMENT_NODE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
            1 << Node.ELEMENT_NODE | 1 << Node.PROCESSING_INSTRUCTION_NODE |
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
            1 << Node.COMMENT_NODE | 1 << Node.DOCUMENT_TYPE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        kidOK[Node.DOCUMENT_FRAGMENT_NODE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        kidOK[Node.ENTITY_NODE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        kidOK[Node.ENTITY_REFERENCE_NODE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        kidOK[Node.ELEMENT_NODE] =
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
            1 << Node.ELEMENT_NODE | 1 << Node.PROCESSING_INSTRUCTION_NODE |
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            1 << Node.COMMENT_NODE | 1 << Node.TEXT_NODE |
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
            1 << Node.CDATA_SECTION_NODE | 1 << Node.ENTITY_REFERENCE_NODE ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        kidOK[Node.ATTRIBUTE_NODE] = 1 << Node.TEXT_NODE | 1 << Node.ENTITY_REFERENCE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        kidOK[Node.DOCUMENT_TYPE_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        kidOK[Node.PROCESSING_INSTRUCTION_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        kidOK[Node.COMMENT_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        kidOK[Node.TEXT_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        kidOK[Node.CDATA_SECTION_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        kidOK[Node.NOTATION_NODE] = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    } // static
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    private Document fDocument;
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    private CoreDocumentImpl fDocumentImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    private boolean fStorePSVI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    private Node fTarget;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    private Node fNextSibling;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    private Node fCurrentNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    private Node fFragmentRoot;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   110
    private final List<Node> fTargetChildren = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    private boolean fIgnoreChars;
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    private final QName fAttributeQName = new QName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    public DOMResultBuilder() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     * DOMDocumentHandler methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    public void setDOMResult(DOMResult result) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        fCurrentNode = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        fFragmentRoot = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        fIgnoreChars = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        fTargetChildren.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        if (result != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
            fTarget = result.getNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
            fNextSibling = result.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
            fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        fTarget = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        fNextSibling = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        fDocument = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        fDocumentImpl = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        fStorePSVI = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    public void doctypeDecl(DocumentType node) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
        /** Create new DocumentType node for the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        if (fDocumentImpl != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
            final String internalSubset = node.getInternalSubset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            /** Copy internal subset. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            if (internalSubset != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
            /** Copy entities. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
            NamedNodeMap oldMap = node.getEntities();
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            NamedNodeMap newMap = docType.getEntities();
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
            int length = oldMap.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
            for (int i = 0; i < length; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                Entity oldEntity = (Entity) oldMap.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                newEntity.setPublicId(oldEntity.getPublicId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                newEntity.setSystemId(oldEntity.getSystemId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                newEntity.setNotationName(oldEntity.getNotationName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                newMap.setNamedItem(newEntity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
            /** Copy notations. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
            oldMap = node.getNotations();
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
            newMap = docType.getNotations();
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
            length = oldMap.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
            for (int i = 0; i < length; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                Notation oldNotation = (Notation) oldMap.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                newNotation.setPublicId(oldNotation.getPublicId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                newNotation.setSystemId(oldNotation.getSystemId());
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                newMap.setNamedItem(newNotation);
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
            append(docType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    public void characters(Text node) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        /** Create new Text node for the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        append(fDocument.createTextNode(node.getNodeValue()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    public void cdata(CDATASection node) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        /** Create new CDATASection node for the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        append(fDocument.createCDATASection(node.getNodeValue()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    public void comment(Comment node) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        /** Create new Comment node for the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        append(fDocument.createComment(node.getNodeValue()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    public void processingInstruction(ProcessingInstruction node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        /** Create new ProcessingInstruction node for the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        append(fDocument.createProcessingInstruction(node.getTarget(), node.getData()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    public void setIgnoringCharacters(boolean ignore) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        fIgnoreChars = ignore;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     * XMLDocumentHandler methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    public void startDocument(XMLLocator locator, String encoding,
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            NamespaceContext namespaceContext, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    public void xmlDecl(String version, String encoding, String standalone,
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
            Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    public void doctypeDecl(String rootElement, String publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            String systemId, Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    public void comment(XMLString text, Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    public void processingInstruction(String target, XMLString data,
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
            Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    public void startElement(QName element, XMLAttributes attributes,
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            Augmentations augs) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        Element elem;
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        int attrCount = attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        if (fDocumentImpl == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            elem = fDocument.createElementNS(element.uri, element.rawname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
            for (int i = 0; i < attrCount; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                attributes.getName(i, fAttributeQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
        // If it's a Xerces DOM store type information for attributes, set idness, etc..
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            for (int i = 0; i < attrCount; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                attributes.getName(i, fAttributeQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                        fAttributeQName.rawname, fAttributeQName.localpart);
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                attr.setValue(attributes.getValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                // write type information to this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                if (attrPSVI != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                    if (fStorePSVI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                        ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                    Object type = attrPSVI.getMemberTypeDefinition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
                    if (type == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                        type = attrPSVI.getTypeDefinition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                        if (type != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                            attr.setType (type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                            if (((XSSimpleType) type).isIDType()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                                ((ElementImpl) elem).setIdAttributeNode (attr, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                        attr.setType (type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                        if (((XSSimpleType) type).isIDType()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                attr.setSpecified(attributes.isSpecified(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                elem.setAttributeNode(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        append(elem);
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        fCurrentNode = elem;
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        if (fFragmentRoot == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            fFragmentRoot = elem;
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    public void emptyElement(QName element, XMLAttributes attributes,
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            Augmentations augs) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        startElement(element, attributes, augs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        endElement(element, augs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    public void startGeneralEntity(String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            XMLResourceIdentifier identifier, String encoding,
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    public void textDecl(String version, String encoding, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    public void endGeneralEntity(String name, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    public void characters(XMLString text, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        if (!fIgnoreChars) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            append(fDocument.createTextNode(text.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    public void ignorableWhitespace(XMLString text, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
            throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        characters(text, augs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    public void endElement(QName element, Augmentations augs)
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
            throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
        // write type information to this element
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        if (augs != null && fDocumentImpl != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            if (elementPSVI != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                if (fStorePSVI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
                    ((PSVIElementNSImpl)fCurrentNode).setPSVI(elementPSVI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
                XSTypeDefinition type = elementPSVI.getMemberTypeDefinition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
                if (type == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
                    type = elementPSVI.getTypeDefinition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                ((ElementNSImpl)fCurrentNode).setType(type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
        // adjust current node reference
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
        if (fCurrentNode == fFragmentRoot) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
            fCurrentNode = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
            fFragmentRoot = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        fCurrentNode = fCurrentNode.getParentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    public void startCDATA(Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    public void endCDATA(Augmentations augs) throws XNIException {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    public void endDocument(Augmentations augs) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        if (fNextSibling == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   336
            for (Node node : fTargetChildren) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   337
                fTarget.appendChild(node);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        else {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   341
            for (Node node : fTargetChildren) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   342
                fTarget.insertBefore(node, fNextSibling);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    public void setDocumentSource(XMLDocumentSource source) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    public XMLDocumentSource getDocumentSource() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     * Other methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
    private void append(Node node) throws XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
        if (fCurrentNode != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
            fCurrentNode.appendChild(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
            /** Check if this node can be attached to the target. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
            if ((kidOK[fTarget.getNodeType()] & (1 << node.getNodeType())) == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                throw new XNIException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
            fTargetChildren.add(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
} // DOMResultBuilder