List of usage examples for java.util ServiceLoader load
@CallerSensitive public static <S> ServiceLoader<S> load(Class<S> service)
From source file:org.commonjava.maven.cartographer.ftest.AbstractCartographerTCK.java
@Before public void before() throws Exception { final ServiceLoader<CartoTCKDriver> driverLoader = ServiceLoader.load(CartoTCKDriver.class); final Iterator<CartoTCKDriver> driverIter = driverLoader.iterator(); if (!driverIter.hasNext()) { throw new IllegalStateException("No TCK driver found!"); }/*from w ww .j ava 2s. co m*/ driver = driverIter.next(); carto = driver.start(temp); }
From source file:net.hamnaberg.rest.RESTClient.java
public RESTClient(HTTPCache cache, Option<String> username, Option<String> password) { Validate.notNull(cache, "Cache may not be null"); Validate.notNull(username, "Username option may not be null"); Validate.notNull(password, "password option may not be null"); if (username.isSome() && password.isSome()) { challenge = new UsernamePasswordChallenge(username.some(), password.some()); } else {/*from w ww . j a va 2 s .co m*/ challenge = null; } this.cache = cache; ServiceLoader<HandlerSpi> spis = ServiceLoader.load(HandlerSpi.class); for (HandlerSpi spi : spis) { registerHandler(spi.createHandler()); } }
From source file:org.forgerock.openidm.shell.impl.BasicCommandScope.java
/** * Produce help text.//from w w w . j a va 2 s.c o m * * @param session the command session. */ @Descriptor("Displays available commands.") public void help(CommandSession session) { ServiceLoader<CustomCommandScope> ldr = ServiceLoader.load(CustomCommandScope.class); PrintStream console = session.getConsole(); for (CustomCommandScope cmdScope : ldr) { String scope = cmdScope.getScope(); Map<String, String> functionMap = cmdScope.getFunctionMap(); if (StringUtils.isNotEmpty(scope) && functionMap != null) { int maxEntryLen = 0; for (Map.Entry<String, String> entry : functionMap.entrySet()) { int len = scope.length() + entry.getKey().length() + 4; // 4 for ':' +3 space maxEntryLen = len > maxEntryLen ? len : maxEntryLen; } StringBuilder spaceBuilder = new StringBuilder(); for (int i = 0; i < maxEntryLen; i++) { spaceBuilder.append(' '); } String spacer = spaceBuilder.toString(); for (Map.Entry<String, String> entry : functionMap.entrySet()) { String name = scope + ":" + entry.getKey(); String desc = entry.getValue(); console.append(LEAD_OPTION_SPACE).append(name) .append(spacer.substring(Math.min(name.length(), spacer.length()))).println(desc); } } } }
From source file:org.ops4j.pax.exam.forked.ForkedFrameworkFactoryTest.java
@Test public void forkEquinox() throws BundleException, IOException, InterruptedException, NotBoundException, URISyntaxException { ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class); FrameworkFactory frameworkFactory = loader.iterator().next(); ForkedFrameworkFactory forkedFactory = new ForkedFrameworkFactory(frameworkFactory); Map<String, Object> frameworkProperties = new HashMap<String, Object>(); frameworkProperties.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath()); RemoteFramework framework = forkedFactory.fork(Collections.<String>emptyList(), Collections.<String, String>emptyMap(), frameworkProperties); framework.start();//from w ww . ja v a 2 s .co m long bundleId = framework.installBundle("file:target/bundles/regression-pde-bundle-2.3.0.jar"); framework.startBundle(bundleId); framework.callService("(objectClass=org.ops4j.pax.exam.regression.pde.HelloService)", "getMessage"); Thread.sleep(3000); framework.stop(); forkedFactory.join(); }
From source file:org.apache.hadoop.gateway.deploy.impl.ShiroDeploymentContributorTest.java
@Test public void testServiceLoader() throws Exception { ServiceLoader loader = ServiceLoader.load(ProviderDeploymentContributor.class); Iterator iterator = loader.iterator(); assertThat("Service iterator empty.", iterator.hasNext()); while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof ShiroDeploymentContributor) { return; }/*from w w w .j a v a 2 s . c o m*/ } fail("Failed to find " + ShiroDeploymentContributor.class.getName() + " via service loader."); }
From source file:org.maodian.flyingcat.xmpp.XmppServer.java
private XmppServer preRun(ApplicationContext beanFactory) { GlobalContext ctx = beanFactory.getBean(GlobalContext.class); ServiceLoader<Extension> extLoader = ServiceLoader.load(Extension.class); for (Extension ext : extLoader) { ext.setBeanFactory(beanFactory); ext.register(ctx);//from w ww . j ava 2s . c o m } return this; }
From source file:eu.itesla_project.commons.tools.Main.java
private static Tool findTool(String commandName) { for (Tool tool : ServiceLoader.load(Tool.class)) { if (tool.getCommand().getName().equals(commandName)) { return tool; }// ww w .ja va 2s. c o m } return null; }
From source file:org.opencms.ui.contextmenu.CmsContextMenuItemProviderGroup.java
/** * Creates a new instance.<p>/* www .j a va2 s. c o m*/ */ public CmsContextMenuItemProviderGroup() { Iterator<I_CmsContextMenuItemProvider> providersIt = ServiceLoader.load(I_CmsContextMenuItemProvider.class) .iterator(); while (providersIt.hasNext()) { try { addProvider(providersIt.next()); } catch (Throwable t) { LOG.error("Error loading context menu provider from classpath.", t); } } }
From source file:org.apache.phoenix.util.InstanceResolver.java
private synchronized static <T> T resolveSingleton(Class<T> clazz, T defaultInstance) { ServiceLoader<T> loader = ServiceLoader.load(clazz); // returns the first registered instance found for (T singleton : loader) { return singleton; }// w w w.java2 s .c om return defaultInstance; }
From source file:au.edu.jcu.fascinator.portal.sso.shibboleth.roles.simple.SimpleShibbolethRoleManager.java
public SimpleShibbolethRoleManager() { try {/*from www . ja v a2 s. c o m*/ JsonSimpleConfig config = new JsonSimpleConfig(); cfg = config.getObject(SHIBBOLETH_PLUGIN_ID, SimpleShibbolethRoleManager.class.getSimpleName()); ServiceLoader<ShibSimpleRoleOperator> providers = ServiceLoader.load(ShibSimpleRoleOperator.class); for (ShibSimpleRoleOperator provider : providers) { operations.put(provider.getOperator(), provider); logger.trace(String.format("Loaded Simple Shibboleth Role Operation: %s as %s", provider.getOperator(), provider.getClass())); } } catch (IOException e) { logger.error(e.getMessage(), e); } }