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 
  24 package org.jemmy.lookup;
  25 
  26 import org.jemmy.control.Wrap;
  27 import org.jemmy.control.Wrapper;
  28 import org.jemmy.env.Environment;
  29 import org.jemmy.interfaces.Parent;
  30 
  31 /**
  32  *
  33  * @param <T>
  34  * @author shura
  35  */
  36 public class ParentImpl<T> extends AbstractParent<T> {
  37 
  38     private Class<T> type;
  39     private ControlHierarchy ch;
  40     private ControlList cl;
  41     private Environment env;
  42     private Wrapper wrapper;
  43 
  44     /**
  45      *
  46      * @param env
  47      * @param type
  48      * @param ch
  49      */
  50     public ParentImpl(Environment env, Class<T> type, ControlHierarchy ch) {
  51         this(env, type, ch, Wrap.getWrapper());
  52     }
  53     /**
  54      *
  55      * @param env
  56      * @param type
  57      * @param ch
  58      * @param wrapper
  59      */
  60     public ParentImpl(Environment env, Class<T> type, ControlHierarchy ch, Wrapper wrapper) {
  61         this.type = type;
  62         this.ch = ch;
  63         this.env = env;
  64         this.wrapper = wrapper;
  65     }
  66 
  67     /**
  68      *
  69      * @param env
  70      * @param type
  71      * @param cl
  72      */
  73     public ParentImpl(Environment env, Class<T> type, ControlList cl) {
  74         this(env, type, cl, Wrap.getWrapper());
  75     }
  76     /**
  77      *
  78      * @param env
  79      * @param type
  80      * @param cl
  81      * @param wrapper
  82      */
  83     public ParentImpl(Environment env, Class<T> type, ControlList cl, Wrapper wrapper) {
  84         this.type = type;
  85         this.cl = cl;
  86         this.env = env;
  87         this.wrapper = wrapper;
  88     }
  89 
  90     public <ST extends T> Lookup<ST> lookup(Class<ST> controlClass, LookupCriteria<ST> criteria) {
  91         if(ch != null) {
  92             return new HierarchyLookup<ST>(env, ch, wrapper, controlClass, criteria);
  93         } else if(cl != null) {
  94             return new PlainLookup<ST>(env, cl, wrapper, controlClass, criteria);
  95         }
  96         throw new IllegalStateException();
  97     }
  98 
  99     public Lookup<T> lookup(LookupCriteria<T> criteria) {
 100         return lookup(type, criteria);
 101     }
 102 
 103     public Class<T> getType() {
 104         return type;
 105     }
 106 
 107 }