1 /*
   2  * Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.jemmy.action;
  24 
  25 
  26 import org.jemmy.env.Environment;
  27 
  28 
  29 /**
  30  * An action to get some value.
  31  * @param <T> 
  32  * @author shura
  33  */
  34 public abstract class GetAction<T> extends Action {
  35 
  36     private boolean finished = false;
  37     private T result = null;
  38 
  39     /**
  40      *
  41      */
  42     public GetAction() {
  43     }
  44 
  45     /**
  46      *
  47      * @return
  48      */
  49     public boolean isFinished() {
  50         return finished;
  51     }
  52 
  53     /**
  54      *
  55      * @return
  56      */
  57     public T getResult() {
  58         return result;
  59     }
  60 
  61     /**
  62      *
  63      * @param result
  64      */
  65     protected void setResult(T result) {
  66         this.result = result;
  67         finished = true;
  68     }
  69 
  70     /**
  71      * Dispatches action through the system UI queue to get the result.
  72      * @param env Environment to
  73      * {@linkplain Environment#getExecutor() get} executor and to pass to
  74      * {@linkplain ActionExecutor#execute(org.jemmy.env.Environment, boolean, 
  75      * org.jemmy.action.Action, java.lang.Object[]) execute()} method.
  76      * @param parameters Parameters to pass to {@linkplain
  77      * #run(java.lang.Object[]) run()} method.
  78      * @return value returned by {@linkplain #getResult() getResult()} method.
  79      */
  80     public T dispatch(Environment env, Object... parameters) {
  81         env.getExecutor().execute(env, true, this, parameters);
  82         return getResult();
  83     }
  84 
  85 }