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