DriverManager.java revision 13978:1993af50385d
1109998Smarkm/*
2280304Sjkim * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3280304Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4280304Sjkim *
5109998Smarkm * This code is free software; you can redistribute it and/or modify it
6109998Smarkm * under the terms of the GNU General Public License version 2 only, as
7109998Smarkm * published by the Free Software Foundation.
8109998Smarkm *
9109998Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT
10109998Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11109998Smarkm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12109998Smarkm * version 2 for more details (a copy is included in the LICENSE file that
13109998Smarkm * accompanied this code).
14280304Sjkim *
15109998Smarkm * You should have received a copy of the GNU General Public License version
16109998Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
17109998Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18109998Smarkm *
19109998Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20109998Smarkm * or visit www.oracle.com if you need additional information or have any
21109998Smarkm * questions.
22109998Smarkm */
23109998Smarkmpackage org.netbeans.jemmy.drivers;
24109998Smarkm
25109998Smarkmimport org.netbeans.jemmy.JemmyException;
26109998Smarkmimport org.netbeans.jemmy.JemmyProperties;
27109998Smarkmimport org.netbeans.jemmy.operators.ComponentOperator;
28109998Smarkm
29109998Smarkm/**
30109998Smarkm * Manages driver set.
31109998Smarkm */
32109998Smarkmpublic class DriverManager {
33109998Smarkm
34109998Smarkm    /**
35109998Smarkm     * Symbolic constant - prefix for drivers names.
36109998Smarkm     */
37109998Smarkm    public static final String DRIVER_ID = "drivers.";
38109998Smarkm    /**
39109998Smarkm     * Symbolic constant for tree drivers.
40109998Smarkm     */
41109998Smarkm    public static final String TREE_DRIVER_ID = DRIVER_ID + "tree";
42109998Smarkm    /**
43109998Smarkm     * Symbolic constant for text drivers.
44109998Smarkm     */
45109998Smarkm    public static final String TEXT_DRIVER_ID = DRIVER_ID + "text";
46109998Smarkm    /**
47109998Smarkm     * Symbolic constant for key drivers.
48109998Smarkm     */
49109998Smarkm    public static final String KEY_DRIVER_ID = DRIVER_ID + "key";
50109998Smarkm    /**
51109998Smarkm     * Symbolic constant for mouse drivers.
52109998Smarkm     */
53109998Smarkm    public static final String MOUSE_DRIVER_ID = DRIVER_ID + "mouse";
54109998Smarkm    /**
55109998Smarkm     * Symbolic constant for scroll drivers.
56109998Smarkm     */
57109998Smarkm    public static final String SCROLL_DRIVER_ID = DRIVER_ID + "scroll";
58109998Smarkm    /**
59109998Smarkm     * Symbolic constant for button drivers.
60109998Smarkm     */
61109998Smarkm    public static final String BUTTON_DRIVER_ID = DRIVER_ID + "button";
62109998Smarkm    /**
63160814Ssimon     * Symbolic constant for list drivers.
64109998Smarkm     */
65280304Sjkim    public static final String LIST_DRIVER_ID = DRIVER_ID + "list";
66280304Sjkim    /**
67280304Sjkim     * Symbolic constant for multiselection list drivers.
68280304Sjkim     */
69280304Sjkim    public static final String MULTISELLIST_DRIVER_ID = DRIVER_ID + "multisellist";
70109998Smarkm    /**
71109998Smarkm     * Symbolic constant for reorderable list drivers.
72280304Sjkim     */
73109998Smarkm    public static final String ORDEREDLIST_DRIVER_ID = DRIVER_ID + "orderedlist";
74109998Smarkm    /**
75109998Smarkm     * Symbolic constant for table drivers.
76109998Smarkm     */
77280304Sjkim    public static final String TABLE_DRIVER_ID = DRIVER_ID + "table";
78280304Sjkim    /**
79280304Sjkim     * Symbolic constant for window drivers.
80280304Sjkim     */
81109998Smarkm    public static final String WINDOW_DRIVER_ID = DRIVER_ID + "window";
82109998Smarkm    /**
83280304Sjkim     * Symbolic constant for window drivers.
84280304Sjkim     */
85280304Sjkim    public static final String FRAME_DRIVER_ID = DRIVER_ID + "frame";
86280304Sjkim    /**
87280304Sjkim     * Symbolic constant for window drivers.
88280304Sjkim     */
89109998Smarkm    public static final String INTERNAL_FRAME_DRIVER_ID = DRIVER_ID + "internal_frame";
90109998Smarkm    /**
91109998Smarkm     * Symbolic constant for frame drivers.
92280304Sjkim     */
93109998Smarkm    public static final String FOCUS_DRIVER_ID = DRIVER_ID + "focus";
94109998Smarkm    /**
95109998Smarkm     * Symbolic constant for menu drivers.
96280304Sjkim     */
97109998Smarkm    public static final String MENU_DRIVER_ID = DRIVER_ID + "menu";
98109998Smarkm
99109998Smarkm    //cannot be instantiated!
100109998Smarkm    private DriverManager() {
101280304Sjkim    }
102280304Sjkim
103280304Sjkim    /**
104280304Sjkim     * Searches a driver.
105280304Sjkim     *
106109998Smarkm     * @param id Driver type id.
107109998Smarkm     * @param operatorClass Class to get an driver for.
108109998Smarkm     * @param props Instance to get driver from.
109109998Smarkm     * @return a driver.
110280304Sjkim     * @see #setDriver
111280304Sjkim     */
112280304Sjkim    public static Object getDriver(String id, Class<?> operatorClass, JemmyProperties props) {
113280304Sjkim        Object result = getADriver(id, operatorClass, props);
114280304Sjkim        if (result == null) {
115280304Sjkim            return getDriver(id, operatorClass);
116280304Sjkim        } else {
117109998Smarkm            return result;
118109998Smarkm        }
119280304Sjkim    }
120280304Sjkim
121109998Smarkm    /**
122280304Sjkim     * Searches a driver. Uses {@code operator.getProperties()} to receive
123280304Sjkim     * JemmyProperties instance.
124280304Sjkim     *
125280304Sjkim     * @param id Driver type id.
126280304Sjkim     * @param operator Operator to get an driver for.
127280304Sjkim     * @return a driver.
128280304Sjkim     * @see #setDriver
129280304Sjkim     */
130280304Sjkim    public static Object getDriver(String id, ComponentOperator operator) {
131280304Sjkim        return getDriver(id, operator.getClass(), operator.getProperties());
132280304Sjkim    }
133280304Sjkim
134280304Sjkim    /**
135280304Sjkim     * Searches a driver. Uses current JemmyProperties.
136280304Sjkim     *
137280304Sjkim     * @param id Driver type id.
138109998Smarkm     * @param operatorClass Class to get an driver for.
139109998Smarkm     * @return a driver.
140160814Ssimon     * @see #setDriver
141280304Sjkim     */
142109998Smarkm    public static Object getDriver(String id, Class<?> operatorClass) {
143280304Sjkim        Object result = getADriver(id, operatorClass, JemmyProperties.getProperties());
144291721Sjkim        if (result == null) {
145291721Sjkim            throw (new JemmyException("No \"" + id + "\" driver registered for "
146291721Sjkim                    + operatorClass.getName() + " class!"));
147280304Sjkim        } else {
148280304Sjkim            return result;
149280304Sjkim        }
150280304Sjkim    }
151280304Sjkim
152280304Sjkim    /**
153109998Smarkm     * Sets driver for an operator class.
154     *
155     * @param id Driver type id.
156     * @param driver A driver to be installed.
157     * @param operatorClass Class to set driver for.
158     * @see #getDriver
159     */
160    public static void setDriver(String id, Object driver, Class<?> operatorClass) {
161        JemmyProperties.
162                setCurrentProperty(makeID(id, operatorClass), driver);
163        if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
164            JemmyProperties.getCurrentOutput().printLine("Installing "
165                    + driver.getClass().getName()
166                    + " drifer for "
167                    + operatorClass.getName()
168                    + " operators.");
169        }
170    }
171
172    /**
173     * Sets driver for an operator class name.
174     *
175     * @param id Driver type id.
176     * @param driver A driver to be installed.
177     * @param operatorClassName A name of operator class.
178     * @see #getDriver
179     */
180    public static void setDriver(String id, Object driver, String operatorClassName) {
181        JemmyProperties.
182                setCurrentProperty(makeID(id, operatorClassName), driver);
183        if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
184            JemmyProperties.getCurrentOutput().printLine("Installing "
185                    + driver.getClass().getName()
186                    + " drifer for "
187                    + operatorClassName
188                    + " operators.");
189        }
190    }
191
192    /**
193     * Sets driver for all classes supported by driver.
194     *
195     * @param id Driver type id.
196     * @param driver A driver to be installed.
197     * @see #getDriver
198     */
199    public static void setDriver(String id, Driver driver) {
200        Class<?>[] supported = driver.getSupported();
201        for (Class<?> aSupported : supported) {
202            setDriver(id, driver, aSupported);
203        }
204    }
205
206    /**
207     * Sets driver for all classes supported by driver.
208     *
209     * @param id Driver type id.
210     * @param driver A driver to be installed.
211     * @see #getDriver
212     */
213    public static void setDriver(String id, LightDriver driver) {
214        String[] supported = driver.getSupported();
215        for (String aSupported : supported) {
216            setDriver(id, driver, aSupported);
217        }
218    }
219
220    /**
221     * Removes driver for operator class.
222     *
223     * @param id Driver type to remove.
224     * @param operatorClass Class to remove driver for.
225     */
226    public static void removeDriver(String id, Class<?> operatorClass) {
227        JemmyProperties.
228                removeCurrentProperty(makeID(id, operatorClass));
229        if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
230            JemmyProperties.getCurrentOutput().printLine("Uninstalling a drifer for "
231                    + operatorClass.getName()
232                    + " operators.");
233        }
234    }
235
236    /**
237     * Removes driver for operator class.
238     *
239     * @param id Driver type to remove.
240     * @param operatorClassName A name of operator class.
241     */
242    public static void removeDriver(String id, String operatorClassName) {
243        JemmyProperties.
244                removeCurrentProperty(makeID(id, operatorClassName));
245        if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
246            JemmyProperties.getCurrentOutput().printLine("Uninstalling a drifer for "
247                    + operatorClassName
248                    + " operators.");
249        }
250    }
251
252    /**
253     * Removes driver for operator classes.
254     *
255     * @param id Driver type to remove.
256     * @param operatorClasses Classes to remove driver for.
257     */
258    public static void removeDriver(String id, Class<?>[] operatorClasses) {
259        for (Class<?> operatorClass : operatorClasses) {
260            removeDriver(id, operatorClass);
261        }
262    }
263
264    /**
265     * Removes driver for operator classes.
266     *
267     * @param id Driver type to remove.
268     * @param operatorClassNames Names of operator classes.
269     */
270    public static void removeDriver(String id, String[] operatorClassNames) {
271        for (String operatorClassName : operatorClassNames) {
272            removeDriver(id, operatorClassName);
273        }
274    }
275
276    /**
277     * Removes driver for all supported classes.
278     *
279     * @param id Driver type to remove.
280     */
281    public static void removeDrivers(String id) {
282        String[] keys = JemmyProperties.getCurrentKeys();
283        for (String key : keys) {
284            if (key.startsWith(id)) {
285                JemmyProperties.
286                        removeCurrentProperty(key);
287            }
288        }
289    }
290
291    /**
292     * Returns {@code TREE_DRIVER_ID} driver.
293     *
294     * @param operatorClass Class to find driver for.
295     * @return a driver
296     * @see #setTreeDriver
297     */
298    public static TreeDriver getTreeDriver(Class<?> operatorClass) {
299        return (TreeDriver) getDriver(TREE_DRIVER_ID, operatorClass);
300    }
301
302    /**
303     * Returns {@code TREE_DRIVER_ID} driver.
304     *
305     * @param operator Operator to find driver for.
306     * @return a driver
307     * @see #setTreeDriver
308     */
309    public static TreeDriver getTreeDriver(ComponentOperator operator) {
310        return (TreeDriver) getDriver(TREE_DRIVER_ID, operator.getClass());
311    }
312
313    /**
314     * Defines {@code TREE_DRIVER_ID} driver.
315     *
316     * @param driver a driver
317     * @see #getTreeDriver
318     */
319    public static void setTreeDriver(TreeDriver driver) {
320        setDriver(TREE_DRIVER_ID, driver);
321    }
322
323    /**
324     * Returns {@code TEXT_DRIVER_ID} driver.
325     *
326     * @param operatorClass Class to find driver for.
327     * @return a driver
328     * @see #setTextDriver
329     */
330    public static TextDriver getTextDriver(Class<?> operatorClass) {
331        return (TextDriver) getDriver(TEXT_DRIVER_ID, operatorClass);
332    }
333
334    /**
335     * Returns {@code TEXT_DRIVER_ID} driver.
336     *
337     * @param operator Operator to find driver for.
338     * @return a driver
339     * @see #setTextDriver
340     */
341    public static TextDriver getTextDriver(ComponentOperator operator) {
342        return (TextDriver) getDriver(TEXT_DRIVER_ID, operator.getClass());
343    }
344
345    /**
346     * Defines {@code TEXT_DRIVER_ID} driver.
347     *
348     * @param driver a driver
349     * @see #getTextDriver
350     */
351    public static void setTextDriver(TextDriver driver) {
352        setDriver(TEXT_DRIVER_ID, driver);
353    }
354
355    /**
356     * Returns {@code KEY_DRIVER_ID} driver.
357     *
358     * @param operatorClass Class to find driver for.
359     * @return a driver
360     * @see #setKeyDriver
361     */
362    public static KeyDriver getKeyDriver(Class<?> operatorClass) {
363        return (KeyDriver) getDriver(KEY_DRIVER_ID, operatorClass);
364    }
365
366    /**
367     * Returns {@code KEY_DRIVER_ID} driver.
368     *
369     * @param operator Operator to find driver for.
370     * @return a driver
371     * @see #setKeyDriver
372     */
373    public static KeyDriver getKeyDriver(ComponentOperator operator) {
374        return (KeyDriver) getDriver(KEY_DRIVER_ID, operator.getClass());
375    }
376
377    /**
378     * Defines {@code KEY_DRIVER_ID} driver.
379     *
380     * @param driver a driver
381     * @see #getKeyDriver
382     */
383    public static void setKeyDriver(KeyDriver driver) {
384        setDriver(KEY_DRIVER_ID, driver);
385    }
386
387    /**
388     * Returns {@code MOUSE_DRIVER_ID} driver.
389     *
390     * @param operatorClass Class to find driver for.
391     * @return a driver
392     * @see #setMouseDriver
393     */
394    public static MouseDriver getMouseDriver(Class<?> operatorClass) {
395        return (MouseDriver) getDriver(MOUSE_DRIVER_ID, operatorClass);
396    }
397
398    /**
399     * Returns {@code MOUSE_DRIVER_ID} driver.
400     *
401     * @param operator Operator to find driver for.
402     * @return a driver
403     * @see #setMouseDriver
404     */
405    public static MouseDriver getMouseDriver(ComponentOperator operator) {
406        return (MouseDriver) getDriver(MOUSE_DRIVER_ID, operator.getClass());
407    }
408
409    /**
410     * Defines {@code MOUSE_DRIVER_ID} driver.
411     *
412     * @param driver a driver
413     * @see #getMouseDriver
414     */
415    public static void setMouseDriver(MouseDriver driver) {
416        setDriver(MOUSE_DRIVER_ID, driver);
417    }
418
419    /**
420     * Returns {@code SCROLL_DRIVER_ID} driver.
421     *
422     * @param operatorClass Class to find driver for.
423     * @return a driver
424     * @see #setScrollDriver
425     */
426    public static ScrollDriver getScrollDriver(Class<?> operatorClass) {
427        return (ScrollDriver) getDriver(SCROLL_DRIVER_ID, operatorClass);
428    }
429
430    /**
431     * Returns {@code SCROLL_DRIVER_ID} driver.
432     *
433     * @param operator Operator to find driver for.
434     * @return a driver
435     * @see #setScrollDriver
436     */
437    public static ScrollDriver getScrollDriver(ComponentOperator operator) {
438        return (ScrollDriver) getDriver(SCROLL_DRIVER_ID, operator.getClass());
439    }
440
441    /**
442     * Defines {@code SCROLL_DRIVER_ID} driver.
443     *
444     * @param driver a driver
445     * @see #getScrollDriver
446     */
447    public static void setScrollDriver(ScrollDriver driver) {
448        setDriver(SCROLL_DRIVER_ID, driver);
449    }
450
451    /**
452     * Returns {@code BUTTON_DRIVER_ID} driver.
453     *
454     * @param operatorClass Class to find driver for.
455     * @return a driver
456     * @see #setButtonDriver
457     */
458    public static ButtonDriver getButtonDriver(Class<?> operatorClass) {
459        return (ButtonDriver) getDriver(BUTTON_DRIVER_ID, operatorClass);
460    }
461
462    /**
463     * Returns {@code BUTTON_DRIVER_ID} driver.
464     *
465     * @param operator Operator to find driver for.
466     * @return a driver
467     * @see #setButtonDriver
468     */
469    public static ButtonDriver getButtonDriver(ComponentOperator operator) {
470        return (ButtonDriver) getDriver(BUTTON_DRIVER_ID, operator.getClass());
471    }
472
473    /**
474     * Defines {@code BUTTON_DRIVER_ID} driver.
475     *
476     * @param driver a driver
477     * @see #getButtonDriver
478     */
479    public static void setButtonDriver(ButtonDriver driver) {
480        setDriver(BUTTON_DRIVER_ID, driver);
481    }
482
483    /**
484     * Returns {@code LIST_DRIVER_ID} driver.
485     *
486     * @param operatorClass Class to find driver for.
487     * @return a driver
488     * @see #setListDriver
489     */
490    public static ListDriver getListDriver(Class<?> operatorClass) {
491        return (ListDriver) getDriver(LIST_DRIVER_ID, operatorClass);
492    }
493
494    /**
495     * Returns {@code LIST_DRIVER_ID} driver.
496     *
497     * @param operator Operator to find driver for.
498     * @return a driver
499     * @see #setListDriver
500     */
501    public static ListDriver getListDriver(ComponentOperator operator) {
502        return (ListDriver) getDriver(LIST_DRIVER_ID, operator.getClass());
503    }
504
505    /**
506     * Defines {@code LIST_DRIVER_ID} driver.
507     *
508     * @param driver a driver
509     * @see #getListDriver
510     */
511    public static void setListDriver(ListDriver driver) {
512        setDriver(LIST_DRIVER_ID, driver);
513    }
514
515    /**
516     * Returns {@code MULTISELLIST_DRIVER_ID} driver.
517     *
518     * @param operatorClass Class to find driver for.
519     * @return a driver
520     * @see #setMultiSelListDriver
521     */
522    public static MultiSelListDriver getMultiSelListDriver(Class<?> operatorClass) {
523        return (MultiSelListDriver) getDriver(MULTISELLIST_DRIVER_ID, operatorClass);
524    }
525
526    /**
527     * Returns {@code MULTISELLIST_DRIVER_ID} driver.
528     *
529     * @param operator Operator to find driver for.
530     * @return a driver
531     * @see #setMultiSelListDriver
532     */
533    public static MultiSelListDriver getMultiSelListDriver(ComponentOperator operator) {
534        return (MultiSelListDriver) getDriver(MULTISELLIST_DRIVER_ID, operator.getClass());
535    }
536
537    /**
538     * Defines {@code MULTISELLIST_DRIVER_ID} driver.
539     *
540     * @param driver a driver
541     * @see #getMultiSelListDriver
542     */
543    public static void setMultiSelListDriver(MultiSelListDriver driver) {
544        setDriver(MULTISELLIST_DRIVER_ID, driver);
545    }
546
547    /**
548     * Returns {@code ORDEREDLIST_DRIVER_ID} driver.
549     *
550     * @param operatorClass Class to find driver for.
551     * @return a driver
552     * @see #setOrderedListDriver
553     */
554    public static OrderedListDriver getOrderedListDriver(Class<?> operatorClass) {
555        return (OrderedListDriver) getDriver(ORDEREDLIST_DRIVER_ID, operatorClass);
556    }
557
558    /**
559     * Returns {@code ORDEREDLIST_DRIVER_ID} driver.
560     *
561     * @param operator Operator to find driver for.
562     * @return a driver
563     * @see #setOrderedListDriver
564     */
565    public static OrderedListDriver getOrderedListDriver(ComponentOperator operator) {
566        return (OrderedListDriver) getDriver(ORDEREDLIST_DRIVER_ID, operator.getClass());
567    }
568
569    /**
570     * Defines {@code ORDEREDLIST_DRIVER_ID} driver.
571     *
572     * @param driver a driver
573     * @see #getOrderedListDriver
574     */
575    public static void setOrderedListDriver(OrderedListDriver driver) {
576        setDriver(ORDEREDLIST_DRIVER_ID, driver);
577    }
578
579    /**
580     * Returns {@code TABLE_DRIVER_ID} driver.
581     *
582     * @param operatorClass Class to find driver for.
583     * @return a driver
584     * @see #setTableDriver
585     */
586    public static TableDriver getTableDriver(Class<?> operatorClass) {
587        return (TableDriver) getDriver(TABLE_DRIVER_ID, operatorClass);
588    }
589
590    /**
591     * Returns {@code TABLE_DRIVER_ID} driver.
592     *
593     * @param operator Operator to find driver for.
594     * @return a driver
595     * @see #setTableDriver
596     */
597    public static TableDriver getTableDriver(ComponentOperator operator) {
598        return (TableDriver) getDriver(TABLE_DRIVER_ID, operator.getClass());
599    }
600
601    /**
602     * Defines {@code TABLE_DRIVER_ID} driver.
603     *
604     * @param driver a driver
605     * @see #getTableDriver
606     */
607    public static void setTableDriver(TableDriver driver) {
608        setDriver(TABLE_DRIVER_ID, driver);
609    }
610
611    /**
612     * Returns {@code WINDOW_DRIVER_ID} driver.
613     *
614     * @param operatorClass Class to find driver for.
615     * @return a driver
616     * @see #setWindowDriver
617     */
618    public static WindowDriver getWindowDriver(Class<?> operatorClass) {
619        return (WindowDriver) getDriver(WINDOW_DRIVER_ID, operatorClass);
620    }
621
622    /**
623     * Returns {@code WINDOW_DRIVER_ID} driver.
624     *
625     * @param operator Operator to find driver for.
626     * @return a driver
627     * @see #setWindowDriver
628     */
629    public static WindowDriver getWindowDriver(ComponentOperator operator) {
630        return (WindowDriver) getDriver(WINDOW_DRIVER_ID, operator.getClass());
631    }
632
633    /**
634     * Defines {@code WINDOW_DRIVER_ID} driver.
635     *
636     * @param driver a driver
637     * @see #getWindowDriver
638     */
639    public static void setWindowDriver(WindowDriver driver) {
640        setDriver(WINDOW_DRIVER_ID, driver);
641    }
642
643    /**
644     * Returns {@code FRAME_DRIVER_ID} driver.
645     *
646     * @param operatorClass Class to find driver for.
647     * @return a driver
648     * @see #setFrameDriver
649     */
650    public static FrameDriver getFrameDriver(Class<?> operatorClass) {
651        return (FrameDriver) getDriver(FRAME_DRIVER_ID, operatorClass);
652    }
653
654    /**
655     * Returns {@code FRAME_DRIVER_ID} driver.
656     *
657     * @param operator Operator to find driver for.
658     * @return a driver
659     * @see #setFrameDriver
660     */
661    public static FrameDriver getFrameDriver(ComponentOperator operator) {
662        return (FrameDriver) getDriver(FRAME_DRIVER_ID, operator.getClass());
663    }
664
665    /**
666     * Defines {@code FRAME_DRIVER_ID} driver.
667     *
668     * @param driver a driver
669     * @see #getFrameDriver
670     */
671    public static void setFrameDriver(FrameDriver driver) {
672        setDriver(FRAME_DRIVER_ID, driver);
673    }
674
675    /**
676     * Returns {@code INTERNAL_FRAME_DRIVER_ID} driver.
677     *
678     * @param operatorClass Class to find driver for.
679     * @return a driver
680     * @see #setInternalFrameDriver
681     */
682    public static InternalFrameDriver getInternalFrameDriver(Class<?> operatorClass) {
683        return (InternalFrameDriver) getDriver(INTERNAL_FRAME_DRIVER_ID, operatorClass);
684    }
685
686    /**
687     * Returns {@code INTERNAL_FRAME_DRIVER_ID} driver.
688     *
689     * @param operator Operator to find driver for.
690     * @return a driver
691     * @see #setInternalFrameDriver
692     */
693    public static InternalFrameDriver getInternalFrameDriver(ComponentOperator operator) {
694        return (InternalFrameDriver) getDriver(INTERNAL_FRAME_DRIVER_ID, operator.getClass());
695    }
696
697    /**
698     * Defines {@code INTERNAL_FRAME_DRIVER_ID} driver.
699     *
700     * @param driver a driver
701     * @see #getInternalFrameDriver
702     */
703    public static void setInternalFrameDriver(InternalFrameDriver driver) {
704        setDriver(INTERNAL_FRAME_DRIVER_ID, driver);
705    }
706
707    /**
708     * Returns {@code FOCUS_DRIVER_ID} driver.
709     *
710     * @param operatorClass Class to find driver for.
711     * @return a driver
712     * @see #setFocusDriver
713     */
714    public static FocusDriver getFocusDriver(Class<?> operatorClass) {
715        return (FocusDriver) getDriver(FOCUS_DRIVER_ID, operatorClass);
716    }
717
718    /**
719     * Returns {@code FOCUS_DRIVER_ID} driver.
720     *
721     * @param operator Operator to find driver for.
722     * @return a driver
723     * @see #setFocusDriver
724     */
725    public static FocusDriver getFocusDriver(ComponentOperator operator) {
726        return (FocusDriver) getDriver(FOCUS_DRIVER_ID, operator.getClass());
727    }
728
729    /**
730     * Defines {@code FOCUS_DRIVER_ID} driver.
731     *
732     * @param driver a driver
733     * @see #getFocusDriver
734     */
735    public static void setFocusDriver(FocusDriver driver) {
736        setDriver(FOCUS_DRIVER_ID, driver);
737    }
738
739    /**
740     * Returns {@code MENU_DRIVER_ID} driver.
741     *
742     * @param operatorClass Class to find driver for.
743     * @return a driver
744     * @see #setMenuDriver
745     */
746    public static MenuDriver getMenuDriver(Class<?> operatorClass) {
747        return (MenuDriver) getDriver(MENU_DRIVER_ID, operatorClass);
748    }
749
750    /**
751     * Returns {@code MENU_DRIVER_ID} driver.
752     *
753     * @param operator Operator to find driver for.
754     * @return a driver
755     * @see #setMenuDriver
756     */
757    public static MenuDriver getMenuDriver(ComponentOperator operator) {
758        return (MenuDriver) getDriver(MENU_DRIVER_ID, operator.getClass());
759    }
760
761    /**
762     * Defines {@code MENU_DRIVER_ID} driver.
763     *
764     * @param driver a driver
765     * @see #getMenuDriver
766     */
767    public static void setMenuDriver(MenuDriver driver) {
768        setDriver(MENU_DRIVER_ID, driver);
769    }
770
771    static void setDriver(String id, Object driver) {
772        if (driver instanceof Driver) {
773            setDriver(id, (Driver) driver);
774        } else if (driver instanceof LightDriver) {
775            setDriver(id, (LightDriver) driver);
776        } else {
777            throw (new JemmyException("Driver is neither Driver nor LightDriver "
778                    + driver.toString()));
779        }
780    }
781
782    //creates driver id
783    private static String makeID(String id, Class<?> operatorClass) {
784        return makeID(id, operatorClass.getName());
785    }
786
787    private static String makeID(String id, String operatorClassName) {
788        return id + "." + operatorClassName;
789    }
790
791    //returns a driver
792    private static Object getADriver(String id, Class<?> operatorClass, JemmyProperties props) {
793        Class<?> superClass = operatorClass;
794        Object drvr;
795        do {
796            drvr = props.
797                    getProperty(makeID(id, superClass));
798            if (drvr != null) {
799                return drvr;
800            }
801        } while (ComponentOperator.class.
802                isAssignableFrom(superClass = superClass.getSuperclass()));
803        return null;
804    }
805
806    static {
807        new InputDriverInstaller().install();
808        new DefaultDriverInstaller().install();
809    }
810}
811