1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* ***** BEGIN LICENSE BLOCK *****
4
* Version: MPL 1.1/GPL 2.0
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 1.1 (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/MPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is Rhino code, released
19
* The Initial Developer of the Original Code is
20
* Netscape Communications Corporation.
21
* Portions created by the Initial Developer are Copyright (C) 1997-1999
22
* the Initial Developer. All Rights Reserved.
30
* Alternatively, the contents of this file may be used under the terms of
31
* the GNU General Public License Version 2 or later (the "GPL"), in which
32
* case the provisions of the GPL are applicable instead of those above. If
33
* you wish to allow use of your version of this file only under the terms of
34
* the GPL and not to allow others to use your version of this file under the
35
* MPL, indicate your decision by deleting the provisions above and replacing
36
* them with the notice and other provisions required by the GPL. If you do
37
* not delete the provisions above, a recipient may use your version of this
38
* file under either the MPL or the GPL.
40
* ***** END LICENSE BLOCK ***** */
42
package org.mozilla.javascript.xmlimpl;
44
import org.mozilla.javascript.*;
45
import org.mozilla.javascript.xml.*;
47
final class XMLWithScope extends NativeWith
49
private static final long serialVersionUID = -696429282095170887L;
51
private XMLLibImpl lib;
52
private int _currIndex;
53
private XMLList _xmlList;
54
private XMLObject _dqPrototype;
56
XMLWithScope(XMLLibImpl lib, Scriptable parent, XMLObject prototype)
58
super(parent, prototype);
64
XMLObject prototype = (XMLObject)getPrototype();
65
// XMLWithScope also handles the .(xxx) DotQuery for XML
66
// basically DotQuery is a for/in/with statement and in
67
// the following 3 statements we setup to signal it's
69
// the index and the object being looped over. The
70
// xws.setPrototype is the scope of the object which is
71
// is a element of the lhs (XMLList).
73
_dqPrototype = prototype;
74
if (prototype instanceof XMLList) {
75
XMLList xl = (XMLList)prototype;
76
if (xl.length() > 0) {
77
setPrototype((Scriptable)(xl.get(0, null)));
80
// Always return the outer-most type of XML lValue of
81
// XML to left of dotQuery.
82
_xmlList = lib.newXMLList();
85
protected Object updateDotQuery(boolean value)
87
// Return null to continue looping
89
XMLObject seed = _dqPrototype;
90
XMLList xmlL = _xmlList;
92
if (seed instanceof XMLList) {
93
// We're a list so keep testing each element of the list if the
94
// result on the top of stack is true then that element is added
95
// to our result list. If false, we try the next element.
96
XMLList orgXmlL = (XMLList)seed;
101
xmlL.addToList(orgXmlL.get(idx, null));
104
// More elements to test?
105
if (++idx < orgXmlL.length()) {
106
// Yes, set our new index, get the next element and
107
// reset the expression to run with this object as
108
// the WITH selector.
110
setPrototype((Scriptable)(orgXmlL.get(idx, null)));
116
// If we're not a XMLList then there's no looping
117
// just return DQPrototype if the result is true.
119
xmlL.addToList(seed);