List of usage examples for java.util ServiceLoader iterator
public Iterator<S> iterator()
From source file:datascript.tools.DataScriptTool.java
private void printExtensions() { ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class); Iterator<Extension> it = loader.iterator(); while (it.hasNext()) { Extension ext = it.next(); System.out.println("Extension: " + ext.getClass().getName()); }//from w ww. j a v a 2 s . c o m }
From source file:org.powertac.customer.CustomerModelService.java
@Override public String initialize(Competition competition, List<String> completedInits) { if (!completedInits.contains("DefaultBroker") || !completedInits.contains("TariffMarket")) return null; super.init(); tariffMarketService.registerNewTariffListener(this); //modelTypes = new ArrayList<Class<AbstractCustomerDeprecated>>(); models = new ArrayList<AbstractCustomer>(); // extract the model types ServiceLoader<AbstractCustomer> loader = ServiceLoader.load(AbstractCustomer.class); // Populate and initialize the models. // Note that the instances loaded by the service loader are discarded -- // the real instances are created by serverConfig. Iterator<AbstractCustomer> modelIterator = loader.iterator(); while (modelIterator.hasNext()) { AbstractCustomer modelEx = modelIterator.next(); for (Object modelObj : serverConfig.configureInstances(modelEx.getClass())) { AbstractCustomer model = (AbstractCustomer) modelObj; models.add(model);/*from w ww.ja v a 2 s .co m*/ model.setServiceAccessor(this); model.initialize(); // set default tariff here to make models testable outside Spring. for (CustomerInfo cust : model.getCustomerInfos()) { tariffMarketService.subscribeToTariff(tariffMarketService.getDefaultTariff(cust.getPowerType()), cust, cust.getPopulation()); customerRepo.add(cust); } } } return "Customer"; }
From source file:datascript.tools.DataScriptTool.java
/** * Installs all extensions that are configured in the services manifest and * detects all options of each extension installed. * /*from w ww . j av a2s . co m*/ * @throws IOException * @throws InstantiationException * @throws IllegalAccessException */ private void prepareExtensions() { ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class, getClass().getClassLoader()); Iterator<Extension> it = loader.iterator(); while (it.hasNext()) { Extension extension = it.next(); extensions.add(extension); extension.getOptions(rdsOptionsToAccept); extension.setParameters(this); } }
From source file:datascript.instance.DataScriptInstanceTool.java
private void prepareExtensions(String[] args) throws IOException, InstantiationException, IllegalAccessException { if (cli == null) return;//from w w w . j ava2s . c om // normalize slashes and backslashes fileName = new File(args[args.length - 1]).getPath(); extensions = new ArrayList<Extension>(); ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class); Iterator<Extension> it = loader.iterator(); while (it.hasNext()) { Extension extension = it.next(); extensions.add(extension); extension.getOptions(rdsOptions); } CmdLineParser parser = new CmdLineParser(); try { cli = parser.parse(rdsOptions, args, false); } catch (ParseException pe) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(pe.getMessage(), rdsOptions); } for (Extension extension : extensions) { extension.setParameters(this); } }
From source file:edu.mayo.cts2.framework.core.plugin.FelixPluginManager.java
protected void initializeNonOsgiPlugins() { ServiceLoader<NonOsgiPluginInitializer> serviceLoader = ServiceLoader.load(NonOsgiPluginInitializer.class); Iterator<NonOsgiPluginInitializer> itr = serviceLoader.iterator(); while (itr.hasNext()) { NonOsgiPluginInitializer pluginInitializer = itr.next(); pluginInitializer.initialize(this); this.nonOsgiPlugins.add(pluginInitializer); }// ww w . j av a 2s. c o m }
From source file:net.sourceforge.pmd.lang.LanguageRegistry.java
private LanguageRegistry() { List<Language> languagesList = new ArrayList<>(); // Use current class' classloader instead of the threads context classloader, see https://github.com/pmd/pmd/issues/1377 ServiceLoader<Language> languageLoader = ServiceLoader.load(Language.class, getClass().getClassLoader()); Iterator<Language> iterator = languageLoader.iterator(); while (iterator.hasNext()) { try {//from w w w . j a v a 2 s . c o m Language language = iterator.next(); languagesList.add(language); } catch (UnsupportedClassVersionError e) { // Some languages require java8 and are therefore only available // if java8 or later is used as runtime. System.err.println("Ignoring language for PMD: " + e.toString()); } } // sort languages by terse name. Avoiding differences in the order of languages // across JVM versions / OS. Collections.sort(languagesList, new Comparator<Language>() { @Override public int compare(Language o1, Language o2) { return o1.getTerseName().compareToIgnoreCase(o2.getTerseName()); } }); // using a linked hash map to maintain insertion order languages = new LinkedHashMap<>(); for (Language language : languagesList) { languages.put(language.getName(), language); } }
From source file:org.acmsl.queryj.tools.QueryJChain.java
/** * Fills given chain with external template bundles. * @param chain the chain./*from w w w .j a v a 2 s . co m*/ * @throws QueryJBuildException if the handlers cannot be retrieved. */ @SuppressWarnings("unchecked") protected void fillTemplateHandlers(@NotNull final Chain<QueryJCommand, QueryJBuildException, CH> chain) throws QueryJBuildException { // Don't know how to fix the generics warnings @NotNull final ServiceLoader<TemplateChainProvider> loader = ServiceLoader.load(TemplateChainProvider.class); if (loader.iterator().hasNext()) { // Don't know how to fix the generics warnings @NotNull final TemplateChainProvider provider = loader.iterator().next(); // Don't know how to fix the generics warnings for (@Nullable final TemplateHandler<?> handler : (List<TemplateHandler<?>>) provider.getHandlers()) { if (handler != null) { chain.add((CH) handler); } } } else { throw new CannotFindTemplatesException(TemplateChainProvider.class); } }
From source file:org.apache.ace.agent.launcher.Launcher.java
/** * Load {@link BundleProvider}s through the {@link ServiceLoader}. * //from w w w . j av a 2 s .c o m * @return list of providers * @throws Exception * on failure */ private BundleProvider[] loadBundleProviders() throws Exception { ServiceLoader<BundleProvider> bundleFactoryLoader = ServiceLoader.load(BundleProvider.class); Iterator<BundleProvider> bundleFactoryIterator = bundleFactoryLoader.iterator(); List<BundleProvider> bundleFactoryList = new ArrayList<>(); while (bundleFactoryIterator.hasNext()) { bundleFactoryList.add(bundleFactoryIterator.next()); } return bundleFactoryList.toArray(new BundleProvider[bundleFactoryList.size()]); }
From source file:org.apache.ace.agent.launcher.Launcher.java
private FrameworkFactory loadFrameworkFactory() throws IllegalStateException { ServiceLoader<FrameworkFactory> frameworkFactoryLoader = ServiceLoader.load(FrameworkFactory.class); Iterator<FrameworkFactory> frameworkFactoryIterator = frameworkFactoryLoader.iterator(); if (!frameworkFactoryIterator.hasNext()) { throw new IllegalStateException("Unable to load any FrameworkFactory"); }/*from w w w . j a v a2s .c om*/ return frameworkFactoryIterator.next(); }
From source file:org.apache.geronimo.mavenplugins.car.AbstractCarMojo.java
protected Framework getFramework(String extraPackages) throws BundleException { setLoggingLevel();/*from w ww.j a v a2 s .c o m*/ Map<String, String> properties = new HashMap<String, String>(); // properties.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); // The following set of packages are the ones that will be exported by the // framework bundle from the core system. We need to explicitly specify // these to give explicit versions to many of the javax.* packages so that // they'll match any of the versions exported by the Geronimo spec jars. // This list and the version numbers needs to be synchronized with the list // in the karaf framework config.properties file. properties.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.6.0," + "org.osgi.framework.launch; version=1.0.0," + "org.osgi.framework.startlevel; version=1.0.0," + "org.osgi.framework.wiring; version=1.0.0," + "org.osgi.framework.hooks.service; version=1.1.0," + "org.osgi.framework.hooks.bundle; version=1.0.0," + "org.osgi.framework.hooks.resolver; version=1.0.0," + "org.osgi.framework.hooks.weaving; version=1.0.0," + "org.osgi.service.packageadmin; version=1.2.0," + "org.osgi.service.startlevel; version=1.1.0," + "org.osgi.service.url; version=1.0.0," + "org.osgi.util.tracker; version=1.5.0," + "javax.accessibility," + "javax.annotation.processing," + "javax.activity," + "javax.crypto," + "javax.crypto.interfaces," + "javax.crypto.spec," + "javax.imageio," + "javax.imageio.event," + "javax.imageio.metadata," + "javax.imageio.plugins.bmp," + "javax.imageio.plugins.jpeg," + "javax.imageio.spi," + "javax.imageio.stream," + "javax.jws;version=2.0," + "javax.jws.soap;version=2.0," + "javax.lang.model," + "javax.lang.model.element," + "javax.lang.model.type," + "javax.lang.model.util," + "javax.management," + "javax.management.loading," + "javax.management.modelmbean," + "javax.management.monitor," + "javax.management.openmbean," + "javax.management.relation," + "javax.management.remote," + "javax.management.remote.rmi," + "javax.management.timer," + "javax.naming," + "javax.naming.directory," + "javax.naming.event," + "javax.naming.ldap," + "javax.naming.spi," + "javax.net," + "javax.net.ssl," + "javax.print," + "javax.print.attribute," + "javax.print.attribute.standard," + "javax.print.event," + "javax.rmi," + "javax.rmi.CORBA," + "javax.rmi.ssl," + "javax.script," + "javax.security.auth," + "javax.security.auth.callback," + "javax.security.auth.kerberos," + "javax.security.auth.login," + "javax.security.auth.spi," + "javax.security.auth.x500," + "javax.security.cert," + "javax.security.sasl," + "javax.sound.midi," + "javax.sound.midi.spi," + "javax.sound.sampled," + "javax.sound.sampled.spi," + "javax.sql," + "javax.sql.rowset," + "javax.sql.rowset.serial," + "javax.sql.rowset.spi," + "javax.swing," + "javax.swing.border," + "javax.swing.colorchooser," + "javax.swing.event," + "javax.swing.filechooser," + "javax.swing.plaf," + "javax.swing.plaf.basic," + "javax.swing.plaf.metal," + "javax.swing.plaf.multi," + "javax.swing.plaf.synth," + "javax.swing.table," + "javax.swing.text," + "javax.swing.text.html," + "javax.swing.text.html.parser," + "javax.swing.text.rtf," + "javax.swing.tree," + "javax.swing.undo," + "javax.tools," + "javax.transaction;javax.transaction.xa;version=1.1;partial=true;mandatory:=partial," + "javax.xml," + "javax.xml.namespace;version=1.0," + "javax.xml.crypto," + "javax.xml.crypto.dom," + "javax.xml.crypto.dsig," + "javax.xml.crypto.dsig.dom," + "javax.xml.crypto.dsig.keyinfo," + "javax.xml.crypto.dsig.spec," + "javax.xml.datatype," + "javax.xml.parsers," + "javax.xml.transform," + "javax.xml.transform.dom," + "javax.xml.transform.sax," + "javax.xml.transform.stax," + "javax.xml.transform.stream," + "javax.xml.validation," + "javax.xml.xpath," + "org.ietf.jgss," + "org.omg.CORBA," + "org.omg.CORBA_2_3," + "org.omg.CORBA_2_3.portable," + "org.omg.CORBA.DynAnyPackage," + "org.omg.CORBA.ORBPackage," + "org.omg.CORBA.portable," + "org.omg.CORBA.TypeCodePackage," + "org.omg.CosNaming," + "org.omg.CosNaming.NamingContextExtPackage," + "org.omg.CosNaming.NamingContextPackage," + "org.omg.Dynamic," + "org.omg.DynamicAny," + "org.omg.DynamicAny.DynAnyFactoryPackage," + "org.omg.DynamicAny.DynAnyPackage," + "org.omg.IOP," + "org.omg.IOP.CodecFactoryPackage," + "org.omg.IOP.CodecPackage," + "org.omg.Messaging," + "org.omg.PortableInterceptor," + "org.omg.PortableInterceptor.ORBInitInfoPackage," + "org.omg.PortableServer," + "org.omg.PortableServer.CurrentPackage," + "org.omg.PortableServer.POAManagerPackage," + "org.omg.PortableServer.POAPackage," + "org.omg.PortableServer.portable," + "org.omg.PortableServer.ServantLocatorPackage," + "org.omg.SendingContext," + "org.omg.stub.java.rmi," + "org.omg.stub.javax.management.remote.rmi," + "org.w3c.dom," + "org.w3c.dom.bootstrap," + "org.w3c.dom.css," + "org.w3c.dom.events," + "org.w3c.dom.html," + "org.w3c.dom.ls," + "org.w3c.dom.ranges," + "org.w3c.dom.stylesheets," + "org.w3c.dom.traversal," + "org.w3c.dom.views," + "org.w3c.dom.xpath," + "org.xml.sax," + "org.xml.sax.ext," + "org.xml.sax.helpers"); properties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "net.sf.cglib.asm," + "net.sf.cglib.core," + "net.sf.cglib.proxy," + "net.sf.cglib.reflect," + "sun.misc," + "sun.reflect," + "org.apache.commons.jexl;version=\"1.1\"," + "org.apache.commons.jexl.context;version=\"1.1\"," + "org.apache.commons.jexl.resolver;version=\"1.1\"," + "org.apache.geronimo.main," + "org.apache.geronimo.cli," + "org.apache.geronimo.cli.client," + "org.apache.geronimo.cli.daemon," + "org.apache.geronimo.common," + "org.apache.geronimo.common.propertyeditor," + "org.apache.geronimo.crypto," + "org.apache.geronimo.gbean," + "org.apache.geronimo.gbean.annotation," + "org.apache.geronimo.gbean.runtime," + "org.apache.geronimo.kernel," + "org.apache.geronimo.kernel.basic," + "org.apache.geronimo.kernel.classloader," + "org.apache.geronimo.kernel.config," + "org.apache.geronimo.kernel.config.xstream," + "org.apache.geronimo.kernel.lifecycle," + "org.apache.geronimo.kernel.management," + "org.apache.geronimo.kernel.osgi," + "org.apache.geronimo.kernel.proxy," + "org.apache.geronimo.kernel.repository," + "org.apache.geronimo.kernel.rmi," + "org.apache.geronimo.kernel.util," + "org.apache.geronimo.system.configuration," + "org.apache.geronimo.system.configuration.cli," + "org.apache.geronimo.system.configuration.condition," + "org.apache.geronimo.system.jmx," + "org.apache.geronimo.system.logging," + "org.apache.geronimo.system.logging.log4j," + "org.apache.geronimo.system.main," + "org.apache.geronimo.system.plugin," + "org.apache.geronimo.system.plugin.model," + "org.apache.geronimo.system.properties," + "org.apache.geronimo.system.repository," + "org.apache.geronimo.system.resolver," + "org.apache.geronimo.system.serverinfo," + "org.apache.geronimo.system.threads," + "org.apache.geronimo.system.util," + "org.apache.geronimo.transformer," + "org.apache.geronimo.mavenplugins.car," + "org.apache.karaf.jaas.boot;version=\"2.2.1\"," + "org.apache.yoko," + "org.apache.yoko.osgi," + "org.apache.yoko.rmispec.util," + "org.apache.geronimo.hook" + extraPackages ); /* "org.apache.log4j;version=\"1.2.12\"," + "org.apache.log4j.helpers;version=\"1.2.12\"," + "org.apache.log4j.spi;version=\"1.2.12\"," + "org.apache.log4j.xml;version=\"1.2.12\"," + "org.codehaus.classworlds," + "org.codehaus.classworlds.realm," + "org.codehaus.plexus," + "org.codehaus.plexus.archiver," + "org.codehaus.plexus.archiver.jar," + "org.codehaus.plexus.archiver.tar," + "org.codehaus.plexus.archiver.util," + "org.codehaus.plexus.archiver.zip," + "org.codehaus.plexus.component," + "org.codehaus.plexus.component.annotations," + "org.codehaus.plexus.component.composition," + "org.codehaus.plexus.component.configurator," + "org.codehaus.plexus.component.configurator.converters," + "org.codehaus.plexus.component.configurator.expression," + "org.codehaus.plexus.component.discovery," + "org.codehaus.plexus.component.factory," + "org.codehaus.plexus.component.manager," + "org.codehaus.plexus.component.repository," + "org.codehaus.plexus.component.repository.exception," + "org.codehaus.plexus.component.repository.io," + "org.codehaus.plexus.configuration," + "org.codehaus.plexus.configuration.processor," + "org.codehaus.plexus.configuration.xml," + "org.codehaus.plexus.context," + "org.codehaus.plexus.embed," + "org.codehaus.plexus.lifecycle," + "org.codehaus.plexus.lifecycle.phase," + "org.codehaus.plexus.logging," + "org.codehaus.plexus.logging.console," + "org.codehaus.plexus.personality," + "org.codehaus.plexus.personality.plexus," + "org.codehaus.plexus.personality.plexus.lifecycle," + "org.codehaus.plexus.personality.plexus.lifecycle.phase," + "org.codehaus.plexus.util," + "org.codehaus.plexus.util.xml," + "org.apache.maven," + "org.apache.maven.plugin," + "org.apache.maven.lifecyle," + "org.apache.maven.shared," + "org.apache.maven.shared.filtering," + "com.thoughtworks.xstream," + "com.thoughtworks.xstream.alias," + "com.thoughtworks.xstream.converters," + "com.thoughtworks.xstream.converters.basic," + "com.thoughtworks.xstream.converters.reflection," + "com.thoughtworks.xstream.core," + "com.thoughtworks.xstream.io," + "com.thoughtworks.xstream.io.xml," + "com.thoughtworks.xstream.mapper," + "javax.management," + "javax.rmi.ssl," + "javax.xml.parsers," + "javax.xml.transform," + "net.sf.cglib.asm," + "net.sf.cglib.core," + "net.sf.cglib.proxy," + "net.sf.cglib.reflect," + "org.apache.xbean.recipe;version=\"3.6\"," + "org.objectweb.asm," + "org.objectweb.asm.commons," + "org.osgi.framework;version=\"1.4\"," + "org.slf4j;version=\"1.5.6\"," + "org.slf4j.impl;version=\"1.5.6\"," + "org.slf4j.bridge;version=\"1.5.6\"," + "org.w3c.dom," + "org.xml.sax," + "org.xml.sax.helpers," + "sun.misc," + "org.apache.xmlbeans," + "org.apache.xml.resolver," + "org.apache.commons.cli," + "javax.enterprise.deploy," + "javax.enterprise.deploy.model," + "javax.enterprise.deploy.shared," + "javax.enterprise.deploy.spi"); */ properties.put(Constants.FRAMEWORK_BOOTDELEGATION, "sun.*,com.sun.*"); File storageDir = new File(basedir, "target/bundle-cache"); properties.put(Constants.FRAMEWORK_STORAGE, storageDir.getAbsolutePath()); if (log.isDebugEnabled()) { properties.put("felix.log.level", "4"); } /* * A hack for Equinox to restore FrameworkProperties to the initial state. * If the FrameworkProperties is not restored to the initial state, Equinox * will create a separate classloader and load the Geronimo kernel classes * from deployed geronimo-kernel bundle instead of the system bundle. * That will result in ClassCastException. */ resetFrameworkProperties(); ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class); Framework framework = loader.iterator().next().newFramework(properties); framework.start(); //enable mvn url handling // new org.ops4j.pax.url.mvn.internal.Activator().start(framework.getBundleContext()); //don't allow mvn urls if (systemProperties == null) { systemProperties = new HashMap<String, String>(); } systemProperties.put("geronimo.build.car", "true"); //Fix JIRA GERONIMO-5400 if (null == System.getProperty("openejb.log.factory")) { systemProperties.put("openejb.log.factory", "org.apache.openejb.util.PaxLogStreamFactory"); } systemProperties.put("karaf.startLocalConsole", "false"); systemProperties.put("openejb.geronimo", "true"); setSystemProperties(); return framework; }