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