List of usage examples for org.apache.commons.discovery.tools Service providers
public static Enumeration providers(Class spiClass)
Enumeration
instead of Interator
. From source file:net.sf.joost.stx.TransformerHandlerResolverImpl.java
/** * Initialize the object//from ww w .java 2 s. c o m * It scans plugins directories and create a hashtable of all implemented * filter-methods and their factories. * In case of duplicated method implementations its behaviour is * defined by {link @flgName} system property. * @throws SAXException when duplicated method implementation is found * and has been asked to raise an exception */ private static synchronized void init() throws SAXException { // check again, in case this method has been called twice if (!notInitializedYet) return; if (DEBUG) log.debug("init() : entering"); // system property which says what to do in case of // duplicated method implementations String prop = System.getProperty(flgName); if (DEBUG) log.debug(flgName + "=" + prop); int flg; // fail with exception if duplicate is found if ("fail".equalsIgnoreCase(prop)) flg = FLAG_FAIL; // ignore duplicate and print info message else if ("ignore".equalsIgnoreCase(prop)) flg = FLAG_IGNORE; // accept duplicate and print warning message else // just a warning and replace flg = FLAG_REPLACE; // plugin classes Enumeration clss = Service.providers(TransformerHandlerResolver.class); // loop over founded classes while (clss.hasMoreElements()) { TransformerHandlerResolver plg = (TransformerHandlerResolver) clss.nextElement(); if (DEBUG) log.debug("scanning implemented stx-filter-methods of class" + plg.getClass()); // lookup over implemented methods String[] uriMethods = plg.resolves(); for (int i = 0; i < uriMethods.length; i++) { // method name (url) String mt = uriMethods[i]; if (DEBUG) log.debug("stx-filter-method found : " + mt); // see if method is already defined by some other plugin ? TransformerHandlerResolver firstPlg = (TransformerHandlerResolver) plugins.get(mt); if (null != firstPlg) { String msg = "Plugin '" + plg.getClass() + "' implements stx-filter-method '" + mt + "' which already has been implemented by '" + firstPlg.getClass().toString() + "'!"; if (flg == FLAG_FAIL) { if (DEBUG) log.debug("plugin already implemented!"); throw new SAXException(msg); } else if (flg == FLAG_IGNORE) { if (log != null) log.warn(msg + "\nImplementation ignored, " + "using first plugin!"); } else { // replace + warning if (log != null) log.warn(msg + "\nUsing new implementation, " + "previous plugin ignored!"); plugins.put(mt, plg); } } else { // add method to the hashtable plugins.put(mt, plg); } } } // revert init() flag notInitializedYet = false; if (DEBUG) log.debug("init() : exiting"); }
From source file:ch.arrenbrecht.jcite.JCite.java
public JCite() { super();//from w w w .j a v a 2 s . co m registerCitelet(new JavaCitelet(this)); registerCitelet(new PlainJavaCitelet(this)); registerCitelet(new TextCitelet(this)); registerCitelet(new PlainTextCitelet(this)); registerCitelet(new RawTextCitelet(this)); registerCitelet(new PathCitelet(this)); registerCitelet(new IncludeCitelet(this)); @SuppressWarnings("rawtypes") // final Enumeration providers = Service.providers(JCiteletProvider.class); while (providers.hasMoreElements()) { final JCiteletProvider provider = (JCiteletProvider) providers.nextElement(); registerCitelet(provider.getCitelet(this)); } }
From source file:org.soaplab.services.GenUtils.java
/********************************************************************* * Return an enumeration of instances of given class, as found by * the SPI mechanism (as described in/* ww w . j av a 2s. c o m*/ * sun/jdk1.3.1/docs/guide/jar/jar.html#Service Provider). <p> * * @param svc SPI to look for and load * @return instances of 'svc' (implementing it or extending it) ********************************************************************/ @SuppressWarnings("unchecked") public static <SVC> Enumeration<SVC> spiProviders(Class<SVC> svc) { return Service.providers(svc); }