Skip to content

Commit 11b4efe

Browse files
committed
[bidi[java] Add local value types for script module
1 parent 11f7b1a commit 11b4efe

File tree

8 files changed

+300
-0
lines changed

8 files changed

+300
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.List;
20+
import java.util.Map;
21+
22+
public class ArrayLocalValue extends LocalValue {
23+
24+
private final List<LocalValue> value;
25+
26+
public ArrayLocalValue(List<LocalValue> value) {
27+
this.value = value;
28+
}
29+
30+
@Override
31+
public Map<String, Object> asMap() {
32+
return Map.of("type", "array", "value", value);
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.Map;
20+
21+
public class DateLocalValue extends LocalValue {
22+
23+
private final String value;
24+
25+
public DateLocalValue(String value) {
26+
this.value = value;
27+
}
28+
29+
@Override
30+
public Map<String, Object> asMap() {
31+
return Map.of("type", "date", "value", value);
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.Map;
20+
21+
public abstract class LocalValue {
22+
public abstract Map<String, Object> asMap();
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
public class MapLocalValue extends LocalValue {
24+
25+
private final Map<Object, LocalValue> map;
26+
27+
public MapLocalValue(Map<Object, LocalValue> map) {
28+
this.map = map;
29+
}
30+
31+
@Override
32+
public Map<String, Object> asMap() {
33+
List<List<Object>> value = new ArrayList<>();
34+
35+
map.forEach(
36+
(k, v) -> {
37+
List<Object> entry = new ArrayList<>();
38+
entry.add(k);
39+
entry.add(v);
40+
value.add(entry);
41+
});
42+
43+
return Map.of("type", "map", "value", value);
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
public class ObjectLocalValue extends LocalValue {
24+
25+
private final Map<Object, LocalValue> map;
26+
27+
public ObjectLocalValue(Map<Object, LocalValue> map) {
28+
this.map = map;
29+
}
30+
31+
@Override
32+
public Map<String, Object> asMap() {
33+
List<List<Object>> value = new ArrayList<>();
34+
35+
map.forEach(
36+
(k, v) -> {
37+
List<Object> entry = new ArrayList<>();
38+
entry.add(k);
39+
entry.add(v);
40+
value.add(entry);
41+
});
42+
43+
return Map.of("type", "object", "value", value);
44+
}
45+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
20+
import java.util.Map;
21+
import java.util.TreeMap;
22+
import org.openqa.selenium.json.JsonInput;
23+
24+
public class RegExpValue extends LocalValue {
25+
26+
private final String pattern;
27+
private String flags;
28+
29+
public RegExpValue(String pattern) {
30+
this.pattern = pattern;
31+
}
32+
33+
public RegExpValue(String pattern, String flags) {
34+
this.pattern = pattern;
35+
this.flags = flags;
36+
}
37+
38+
public static RegExpValue fromJson(JsonInput input) {
39+
String pattern = null;
40+
String flags = null;
41+
42+
input.beginObject();
43+
while (input.hasNext()) {
44+
switch (input.nextName()) {
45+
case "pattern":
46+
pattern = input.read(String.class);
47+
break;
48+
49+
case "flags":
50+
flags = input.read(String.class);
51+
break;
52+
53+
default:
54+
input.skipValue();
55+
break;
56+
}
57+
}
58+
59+
input.endObject();
60+
61+
return new RegExpValue(pattern, flags);
62+
}
63+
64+
@Override
65+
public Map<String, Object> asMap() {
66+
Map<String, Object> toReturn = new TreeMap<>();
67+
68+
toReturn.put("pattern", this.pattern);
69+
70+
if (flags != null) {
71+
toReturn.put("flags", this.flags);
72+
}
73+
74+
return Map.of("type", "regexp", "value", toReturn);
75+
}
76+
77+
public String getPattern() {
78+
return pattern;
79+
}
80+
81+
public String getFlags() {
82+
return flags;
83+
}
84+
}

java/src/org/openqa/selenium/bidi/script/RemoteReference.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public RemoteReference(RemoteReferenceType type, String value) {
4040
}
4141
}
4242

43+
@Override
4344
public Map<String, Object> asMap() {
4445
Map<String, String> toReturn = new TreeMap<>();
4546
if (handle != null) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License
17+
package org.openqa.selenium.bidi.script;
18+
19+
import java.util.Map;
20+
import java.util.Set;
21+
22+
public class SetLocalValue extends LocalValue {
23+
24+
private final Set<LocalValue> value;
25+
26+
public SetLocalValue(Set<LocalValue> value) {
27+
this.value = value;
28+
}
29+
30+
@Override
31+
public Map<String, Object> asMap() {
32+
33+
return Map.of("type", "set", "value", value);
34+
}
35+
}

0 commit comments

Comments
 (0)