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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package org.jemmy.lookup; 27 28 import org.jemmy.control.Wrap; 29 import org.jemmy.control.Wrapper; 30 import org.jemmy.env.Environment; 31 import org.jemmy.interfaces.Parent; 32 33 /** 34 * 35 * @param <T> 36 * @author shura 37 */ 38 public class ParentImpl<T> extends AbstractParent<T> { 39 40 private Class<T> type; 41 private ControlHierarchy ch; 42 private ControlList cl; 43 private Environment env; 44 private Wrapper wrapper; 45 46 /** 47 * 48 * @param env 49 * @param type 50 * @param ch 51 */ 52 public ParentImpl(Environment env, Class<T> type, ControlHierarchy ch) { 53 this(env, type, ch, Wrap.getWrapper()); 54 } 55 /** 56 * 57 * @param env 58 * @param type 59 * @param ch 60 * @param wrapper 61 */ 62 public ParentImpl(Environment env, Class<T> type, ControlHierarchy ch, Wrapper wrapper) { 63 this.type = type; 64 this.ch = ch; 65 this.env = env; 66 this.wrapper = wrapper; 67 } 68 69 /** 70 * 71 * @param env 72 * @param type 73 * @param cl 74 */ 75 public ParentImpl(Environment env, Class<T> type, ControlList cl) { 76 this(env, type, cl, Wrap.getWrapper()); 77 } 78 /** 79 * 80 * @param env 81 * @param type 82 * @param cl 83 * @param wrapper 84 */ 85 public ParentImpl(Environment env, Class<T> type, ControlList cl, Wrapper wrapper) { 86 this.type = type; 87 this.cl = cl; 88 this.env = env; 89 this.wrapper = wrapper; 90 } 91 92 public <ST extends T> Lookup<ST> lookup(Class<ST> controlClass, LookupCriteria<ST> criteria) { 93 if(ch != null) { 94 return new HierarchyLookup<ST>(env, ch, wrapper, controlClass, criteria); 95 } else if(cl != null) { 96 return new PlainLookup<ST>(env, cl, wrapper, controlClass, criteria); 97 } 98 throw new IllegalStateException(); 99 } 100 101 public Lookup<T> lookup(LookupCriteria<T> criteria) { 102 return lookup(type, criteria); 103 } 104 105 public Class<T> getType() { 106 return type; 107 } 108 109 }