1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 
  23 /*
  24  * WARNING: because java doesn't support multi-inheritance some code is
  25  * duplicated. If you're changing this file you probably want to change
  26  * DeferredElementImpl.java at the same time.
  27  *
  28  */
  29 
  30 package com.sun.org.apache.xerces.internal.dom;
  31 
  32 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
  33 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
  34 import org.w3c.dom.NamedNodeMap;
  35 
  36 
  37 /**
  38  * DeferredElementNSImpl is to ElementNSImpl, what DeferredElementImpl is to
  39  * ElementImpl.
  40  *
  41  * @xerces.internal
  42  *
  43  * @see DeferredElementImpl
  44  */
  45 public class DeferredElementNSImpl
  46     extends ElementNSImpl
  47     implements DeferredNode {
  48 
  49     //
  50     // Constants
  51     //
  52 
  53     /** Serialization version. */
  54     static final long serialVersionUID = -5001885145370927385L;
  55 
  56     //
  57     // Data
  58     //
  59 
  60     /** Node index. */
  61     protected transient int fNodeIndex;
  62 
  63     //
  64     // Constructors
  65     //
  66 
  67     /**
  68      * This is the deferred constructor. Only the fNodeIndex is given here. All
  69      * other data, can be requested from the ownerDocument via the index.
  70      */
  71     DeferredElementNSImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
  72         super(ownerDoc, null);
  73 
  74         fNodeIndex = nodeIndex;
  75         needsSyncChildren(true);
  76 
  77     } // <init>(DocumentImpl,int)
  78 
  79     //
  80     // DeferredNode methods
  81     //
  82 
  83     /** Returns the node index. */
  84     public final int getNodeIndex() {
  85         return fNodeIndex;
  86     }
  87 
  88     //
  89     // Protected methods
  90     //
  91 
  92     /** Synchronizes the data (name and value) for fast nodes. */
  93     protected final void synchronizeData() {
  94 
  95         // no need to sync in the future
  96         needsSyncData(false);
  97 
  98         // fluff data
  99         DeferredDocumentImpl ownerDocument =
 100             (DeferredDocumentImpl) this.ownerDocument;
 101 
 102         // we don't want to generate any event for this so turn them off
 103         boolean orig = ownerDocument.mutationEvents;
 104         ownerDocument.mutationEvents = false;
 105 
 106         name = ownerDocument.getNodeName(fNodeIndex);
 107 
 108         // extract local part from QName
 109         int index = name.indexOf(':');
 110         if (index < 0) {
 111             localName = name;
 112         }
 113         else {
 114             localName = name.substring(index + 1);
 115         }
 116 
 117             namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
 118         type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);
 119 
 120         // attributes
 121         setupDefaultAttributes();
 122         int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
 123         if (attrIndex != -1) {
 124             NamedNodeMap attrs = getAttributes();
 125             boolean seenSchemaDefault = false;
 126             do {
 127                 AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
 128                 // Take special care of schema defaulted attributes. Calling the
 129                 // non-namespace aware setAttributeNode() method could overwrite
 130                 // another attribute with the same local name.
 131                 if (!attr.getSpecified() && (seenSchemaDefault ||
 132                     (attr.getNamespaceURI() != null &&
 133                     attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
 134                     attr.getName().indexOf(':') < 0))) {
 135                     seenSchemaDefault = true;
 136                     attrs.setNamedItemNS(attr);
 137                 }
 138                 else {
 139                     attrs.setNamedItem(attr);
 140                 }
 141                 attrIndex = ownerDocument.getPrevSibling(attrIndex);
 142             } while (attrIndex != -1);
 143         }
 144 
 145         // set mutation events flag back to its original value
 146         ownerDocument.mutationEvents = orig;
 147 
 148     } // synchronizeData()
 149 
 150     /**
 151      * Synchronizes the node's children with the internal structure.
 152      * Fluffing the children at once solves a lot of work to keep
 153      * the two structures in sync. The problem gets worse when
 154      * editing the tree -- this makes it a lot easier.
 155      */
 156     protected final void synchronizeChildren() {
 157         DeferredDocumentImpl ownerDocument =
 158             (DeferredDocumentImpl) ownerDocument();
 159         ownerDocument.synchronizeChildren(this, fNodeIndex);
 160     } // synchronizeChildren()
 161 
 162 } // class DeferredElementImpl