2 * Copyright (c) 2010-2022 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.groovyscripting.internal;
15 import java.util.List;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
19 import javax.script.ScriptEngine;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.automation.module.script.AbstractScriptEngineFactory;
24 import org.openhab.core.automation.module.script.ScriptEngineFactory;
25 import org.osgi.service.component.annotations.Component;
28 * This is an implementation of a {@link ScriptEngineFactory} for Groovy.
30 * @author Wouter Born - Initial contribution
32 @Component(service = ScriptEngineFactory.class)
34 public class GroovyScriptEngineFactory extends AbstractScriptEngineFactory {
36 private final org.codehaus.groovy.jsr223.GroovyScriptEngineFactory factory = new org.codehaus.groovy.jsr223.GroovyScriptEngineFactory();
38 private final List<String> scriptTypes = (List<String>) Stream.of(factory.getExtensions(), factory.getMimeTypes())
39 .flatMap(List::stream) //
40 .collect(Collectors.toUnmodifiableList());
43 public List<String> getScriptTypes() {
48 public @Nullable ScriptEngine createScriptEngine(String scriptType) {
49 return scriptTypes.contains(scriptType) ? factory.getScriptEngine() : null;