1 22 23 package org.xquark.extractor.runtime; 24 25 import java.util.List ; 26 27 import org.xquark.schema.validation.PSVInfoSetProvider; 28 import org.xquark.xml.xdbc.XMLDBCException; 29 import org.xquark.xquery.xdbc.XDBCResultSetInterface; 30 31 35 public class UnionResultSet implements XDBCResultSetInterface { 36 37 private static final String RCSRevision = "$Revision: 1.3 $"; 38 private static final String RCSName = "$Name: $"; 39 40 private List _sRSList = null; 41 private int _sRSNum = 0; 42 private SynchronizedResultSet _cRS = null; 43 private int _cRSIndex = -1; 44 45 public UnionResultSet() { 46 } 47 48 public UnionResultSet(List sRSList) { 49 setSubResultSetList(sRSList); 50 } 51 52 public void setSubResultSetList(List sRSList) { 53 _sRSList = sRSList; 54 _sRSNum = _sRSList.size(); 55 _cRSIndex = 0; 56 _cRS = (SynchronizedResultSet)_sRSList.get(_cRSIndex); 57 } 58 59 public String fetch(String path,int nodeAccessor,String loopID) throws XMLDBCException { 60 return fetch(path,nodeAccessor); 61 } 62 public String fetch(String path,int nodeAccessor) throws XMLDBCException { 63 return fetch(path,nodeAccessor, (PSVInfoSetProvider)null); 64 } 65 public String fetch(String path,int nodeAccessor,String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException { 66 return fetch(path,nodeAccessor,psvisp); 67 } 68 public String fetch(String path,int nodeAccessor, PSVInfoSetProvider psvisp) throws XMLDBCException { 69 return _cRS.fetch(path, nodeAccessor, psvisp); 70 } 71 72 public void generate(String path,int nodeAccessor,String loopID) throws XMLDBCException{ 73 generate(path, nodeAccessor); 74 } 75 public void generate(String path,int nodeAccessor) throws XMLDBCException{ 76 generate(path, nodeAccessor, (PSVInfoSetProvider)null); 77 } 78 public void generate(String path,int nodeAccessor,String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException{ 79 generate(path, nodeAccessor, psvisp); 80 } 81 public void generate(String path,int nodeAccessor, PSVInfoSetProvider psvisp) throws XMLDBCException{ 82 _cRS.generate(path, nodeAccessor, psvisp); 83 } 84 85 public void getIdentifiers(Object [] identifiers) throws XMLDBCException{ 86 _cRS.getIdentifiers(identifiers); 87 shiftIdentifiers(_cRS, identifiers); 88 } 89 90 public void getNextIdentifiers(Object [] identifiers) throws XMLDBCException { 91 if (_cRS.hasNext()) { 92 _cRS.getNextIdentifiers(identifiers); 93 shiftIdentifiers(_cRS, identifiers); 94 } 95 else { 96 SynchronizedResultSet rs = null; 97 for (int i = _cRSIndex +1 ; i < _sRSNum; i++) { 98 rs = (SynchronizedResultSet)_sRSList.get(i); 99 if (rs.hasNext()) { 100 rs.getNextIdentifiers(identifiers); 101 shiftIdentifiers(rs, identifiers); 102 break; 103 } 104 } 105 } 106 } 107 108 public boolean next() throws XMLDBCException{ 109 boolean retVal = false; 110 retVal = _cRS.next(); 111 if (!retVal) { 112 SynchronizedResultSet rs = null; 113 for (int i = _cRSIndex +1 ; i < _sRSNum; i++) { 114 rs = (SynchronizedResultSet)_sRSList.get(i); 115 retVal = rs.next(); 116 if (retVal) { 117 _cRSIndex = i; 118 _cRS = rs; 119 break; 120 } 121 } 122 } 123 return retVal; 124 } 125 126 public boolean hasNext() throws XMLDBCException{ 127 boolean retVal = false; 128 retVal = _cRS.hasNext(); 129 if (!retVal) { 130 SynchronizedResultSet rs = null; 131 for (int i = _cRSIndex +1 ; i < _sRSNum; i++) { 132 rs = (SynchronizedResultSet)_sRSList.get(i); 133 retVal = rs.hasNext(); 134 if (retVal) { 135 break; 136 } 137 } 138 } 139 return retVal; 140 } 141 146 public void setContentHandler(org.xml.sax.ContentHandler handler){ 147 SynchronizedResultSet rs = null; 148 for (int i = 0; i < _sRSNum; i++) { 149 rs = (SynchronizedResultSet)_sRSList.get(i); 150 rs.setContentHandler(handler); 151 } 152 } 153 154 public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler) { 155 SynchronizedResultSet rs = null; 156 for (int i = 0; i < _sRSNum; i++) { 157 rs = (SynchronizedResultSet)_sRSList.get(i); 158 rs.setLexicalHandler(handler); 159 } 160 } 161 162 public void setErrorHandler(org.xml.sax.ErrorHandler handler){ 163 SynchronizedResultSet rs = null; 164 for (int i = 0; i < _sRSNum; i++) { 165 rs = (SynchronizedResultSet)_sRSList.get(i); 166 rs.setErrorHandler(handler); 167 } 168 } 169 170 public void close() throws XMLDBCException { 171 if (_sRSList != null) { 172 SynchronizedResultSet rs = null; 173 for (int i = 0; i < _sRSNum; i++) { 174 rs = (SynchronizedResultSet)_sRSList.get(i); 175 rs.close(); 176 } 177 _sRSList = null; 178 } 179 } 180 181 private void shiftIdentifiers(SynchronizedResultSet rs, Object [] ids) throws XMLDBCException { 182 int position = 0; 183 for (int i = 0; i < _sRSNum; i++) { 184 rs = (SynchronizedResultSet)_sRSList.get(i); 185 if (rs != _cRS) { 186 position += rs.getReconstructionIdCount(); 187 } 188 else { 189 break; 190 } 191 } 192 193 if (0 != position) { 194 for (int i = 0; i < _cRS.getReconstructionIdCount(); i++) { 195 ids[i + position] = ids[i]; 196 ids[i] = null; 197 } 198 } 199 } 200 } 201 | Popular Tags |