001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers;
048:
049: import java.util.Hashtable;
050:
051: import org.netbeans.jemmy.JemmyException;
052: import org.netbeans.jemmy.JemmyProperties;
053: import org.netbeans.jemmy.Timeout;
054:
055: import org.netbeans.jemmy.operators.ComponentOperator;
056:
057: /**
058: * Manages driver set.
059: */
060: public class DriverManager {
061: /**
062: * Symbolic constant - prefix for drivers names.
063: */
064: public static final String DRIVER_ID = "drivers.";
065: /**
066: * Symbolic constant for tree drivers.
067: */
068: public static final String TREE_DRIVER_ID = DRIVER_ID + "tree";
069: /**
070: * Symbolic constant for text drivers.
071: */
072: public static final String TEXT_DRIVER_ID = DRIVER_ID + "text";
073: /**
074: * Symbolic constant for key drivers.
075: */
076: public static final String KEY_DRIVER_ID = DRIVER_ID + "key";
077: /**
078: * Symbolic constant for mouse drivers.
079: */
080: public static final String MOUSE_DRIVER_ID = DRIVER_ID + "mouse";
081: /**
082: * Symbolic constant for scroll drivers.
083: */
084: public static final String SCROLL_DRIVER_ID = DRIVER_ID + "scroll";
085: /**
086: * Symbolic constant for button drivers.
087: */
088: public static final String BUTTON_DRIVER_ID = DRIVER_ID + "button";
089: /**
090: * Symbolic constant for list drivers.
091: */
092: public static final String LIST_DRIVER_ID = DRIVER_ID + "list";
093: /**
094: * Symbolic constant for multiselection list drivers.
095: */
096: public static final String MULTISELLIST_DRIVER_ID = DRIVER_ID
097: + "multisellist";
098: /**
099: * Symbolic constant for reorderable list drivers.
100: */
101: public static final String ORDEREDLIST_DRIVER_ID = DRIVER_ID
102: + "orderedlist";
103: /**
104: * Symbolic constant for table drivers.
105: */
106: public static final String TABLE_DRIVER_ID = DRIVER_ID + "table";
107: /**
108: * Symbolic constant for window drivers.
109: */
110: public static final String WINDOW_DRIVER_ID = DRIVER_ID + "window";
111: /**
112: * Symbolic constant for window drivers.
113: */
114: public static final String FRAME_DRIVER_ID = DRIVER_ID + "frame";
115: /**
116: * Symbolic constant for window drivers.
117: */
118: public static final String INTERNAL_FRAME_DRIVER_ID = DRIVER_ID
119: + "internal_frame";
120: /**
121: * Symbolic constant for frame drivers.
122: */
123: public static final String FOCUS_DRIVER_ID = DRIVER_ID + "focus";
124: /**
125: * Symbolic constant for menu drivers.
126: */
127: public static final String MENU_DRIVER_ID = DRIVER_ID + "menu";
128:
129: //cannot be instantiated!
130: private DriverManager() {
131: }
132:
133: /**
134: * Searches a driver.
135: * @param id Driver type id.
136: * @param operatorClass Class to get an driver for.
137: * @param props Instance to get driver from.
138: * @return a driver.
139: * @see #setDriver
140: */
141: public static Object getDriver(String id, Class operatorClass,
142: JemmyProperties props) {
143: Object result = getADriver(id, operatorClass, props);
144: if (result == null) {
145: return (getDriver(id, operatorClass));
146: } else {
147: return (result);
148: }
149: }
150:
151: /**
152: * Searches a driver. Uses <code>operator.getProperties()</code> to
153: * receive JemmyProperties instance.
154: * @param id Driver type id.
155: * @param operator Operator to get an driver for.
156: * @return a driver.
157: * @see #setDriver
158: */
159: public static Object getDriver(String id, ComponentOperator operator) {
160: return (getDriver(id, operator.getClass(), operator
161: .getProperties()));
162: }
163:
164: /**
165: * Searches a driver.
166: * Uses current JemmyProperties.
167: * @param id Driver type id.
168: * @param operatorClass Class to get an driver for.
169: * @return a driver.
170: * @see #setDriver
171: */
172: public static Object getDriver(String id, Class operatorClass) {
173: Object result = getADriver(id, operatorClass, JemmyProperties
174: .getProperties());
175: if (result == null) {
176: throw (new JemmyException("No \"" + id
177: + "\" driver registered for "
178: + operatorClass.getName() + " class!"));
179: } else {
180: return (result);
181: }
182: }
183:
184: /**
185: * Sets driver for an operator class.
186: * @param id Driver type id.
187: * @param driver A driver to be installed.
188: * @param operatorClass Class to set driver for.
189: * @see #getDriver
190: */
191: public static void setDriver(String id, Object driver,
192: Class operatorClass) {
193: JemmyProperties.setCurrentProperty(makeID(id, operatorClass),
194: driver);
195: if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
196: JemmyProperties.getCurrentOutput().printLine(
197: "Installing " + driver.getClass().getName()
198: + " drifer for " + operatorClass.getName()
199: + " operators.");
200: }
201: }
202:
203: /**
204: * Sets driver for an operator class name.
205: * @param id Driver type id.
206: * @param driver A driver to be installed.
207: * @param operatorClassName A name of operator class.
208: * @see #getDriver
209: */
210: public static void setDriver(String id, Object driver,
211: String operatorClassName) {
212: JemmyProperties.setCurrentProperty(
213: makeID(id, operatorClassName), driver);
214: if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
215: JemmyProperties.getCurrentOutput().printLine(
216: "Installing " + driver.getClass().getName()
217: + " drifer for " + operatorClassName
218: + " operators.");
219: }
220: }
221:
222: /**
223: * Sets driver for all classes supported by driver.
224: * @param id Driver type id.
225: * @param driver A driver to be installed.
226: * @see #getDriver
227: */
228: public static void setDriver(String id, Driver driver) {
229: Class[] supported = driver.getSupported();
230: for (int i = 0; i < supported.length; i++) {
231: setDriver(id, driver, supported[i]);
232: }
233: }
234:
235: /**
236: * Sets driver for all classes supported by driver.
237: * @param id Driver type id.
238: * @param driver A driver to be installed.
239: * @see #getDriver
240: */
241: public static void setDriver(String id, LightDriver driver) {
242: String[] supported = driver.getSupported();
243: for (int i = 0; i < supported.length; i++) {
244: setDriver(id, driver, supported[i]);
245: }
246: }
247:
248: /**
249: * Removes driver for operator class.
250: * @param id Driver type to remove.
251: * @param operatorClass Class to remove driver for.
252: */
253: public static void removeDriver(String id, Class operatorClass) {
254: JemmyProperties
255: .removeCurrentProperty(makeID(id, operatorClass));
256: if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
257: JemmyProperties.getCurrentOutput().printLine(
258: "Uninstalling a drifer for "
259: + operatorClass.getName() + " operators.");
260: }
261: }
262:
263: /**
264: * Removes driver for operator class.
265: * @param id Driver type to remove.
266: * @param operatorClassName A name of operator class.
267: */
268: public static void removeDriver(String id, String operatorClassName) {
269: JemmyProperties.removeCurrentProperty(makeID(id,
270: operatorClassName));
271: if (Boolean.getBoolean(DRIVER_ID + "trace_output")) {
272: JemmyProperties.getCurrentOutput().printLine(
273: "Uninstalling a drifer for " + operatorClassName
274: + " operators.");
275: }
276: }
277:
278: /**
279: * Removes driver for operator classes.
280: * @param id Driver type to remove.
281: * @param operatorClasses Classes to remove driver for.
282: */
283: public static void removeDriver(String id, Class[] operatorClasses) {
284: for (int i = 0; i < operatorClasses.length; i++) {
285: removeDriver(id, operatorClasses[i]);
286: }
287: }
288:
289: /**
290: * Removes driver for operator classes.
291: * @param id Driver type to remove.
292: * @param operatorClassNames Names of operator classes.
293: */
294: public static void removeDriver(String id,
295: String[] operatorClassNames) {
296: for (int i = 0; i < operatorClassNames.length; i++) {
297: removeDriver(id, operatorClassNames[i]);
298: }
299: }
300:
301: /**
302: * Removes driver for all supported classes.
303: * @param id Driver type to remove.
304: */
305: public static void removeDrivers(String id) {
306: String[] keys = JemmyProperties.getCurrentKeys();
307: for (int i = 0; i < keys.length; i++) {
308: if (keys[i].startsWith(id)) {
309: JemmyProperties.removeCurrentProperty(keys[i]);
310: }
311: }
312: }
313:
314: /**
315: * Returns <code>TREE_DRIVER_ID</code> driver.
316: * @param operatorClass Class to find driver for.
317: * @return a driver
318: * @see #setTreeDriver
319: */
320: public static TreeDriver getTreeDriver(Class operatorClass) {
321: return ((TreeDriver) getDriver(TREE_DRIVER_ID, operatorClass));
322: }
323:
324: /**
325: * Returns <code>TREE_DRIVER_ID</code> driver.
326: * @param operator Operator to find driver for.
327: * @return a driver
328: * @see #setTreeDriver
329: */
330: public static TreeDriver getTreeDriver(ComponentOperator operator) {
331: return ((TreeDriver) getDriver(TREE_DRIVER_ID, operator
332: .getClass()));
333: }
334:
335: /**
336: * Defines <code>TREE_DRIVER_ID</code> driver.
337: * @param driver a driver
338: * @see #getTreeDriver
339: */
340: public static void setTreeDriver(TreeDriver driver) {
341: setDriver(TREE_DRIVER_ID, driver);
342: }
343:
344: /**
345: * Returns <code>TEXT_DRIVER_ID</code> driver.
346: * @param operatorClass Class to find driver for.
347: * @return a driver
348: * @see #setTextDriver
349: */
350: public static TextDriver getTextDriver(Class operatorClass) {
351: return ((TextDriver) getDriver(TEXT_DRIVER_ID, operatorClass));
352: }
353:
354: /**
355: * Returns <code>TEXT_DRIVER_ID</code> driver.
356: * @param operator Operator to find driver for.
357: * @return a driver
358: * @see #setTextDriver
359: */
360: public static TextDriver getTextDriver(ComponentOperator operator) {
361: return ((TextDriver) getDriver(TEXT_DRIVER_ID, operator
362: .getClass()));
363: }
364:
365: /**
366: * Defines <code>TEXT_DRIVER_ID</code> driver.
367: * @param driver a driver
368: * @see #getTextDriver
369: */
370: public static void setTextDriver(TextDriver driver) {
371: setDriver(TEXT_DRIVER_ID, driver);
372: }
373:
374: /**
375: * Returns <code>KEY_DRIVER_ID</code> driver.
376: * @param operatorClass Class to find driver for.
377: * @return a driver
378: * @see #setKeyDriver
379: */
380: public static KeyDriver getKeyDriver(Class operatorClass) {
381: return ((KeyDriver) getDriver(KEY_DRIVER_ID, operatorClass));
382: }
383:
384: /**
385: * Returns <code>KEY_DRIVER_ID</code> driver.
386: * @param operator Operator to find driver for.
387: * @return a driver
388: * @see #setKeyDriver
389: */
390: public static KeyDriver getKeyDriver(ComponentOperator operator) {
391: return ((KeyDriver) getDriver(KEY_DRIVER_ID, operator
392: .getClass()));
393: }
394:
395: /**
396: * Defines <code>KEY_DRIVER_ID</code> driver.
397: * @param driver a driver
398: * @see #getKeyDriver
399: */
400: public static void setKeyDriver(KeyDriver driver) {
401: setDriver(KEY_DRIVER_ID, driver);
402: }
403:
404: /**
405: * Returns <code>MOUSE_DRIVER_ID</code> driver.
406: * @param operatorClass Class to find driver for.
407: * @return a driver
408: * @see #setMouseDriver
409: */
410: public static MouseDriver getMouseDriver(Class operatorClass) {
411: return ((MouseDriver) getDriver(MOUSE_DRIVER_ID, operatorClass));
412: }
413:
414: /**
415: * Returns <code>MOUSE_DRIVER_ID</code> driver.
416: * @param operator Operator to find driver for.
417: * @return a driver
418: * @see #setMouseDriver
419: */
420: public static MouseDriver getMouseDriver(ComponentOperator operator) {
421: return ((MouseDriver) getDriver(MOUSE_DRIVER_ID, operator
422: .getClass()));
423: }
424:
425: /**
426: * Defines <code>MOUSE_DRIVER_ID</code> driver.
427: * @param driver a driver
428: * @see #getMouseDriver
429: */
430: public static void setMouseDriver(MouseDriver driver) {
431: setDriver(MOUSE_DRIVER_ID, driver);
432: }
433:
434: /**
435: * Returns <code>SCROLL_DRIVER_ID</code> driver.
436: * @param operatorClass Class to find driver for.
437: * @return a driver
438: * @see #setScrollDriver
439: */
440: public static ScrollDriver getScrollDriver(Class operatorClass) {
441: return ((ScrollDriver) getDriver(SCROLL_DRIVER_ID,
442: operatorClass));
443: }
444:
445: /**
446: * Returns <code>SCROLL_DRIVER_ID</code> driver.
447: * @param operator Operator to find driver for.
448: * @return a driver
449: * @see #setScrollDriver
450: */
451: public static ScrollDriver getScrollDriver(
452: ComponentOperator operator) {
453: return ((ScrollDriver) getDriver(SCROLL_DRIVER_ID, operator
454: .getClass()));
455: }
456:
457: /**
458: * Defines <code>SCROLL_DRIVER_ID</code> driver.
459: * @param driver a driver
460: * @see #getScrollDriver
461: */
462: public static void setScrollDriver(ScrollDriver driver) {
463: setDriver(SCROLL_DRIVER_ID, driver);
464: }
465:
466: /**
467: * Returns <code>BUTTON_DRIVER_ID</code> driver.
468: * @param operatorClass Class to find driver for.
469: * @return a driver
470: * @see #setButtonDriver
471: */
472: public static ButtonDriver getButtonDriver(Class operatorClass) {
473: return ((ButtonDriver) getDriver(BUTTON_DRIVER_ID,
474: operatorClass));
475: }
476:
477: /**
478: * Returns <code>BUTTON_DRIVER_ID</code> driver.
479: * @param operator Operator to find driver for.
480: * @return a driver
481: * @see #setButtonDriver
482: */
483: public static ButtonDriver getButtonDriver(
484: ComponentOperator operator) {
485: return ((ButtonDriver) getDriver(BUTTON_DRIVER_ID, operator
486: .getClass()));
487: }
488:
489: /**
490: * Defines <code>BUTTON_DRIVER_ID</code> driver.
491: * @param driver a driver
492: * @see #getButtonDriver
493: */
494: public static void setButtonDriver(ButtonDriver driver) {
495: setDriver(BUTTON_DRIVER_ID, driver);
496: }
497:
498: /**
499: * Returns <code>LIST_DRIVER_ID</code> driver.
500: * @param operatorClass Class to find driver for.
501: * @return a driver
502: * @see #setListDriver
503: */
504: public static ListDriver getListDriver(Class operatorClass) {
505: return ((ListDriver) getDriver(LIST_DRIVER_ID, operatorClass));
506: }
507:
508: /**
509: * Returns <code>LIST_DRIVER_ID</code> driver.
510: * @param operator Operator to find driver for.
511: * @return a driver
512: * @see #setListDriver
513: */
514: public static ListDriver getListDriver(ComponentOperator operator) {
515: return ((ListDriver) getDriver(LIST_DRIVER_ID, operator
516: .getClass()));
517: }
518:
519: /**
520: * Defines <code>LIST_DRIVER_ID</code> driver.
521: * @param driver a driver
522: * @see #getListDriver
523: */
524: public static void setListDriver(ListDriver driver) {
525: setDriver(LIST_DRIVER_ID, driver);
526: }
527:
528: /**
529: * Returns <code>MULTISELLIST_DRIVER_ID</code> driver.
530: * @param operatorClass Class to find driver for.
531: * @return a driver
532: * @see #setMultiSelListDriver
533: */
534: public static MultiSelListDriver getMultiSelListDriver(
535: Class operatorClass) {
536: return ((MultiSelListDriver) getDriver(MULTISELLIST_DRIVER_ID,
537: operatorClass));
538: }
539:
540: /**
541: * Returns <code>MULTISELLIST_DRIVER_ID</code> driver.
542: * @param operator Operator to find driver for.
543: * @return a driver
544: * @see #setMultiSelListDriver
545: */
546: public static MultiSelListDriver getMultiSelListDriver(
547: ComponentOperator operator) {
548: return ((MultiSelListDriver) getDriver(MULTISELLIST_DRIVER_ID,
549: operator.getClass()));
550: }
551:
552: /**
553: * Defines <code>MULTISELLIST_DRIVER_ID</code> driver.
554: * @param driver a driver
555: * @see #getMultiSelListDriver
556: */
557: public static void setMultiSelListDriver(MultiSelListDriver driver) {
558: setDriver(MULTISELLIST_DRIVER_ID, driver);
559: }
560:
561: /**
562: * Returns <code>ORDEREDLIST_DRIVER_ID</code> driver.
563: * @param operatorClass Class to find driver for.
564: * @return a driver
565: * @see #setOrderedListDriver
566: */
567: public static OrderedListDriver getOrderedListDriver(
568: Class operatorClass) {
569: return ((OrderedListDriver) getDriver(ORDEREDLIST_DRIVER_ID,
570: operatorClass));
571: }
572:
573: /**
574: * Returns <code>ORDEREDLIST_DRIVER_ID</code> driver.
575: * @param operator Operator to find driver for.
576: * @return a driver
577: * @see #setOrderedListDriver
578: */
579: public static OrderedListDriver getOrderedListDriver(
580: ComponentOperator operator) {
581: return ((OrderedListDriver) getDriver(ORDEREDLIST_DRIVER_ID,
582: operator.getClass()));
583: }
584:
585: /**
586: * Defines <code>ORDEREDLIST_DRIVER_ID</code> driver.
587: * @param driver a driver
588: * @see #getOrderedListDriver
589: */
590: public static void setOrderedListDriver(OrderedListDriver driver) {
591: setDriver(ORDEREDLIST_DRIVER_ID, driver);
592: }
593:
594: /**
595: * Returns <code>TABLE_DRIVER_ID</code> driver.
596: * @param operatorClass Class to find driver for.
597: * @return a driver
598: * @see #setTableDriver
599: */
600: public static TableDriver getTableDriver(Class operatorClass) {
601: return ((TableDriver) getDriver(TABLE_DRIVER_ID, operatorClass));
602: }
603:
604: /**
605: * Returns <code>TABLE_DRIVER_ID</code> driver.
606: * @param operator Operator to find driver for.
607: * @return a driver
608: * @see #setTableDriver
609: */
610: public static TableDriver getTableDriver(ComponentOperator operator) {
611: return ((TableDriver) getDriver(TABLE_DRIVER_ID, operator
612: .getClass()));
613: }
614:
615: /**
616: * Defines <code>TABLE_DRIVER_ID</code> driver.
617: * @param driver a driver
618: * @see #getTableDriver
619: */
620: public static void setTableDriver(TableDriver driver) {
621: setDriver(TABLE_DRIVER_ID, driver);
622: }
623:
624: /**
625: * Returns <code>WINDOW_DRIVER_ID</code> driver.
626: * @param operatorClass Class to find driver for.
627: * @return a driver
628: * @see #setWindowDriver
629: */
630: public static WindowDriver getWindowDriver(Class operatorClass) {
631: return ((WindowDriver) getDriver(WINDOW_DRIVER_ID,
632: operatorClass));
633: }
634:
635: /**
636: * Returns <code>WINDOW_DRIVER_ID</code> driver.
637: * @param operator Operator to find driver for.
638: * @return a driver
639: * @see #setWindowDriver
640: */
641: public static WindowDriver getWindowDriver(
642: ComponentOperator operator) {
643: return ((WindowDriver) getDriver(WINDOW_DRIVER_ID, operator
644: .getClass()));
645: }
646:
647: /**
648: * Defines <code>WINDOW_DRIVER_ID</code> driver.
649: * @param driver a driver
650: * @see #getWindowDriver
651: */
652: public static void setWindowDriver(WindowDriver driver) {
653: setDriver(WINDOW_DRIVER_ID, driver);
654: }
655:
656: /**
657: * Returns <code>FRAME_DRIVER_ID</code> driver.
658: * @param operatorClass Class to find driver for.
659: * @return a driver
660: * @see #setFrameDriver
661: */
662: public static FrameDriver getFrameDriver(Class operatorClass) {
663: return ((FrameDriver) getDriver(FRAME_DRIVER_ID, operatorClass));
664: }
665:
666: /**
667: * Returns <code>FRAME_DRIVER_ID</code> driver.
668: * @param operator Operator to find driver for.
669: * @return a driver
670: * @see #setFrameDriver
671: */
672: public static FrameDriver getFrameDriver(ComponentOperator operator) {
673: return ((FrameDriver) getDriver(FRAME_DRIVER_ID, operator
674: .getClass()));
675: }
676:
677: /**
678: * Defines <code>FRAME_DRIVER_ID</code> driver.
679: * @param driver a driver
680: * @see #getFrameDriver
681: */
682: public static void setFrameDriver(FrameDriver driver) {
683: setDriver(FRAME_DRIVER_ID, driver);
684: }
685:
686: /**
687: * Returns <code>INTERNAL_FRAME_DRIVER_ID</code> driver.
688: * @param operatorClass Class to find driver for.
689: * @return a driver
690: * @see #setInternalFrameDriver
691: */
692: public static InternalFrameDriver getInternalFrameDriver(
693: Class operatorClass) {
694: return ((InternalFrameDriver) getDriver(
695: INTERNAL_FRAME_DRIVER_ID, operatorClass));
696: }
697:
698: /**
699: * Returns <code>INTERNAL_FRAME_DRIVER_ID</code> driver.
700: * @param operator Operator to find driver for.
701: * @return a driver
702: * @see #setInternalFrameDriver
703: */
704: public static InternalFrameDriver getInternalFrameDriver(
705: ComponentOperator operator) {
706: return ((InternalFrameDriver) getDriver(
707: INTERNAL_FRAME_DRIVER_ID, operator.getClass()));
708: }
709:
710: /**
711: * Defines <code>INTERNAL_FRAME_DRIVER_ID</code> driver.
712: * @param driver a driver
713: * @see #getInternalFrameDriver
714: */
715: public static void setInternalFrameDriver(InternalFrameDriver driver) {
716: setDriver(INTERNAL_FRAME_DRIVER_ID, driver);
717: }
718:
719: /**
720: * Returns <code>FOCUS_DRIVER_ID</code> driver.
721: * @param operatorClass Class to find driver for.
722: * @return a driver
723: * @see #setFocusDriver
724: */
725: public static FocusDriver getFocusDriver(Class operatorClass) {
726: return ((FocusDriver) getDriver(FOCUS_DRIVER_ID, operatorClass));
727: }
728:
729: /**
730: * Returns <code>FOCUS_DRIVER_ID</code> driver.
731: * @param operator Operator to find driver for.
732: * @return a driver
733: * @see #setFocusDriver
734: */
735: public static FocusDriver getFocusDriver(ComponentOperator operator) {
736: return ((FocusDriver) getDriver(FOCUS_DRIVER_ID, operator
737: .getClass()));
738: }
739:
740: /**
741: * Defines <code>FOCUS_DRIVER_ID</code> driver.
742: * @param driver a driver
743: * @see #getFocusDriver
744: */
745: public static void setFocusDriver(FocusDriver driver) {
746: setDriver(FOCUS_DRIVER_ID, driver);
747: }
748:
749: /**
750: * Returns <code>MENU_DRIVER_ID</code> driver.
751: * @param operatorClass Class to find driver for.
752: * @return a driver
753: * @see #setMenuDriver
754: */
755: public static MenuDriver getMenuDriver(Class operatorClass) {
756: return ((MenuDriver) getDriver(MENU_DRIVER_ID, operatorClass));
757: }
758:
759: /**
760: * Returns <code>MENU_DRIVER_ID</code> driver.
761: * @param operator Operator to find driver for.
762: * @return a driver
763: * @see #setMenuDriver
764: */
765: public static MenuDriver getMenuDriver(ComponentOperator operator) {
766: return ((MenuDriver) getDriver(MENU_DRIVER_ID, operator
767: .getClass()));
768: }
769:
770: /**
771: * Defines <code>MENU_DRIVER_ID</code> driver.
772: * @param driver a driver
773: * @see #getMenuDriver
774: */
775: public static void setMenuDriver(MenuDriver driver) {
776: setDriver(MENU_DRIVER_ID, driver);
777: }
778:
779: static void setDriver(String id, Object driver) {
780: if (driver instanceof Driver) {
781: setDriver(id, (Driver) driver);
782: } else if (driver instanceof LightDriver) {
783: setDriver(id, (LightDriver) driver);
784: } else {
785: throw (new JemmyException(
786: "Driver is neither Driver nor LightDriver "
787: + driver.toString()));
788: }
789: }
790:
791: //creates driver id
792: private static String makeID(String id, Class operatorClass) {
793: return (makeID(id, operatorClass.getName()));
794: }
795:
796: private static String makeID(String id, String operatorClassName) {
797: return (id + "." + operatorClassName);
798: }
799:
800: //returns a driver
801: private static Object getADriver(String id, Class operatorClass,
802: JemmyProperties props) {
803: Class super Class = operatorClass;
804: Object drvr;
805: do {
806: drvr = props.getProperty(makeID(id, super Class));
807: if (drvr != null) {
808: return (drvr);
809: }
810: } while (ComponentOperator.class
811: .isAssignableFrom(super Class = super Class
812: .getSuperclass()));
813: return (null);
814: }
815:
816: static {
817: new InputDriverInstaller().install();
818: new DefaultDriverInstaller().install();
819: }
820: }
|