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  * WARNING: because java doesn't support multi-inheritance some code is
  23  * duplicated. If you're changing this file you probably want to change
  24  * DeferredAttrImpl.java at the same time.
  25  */
  26 
  27 
  28 package com.sun.org.apache.xerces.internal.dom;
  29 
  30 /**
  31  * DeferredAttrNSImpl is to AttrNSImpl, what DeferredAttrImpl is to
  32  * AttrImpl.
  33  *
  34  * @xerces.internal
  35  *
  36  * @author Andy Clark, IBM
  37  * @author Arnaud  Le Hors, IBM
  38  * @see DeferredAttrImpl
  39  */
  40 public final class DeferredAttrNSImpl
  41     extends AttrNSImpl
  42     implements DeferredNode {
  43 
  44     //
  45     // Constants
  46     //
  47 
  48     /** Serialization version. */
  49     static final long serialVersionUID = 6074924934945957154L;
  50 
  51     //
  52     // Data
  53     //
  54 
  55     /** Node index. */
  56     protected transient int fNodeIndex;
  57 
  58     //
  59     // Constructors
  60     //
  61 
  62     /**
  63      * This is the deferred constructor. Only the fNodeIndex is given here.
  64      * All other data, can be requested from the ownerDocument via the index.
  65      */
  66     DeferredAttrNSImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
  67         super(ownerDocument, null);
  68 
  69         fNodeIndex = nodeIndex;
  70         needsSyncData(true);
  71         needsSyncChildren(true);
  72 
  73     } // <init>(DeferredDocumentImpl,int)
  74 
  75     //
  76     // DeferredNode methods
  77     //
  78 
  79     /** Returns the node index. */
  80     public int getNodeIndex() {
  81         return fNodeIndex;
  82     }
  83 
  84     //
  85     // Protected methods
  86     //
  87 
  88     /** Synchronizes the data (name and value) for fast nodes. */
  89     protected void synchronizeData() {
  90 
  91         // no need to sync in the future
  92         needsSyncData(false);
  93 
  94         // fluff data
  95         DeferredDocumentImpl ownerDocument =
  96             (DeferredDocumentImpl) ownerDocument();
  97         name = ownerDocument.getNodeName(fNodeIndex);
  98 
  99         // extract prefix and local part from QName
 100         int index = name.indexOf(':');
 101         if (index < 0) {
 102             localName = name;
 103         }
 104         else {
 105             localName = name.substring(index + 1);
 106         }
 107 
 108         int extra = ownerDocument.getNodeExtra(fNodeIndex);
 109         isSpecified((extra & SPECIFIED) != 0);
 110         isIdAttribute((extra & ID) != 0);
 111 
 112         namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
 113 
 114         int extraNode = ownerDocument.getLastChild(fNodeIndex);
 115         type = ownerDocument.getTypeInfo(extraNode);
 116     } // synchronizeData()
 117 
 118     /**
 119      * Synchronizes the node's children with the internal structure.
 120      * Fluffing the children at once solves a lot of work to keep
 121      * the two structures in sync. The problem gets worse when
 122      * editing the tree -- this makes it a lot easier.
 123      */
 124     protected void synchronizeChildren() {
 125         DeferredDocumentImpl ownerDocument =
 126             (DeferredDocumentImpl) ownerDocument();
 127         ownerDocument.synchronizeChildren(this, fNodeIndex);
 128     } // synchronizeChildren()
 129 
 130 } // class DeferredAttrImpl