18
18
19
19
import java .util .List ;
20
20
import java .util .Objects ;
21
+ import java .util .logging .Level ;
22
+ import org .openqa .selenium .internal .Require ;
21
23
import org .openqa .selenium .json .JsonInput ;
22
24
23
25
public class SeleniumManagerOutput {
24
26
25
- public List <Log > logs ;
26
- public Result result ;
27
+ private List <Log > logs ;
28
+ private Result result ;
27
29
28
30
public List <Log > getLogs () {
29
31
return logs ;
@@ -42,43 +44,76 @@ public void setResult(Result result) {
42
44
}
43
45
44
46
public static class Log {
45
- public String level ;
46
- long timestamp ;
47
- public String message ;
47
+ private final Level level ;
48
+ private final long timestamp ;
49
+ private final String message ;
48
50
49
- public String getLevel () {
50
- return level ;
51
+ public Log (Level level , long timestamp , String message ) {
52
+ this .level = Require .nonNull ("level" , level );
53
+ this .timestamp = timestamp ;
54
+ this .message = Require .nonNull ("message" , message );
51
55
}
52
56
53
- public void setLevel ( String level ) {
54
- this . level = level ;
57
+ public Level getLevel ( ) {
58
+ return level ;
55
59
}
56
60
57
61
public long getTimestamp () {
58
62
return timestamp ;
59
63
}
60
64
61
- public void setTimestamp (long timestamp ) {
62
- this .timestamp = timestamp ;
63
- }
64
-
65
65
public String getMessage () {
66
66
return message ;
67
67
}
68
68
69
- public void setMessage (String message ) {
70
- this .message = message ;
69
+ private static Log fromJson (JsonInput input ) {
70
+ Level level = Level .FINE ;
71
+ long timestamp = System .currentTimeMillis ();
72
+ String message = "" ;
73
+
74
+ input .beginObject ();
75
+ while (input .hasNext ()) {
76
+ switch (input .nextName ()) {
77
+ case "level" :
78
+ switch (input .nextString ().toLowerCase ()) {
79
+ case "error" :
80
+ case "warn" :
81
+ level = Level .WARNING ;
82
+ break ;
83
+
84
+ case "info" :
85
+ level = Level .INFO ;
86
+ break ;
87
+
88
+ default :
89
+ level = Level .FINE ;
90
+ break ;
91
+ }
92
+ break ;
93
+
94
+ case "timestamp" :
95
+ timestamp = input .nextNumber ().longValue ();
96
+ break ;
97
+
98
+ case "message" :
99
+ message = input .nextString ();
100
+ break ;
101
+ }
102
+ }
103
+ input .endObject ();
104
+
105
+ return new Log (level , timestamp , message );
71
106
}
72
107
}
73
108
74
109
public static class Result {
75
- public int code ;
76
- public String message ;
77
- public String driverPath ;
78
- public String browserPath ;
110
+ private final int code ;
111
+ private final String message ;
112
+ private final String driverPath ;
113
+ private final String browserPath ;
79
114
80
115
public Result (String driverPath ) {
81
- this . driverPath = driverPath ;
116
+ this ( 0 , null , driverPath , null ) ;
82
117
}
83
118
84
119
public Result (int code , String message , String driverPath , String browserPath ) {
@@ -92,34 +127,18 @@ public int getCode() {
92
127
return code ;
93
128
}
94
129
95
- public void setCode (int code ) {
96
- this .code = code ;
97
- }
98
-
99
130
public String getMessage () {
100
131
return message ;
101
132
}
102
133
103
- public void setMessage (String message ) {
104
- this .message = message ;
105
- }
106
-
107
134
public String getDriverPath () {
108
135
return driverPath ;
109
136
}
110
137
111
- public void setDriverPath (String driverPath ) {
112
- this .driverPath = driverPath ;
113
- }
114
-
115
138
public String getBrowserPath () {
116
139
return browserPath ;
117
140
}
118
141
119
- public void setBrowserPath (String browserPath ) {
120
- this .browserPath = browserPath ;
121
- }
122
-
123
142
@ Override
124
143
public String toString () {
125
144
return "Result{"
@@ -154,7 +173,7 @@ public int hashCode() {
154
173
return Objects .hash (code , message , driverPath , browserPath );
155
174
}
156
175
157
- public static Result fromJson (JsonInput input ) {
176
+ private static Result fromJson (JsonInput input ) {
158
177
int code = 0 ;
159
178
String message = null ;
160
179
String driverPath = null ;
0 commit comments