com.gargoylesoftware.htmlunit.javascript.host
Class NodeList

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.NodeList
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.Callable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Function, net.sourceforge.htmlunit.corejs.javascript.Scriptable, NodeList
Direct Known Subclasses:
HTMLCollection

public class NodeList
extends SimpleScriptable
implements net.sourceforge.htmlunit.corejs.javascript.Function, NodeList

An array of elements. Used for the element arrays returned by document.all, document.all.tags('x'), document.forms, window.frames, etc. Note that this class must not be used for collections that can be modified, for example map.areas and select.options.
This class (like all classes in this package) is specific for the JavaScript engine. Users of HtmlUnit shouldn't use it directly.

Version:
$Revision: 8339 $
Author:
Daniel Gredler, Marc Guillemot, Chris Erskine, Ahmed Ashour
See Also:
Serialized Form

Nested Class Summary
protected static class NodeList.EffectOnCache
          Cache effect of some changes.
 
Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
  NodeList()
          Creates an instance.
  NodeList(DomNode parentScope, boolean attributeChangeSensitive, String description)
          Creates an instance.
protected NodeList(DomNode parentScope, List<?> initialElements)
          Constructs an instance with an initial cache value.
 
Method Summary
protected  void addElementIds(List<String> idList, List<Object> elements)
          Adds the ids of the collection's elements to the idList.
 boolean avoidObjectDetection()
          Only needed to make collections like document.all available but "invisible" when simulating Firefox.
 Object call(net.sourceforge.htmlunit.corejs.javascript.Context cx, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args)
          
protected  List<Object> computeElements()
          Returns the elements whose associated host objects are available through this collection.
 net.sourceforge.htmlunit.corejs.javascript.Scriptable construct(net.sourceforge.htmlunit.corejs.javascript.Context cx, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, Object[] args)
          
static NodeList emptyCollection(Window window)
          Gets an empty collection.
protected  Object equivalentValues(Object other)
          Called for the js "==".
 Object get(int index, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Returns the element at the specified index, or NOT_FOUND if the index is invalid.
protected  Iterable<DomNode> getCandidates()
          Gets the DOM node that have to be examined to see if they are matching.
 String getClassName()
          Returns the JavaScript class name.
protected  NodeList.EffectOnCache getEffectOnCache(HtmlAttributeChangeEvent event)
          Gets the effect of the change on an attribute of the reference node on this collection's cache.
 List<Object> getElements()
          Gets the HTML elements from cache or retrieve them at first call.
 Object[] getIds()
          .
 int getLength()
          
protected  net.sourceforge.htmlunit.corejs.javascript.Scriptable getScriptableForElement(Object object)
          Gets the scriptable for the provided element that may already be the right scriptable.
protected  Object getWithPreemption(String name)
          Returns the element or elements that match the specified key.
 boolean has(int index, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          
 boolean has(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          
protected  boolean isMatching(DomNode node)
          Indicates if the node should belong to the collection.
 Node item(int index)
          
 Object item(Object index)
          Returns the item or items corresponding to the specified index or key.
 void setAvoidObjectDetection(boolean newValue)
           
 String toString()
          
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, get, getBrowserVersion, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement, setParentScope
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
delete, delete, get, getDefaultValue, getParentScope, getPrototype, hasInstance, put, put, setParentScope, setPrototype
 

Constructor Detail

NodeList

public NodeList()
Creates an instance. JavaScript objects must have a default constructor. Don't call.


NodeList

public NodeList(DomNode parentScope,
                boolean attributeChangeSensitive,
                String description)
Creates an instance.

Parameters:
parentScope - parent scope
attributeChangeSensitive - indicates if the content of the collection may change when an attribute of a descendant node of parentScope changes (attribute added, modified or removed)
description - a text useful for debugging

NodeList

protected NodeList(DomNode parentScope,
                   List<?> initialElements)
Constructs an instance with an initial cache value.

Parameters:
parentScope - the parent scope, on which we listen for changes
initialElements - the initial content for the cache
Method Detail

emptyCollection

public static NodeList emptyCollection(Window window)
Gets an empty collection.

Parameters:
window - the current scope
Returns:
an empty collection

avoidObjectDetection

public boolean avoidObjectDetection()
Only needed to make collections like document.all available but "invisible" when simulating Firefox.

Overrides:
avoidObjectDetection in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

setAvoidObjectDetection

public void setAvoidObjectDetection(boolean newValue)
Parameters:
newValue - the new value

call

public Object call(net.sourceforge.htmlunit.corejs.javascript.Context cx,
                   net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
                   net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj,
                   Object[] args)

Specified by:
call in interface net.sourceforge.htmlunit.corejs.javascript.Callable
Specified by:
call in interface net.sourceforge.htmlunit.corejs.javascript.Function

construct

public final net.sourceforge.htmlunit.corejs.javascript.Scriptable construct(net.sourceforge.htmlunit.corejs.javascript.Context cx,
                                                                             net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
                                                                             Object[] args)

Specified by:
construct in interface net.sourceforge.htmlunit.corejs.javascript.Function

get

public final Object get(int index,
                        net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Returns the element at the specified index, or NOT_FOUND if the index is invalid.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getElements

public List<Object> getElements()
Gets the HTML elements from cache or retrieve them at first call.

Returns:
the list of HtmlElement contained in this collection

computeElements

protected List<Object> computeElements()
Returns the elements whose associated host objects are available through this collection.

Returns:
the elements whose associated host objects are available through this collection

getCandidates

protected Iterable<DomNode> getCandidates()
Gets the DOM node that have to be examined to see if they are matching. Default implementation looks at all descendants of reference node.

Returns:
the nodes

isMatching

protected boolean isMatching(DomNode node)
Indicates if the node should belong to the collection. Belongs to the refactoring effort to improve HTMLCollection's performance.

Parameters:
node - the node to test. Will be a child node of the reference node.
Returns:
false here as subclasses for concrete collections should decide it.

getWithPreemption

protected Object getWithPreemption(String name)
Returns the element or elements that match the specified key. If it is the name of a property, the property value is returned. If it is the id of an element in the array, that element is returned. Finally, if it is the name of an element or elements in the array, then all those elements are returned. Otherwise, Scriptable.NOT_FOUND is returned.

Called by SimpleScriptable.get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.

IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!

Overrides:
getWithPreemption in class SimpleScriptable
Parameters:
name - the property name
Returns:
Scriptable.NOT_FOUND if not found

getLength

public final int getLength()

Specified by:
getLength in interface NodeList

item

public final Object item(Object index)
Returns the item or items corresponding to the specified index or key.

Parameters:
index - the index or key corresponding to the element or elements to return
Returns:
the element or elements corresponding to the specified index or key
See Also:
MSDN doc

toString

public String toString()

Overrides:
toString in class Object

equivalentValues

protected Object equivalentValues(Object other)
Called for the js "==".

Overrides:
equivalentValues in class SimpleScriptable

has

public boolean has(int index,
                   net.sourceforge.htmlunit.corejs.javascript.Scriptable start)

Specified by:
has in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
has in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

has

public boolean has(String name,
                   net.sourceforge.htmlunit.corejs.javascript.Scriptable start)

Specified by:
has in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
has in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getIds

public Object[] getIds()
.

Specified by:
getIds in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getIds in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

addElementIds

protected void addElementIds(List<String> idList,
                             List<Object> elements)
Adds the ids of the collection's elements to the idList.

Parameters:
idList - the list to add the ids to
elements - the collection's elements

getEffectOnCache

protected NodeList.EffectOnCache getEffectOnCache(HtmlAttributeChangeEvent event)
Gets the effect of the change on an attribute of the reference node on this collection's cache.

Parameters:
event - the change event
Returns:
the effect on cache

item

public Node item(int index)

Specified by:
item in interface NodeList

getScriptableForElement

protected net.sourceforge.htmlunit.corejs.javascript.Scriptable getScriptableForElement(Object object)
Gets the scriptable for the provided element that may already be the right scriptable.

Parameters:
object - the object for which to get the scriptable
Returns:
the scriptable

getClassName

public String getClassName()
Returns the JavaScript class name.

Specified by:
getClassName in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getClassName in class SimpleScriptable
Returns:
the JavaScript class name


Copyright © 2002–2013 Gargoyle Software Inc.. All rights reserved.