001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat <tdelprat@nuxeo.com>
016 */
017package org.nuxeo.automation.scripting.api;
018
019import java.io.InputStream;
020
021import javax.script.ScriptException;
022
023import org.nuxeo.automation.scripting.internals.ScriptOperationContext;
024import org.nuxeo.ecm.automation.OperationException;
025import org.nuxeo.ecm.core.api.CoreSession;
026
027/**
028 * @since 7.2
029 */
030public interface AutomationScriptingService {
031
032    /**
033     * @since 7.3
034     */
035    void setOperationContext(ScriptOperationContext ctx);
036
037    /**
038     * @return The default JS binding wrapper injected into Nashorn.
039     */
040    String getJSWrapper() throws OperationException;
041
042    /**
043     * Run Automation Scripting with given 'JavaScript' InputStream and CoreSession.
044     * @param in
045     * @param session
046     * @throws ScriptException
047     */
048    void run(InputStream in, CoreSession session) throws ScriptException, OperationException;
049
050    /**
051     * Run Automation Scripting for a given 'JavaScript' script and CoreSession.
052     * @param script
053     * @param session
054     * @throws ScriptException
055     */
056    void run(String script, CoreSession session) throws ScriptException, OperationException;
057
058    /**
059     * @param scriptingOperationInterface
060     * @param script
061     * @param session
062     * @param <T>
063     * @return
064     * @throws ScriptException
065     */
066    <T> T getInterface(Class<T> scriptingOperationInterface, String script,
067            CoreSession session) throws ScriptException, OperationException;
068
069}