1/*2Copyright 2007-2010 Selenium committers3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12 */13package org.openqa.selenium.remote.html5;14import com.google.common.collect.ImmutableMap;15import com.google.common.collect.Iterables;16import com.google.common.collect.Lists;17import org.openqa.selenium.html5.DatabaseStorage;18import org.openqa.selenium.html5.ResultSet;19import org.openqa.selenium.html5.ResultSetRows;20import org.openqa.selenium.remote.AugmenterProvider;21import org.openqa.selenium.remote.DriverCommand;22import org.openqa.selenium.remote.ExecuteMethod;23import org.openqa.selenium.remote.InterfaceImplementation;24import org.openqa.selenium.remote.internal.WebElementToJsonConverter;25import java.lang.reflect.Method;26import java.util.List;27import java.util.Map;28public class AddDatabaseStorage implements AugmenterProvider {29 public Class<?> getDescribedInterface() {30 return DatabaseStorage.class;31 }32 public InterfaceImplementation getImplementation(Object value) {33 return new InterfaceImplementation() {34 public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {35 String databaseName = (String) args[0];36 String query = (String) args[1];37 Object[] arguments = (Object[]) args[2];38 query = query.replaceAll("\"", "\\\"");39 Iterable<Object> convertedArgs = Iterables.transform(40 Lists.newArrayList(arguments), new WebElementToJsonConverter());41 Map<String, ?> params = ImmutableMap.of(42 "dbName", databaseName,43 "query", query,44 "args", Lists.newArrayList(convertedArgs));45 Map<Object, Object> resultAsMap =46 (Map<Object, Object>) executeMethod.execute(DriverCommand.EXECUTE_SQL, params);47 ResultSet rs = new ResultSet(((Long) resultAsMap.get("insertId")).intValue(),48 ((Long) resultAsMap.get("rowsAffected")).intValue(),49 new ResultSetRows((List<Map<String, Object>>) resultAsMap.get("rows")));50 return rs;51 }52 };53 }54}...