1 /* |
1 /* |
2 * reserved comment block |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT REMOVE OR ALTER! |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
20 */ |
20 */ |
21 |
21 |
22 package com.sun.org.apache.xml.internal.dtm.ref; |
22 package com.sun.org.apache.xml.internal.dtm.ref; |
23 |
23 |
24 import com.sun.org.apache.xml.internal.dtm.*; |
24 import com.sun.org.apache.xml.internal.dtm.*; |
|
25 import com.sun.org.apache.xml.internal.res.XMLErrorResources; |
|
26 import com.sun.org.apache.xml.internal.res.XMLMessages; |
|
27 import com.sun.org.apache.xml.internal.utils.BoolStack; |
25 import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector; |
28 import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector; |
26 import com.sun.org.apache.xml.internal.utils.BoolStack; |
|
27 |
|
28 import java.util.Vector; |
|
29 |
|
30 import javax.xml.transform.Source; |
|
31 |
|
32 import com.sun.org.apache.xml.internal.utils.XMLString; |
29 import com.sun.org.apache.xml.internal.utils.XMLString; |
33 import com.sun.org.apache.xml.internal.utils.XMLStringFactory; |
30 import com.sun.org.apache.xml.internal.utils.XMLStringFactory; |
34 |
|
35 import com.sun.org.apache.xml.internal.res.XMLMessages; |
|
36 import com.sun.org.apache.xml.internal.res.XMLErrorResources; |
|
37 |
|
38 import java.io.*; // for dumpDTM |
31 import java.io.*; // for dumpDTM |
|
32 import java.util.Vector; |
|
33 import javax.xml.transform.Source; |
39 |
34 |
40 /** |
35 /** |
41 * The <code>DTMDefaultBase</code> class serves as a helper base for DTMs. |
36 * The <code>DTMDefaultBase</code> class serves as a helper base for DTMs. |
42 * It sets up structures for navigation and type, while leaving data |
37 * It sets up structures for navigation and type, while leaving data |
43 * management and construction to the derived classes. |
38 * management and construction to the derived classes. |
72 |
67 |
73 /** Previous sibling values, one array element for each node. */ |
68 /** Previous sibling values, one array element for each node. */ |
74 protected SuballocatedIntVector m_parent; |
69 protected SuballocatedIntVector m_parent; |
75 |
70 |
76 /** Vector of SuballocatedIntVectors of NS decl sets */ |
71 /** Vector of SuballocatedIntVectors of NS decl sets */ |
77 protected Vector m_namespaceDeclSets = null; |
72 protected Vector<SuballocatedIntVector> m_namespaceDeclSets = null; |
78 |
73 |
79 /** SuballocatedIntVector of elements at which corresponding |
74 /** SuballocatedIntVector of elements at which corresponding |
80 * namespaceDeclSets were defined */ |
75 * namespaceDeclSets were defined */ |
81 protected SuballocatedIntVector m_namespaceDeclSetElements = null; |
76 protected SuballocatedIntVector m_namespaceDeclSetElements = null; |
82 |
77 |
1239 } |
1234 } |
1240 |
1235 |
1241 return DTM.NULL; |
1236 return DTM.NULL; |
1242 } |
1237 } |
1243 |
1238 |
1244 /** Lazily created namespace lists. */ |
|
1245 private Vector m_namespaceLists = null; // on demand |
|
1246 |
|
1247 |
1239 |
1248 /** Build table of namespace declaration |
1240 /** Build table of namespace declaration |
1249 * locations during DTM construction. Table is a Vector of |
1241 * locations during DTM construction. Table is aArrayList<>of |
1250 * SuballocatedIntVectors containing the namespace node HANDLES declared at |
1242 * SuballocatedIntVectors containing the namespace node HANDLES declared at |
1251 * that ID, plus an SuballocatedIntVector of the element node INDEXES at which |
1243 * that ID, plus an SuballocatedIntVector of the element node INDEXES at which |
1252 * these declarations appeared. |
1244 * these declarations appeared. |
1253 * |
1245 * |
1254 * NOTE: Since this occurs during model build, nodes will be encountered |
1246 * NOTE: Since this occurs during model build, nodes will be encountered |
1265 { |
1257 { |
1266 |
1258 |
1267 // First |
1259 // First |
1268 m_namespaceDeclSetElements=new SuballocatedIntVector(32); |
1260 m_namespaceDeclSetElements=new SuballocatedIntVector(32); |
1269 m_namespaceDeclSetElements.addElement(elementNodeIndex); |
1261 m_namespaceDeclSetElements.addElement(elementNodeIndex); |
1270 m_namespaceDeclSets=new Vector(); |
1262 m_namespaceDeclSets=new Vector<>(); |
1271 nsList=new SuballocatedIntVector(32); |
1263 nsList=new SuballocatedIntVector(32); |
1272 m_namespaceDeclSets.addElement(nsList); |
1264 m_namespaceDeclSets.add(nsList); |
1273 } |
1265 } |
1274 else |
1266 else |
1275 { |
1267 { |
1276 // Most recent. May be -1 (none) if DTM was pruned. |
1268 // Most recent. May be -1 (none) if DTM was pruned. |
1277 // %OPT% Is there a lastElement() method? Should there be? |
1269 // %OPT% Is there a lastElement() method? Should there be? |
1278 int last=m_namespaceDeclSetElements.size()-1; |
1270 int last=m_namespaceDeclSetElements.size()-1; |
1279 |
1271 |
1280 if(last>=0 && elementNodeIndex==m_namespaceDeclSetElements.elementAt(last)) |
1272 if(last>=0 && elementNodeIndex==m_namespaceDeclSetElements.elementAt(last)) |
1281 { |
1273 { |
1282 nsList=(SuballocatedIntVector)m_namespaceDeclSets.elementAt(last); |
1274 nsList=m_namespaceDeclSets.get(last); |
1283 } |
1275 } |
1284 } |
1276 } |
1285 if(nsList==null) |
1277 if(nsList==null) |
1286 { |
1278 { |
1287 m_namespaceDeclSetElements.addElement(elementNodeIndex); |
1279 m_namespaceDeclSetElements.addElement(elementNodeIndex); |
1306 } |
1298 } |
1307 } else { |
1299 } else { |
1308 nsList=new SuballocatedIntVector(32); |
1300 nsList=new SuballocatedIntVector(32); |
1309 } |
1301 } |
1310 |
1302 |
1311 m_namespaceDeclSets.addElement(nsList); |
1303 m_namespaceDeclSets.add(nsList); |
1312 } |
1304 } |
1313 |
1305 |
1314 // Handle overwriting inherited. |
1306 // Handle overwriting inherited. |
1315 // %OPT% Keep sorted? (By expanded-name rather than by doc order...) |
1307 // %OPT% Keep sorted? (By expanded-name rather than by doc order...) |
1316 // Downside: Would require insertElementAt if not found, |
1308 // Downside: Would require insertElementAt if not found, |
1342 // %OPT% Is binary-search really saving us a lot versus linear? |
1334 // %OPT% Is binary-search really saving us a lot versus linear? |
1343 // (... It may be, in large docs with many NS decls.) |
1335 // (... It may be, in large docs with many NS decls.) |
1344 int wouldBeAt=findInSortedSuballocatedIntVector(m_namespaceDeclSetElements, |
1336 int wouldBeAt=findInSortedSuballocatedIntVector(m_namespaceDeclSetElements, |
1345 elementNodeIndex); |
1337 elementNodeIndex); |
1346 if(wouldBeAt>=0) // Found it |
1338 if(wouldBeAt>=0) // Found it |
1347 return (SuballocatedIntVector) m_namespaceDeclSets.elementAt(wouldBeAt); |
1339 return m_namespaceDeclSets.get(wouldBeAt); |
1348 if(wouldBeAt == -1) // -1-wouldbeat == 0 |
1340 if(wouldBeAt == -1) // -1-wouldbeat == 0 |
1349 return null; // Not after anything; definitely not found |
1341 return null; // Not after anything; definitely not found |
1350 |
1342 |
1351 // Not found, but we know where it should have been. |
1343 // Not found, but we know where it should have been. |
1352 // Search back until we find an ancestor or run out. |
1344 // Search back until we find an ancestor or run out. |
1370 } else { |
1362 } else { |
1371 uppermostNSCandidateID = rootID; |
1363 uppermostNSCandidateID = rootID; |
1372 } |
1364 } |
1373 |
1365 |
1374 if (candidate == uppermostNSCandidateID) { |
1366 if (candidate == uppermostNSCandidateID) { |
1375 return (SuballocatedIntVector)m_namespaceDeclSets.elementAt(wouldBeAt); |
1367 return m_namespaceDeclSets.get(wouldBeAt); |
1376 } |
1368 } |
1377 } |
1369 } |
1378 |
1370 |
1379 while(wouldBeAt>=0 && ancestor>0) |
1371 while(wouldBeAt>=0 && ancestor>0) |
1380 { |
1372 { |
1381 if (candidate==ancestor) { |
1373 if (candidate==ancestor) { |
1382 // Found ancestor in list |
1374 // Found ancestor in list |
1383 return (SuballocatedIntVector)m_namespaceDeclSets.elementAt(wouldBeAt); |
1375 return m_namespaceDeclSets.get(wouldBeAt); |
1384 } else if (candidate<ancestor) { |
1376 } else if (candidate<ancestor) { |
1385 // Too deep in tree |
1377 // Too deep in tree |
1386 do { |
1378 do { |
1387 ancestor=_parent(ancestor); |
1379 ancestor=_parent(ancestor); |
1388 } while (candidate < ancestor); |
1380 } while (candidate < ancestor); |