Skip to content

Commit

Permalink
[bidi[java] Add local value types for script module
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Oct 26, 2023
1 parent 11f7b1a commit 11b4efe
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 0 deletions.
34 changes: 34 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/ArrayLocalValue.java
@@ -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 java/src/org/openqa/selenium/bidi/script/DateLocalValue.java
@@ -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);
}
}
23 changes: 23 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/LocalValue.java
@@ -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 java/src/org/openqa/selenium/bidi/script/MapLocalValue.java
@@ -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 java/src/org/openqa/selenium/bidi/script/ObjectLocalValue.java
@@ -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);
}
}
84 changes: 84 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/RegExpValue.java
@@ -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;
}
}
Expand Up @@ -40,6 +40,7 @@ public RemoteReference(RemoteReferenceType type, String value) {
}
}

@Override
public Map<String, Object> asMap() {
Map<String, String> toReturn = new TreeMap<>();
if (handle != null) {
Expand Down
35 changes: 35 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/SetLocalValue.java
@@ -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);
}
}

0 comments on commit 11b4efe

Please sign in to comment.