@Test public void resolveScriptEngineWhenNoScriptEngineResolverIsPresent() throws InvalidSyntaxException { ScriptBindingsFactory mock = mock(ScriptBindingsFactory.class); TestOsgiScriptingEngines osgiScriptingEngines = new TestOsgiScriptingEngines(mock); BundleContext context = mock(BundleContext.class); osgiScriptingEngines.ctx = context; ScriptEngine scriptEngine = osgiScriptingEngines.resolveScriptEngine("foo"); assertThat(scriptEngine, is(nullValue())); }
ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; }
OsgiScriptingEngines extends ScriptingEngines { ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; } }
OsgiScriptingEngines extends ScriptingEngines { ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; } OsgiScriptingEngines(ScriptBindingsFactory scriptBindingsFactory); }
OsgiScriptingEngines extends ScriptingEngines { ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; } OsgiScriptingEngines(ScriptBindingsFactory scriptBindingsFactory); @Override ScriptEngine getScriptEngineForLanguage(String language); }
OsgiScriptingEngines extends ScriptingEngines { ScriptEngine resolveScriptEngine(String scriptEngineName) throws InvalidSyntaxException { Collection<ServiceReference<ScriptEngineResolver>> refs = getBundleContext().getServiceReferences( ScriptEngineResolver.class, null); if (refs == null) { LOGGER.info("No OSGi script engine resolvers available!"); return null; } LOGGER.fine("Found " + refs.size() + " OSGi ScriptEngineResolver services"); for (ServiceReference<ScriptEngineResolver> ref : refs) { ScriptEngineResolver resolver = getBundleContext().getService(ref); ScriptEngine engine = resolver .resolveScriptEngine(scriptEngineName); getBundleContext().ungetService(ref); LOGGER.fine("OSGi resolver " + resolver + " produced " + scriptEngineName + " engine " + engine); if (engine != null) { return engine; } } return null; } OsgiScriptingEngines(ScriptBindingsFactory scriptBindingsFactory); @Override ScriptEngine getScriptEngineForLanguage(String language);  }