Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.accumulo.shell.commands;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import org.apache.accumulo.shell.Shell;
import org.apache.accumulo.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
public class ScriptCommand extends Command {
// Command to allow user to run scripts, see JSR-223
// http://www.oracle.com/technetwork/articles/javase/scripting-140262.html
protected Option list, engine, script, file, args, out, function, object;
private static final String DEFAULT_ENGINE = "rhino";
@Override
public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
boolean invoke = false;
ScriptEngineManager mgr = new ScriptEngineManager();
if (cl.hasOption(list.getOpt())) {
listJSREngineInfo(mgr, shellState);
} else if (cl.hasOption(file.getOpt()) || cl.hasOption(script.getOpt())) {
String engineName = DEFAULT_ENGINE;
if (cl.hasOption(engine.getOpt())) {
engineName = cl.getOptionValue(engine.getOpt());
}
ScriptEngine engine = mgr.getEngineByName(engineName);
if (null == engine) {
shellState.printException(new Exception(engineName + " not found"));
return 1;
}
if (cl.hasOption(object.getOpt()) || cl.hasOption(function.getOpt())) {
if (!(engine instanceof Invocable)) {
shellState.printException(
new Exception(engineName + " does not support invoking functions or methods"));
return 1;
}
invoke = true;
}
ScriptContext ctx = new SimpleScriptContext();
// Put the following objects into the context so that they
// are available to the scripts
// TODO: What else should go in here?
Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE);
b.put("connection", shellState.getConnector());
List