abbot.script
Class ComponentReference

java.lang.Object
  |
  +--abbot.script.ComponentReference
All Implemented Interfaces:
Tags, XMLifiable

public class ComponentReference
extends Object
implements Tags, XMLifiable

Encapsulate as much information as is available to identify a GUI component. Usage:

<component id="..." class="..." [...]>
A number of optional tags are supported to provide an increasingly precise specification of the desired component:
(This list subject to change as required by the DefaultComponentFinder).


Field Summary
static int MW_FAILURE
          Match weight corresponding to no possible match.
static Collection VALID_ATTRIBUTES
           
 
Fields inherited from interface abbot.script.Tags
TAG_ACTION, TAG_ARGS, TAG_ASSERT, TAG_AWTTESTSCRIPT, TAG_CALL, TAG_CLASS, TAG_CLASSPATH, TAG_COMMENT, TAG_COMPONENT, TAG_COUNT, TAG_DELEGATE, TAG_DESC, TAG_DOCBASE, TAG_EVENT, TAG_FILENAME, TAG_FORKED, TAG_HEIGHT, TAG_HORDER, TAG_ID, TAG_INDEX, TAG_INVERT, TAG_INVOKER, TAG_KEYCHAR, TAG_KEYCODE, TAG_KIND, TAG_LAUNCH, TAG_METHOD, TAG_MODIFIERS, TAG_NAME, TAG_PARAMS, TAG_PARENT, TAG_POLL_INTERVAL, TAG_PROPERTY, TAG_SAMPLE, TAG_SCRIPT, TAG_SEQUENCE, TAG_SLOW, TAG_STOP_ON_ERROR, TAG_STOP_ON_FAILURE, TAG_TAG, TAG_TERMINATE, TAG_THREADED, TAG_TIMEOUT, TAG_TITLE, TAG_TRIGGER, TAG_TYPE, TAG_VALUE, TAG_VMARGS, TAG_VORDER, TAG_WAIT, TAG_WIDTH, TAG_WINDOW, TAG_X, TAG_Y
 
Constructor Summary
ComponentReference(Resolver resolver, Class cls, Map attributes)
           
ComponentReference(Resolver resolver, Component comp)
          Create a reference based on the given component.
ComponentReference(Resolver resolver, Component comp, boolean resolve)
          Create a reference based on the given component.
ComponentReference(Resolver resolver, org.jdom.Element el)
          For creation from XML.
ComponentReference(String id, Class compClass)
          For general component lookup by class name.
ComponentReference(String id, Class compClass, String name, String tag)
          For general component lookup.
ComponentReference(String id, Class compClass, String name, String tag, String title)
          For general component lookup.
ComponentReference(String id, Class compClass, String name, String tag, String title, ComponentReference parent, int index)
          For general component lookup.
ComponentReference(String id, Class compClass, String name, String tag, String title, ComponentReference parent, int index, ComponentReference invokerOrWindow)
          For general component lookup.
 
Method Summary
 boolean equals(Object obj)
          Two ComponentReferences with identical XML representations should be equal.
 Component findInHierarchy(ComponentFinder finder)
          Using the given finder to read the current hierarchy, match this reference against an existing component.
 void fromXML(String xml)
          Set all options based on the given XML.
 String getAttribute(String key)
           
 String getID()
           
 int getIndex()
          Deprecated. use getAttribute(TAG_INDEX) instead.
 String getInvokerID()
          Deprecated. use getAttribute(TAG_INVOKER) instead.
 ComponentReference getInvokerReference()
           
(package private)  int getMatchWeight(Component comp)
          Return a measure of how well the given component matches the given component reference.
 String getName()
          Deprecated. use getAttribute(TAG_NAME) instead.
(package private) static String getOrder(Component original, Component[] matchList, boolean horizontal)
          Return the order of the given component among the array given, sorted by horizontal or vertical screen position.
 ComponentReference getParentReference()
           
 String getRefClassName()
           
 String getTag()
          Deprecated. use getAttribute(TAG_TAG) instead.
 String getTitle()
          Deprecated. use getAttribute(TAG_TITLE) instead.
 String getWindowID()
          Deprecated. use getAttribute(TAG_WINDOW) instead.
 ComponentReference getWindowReference()
          Reference ID of this component's parent window (optional).
 boolean isAssignableFrom(Class cls)
          Return whether this reference has the same class or is a superclass of the given component's class.
static ComponentReference matchExisting(Component comp, Collection existing)
          Match the given component against an existing set of references.
(package private)  void setAttribute(String key, String value)
          For package-level testing only.
 String toEditableString()
          Provide an editable string representation of the object.
 String toString()
          Return a human-readable representation.
 org.jdom.Element toXML()
          Provide an XML representation of the object.
 String toXMLString()
           
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MW_FAILURE

public static final int MW_FAILURE
Match weight corresponding to no possible match.

VALID_ATTRIBUTES

public static final Collection VALID_ATTRIBUTES
Constructor Detail

ComponentReference

public ComponentReference(String id,
                          Class compClass)
For general component lookup by class name.
Parameters:
id - Desired ID for the reference. Only used if this reference is to be passed as the parent, window, or invoker of another.
compClass - Class of the component (required)

ComponentReference

public ComponentReference(String id,
                          Class compClass,
                          String name,
                          String tag)
For general component lookup.
Parameters:
id - Desired ID for the reference. Only used if this reference is to be passed as the parent, window, or invoker of another.
compClass - Class of the component (required)
name - Name of the component, or null
tag - Tag as returned by ComponentTester.getTag(Component)

ComponentReference

public ComponentReference(String id,
                          Class compClass,
                          String name,
                          String tag,
                          String title)
For general component lookup.
Parameters:
id - Desired ID for the reference. Only used if this reference is to be passed as the parent, window, or invoker of another.
compClass - Class of the component (required)
name - Name of the component, or null
tag - Tag as returned by ComponentTester.getTag(Component)
title - Owning Frame/Dialog title, or null

ComponentReference

public ComponentReference(String id,
                          Class compClass,
                          String name,
                          String tag,
                          String title,
                          ComponentReference parent,
                          int index)
For general component lookup.
Parameters:
id - Desired ID for the reference. Only used if this reference is to be passed as the parent, window, or invoker of another.
compClass - Class of the component (required)
name - Name of the component, or null
tag - Tag as returned by ComponentTester.getTag(Component)
title - Owning Frame/Dialog title, or null
parent - Reference to parent, or null
index - Index within parent, or -1

ComponentReference

public ComponentReference(String id,
                          Class compClass,
                          String name,
                          String tag,
                          String title,
                          ComponentReference parent,
                          int index,
                          ComponentReference invokerOrWindow)
For general component lookup.
Parameters:
id - Desired ID for the reference. Only used if this reference is to be passed as the parent, window, or invoker of another.
compClass - Class of the component (required)
name - Name of the component, or null
tag - Tag as returned by ComponentTester.getTag(Component)
title - Owning Frame/Dialog title, or null
parent - Reference to parent, or null
index - Index within parent, or -1
invokerOrWindow - Window reference, invoker, or null

ComponentReference

public ComponentReference(Resolver resolver,
                          org.jdom.Element el)
                   throws InvalidScriptException
For creation from XML.

ComponentReference

public ComponentReference(Resolver resolver,
                          Class cls,
                          Map attributes)

ComponentReference

public ComponentReference(Resolver resolver,
                          Component comp)
Create a reference based on the given component. May recursively add other components required to identify this one.

ComponentReference

public ComponentReference(Resolver resolver,
                          Component comp,
                          boolean resolve)
Create a reference based on the given component. May recursively add other components required to identify this one if resolve is true.
Method Detail

getID

public String getID()

getRefClassName

public String getRefClassName()

getAttribute

public String getAttribute(String key)

setAttribute

void setAttribute(String key,
                  String value)
For package-level testing only.

isAssignableFrom

public boolean isAssignableFrom(Class cls)
Return whether this reference has the same class or is a superclass of the given component's class. Simply compare class names to avoid class loader conflicts. Note that this does not take into account interfaces (which is okay, since with GUI components we're only concerned with class inheritance).

getParentReference

public ComponentReference getParentReference()

getWindowReference

public ComponentReference getWindowReference()
Reference ID of this component's parent window (optional).

getInvokerReference

public ComponentReference getInvokerReference()

fromXML

public void fromXML(String xml)
             throws InvalidScriptException
Set all options based on the given XML.

toXML

public org.jdom.Element toXML()
Description copied from interface: XMLifiable
Provide an XML representation of the object.
Specified by:
toXML in interface XMLifiable

toEditableString

public String toEditableString()
Description copied from interface: XMLifiable
Provide an editable string representation of the object. Usually will be a String form of the XML, but may be something simpler if it doesn't make sense to provide the full XML.
Specified by:
toEditableString in interface XMLifiable

equals

public boolean equals(Object obj)
Two ComponentReferences with identical XML representations should be equal.
Overrides:
equals in class Object

toString

public String toString()
Return a human-readable representation.
Overrides:
toString in class Object

toXMLString

public String toXMLString()

getOrder

static String getOrder(Component original,
                       Component[] matchList,
                       boolean horizontal)
Return the order of the given component among the array given, sorted by horizontal or vertical screen position. All components with the same effective value will have the same order.

getMatchWeight

int getMatchWeight(Component comp)
Return a measure of how well the given component matches the given component reference. The weight performs two functions; one is to loosely match so that we can find a component even if some of its attributes have changed. The other is to distinguish between similar components.

In general, we want to match if we get any weight at all, and there's only one component that matches.


matchExisting

public static ComponentReference matchExisting(Component comp,
                                               Collection existing)
Match the given component against an existing set of references.

findInHierarchy

public Component findInHierarchy(ComponentFinder finder)
                          throws ComponentNotFoundException,
                                 MultipleComponentsFoundException
Using the given finder to read the current hierarchy, match this reference against an existing component.

getName

public String getName()
Deprecated. use getAttribute(TAG_NAME) instead.


getTag

public String getTag()
Deprecated. use getAttribute(TAG_TAG) instead.


getInvokerID

public String getInvokerID()
Deprecated. use getAttribute(TAG_INVOKER) instead.


getWindowID

public String getWindowID()
Deprecated. use getAttribute(TAG_WINDOW) instead.


getTitle

public String getTitle()
Deprecated. use getAttribute(TAG_TITLE) instead.


getIndex

public int getIndex()
Deprecated. use getAttribute(TAG_INDEX) instead.



Copyright © 2002-2003 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge