package ipreomobile core Created by Asterium on 11 02 2015 public clas

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package ipreomobile.core;
/**
* Created by Asterium on 11.02.2015.
*/
public class PageBuilderOptimusPrime {
public static <T> T getPage(java.lang.Class<T> pageClass){
return getTabletOrPhonePage(pageClass);
}
public static <T> T build(java.lang.Class<T> pageClass){
return getPage(pageClass);
}
private static <T> T getTabletOrPhonePage(java.lang.Class<T> baseClass) {
String simpleBaseClassName = baseClass.getSimpleName();
String requiredClassName;
switch (System.getProperty("test.browser")) {
case "chrome_tablet":
case "ipad":
case "ipad_simulator":
case "android_tablet":
requiredClassName = "T" + simpleBaseClassName;
break;
case "iphone":
case "iphone_simulator":
case "android_phone":
case "chrome_phone":
requiredClassName = "P" + simpleBaseClassName;
break;
default:
throw new Error("Unsupported browser: " + System.getProperty("test.browser"));
}
try {
String requiredClassFullName = baseClass.getName().replace(simpleBaseClassName, requiredClassName);
Class<?> requiredClass = Class.forName(requiredClassFullName);
return (T) requiredClass.newInstance();
} catch (ClassNotFoundException e) {
try {
return (T) baseClass.newInstance();
} catch (InstantiationException | IllegalAccessException e1) {
throw new Error("Cannot create page for base class' "+simpleBaseClassName+"':", e);
}
} catch (IllegalAccessException | InstantiationException e){
throw new Error("Cannot create page for concrete class' "+requiredClassName+"':", e);
}
}
}