2 * Copyright (c) 2010-2023 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;
25 import org.eclipse.jdt.annotation.NonNull;
28 * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
31 * @author Jonathan Gilbert - Initial contribution
33 public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable<T extends ScriptEngine & Invocable & AutoCloseable>
34 implements ScriptEngine, Invocable, AutoCloseable {
35 protected @NonNull T delegate;
37 public DelegatingScriptEngineWithInvocableAndAutocloseable(@NonNull T delegate) {
38 this.delegate = delegate;
42 public Object eval(String s, ScriptContext scriptContext) throws ScriptException {
43 return delegate.eval(s, scriptContext);
47 public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
48 return delegate.eval(reader, scriptContext);
52 public Object eval(String s) throws ScriptException {
53 return delegate.eval(s);
57 public Object eval(Reader reader) throws ScriptException {
58 return delegate.eval(reader);
62 public Object eval(String s, Bindings bindings) throws ScriptException {
63 return delegate.eval(s, bindings);
67 public Object eval(Reader reader, Bindings bindings) throws ScriptException {
68 return delegate.eval(reader, bindings);
72 public void put(String s, Object o) {
77 public Object get(String s) {
78 return delegate.get(s);
82 public Bindings getBindings(int i) {
83 return delegate.getBindings(i);
87 public void setBindings(Bindings bindings, int i) {
88 delegate.setBindings(bindings, i);
92 public Bindings createBindings() {
93 return delegate.createBindings();
97 public ScriptContext getContext() {
98 return delegate.getContext();
102 public void setContext(ScriptContext scriptContext) {
103 delegate.setContext(scriptContext);
107 public ScriptEngineFactory getFactory() {
108 return delegate.getFactory();
112 public Object invokeMethod(Object o, String s, Object... objects)
113 throws ScriptException, NoSuchMethodException, IllegalArgumentException {
114 return delegate.invokeMethod(o, s, objects);
118 public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException {
119 return delegate.invokeFunction(s, objects);
123 public <T> T getInterface(Class<T> aClass) {
124 return delegate.getInterface(aClass);
128 public <T> T getInterface(Object o, Class<T> aClass) {
129 return delegate.getInterface(o, aClass);
133 public void close() throws Exception {