Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi[java] Add local value types for script module
- Loading branch information
Showing
8 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
java/src/org/openqa/selenium/bidi/script/ArrayLocalValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ArrayLocalValue extends LocalValue { | ||
|
||
private final List<LocalValue> value; | ||
|
||
public ArrayLocalValue(List<LocalValue> value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
return Map.of("type", "array", "value", value); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
java/src/org/openqa/selenium/bidi/script/DateLocalValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.Map; | ||
|
||
public class DateLocalValue extends LocalValue { | ||
|
||
private final String value; | ||
|
||
public DateLocalValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
return Map.of("type", "date", "value", value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class LocalValue { | ||
public abstract Map<String, Object> asMap(); | ||
} |
45 changes: 45 additions & 0 deletions
45
java/src/org/openqa/selenium/bidi/script/MapLocalValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MapLocalValue extends LocalValue { | ||
|
||
private final Map<Object, LocalValue> map; | ||
|
||
public MapLocalValue(Map<Object, LocalValue> map) { | ||
this.map = map; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
List<List<Object>> value = new ArrayList<>(); | ||
|
||
map.forEach( | ||
(k, v) -> { | ||
List<Object> entry = new ArrayList<>(); | ||
entry.add(k); | ||
entry.add(v); | ||
value.add(entry); | ||
}); | ||
|
||
return Map.of("type", "map", "value", value); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
java/src/org/openqa/selenium/bidi/script/ObjectLocalValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ObjectLocalValue extends LocalValue { | ||
|
||
private final Map<Object, LocalValue> map; | ||
|
||
public ObjectLocalValue(Map<Object, LocalValue> map) { | ||
this.map = map; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
List<List<Object>> value = new ArrayList<>(); | ||
|
||
map.forEach( | ||
(k, v) -> { | ||
List<Object> entry = new ArrayList<>(); | ||
entry.add(k); | ||
entry.add(v); | ||
value.add(entry); | ||
}); | ||
|
||
return Map.of("type", "object", "value", value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import org.openqa.selenium.json.JsonInput; | ||
|
||
public class RegExpValue extends LocalValue { | ||
|
||
private final String pattern; | ||
private String flags; | ||
|
||
public RegExpValue(String pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
public RegExpValue(String pattern, String flags) { | ||
this.pattern = pattern; | ||
this.flags = flags; | ||
} | ||
|
||
public static RegExpValue fromJson(JsonInput input) { | ||
String pattern = null; | ||
String flags = null; | ||
|
||
input.beginObject(); | ||
while (input.hasNext()) { | ||
switch (input.nextName()) { | ||
case "pattern": | ||
pattern = input.read(String.class); | ||
break; | ||
|
||
case "flags": | ||
flags = input.read(String.class); | ||
break; | ||
|
||
default: | ||
input.skipValue(); | ||
break; | ||
} | ||
} | ||
|
||
input.endObject(); | ||
|
||
return new RegExpValue(pattern, flags); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
Map<String, Object> toReturn = new TreeMap<>(); | ||
|
||
toReturn.put("pattern", this.pattern); | ||
|
||
if (flags != null) { | ||
toReturn.put("flags", this.flags); | ||
} | ||
|
||
return Map.of("type", "regexp", "value", toReturn); | ||
} | ||
|
||
public String getPattern() { | ||
return pattern; | ||
} | ||
|
||
public String getFlags() { | ||
return flags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
java/src/org/openqa/selenium/bidi/script/SetLocalValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License | ||
package org.openqa.selenium.bidi.script; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class SetLocalValue extends LocalValue { | ||
|
||
private final Set<LocalValue> value; | ||
|
||
public SetLocalValue(Set<LocalValue> value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
|
||
return Map.of("type", "set", "value", value); | ||
} | ||
} |