| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript.xmlimpl; |
| 8 |
|
| 9 |
import org.mozilla.javascript.*; |
| 10 |
import org.mozilla.javascript.xml.*; |
| 11 |
|
| 12 |
final class XMLWithScope extends NativeWith |
| 13 |
{ |
| 14 |
private static final long serialVersionUID = -696429282095170887L; |
| 15 |
|
| 16 |
private XMLLibImpl lib; |
| 17 |
private int _currIndex; |
| 18 |
private XMLList _xmlList; |
| 19 |
private XMLObject _dqPrototype; |
| 20 |
|
| 21 |
XMLWithScope(XMLLibImpl lib, Scriptable parent, XMLObject prototype) |
| 22 |
{ |
| 23 |
super(parent, prototype); |
| 24 |
this.lib = lib; |
| 25 |
} |
| 26 |
|
| 27 |
void initAsDotQuery() |
| 28 |
{ |
| 29 |
XMLObject prototype = (XMLObject)getPrototype(); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
_currIndex = 0; |
| 38 |
_dqPrototype = prototype; |
| 39 |
if (prototype instanceof XMLList) { |
| 40 |
XMLList xl = (XMLList)prototype; |
| 41 |
if (xl.length() > 0) { |
| 42 |
setPrototype((Scriptable)(xl.get(0, null))); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
_xmlList = lib.newXMLList(); |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
protected Object updateDotQuery(boolean value) |
| 52 |
{ |
| 53 |
|
| 54 |
|
| 55 |
XMLObject seed = _dqPrototype; |
| 56 |
XMLList xmlL = _xmlList; |
| 57 |
|
| 58 |
if (seed instanceof XMLList) { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
XMLList orgXmlL = (XMLList)seed; |
| 63 |
|
| 64 |
int idx = _currIndex; |
| 65 |
|
| 66 |
if (value) { |
| 67 |
xmlL.addToList(orgXmlL.get(idx, null)); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
if (++idx < orgXmlL.length()) { |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
_currIndex = idx; |
| 76 |
setPrototype((Scriptable)(orgXmlL.get(idx, null))); |
| 77 |
|
| 78 |
|
| 79 |
return null; |
| 80 |
} |
| 81 |
} else { |
| 82 |
|
| 83 |
|
| 84 |
if (value) { |
| 85 |
xmlL.addToList(seed); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
return xmlL; |
| 90 |
} |
| 91 |
} |