org.netbeans.jemmy.operators
Class Operator

java.lang.Object
  extended by org.netbeans.jemmy.operators.Operator
All Implemented Interfaces:
Outputable, Timeoutable
Direct Known Subclasses:
ComponentOperator

public abstract class Operator
extends Object
implements Timeoutable, Outputable

Keeps all environment and low-level methods.

Author:
Alexandre Iline (alexandre.iline@sun.com)

Nested Class Summary
static interface Operator.ComponentVisualizer
          Interface used to make component visible & ready to to make operations with.
static class Operator.DefaultPathParser
          Used for parsing of path-like strings where path components are separated by a string-separator: "drive|directory|subdirectory|file".
static class Operator.DefaultStringComparator
          Default StringComparator implementation.
static class Operator.Finder
          Allows to bind a compponent by a component type.
protected  class Operator.MapAction
          Can be used to simplify nonprimitive type component's methods mapping.
protected  class Operator.MapBooleanAction
          Can be used to simplify boolean component's methods mapping.
protected  class Operator.MapByteAction
          Can be used to simplify byte component's methods mapping.
protected  class Operator.MapCharacterAction
          Can be used to simplify char component's methods mapping.
protected  class Operator.MapDoubleAction
          Can be used to simplify double component's methods mapping.
protected  class Operator.MapFloatAction
          Can be used to simplify float component's methods mapping.
protected  class Operator.MapIntegerAction
          Can be used to simplify int component's methods mapping.
protected  class Operator.MapLongAction
          Can be used to simplify long component's methods mapping.
protected  class Operator.MapVoidAction
          Can be used to simplify void component's methods mapping.
protected  class Operator.NoBlockingAction
          Can be used to make nonblocking operation implementation.
static interface Operator.PathParser
          Used for parsing of path-like strings.
static interface Operator.StringComparator
          Interface to compare string resources like labels, button text, ...
 
Field Summary
static String CLASS_DPROP
          Identifier for a "class" property.
static String TO_STRING_DPROP
          Identifier for a "toString" property.
 
Constructor Summary
Operator()
          Inits environment.
 
Method Summary
static void addOperatorPackage(String pkgName)
          Adds package to the list of packages containing operators.
protected  String[] addToDump(Hashtable table, String title, Object[] items)
          Adds array of objects to dump hashtable.
protected  String[] addToDump(Hashtable table, String title, Object[][] items)
          Adds two dimentional array of objects to dump hashtable.
 void copyEnvironment(Operator anotherOperator)
          Copies all environment (output, timeouts, visualizer) from another operator.
static ComponentOperator createOperator(Component comp)
          Creates operator for component.
 CharBindingMap getCharBindingMap()
          Returns CharBindingMap used for keyboard operations.
 int getCharKey(char c)
          Returns key code to be pressed for character typing.
 int getCharModifiers(char c)
          Returns modifiers mask for character typing.
 int[] getCharsKeys(char[] c)
          Returns key codes to by pressed for characters typing.
 int[] getCharsKeys(String s)
          Returns key codes to by pressed for the string typing.
 int[] getCharsModifiers(char[] c)
          Returns modifiers masks for characters typing.
 int[] getCharsModifiers(String s)
          Returns modifiers masks for the string typing.
 Operator.StringComparator getComparator()
          Returns object which is used for string comparison.
static Operator.ComponentVisualizer getDefaultComponentVisualizer()
          Returns an object to be used by default to prepare component.
static int getDefaultMouseButton()
          Returns default mouse button mask.
static Operator.PathParser getDefaultPathParser()
          Returns an object used for parsing of path-like strings.
static Operator.StringComparator getDefaultStringComparator()
          Returns string comparator used to init operators.
static boolean getDefaultVerification()
          Says weither newly created operators perform operations verifications by default.
 Hashtable getDump()
          Returns information about component.
static Operator getEnvironmentOperator()
          Returns an operator containing default environment.
 TestOut getOutput()
          Returns print output streams or writers.
 ComponentChooser[] getParentPath(ComponentChooser[] path)
           
 String[] getParentPath(String[] path)
          Creates new array which has all elements from first array, except last element.
 Operator.PathParser getPathParser()
          Returns object which is used for parsing of path-like strings.
static int getPopupMouseButton()
          Returns mask of mouse button which used to popup expanding.
 JemmyProperties getProperties()
          Returns a JemmyProperty object assigned to this operator.
 QueueTool getQueueTool()
          Returns QueueTool is used to work with queue.
abstract  Component getSource()
          Returns object operator is used for.
 Timeouts getTimeouts()
          Return current timeouts.
 boolean getVerification()
          Says weither operator performs operation verifications.
 Operator.ComponentVisualizer getVisualizer()
          Returns component visualizer.
 boolean isCaptionEqual(String caption, String match)
          Compares string using getComparator StringComparator.
static boolean isCaptionEqual(String caption, String match, boolean ce, boolean ccs)
          Deprecated. use another methods with the same name.
static boolean isCaptionEqual(String caption, String match, Operator.StringComparator comparator)
          Compares caption (button text, window title, ...) with a sample text.
protected  void lockQueue()
          Equivalent to getQueue().lock();.
 String[] parseString(String path)
          Parses a string to a string array using a PathParser assigned to this operator.
 String[] parseString(String path, String delim)
          Parses strings like "1|2|3" into arrays {"1", "2", "3"}.
 void printDump()
          Prints component information into operator output.
protected  void produceNoBlocking(Operator.NoBlockingAction action)
          Performs an operation without time control.
protected  void produceNoBlocking(Operator.NoBlockingAction action, Object param)
          Performs an operation without time control.
protected  Object produceTimeRestricted(Action action, long wholeTime)
          Performs an operation with time control.
protected  Object produceTimeRestricted(Action action, Object param, long wholeTime)
          Performs an operation with time control.
protected  Object runMapping(Operator.MapAction action)
          To map nonprimitive type component's method.
protected  boolean runMapping(Operator.MapBooleanAction action)
          To map boolean component's method.
protected  byte runMapping(Operator.MapByteAction action)
          To map byte component's method.
protected  char runMapping(Operator.MapCharacterAction action)
          To map char component's method.
protected  double runMapping(Operator.MapDoubleAction action)
          To map double component's method.
protected  float runMapping(Operator.MapFloatAction action)
          To map float component's method.
protected  int runMapping(Operator.MapIntegerAction action)
          To map int component's method.
protected  long runMapping(Operator.MapLongAction action)
          To map long component's method.
protected  void runMapping(Operator.MapVoidAction action)
          To map void component's method.
 void setCharBindingMap(CharBindingMap map)
          Defines CharBindingMap.
 void setComparator(Operator.StringComparator comparator)
          Defines object which is used for string comparison.
static Operator.ComponentVisualizer setDefaultComponentVisualizer(Operator.ComponentVisualizer visualizer)
          Specifies an object to be used by default to prepare component.
static Operator.PathParser setDefaultPathParser(Operator.PathParser parser)
          Specifies an object used for parsing of path-like strings.
static Operator.StringComparator setDefaultStringComparator(Operator.StringComparator comparator)
          Defines string comparator to be assigned in constructor.
static boolean setDefaultVerification(boolean verification)
          Defines weither newly created operators should perform operation verifications by default.
 void setOutput(TestOut out)
          Defines print output streams or writers.
 void setPathParser(Operator.PathParser parser)
          Specifies object which is used for parsing of path-like strings.
 JemmyProperties setProperties(JemmyProperties properties)
          Assigns a JemmyProperty object to this operator.
 void setTimeouts(Timeouts timeouts)
          Defines current timeouts.
 boolean setVerification(boolean verification)
          Defines weither operator should perform operation verifications.
 void setVisualizer(Operator.ComponentVisualizer vo)
          Changes component visualizer.
 String toStringSource()
          Returns toString() result from component of this operator.
protected  void unlockAndThrow(Exception e)
          Unlocks Queue and then throw exception.
protected  void unlockQueue()
          Equivalent to getQueue().unlock();.
 void waitState(ComponentChooser state)
          Waits a state specified by a ComponentChooser instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_DPROP

public static final String CLASS_DPROP
Identifier for a "class" property.

See Also:
getDump(), Constant Field Values

TO_STRING_DPROP

public static final String TO_STRING_DPROP
Identifier for a "toString" property.

See Also:
getDump(), Constant Field Values
Constructor Detail

Operator

public Operator()
Inits environment.

Method Detail

setDefaultComponentVisualizer

public static Operator.ComponentVisualizer setDefaultComponentVisualizer(Operator.ComponentVisualizer visualizer)
Specifies an object to be used by default to prepare component. Each new operator created after the method using will have defined visualizer. Default implementation is org.netbeans.jemmy.util.DefaultVisualizer class.

Parameters:
visualizer - ComponentVisualizer implementation
Returns:
previous value
See Also:
setVisualizer(Operator.ComponentVisualizer), getDefaultComponentVisualizer(), DefaultVisualizer

getDefaultComponentVisualizer

public static Operator.ComponentVisualizer getDefaultComponentVisualizer()
Returns an object to be used by default to prepare component.

Returns:
Object is used by default to prepare component
See Also:
getVisualizer(), setDefaultComponentVisualizer(Operator.ComponentVisualizer)

setDefaultStringComparator

public static Operator.StringComparator setDefaultStringComparator(Operator.StringComparator comparator)
Defines string comparator to be assigned in constructor.

Parameters:
comparator - the comparator to be used by default.
Returns:
previous value.
See Also:
getDefaultStringComparator(), Operator.StringComparator

getDefaultStringComparator

public static Operator.StringComparator getDefaultStringComparator()
Returns string comparator used to init operators.

Returns:
the comparator used by default.
See Also:
setDefaultStringComparator(Operator.StringComparator), Operator.StringComparator

setDefaultPathParser

public static Operator.PathParser setDefaultPathParser(Operator.PathParser parser)
Specifies an object used for parsing of path-like strings.

Parameters:
parser - the parser.
Returns:
a previous value.
See Also:
Operator.PathParser, getDefaultPathParser()

getDefaultPathParser

public static Operator.PathParser getDefaultPathParser()
Returns an object used for parsing of path-like strings.

Returns:
a parser used by default.
See Also:
Operator.PathParser, setDefaultPathParser(org.netbeans.jemmy.operators.Operator.PathParser)

setDefaultVerification

public static boolean setDefaultVerification(boolean verification)
Defines weither newly created operators should perform operation verifications by default.

Parameters:
verification - a verification mode to be used by default.
Returns:
a prevoius value.
See Also:
getDefaultVerification(), setVerification(boolean)

getDefaultVerification

public static boolean getDefaultVerification()
Says weither newly created operators perform operations verifications by default.

Returns:
a verification mode used by default.
See Also:
setDefaultVerification(boolean), getVerification()

isCaptionEqual

public static boolean isCaptionEqual(String caption,
                                     String match,
                                     boolean ce,
                                     boolean ccs)
Deprecated. use another methods with the same name.

Compares caption (button text, window title, ...) with a sample text.

Parameters:
caption - String to be compared with match. Method returns false, if parameter is null.
match - Sample to compare with. Method returns true, if parameter is null.
ce - Compare exactly. If true, text can be a substring of caption.
ccs - Compare case sensitively. If true, both text and caption are converted to upper case before comparison.
Returns:
true is the captions matched the match.
See Also:
isCaptionEqual(java.lang.String, java.lang.String, boolean, boolean)

isCaptionEqual

public static boolean isCaptionEqual(String caption,
                                     String match,
                                     Operator.StringComparator comparator)
Compares caption (button text, window title, ...) with a sample text.

Parameters:
caption - String to be compared with match
match - Sample to compare with
comparator - StringComparator instance.
Returns:
true is the captions matched the match.
See Also:
isCaptionEqual(java.lang.String, java.lang.String, boolean, boolean)

getDefaultMouseButton

public static int getDefaultMouseButton()
Returns default mouse button mask.

Returns:
InputEvent.BUTTON*_MASK field value

getPopupMouseButton

public static int getPopupMouseButton()
Returns mask of mouse button which used to popup expanding. (InputEvent.BUTTON3_MASK)

Returns:
InputEvent.BUTTON*_MASK field value

createOperator

public static ComponentOperator createOperator(Component comp)
Creates operator for component. Tries to find class with "operator package"."class name"Operator name, where "operator package" is a package from operator packages list, and "class name" is the name of class or one of its superclasses.

Parameters:
comp - Component to create operator for.
Returns:
a new operator with default environment.
See Also:
addOperatorPackage(String)

addOperatorPackage

public static void addOperatorPackage(String pkgName)
Adds package to the list of packages containing operators.
"org.netbeans.jemmy.operators" is in the list by default.

Parameters:
pkgName - Package name.
See Also:
createOperator(Component)

getEnvironmentOperator

public static Operator getEnvironmentOperator()
Returns an operator containing default environment.

Returns:
an empty operator (not having any component source) having default environment.

getSource

public abstract Component getSource()
Returns object operator is used for.

Returns:
an instance of java.awt.Component subclass which this operator was created for.

getQueueTool

public QueueTool getQueueTool()
Returns QueueTool is used to work with queue.

Returns:
a QueueTool.

copyEnvironment

public void copyEnvironment(Operator anotherOperator)
Copies all environment (output, timeouts, visualizer) from another operator.

Parameters:
anotherOperator - an operator to copy the environment to.

setTimeouts

public void setTimeouts(Timeouts timeouts)
Description copied from interface: Timeoutable
Defines current timeouts.

Specified by:
setTimeouts in interface Timeoutable
Parameters:
timeouts - A collection of timeout assignments.
See Also:
Timeoutable.getTimeouts()

getTimeouts

public Timeouts getTimeouts()
Description copied from interface: Timeoutable
Return current timeouts.

Specified by:
getTimeouts in interface Timeoutable
Returns:
the collection of current timeout assignments.
See Also:
Timeoutable.setTimeouts(org.netbeans.jemmy.Timeouts)

getVisualizer

public Operator.ComponentVisualizer getVisualizer()
Returns component visualizer. Visualizer is used from from makeComponentVisible() method.

Returns:
a visualizer assigned to this operator.
See Also:
getDefaultComponentVisualizer(), setVisualizer(Operator.ComponentVisualizer)

setVisualizer

public void setVisualizer(Operator.ComponentVisualizer vo)
Changes component visualizer. Visualizer is used from from makeComponentVisible() method.

Parameters:
vo - a visualizer to assign to this operator.
See Also:
setDefaultComponentVisualizer(Operator.ComponentVisualizer), getVisualizer()

getProperties

public JemmyProperties getProperties()
Returns a JemmyProperty object assigned to this operator.

Returns:
a JemmyProperty object got from the top of property stack or from another operator by copyuing environment.
See Also:
setProperties(org.netbeans.jemmy.JemmyProperties)

setProperties

public JemmyProperties setProperties(JemmyProperties properties)
Assigns a JemmyProperty object to this operator.

Parameters:
properties - a properties to assign to this operator.
Returns:
previously assigned properties.
See Also:
getProperties()

setCharBindingMap

public void setCharBindingMap(CharBindingMap map)
Defines CharBindingMap.

Parameters:
map - a CharBindingMap to use for keyboard operations.
See Also:
CharBindingMap, JemmyProperties.setCurrentCharBindingMap(CharBindingMap), getCharBindingMap()

getCharBindingMap

public CharBindingMap getCharBindingMap()
Returns CharBindingMap used for keyboard operations.

Returns:
a map assigned to this object.
See Also:
setCharBindingMap(org.netbeans.jemmy.CharBindingMap)

setOutput

public void setOutput(TestOut out)
Description copied from interface: Outputable
Defines print output streams or writers.

Specified by:
setOutput in interface Outputable
Parameters:
out - Identify the streams or writers used for print output.
See Also:
Outputable.getOutput()

getOutput

public TestOut getOutput()
Description copied from interface: Outputable
Returns print output streams or writers.

Specified by:
getOutput in interface Outputable
Returns:
an object that contains references to objects for printing to output and err streams.
See Also:
Outputable.setOutput(org.netbeans.jemmy.TestOut)

getComparator

public Operator.StringComparator getComparator()
Returns object which is used for string comparison.

Returns:
a comparator assigned to this operator.
See Also:
Operator.StringComparator, Operator.DefaultStringComparator, setComparator(org.netbeans.jemmy.operators.Operator.StringComparator)

setComparator

public void setComparator(Operator.StringComparator comparator)
Defines object which is used for string comparison.

Parameters:
comparator - a comparator to use for string comparision.
See Also:
Operator.StringComparator, Operator.DefaultStringComparator, getComparator()

getPathParser

public Operator.PathParser getPathParser()
Returns object which is used for parsing of path-like strings.

Returns:
a comparator assigned to this operator.
See Also:
setPathParser(org.netbeans.jemmy.operators.Operator.PathParser)

setPathParser

public void setPathParser(Operator.PathParser parser)
Specifies object which is used for parsing of path-like strings.

Parameters:
parser - a parser to use for path parsing.
See Also:
getPathParser()

setVerification

public boolean setVerification(boolean verification)
Defines weither operator should perform operation verifications.

Parameters:
verification - new value.
Returns:
old value
See Also:
setDefaultVerification(boolean), getDefaultVerification(), getVerification()

getVerification

public boolean getVerification()
Says weither operator performs operation verifications.

Returns:
old value
See Also:
setDefaultVerification(boolean), getDefaultVerification(), setVerification(boolean)

getParentPath

public String[] getParentPath(String[] path)
Creates new array which has all elements from first array, except last element.

Parameters:
path - an original array
Returns:
new array

getParentPath

public ComponentChooser[] getParentPath(ComponentChooser[] path)

parseString

public String[] parseString(String path)
Parses a string to a string array using a PathParser assigned to this operator.

Parameters:
path - an original string
Returns:
created String array.

parseString

public String[] parseString(String path,
                            String delim)
Parses strings like "1|2|3" into arrays {"1", "2", "3"}.

Parameters:
path - an original string
delim - a delimiter string
Returns:
created String array.

getCharKey

public int getCharKey(char c)
Returns key code to be pressed for character typing.

Parameters:
c - Character to be typed.
Returns:
a value of one of the KeyEvent.VK_* fields.
See Also:
CharBindingMap

getCharModifiers

public int getCharModifiers(char c)
Returns modifiers mask for character typing.

Parameters:
c - Character to be typed.
Returns:
a combination of InputEvent.*_MASK fields.
See Also:
CharBindingMap

getCharsKeys

public int[] getCharsKeys(char[] c)
Returns key codes to by pressed for characters typing.

Parameters:
c - Characters to be typed.
Returns:
an array of KeyEvent.VK_* values.
See Also:
CharBindingMap

getCharsModifiers

public int[] getCharsModifiers(char[] c)
Returns modifiers masks for characters typing.

Parameters:
c - Characters to be typed.
Returns:
an array of a combination of InputEvent.*_MASK fields.
See Also:
CharBindingMap

getCharsKeys

public int[] getCharsKeys(String s)
Returns key codes to by pressed for the string typing.

Parameters:
s - String to be typed.
Returns:
an array of KeyEvent.VK_* values.
See Also:
CharBindingMap

getCharsModifiers

public int[] getCharsModifiers(String s)
Returns modifiers masks for the string typing.

Parameters:
s - String to be typed.
Returns:
an array of a combination of InputEvent.*_MASK fields.
See Also:
CharBindingMap

isCaptionEqual

public boolean isCaptionEqual(String caption,
                              String match)
Compares string using getComparator StringComparator.

Parameters:
caption - a caption
match - a pattern
Returns:
true if caption and match match
See Also:
isCaptionEqual(java.lang.String, java.lang.String, boolean, boolean)

printDump

public void printDump()
Prints component information into operator output.


getDump

public Hashtable getDump()
Returns information about component. All records marked by simbolic constants defined in public static final *_DPROP fields for each operator type.

Returns:
a Hashtable containing name-value pairs.

waitState

public void waitState(ComponentChooser state)
Waits a state specified by a ComponentChooser instance.

Parameters:
state - a ComponentChooser defining the state criteria.
Throws:
TimeoutExpiredException - if the state has not achieved in a value defined by "ComponentOperator.WaitStateTimeout"

produceTimeRestricted

protected Object produceTimeRestricted(Action action,
                                       Object param,
                                       long wholeTime)
Performs an operation with time control.

Parameters:
action - an action to execute.
param - an action parameters.
wholeTime - a time for the action to be finished.
Returns:
an action result.

produceTimeRestricted

protected Object produceTimeRestricted(Action action,
                                       long wholeTime)
Performs an operation with time control.

Parameters:
action - an action to execute.
wholeTime - a time for the action to be finished.
Returns:
an action result.

produceNoBlocking

protected void produceNoBlocking(Operator.NoBlockingAction action,
                                 Object param)
Performs an operation without time control.

Parameters:
action - an action to execute.
param - an action parameters.

produceNoBlocking

protected void produceNoBlocking(Operator.NoBlockingAction action)
Performs an operation without time control.

Parameters:
action - an action to execute.

lockQueue

protected void lockQueue()
Equivalent to getQueue().lock();.


unlockQueue

protected void unlockQueue()
Equivalent to getQueue().unlock();.


unlockAndThrow

protected void unlockAndThrow(Exception e)
Unlocks Queue and then throw exception.

Parameters:
e - an exception to be thrown.

runMapping

protected Object runMapping(Operator.MapAction action)
To map nonprimitive type component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
Operator.MapAction

runMapping

protected char runMapping(Operator.MapCharacterAction action)
To map char component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapCharacterAction

runMapping

protected byte runMapping(Operator.MapByteAction action)
To map byte component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapByteAction

runMapping

protected int runMapping(Operator.MapIntegerAction action)
To map int component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapIntegerAction

runMapping

protected long runMapping(Operator.MapLongAction action)
To map long component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapLongAction

runMapping

protected float runMapping(Operator.MapFloatAction action)
To map float component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapFloatAction

runMapping

protected double runMapping(Operator.MapDoubleAction action)
To map double component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapDoubleAction

runMapping

protected boolean runMapping(Operator.MapBooleanAction action)
To map boolean component's method.

Parameters:
action - a mapping action.
Returns:
an action result.
See Also:
runMapping(Operator.MapAction), Operator.MapBooleanAction

runMapping

protected void runMapping(Operator.MapVoidAction action)
To map void component's method.

Parameters:
action - a mapping action.
See Also:
runMapping(Operator.MapAction), Operator.MapVoidAction

addToDump

protected String[] addToDump(Hashtable table,
                             String title,
                             Object[] items)
Adds array of objects to dump hashtable. Is used for multiple properties such as list items and tree nodes.

Parameters:
table - a table to add properties to.
title - property names prefix. Property names are constructed by adding a number to the prefix: title + "_" + Iteger.toString("ordinal index")
items - an array of property values.
Returns:
an array of property names (with added numbers).

addToDump

protected String[] addToDump(Hashtable table,
                             String title,
                             Object[][] items)
Adds two dimentional array of objects to dump hashtable. Is used for multiple properties such as table cells.

Parameters:
table - a table to add properties to.
title - property names prefix. Property names are constructed by adding two numbers to the prefix: title + "_" + Iteger.toString("row index") + "_" + Iteger.toString("column index")
items - an array of property values.
Returns:
an array of property names (with added numbers).

toStringSource

public String toStringSource()
Returns toString() result from component of this operator. It calls getSource().toString() in dispatch thread.

Returns:
toString() result from component of this operator.