2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
14 package org.openhab.automation.jsscripting.internal.scriptengine;
16 import java.io.Reader;
18 import javax.script.Bindings;
19 import javax.script.Invocable;
20 import javax.script.ScriptContext;
21 import javax.script.ScriptEngine;
22 import javax.script.ScriptEngineFactory;
23 import javax.script.ScriptException;
26 * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
29 * @author Jonathan Gilbert - Initial contribution
31 public abstract class DelegatingScriptEngineWithInvocable<T extends ScriptEngine & Invocable>
32 implements ScriptEngine, Invocable {
35 public DelegatingScriptEngineWithInvocable(T delegate) {
36 this.delegate = delegate;
40 public Object eval(String s, ScriptContext scriptContext) throws ScriptException {
41 return delegate.eval(s, scriptContext);
45 public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
46 return delegate.eval(reader, scriptContext);
50 public Object eval(String s) throws ScriptException {
51 return delegate.eval(s);
55 public Object eval(Reader reader) throws ScriptException {
56 return delegate.eval(reader);
60 public Object eval(String s, Bindings bindings) throws ScriptException {
61 return delegate.eval(s, bindings);
65 public Object eval(Reader reader, Bindings bindings) throws ScriptException {
66 return delegate.eval(reader, bindings);
70 public void put(String s, Object o) {
75 public Object get(String s) {
76 return delegate.get(s);
80 public Bindings getBindings(int i) {
81 return delegate.getBindings(i);
85 public void setBindings(Bindings bindings, int i) {
86 delegate.setBindings(bindings, i);
90 public Bindings createBindings() {
91 return delegate.createBindings();
95 public ScriptContext getContext() {
96 return delegate.getContext();
100 public void setContext(ScriptContext scriptContext) {
101 delegate.setContext(scriptContext);
105 public ScriptEngineFactory getFactory() {
106 return delegate.getFactory();
110 public Object invokeMethod(Object o, String s, Object... objects) throws ScriptException, NoSuchMethodException {
111 return delegate.invokeMethod(o, s, objects);
115 public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException {
116 return delegate.invokeFunction(s, objects);
120 public <T> T getInterface(Class<T> aClass) {
121 return delegate.getInterface(aClass);
125 public <T> T getInterface(Object o, Class<T> aClass) {
126 return delegate.getInterface(o, aClass);