/** * <p>Returns the Clock implementation using commons discovery.</p> * * @return the Clock implementation using commons discovery. */ public static Clock getClockImpl() { Clock c = null; try { DiscoverClass dc = new DiscoverClass(); c = (Clock) dc.newInstance( Clock.class, Clock.DEFAULT_CLOCK_IMPL); } catch (Exception ex) { // ignore as default implementation will be used. } return c; }
/** * Find class implementing SPI. * * @param <T> The SPI type * @param <S> Any class extending T * @param spiClass Service Provider Interface Class. * @return Class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded, or if * the resulting class does not implement (or extend) the SPI. */ public <T, S extends T> Class<S> find(Class<T> spiClass) throws DiscoveryException { return find(getClassLoaders(spiClass), new SPInterface<T>(spiClass), nullProperties, (DefaultClassHolder<T>) null); }
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param spiClass Service Provider Interface Class. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public <T> T newInstance(Class<T> spiClass) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return newInstance(getClassLoaders(spiClass), new SPInterface<T>(spiClass), nullProperties, (DefaultClassHolder<T>) null); }
public Object run() { try { return DiscoverClass.newInstance(null, spi, (PropertiesHolder)null, defaultClass); } catch (Exception e) { log.error(Messages.getMessage("exception00"), e); } return null; } });
DiscoverClass discovery = new DiscoverClass(); try properties.load( resource ); Class<?> theClass = discovery.find( interfaceDef, properties, defaultImpl ); LOG.debug( LogMessage.getMessage( message, configFile ) ); Class<?> theClass = discovery.find( interfaceDef, configFile, defaultImpl );
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param loaders The class loaders holder * @param spi Service Provider Interface Class. * @param properties Used to determine name of SPI implementation, * and passed to implementation.init() method if * implementation implements Service interface. * @param defaultImpl Default implementation. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public static <T> T newInstance(ClassLoaders loaders, SPInterface<T> spi, PropertiesHolder properties, DefaultClassHolder<T> defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return spi.newInstance(find(loaders, spi, properties, defaultImpl)); }
String className = getManagedProperty(spiName); if (className != null) { names.add(className); className = getManagedProperty(propertyName); if (className != null) { names.add(className);
: properties.getProperties(spi, loaders); String[] classNames = discoverClassNames(spi, props); Exception error = null;
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param spiClass Service Provider Interface Class. * @param defaultImpl Default implementation. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public <T> T newInstance(Class<T> spiClass, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return newInstance(getClassLoaders(spiClass), new SPInterface<T>(spiClass), nullProperties, new DefaultClassHolder<T>(defaultImpl)); }
public Object run() { try { return DiscoverClass.newInstance(null, spi, (PropertiesHolder)null, defaultClass); } catch (Exception e) { log.error(Messages.getMessage("exception00"), e); } return null; } });
/** * <p>Returns the <code>State</code> implementation in use.</p> * * @return the <code>State</code> implementation in use. */ public static State getStateImpl() { State s = null; try { DiscoverClass dc = new DiscoverClass(); s = (State) dc.newInstance( State.class, State.DEFAULT_STATE_IMPL); } catch (Exception ex) { // ignore as default implementation will be used. } return s; }
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param spiClass Service Provider Interface Class. * @param properties Used to determine name of SPI implementation, * and passed to implementation.init() method if * implementation implements Service interface. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public <T> T newInstance(Class<T> spiClass, Properties properties) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return newInstance(getClassLoaders(spiClass), new SPInterface<T>(spiClass), new PropertiesHolder(properties), (DefaultClassHolder<T>) null); }
public Object run() { try { return DiscoverClass.newInstance(null, spi, (PropertiesHolder)null, defaultClass); } catch (Exception e) { log.error(Messages.getMessage("exception00"), e); } return null; } });
/** * Find class implementing SPI. * * @param <T> The SPI type * @param <S> Any class extending T * @param spiClass Service Provider Interface Class. * @param defaultImpl Default implementation name. * @return Class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded, or if * the resulting class does not implement (or extend) the SPI. */ public <T, S extends T> Class<S> find(Class<T> spiClass, String defaultImpl) throws DiscoveryException { return find(getClassLoaders(spiClass), new SPInterface<T>(spiClass), nullProperties, new DefaultClassHolder<T>(defaultImpl)); }
/** * Create a new factory. * @return a new factory. */ public static UnivariateRealSolverFactory newInstance() { UnivariateRealSolverFactory factory = null; try { DiscoverClass dc = new DiscoverClass(); factory = (UnivariateRealSolverFactory) dc.newInstance( UnivariateRealSolverFactory.class, "org.apache.commons.math.analysis.UnivariateRealSolverFactoryImpl"); } catch(Throwable t) { return new UnivariateRealSolverFactoryImpl(); } return factory; }
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param spiClass Service Provider Interface Class. * @param properties Used to determine name of SPI implementation, * and passed to implementation.init() method if * implementation implements Service interface. * @param defaultImpl Default implementation. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public <T> T newInstance(Class<T> spiClass, Properties properties, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return newInstance(getClassLoaders(spiClass), new SPInterface<T>(spiClass), new PropertiesHolder(properties), new DefaultClassHolder<T>(defaultImpl)); }
obj = DiscoverClass.newInstance(loaders, spi, properties, defaultImpl);
/** * Find class implementing SPI. * * @param <T> The SPI type * @param <S> Any class extending T * @param spiClass Service Provider Interface Class. * @param properties Used to determine name of SPI implementation. * @return Class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded, or if * the resulting class does not implement (or extend) the SPI. */ public <T, S extends T> Class<S> find(Class<T> spiClass, Properties properties) throws DiscoveryException { return find(getClassLoaders(spiClass), new SPInterface<T>(spiClass), new PropertiesHolder(properties), (DefaultClassHolder<T>) null); }
/** * Create an instance of a <code>DescriptiveStatistics</code> * @return a new DescriptiveStatistics instance. * @deprecated to be removed in commons-math 2.0 */ public static DescriptiveStatistics newInstance() { DescriptiveStatistics factory = null; try { DiscoverClass dc = new DiscoverClass(); factory = (DescriptiveStatistics) dc.newInstance( DescriptiveStatistics.class, "org.apache.commons.math.stat.descriptive.DescriptiveStatisticsImpl"); } catch(Throwable t) { return new DescriptiveStatisticsImpl(); } return factory; }
/** * Create new instance of class implementing SPI. * * @param <T> The SPI type * @param spiClass Service Provider Interface Class. * @param propertiesFileName Used to determine name of SPI implementation, * and passed to implementation.init() method if * implementation implements Service interface. * @param defaultImpl Default implementation. * @return Instance of a class implementing the SPI. * @exception DiscoveryException Thrown if the name of a class implementing * the SPI cannot be found, if the class cannot be loaded and * instantiated, or if the resulting class does not implement * (or extend) the SPI. * @throws InstantiationException see {@link Class#newInstance()} * @throws IllegalAccessException see {@link Class#newInstance()} * @throws NoSuchMethodException see {@link Class#newInstance()} * @throws InvocationTargetException see {@link Class#newInstance()} */ public <T> T newInstance(Class<T> spiClass, String propertiesFileName, String defaultImpl) throws DiscoveryException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { return newInstance(getClassLoaders(spiClass), new SPInterface<T>(spiClass), new PropertiesHolder(propertiesFileName), new DefaultClassHolder<T>(defaultImpl)); }