Package org.apache.commons.discovery.tools

Examples of org.apache.commons.discovery.tools.DiscoverClass

  • If the name of the implementation class is non-null, load that class. The class loaded is the first class loaded by the following sequence of class loaders: An exception is thrown if the class cannot be loaded.
  • If the name of the implementation class is null, AND the default implementation class name (defaultImpl) is null, then an exception is thrown.
  • If the name of the implementation class is null, AND the default implementation class (defaultImpl) is non-null, then load the default implementation class. The class loaded is the first class loaded by the following sequence of class loaders:

    This limits the scope in which the default class loader can be found to the SPI, DiscoverSingleton, and System class loaders. The assumption here is that the default implementation is closely associated with the SPI or system, and is not defined in the user's application space.

    An exception is thrown if the class cannot be loaded.

  • Verify that the loaded class implements the SPI: an exception is thrown if the loaded class does not implement the SPI.
  • IMPLEMENTATION NOTE - This implementation is modelled after the SAXParserFactory and DocumentBuilderFactory implementations (corresponding to the JAXP pluggability APIs) found in Apache Xerces.

    @version $Revision: 1090010 $ $Date: 2011-04-07 23:05:58 +0200 (Thu, 07 Apr 2011) $

        public void testViaDiscoverClass() {
            org.apache.commons.discovery.log.SimpleLog.setLevel(logLevel);

            ClassLoaders loaders = ClassLoaders.getAppLoaders(TestInterface2.class, getClass(), false);
           
            DiscoverClass discover = new DiscoverClass(loaders);
            Class implClass = discover.find(TestInterface2.class);
           
            assertTrue("Failed to find an implementation class", implClass != null);
            assertEquals("org.apache.commons.discovery.test.TestImpl2_1", implClass.getName());
           
        }
    View Full Code Here


        @Test
        public void findViaDiscoverClass() {
            ClassLoaders loaders = ClassLoaders.getAppLoaders(TestInterface2.class, getClass(), false);

            DiscoverClass discover = new DiscoverClass(loaders);
            Class<? extends TestInterface2> implClass = discover.find(TestInterface2.class);

            assertTrue("Failed to find an implementation class", implClass != null);
            assertEquals("org.apache.commons.discovery.test.TestImpl2_1", implClass.getName());
        }
    View Full Code Here

        @Test
        public void findInnerImplViaDiscoverClass() {
            ClassLoaders loaders = ClassLoaders.getAppLoaders(TestInterface3.class, getClass(), false);

            DiscoverClass discover = new DiscoverClass(loaders);
            Class<? extends TestInterface3> implClass = discover.find(TestInterface3.class);

            assertTrue("Failed to find an implementation class", implClass != null);
            assertEquals("org.apache.commons.discovery.test.TestImpl3$InnerTestImpl", implClass.getName());

        }
    View Full Code Here

        @Test
        public void instantiateViaDiscoverClass() throws Exception {
            ClassLoaders loaders = ClassLoaders.getAppLoaders(TestInterface2.class, getClass(), false);

            DiscoverClass discoverClass = new DiscoverClass(loaders);
            TestInterface2 serviceImpl = discoverClass.newInstance(TestInterface2.class);

            assertNotNull(serviceImpl);
            assertEquals(TestImpl2_1.class, serviceImpl.getClass());
        }
    View Full Code Here

                                                             ControlBeanContext context,
                                                             String id )
        {
            try
            {
                DiscoverClass discoverer = new DiscoverClass();
                Class factoryClass = discoverer.find( ControlFactory.class, DEFAULT_FACTORY_CLASS );
                ControlFactory factory = (ControlFactory)factoryClass.newInstance();
                return factory.instantiate( beanClass, props, context, id );
            }
            catch ( Exception e )
            {
    View Full Code Here

         * @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();
            }
    View Full Code Here

         * @return a new factory.
         */
        public static TestFactory newInstance() {
            TestFactory factory = null;
            try {
                DiscoverClass dc = new DiscoverClass();
                factory = (TestFactory) dc.newInstance(
                        TestFactory.class,
                "org.apache.commons.math.stat.inference.TestFactoryImpl");
            } catch(Throwable t) {
                return new TestFactoryImpl();
            }
    View Full Code Here

         * @return a new factory.
         */
        public static DistributionFactory newInstance() {
            DistributionFactory factory = null;
            try {
                DiscoverClass dc = new DiscoverClass();
                factory = (DistributionFactory) dc.newInstance(
                    DistributionFactory.class,
                    "org.apache.commons.math.distribution.DistributionFactoryImpl");
            } catch(Throwable t) {
                return new DistributionFactoryImpl();
            }
    View Full Code Here

         * @return a new factory.
         */
        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();
            }
    View Full Code Here

         * @return a new SummaryStatistics instance.
         */
        public static SummaryStatistics newInstance() {
            SummaryStatistics instance = null;
            try {
                DiscoverClass dc = new DiscoverClass();
                instance = (SummaryStatistics) dc.newInstance(
                    SummaryStatistics.class,
                    "org.apache.commons.math.stat.descriptive.SummaryStatisticsImpl");
            } catch(Throwable t) {
                return new SummaryStatisticsImpl();
            }
    View Full Code Here

    TOP

    Related Classes of org.apache.commons.discovery.tools.DiscoverClass

    Copyright © 2018 www.massapicom. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.