com.gargoylesoftware.htmlunit.javascript.host.html
Class HTMLCollection

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
              extended by com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection
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:
HTMLCollectionTags

public class HTMLCollection
extends 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: 7582 $
Author:
Daniel Gredler, Marc Guillemot, Chris Erskine, Ahmed Ashour
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.javascript.host.NodeList
NodeList.EffectOnCache
 
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
HTMLCollection()
          Deprecated. 
HTMLCollection(DomNode parentScope, boolean attributeChangeSensitive, String description)
          Creates an instance.
 
Method Summary
protected  void addElementIds(List<String> idList, List<Object> elements)
          Adds the ids of the collection's elements to the idList.
protected  List<Object> computeElements()
          Returns the elements whose associated host objects are available through this collection.
static HTMLCollection emptyCollection(Window window)
          Gets an empty collection.
protected  Object equivalentValues(Object other)
          Called for the js "==".
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.
 Object[] getIds()
          .
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(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          
protected  boolean isMatching(DomNode node)
          Indicates if the node should belong to the collection.
 Object namedItem(String name)
          Retrieves the item or items corresponding to the specified name (checks ids, and if that does not work, then names).
 Object nextNode()
          Returns the next node in the collection (supporting iteration in IE only).
 void reset()
          Resets the node iterator accessed via nextNode().
 Object tags(String tagName)
          Returns all the elements in this element array that have the specified tag name.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.host.NodeList
avoidObjectDetection, call, construct, get, getEffectOnCache, getElements, getLength, item, item, setAvoidObjectDetection, 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
 
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, has, 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, setParentScope, 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, has, hasInstance, put, put, setParentScope, setPrototype
 

Constructor Detail

HTMLCollection

@Deprecated
public HTMLCollection()
Deprecated. 

Creates an instance. JavaScript objects must have a default constructor. Don't call.


HTMLCollection

public HTMLCollection(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
Method Detail

emptyCollection

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

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

computeElements

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

Overrides:
computeElements in class NodeList
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.

Overrides:
getCandidates in class NodeList
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.

Overrides:
isMatching in class NodeList
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. 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 NodeList
Parameters:
name - the property name
Returns:
Scriptable.NOT_FOUND if not found

namedItem

public final Object namedItem(String name)
Retrieves the item or items corresponding to the specified name (checks ids, and if that does not work, then names).

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

nextNode

public Object nextNode()
Returns the next node in the collection (supporting iteration in IE only).

Returns:
the next node in the collection

reset

public void reset()
Resets the node iterator accessed via nextNode().


tags

public Object tags(String tagName)
Returns all the elements in this element array that have the specified tag name. This method returns an empty element array if there are no elements with the specified tag name.

Parameters:
tagName - the name of the tag of the elements to return
Returns:
all the elements in this element array that have the specified tag name
See Also:
MSDN doc

equivalentValues

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

Overrides:
equivalentValues in class NodeList

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 NodeList

getIds

public Object[] getIds()
..

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

addElementIds

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

Overrides:
addElementIds in class NodeList
Parameters:
idList - the list to add the ids to
elements - the collection's elements

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.

Overrides:
getScriptableForElement in class NodeList
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 NodeList
Returns:
the JavaScript class name


Copyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.