jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/MultiDOM.java
changeset 36486 b84e564d2358
parent 33349 975138b77cff
equal deleted inserted replaced
36280:c870cb782aca 36486:b84e564d2358
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     3  */
     3  */
     4 
       
     5 /*
     4 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     6  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     7  * this work for additional information regarding copyright ownership.
     9  * The ASF licenses this file to You under the Apache License, Version 2.0
     8  * The ASF licenses this file to You under the Apache License, Version 2.0
    28 import com.sun.org.apache.xml.internal.dtm.Axis;
    27 import com.sun.org.apache.xml.internal.dtm.Axis;
    29 import com.sun.org.apache.xml.internal.dtm.DTM;
    28 import com.sun.org.apache.xml.internal.dtm.DTM;
    30 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
    29 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
    31 import com.sun.org.apache.xml.internal.dtm.DTMManager;
    30 import com.sun.org.apache.xml.internal.dtm.DTMManager;
    32 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
    31 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
       
    32 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIterNodeList;
    33 import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
    33 import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
    34 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIterNodeList;
       
    35 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
    34 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
    36 import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
    35 import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
    37 import java.util.HashMap;
    36 import java.util.HashMap;
    38 import java.util.Map;
    37 import java.util.Map;
    39 import org.w3c.dom.Node;
    38 import org.w3c.dom.Node;
   669 
   668 
   670     // %HZ% Does this method make any sense here???
   669     // %HZ% Does this method make any sense here???
   671     public Map<String, Integer> getElementsWithIDs() {
   670     public Map<String, Integer> getElementsWithIDs() {
   672         return _main.getElementsWithIDs();
   671         return _main.getElementsWithIDs();
   673     }
   672     }
       
   673 
       
   674     public void release() {
       
   675         _main.release();
       
   676     }
       
   677 
       
   678     private boolean isMatchingAdapterEntry(DOM entry, DOMAdapter adapter) {
       
   679         DOM dom = adapter.getDOMImpl();
       
   680 
       
   681         return (entry == adapter) || (
       
   682             /*
       
   683              * Method addDOMAdapter overwrites for AdaptiveResultTreeImpl
       
   684              * objects the usual entry with an adapter to the nested
       
   685              * DOM, so we must check this here. See last 'if' statement
       
   686              * of addDOMAdapter.
       
   687              */
       
   688             (dom instanceof AdaptiveResultTreeImpl) &&
       
   689             (entry instanceof DOMAdapter) &&
       
   690             (((AdaptiveResultTreeImpl)dom).getNestedDOM() == ((DOMAdapter)entry).getDOMImpl())
       
   691         );
       
   692     }
       
   693 
       
   694     public void removeDOMAdapter(DOMAdapter adapter) {
       
   695         _documents.remove(adapter.getDocumentURI(0));
       
   696         DOM dom = adapter.getDOMImpl();
       
   697 
       
   698         if (dom instanceof DTMDefaultBase) {
       
   699             SuballocatedIntVector ids = ((DTMDefaultBase) dom).getDTMIDs();
       
   700             int idsSize = ids.size();
       
   701             for (int i = 0; i < idsSize; i++) {
       
   702                 _adapters[ids.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
       
   703             }
       
   704         } else {
       
   705             int id = dom.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
       
   706             if ((id > 0) && (id < _adapters.length) && isMatchingAdapterEntry(_adapters[id], adapter)) {
       
   707                 _adapters[id] = null;
       
   708             } else {
       
   709                 boolean found = false;
       
   710                 for (int i = 0; i < _adapters.length; i++) {
       
   711                     if (isMatchingAdapterEntry(_adapters[id], adapter)) {
       
   712                         _adapters[i] = null;
       
   713                         found = true;
       
   714                         break;
       
   715                     }
       
   716                 }
       
   717             }
       
   718         }
       
   719     }
   674 }
   720 }