]> git.basschouten.com Git - openhab-addons.git/blob
7e00c6af11797999856faa02ace3c630c77b613e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.jsscripting.internal.scriptengine;
14
15 import java.io.Reader;
16
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;
23
24 import org.eclipse.jdt.annotation.NonNull;
25
26 /**
27  * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific
28  * methods.
29  *
30  * @author Jonathan Gilbert - Initial contribution
31  */
32 public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable<T extends ScriptEngine & Invocable & AutoCloseable>
33         implements ScriptEngine, Invocable, AutoCloseable {
34     protected @NonNull T delegate;
35
36     public DelegatingScriptEngineWithInvocableAndAutocloseable(@NonNull T delegate) {
37         this.delegate = delegate;
38     }
39
40     @Override
41     public Object eval(String s, ScriptContext scriptContext) throws ScriptException {
42         return delegate.eval(s, scriptContext);
43     }
44
45     @Override
46     public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
47         return delegate.eval(reader, scriptContext);
48     }
49
50     @Override
51     public Object eval(String s) throws ScriptException {
52         return delegate.eval(s);
53     }
54
55     @Override
56     public Object eval(Reader reader) throws ScriptException {
57         return delegate.eval(reader);
58     }
59
60     @Override
61     public Object eval(String s, Bindings bindings) throws ScriptException {
62         return delegate.eval(s, bindings);
63     }
64
65     @Override
66     public Object eval(Reader reader, Bindings bindings) throws ScriptException {
67         return delegate.eval(reader, bindings);
68     }
69
70     @Override
71     public void put(String s, Object o) {
72         delegate.put(s, o);
73     }
74
75     @Override
76     public Object get(String s) {
77         return delegate.get(s);
78     }
79
80     @Override
81     public Bindings getBindings(int i) {
82         return delegate.getBindings(i);
83     }
84
85     @Override
86     public void setBindings(Bindings bindings, int i) {
87         delegate.setBindings(bindings, i);
88     }
89
90     @Override
91     public Bindings createBindings() {
92         return delegate.createBindings();
93     }
94
95     @Override
96     public ScriptContext getContext() {
97         return delegate.getContext();
98     }
99
100     @Override
101     public void setContext(ScriptContext scriptContext) {
102         delegate.setContext(scriptContext);
103     }
104
105     @Override
106     public ScriptEngineFactory getFactory() {
107         return delegate.getFactory();
108     }
109
110     @Override
111     public Object invokeMethod(Object o, String s, Object... objects)
112             throws ScriptException, NoSuchMethodException, IllegalArgumentException {
113         return delegate.invokeMethod(o, s, objects);
114     }
115
116     @Override
117     public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException {
118         return delegate.invokeFunction(s, objects);
119     }
120
121     @Override
122     public <T> T getInterface(Class<T> aClass) {
123         return delegate.getInterface(aClass);
124     }
125
126     @Override
127     public <T> T getInterface(Object o, Class<T> aClass) {
128         return delegate.getInterface(o, aClass);
129     }
130
131     @Override
132     public void close() throws Exception {
133         delegate.close();
134     }
135 }