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