2 * Copyright (c) 2010-2024 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
13 package org.openhab.automation.jsscripting.internal.scriptengine;
15 import java.io.Reader;
17 import javax.script.Bindings;
18 import javax.script.Invocable;
19 import javax.script.ScriptContext;
20 import javax.script.ScriptEngine;
21 import javax.script.ScriptEngineFactory;
22 import javax.script.ScriptException;
24 import org.eclipse.jdt.annotation.NonNull;
27 * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
30 * @author Jonathan Gilbert - Initial contribution
32 public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable<T extends ScriptEngine & Invocable & AutoCloseable>
33 implements ScriptEngine, Invocable, AutoCloseable {
34 protected @NonNull T delegate;
36 public DelegatingScriptEngineWithInvocableAndAutocloseable(@NonNull T delegate) {
37 this.delegate = delegate;
41 public Object eval(String s, ScriptContext scriptContext) throws ScriptException {
42 return delegate.eval(s, scriptContext);
46 public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
47 return delegate.eval(reader, scriptContext);
51 public Object eval(String s) throws ScriptException {
52 return delegate.eval(s);
56 public Object eval(Reader reader) throws ScriptException {
57 return delegate.eval(reader);
61 public Object eval(String s, Bindings bindings) throws ScriptException {
62 return delegate.eval(s, bindings);
66 public Object eval(Reader reader, Bindings bindings) throws ScriptException {
67 return delegate.eval(reader, bindings);
71 public void put(String s, Object o) {
76 public Object get(String s) {
77 return delegate.get(s);
81 public Bindings getBindings(int i) {
82 return delegate.getBindings(i);
86 public void setBindings(Bindings bindings, int i) {
87 delegate.setBindings(bindings, i);
91 public Bindings createBindings() {
92 return delegate.createBindings();
96 public ScriptContext getContext() {
97 return delegate.getContext();
101 public void setContext(ScriptContext scriptContext) {
102 delegate.setContext(scriptContext);
106 public ScriptEngineFactory getFactory() {
107 return delegate.getFactory();
111 public Object invokeMethod(Object o, String s, Object... objects)
112 throws ScriptException, NoSuchMethodException, IllegalArgumentException {
113 return delegate.invokeMethod(o, s, objects);
117 public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException {
118 return delegate.invokeFunction(s, objects);
122 public <T> T getInterface(Class<T> aClass) {
123 return delegate.getInterface(aClass);
127 public <T> T getInterface(Object o, Class<T> aClass) {
128 return delegate.getInterface(o, aClass);
132 public void close() throws Exception {