Package org.nanocontainer

Examples of org.nanocontainer.DefaultNanoContainer


            }
        }
    }

    private void registerClassLoader(NanoContainer parentContainer, Element childElement) throws IOException, SAXException, ClassNotFoundException {
        NanoContainer nano = new DefaultNanoContainer(parentContainer.getComponentClassLoader(), parentContainer.getPico());
        registerComponentsAndChildContainers(nano, childElement);
    }
View Full Code Here


                return componentInstanceFactory;
            }
            factoryClass = DEFAULT_COMPONENT_INSTANCE_FACTORY;
        }

        NanoContainer adapter = new DefaultNanoContainer();
        adapter.registerComponentImplementation(XMLComponentInstanceFactory.class.getName(), factoryClass);
        return (XMLComponentInstanceFactory) adapter.getPico().getComponentInstances().get(0);
    }
View Full Code Here

    }

    public Object createNewNode(final NanoContainer parentContainer, final Map attributes) throws ClassNotFoundException {
        String builderClass = (String) attributes.remove(CLASS_ATTRIBUTE);

        NanoContainer factory = new DefaultNanoContainer();
        MutablePicoContainer parentPico = parentContainer.getPico();
        factory.getPico().registerComponentInstance(MutablePicoContainer.class, parentPico);
        try {
            factory.registerComponentImplementation(GroovyObject.class, builderClass);
        } catch (ClassNotFoundException e) {
            throw new NanoContainerMarkupException("ClassNotFoundException " + builderClass);
        }
        Object componentInstance = factory.getPico().getComponentInstance(GroovyObject.class);
        return componentInstance;
    }
View Full Code Here

        MutablePicoContainer decoratedPico = getDecorationDelegate().decorate(childContainer);
        if ( isAttribute(attributes, CLASS) )  {
            Class clazz = (Class) attributes.get(CLASS);
            return createNanoContainer(clazz, decoratedPico, parentClassLoader);
        } else {
            return new DefaultNanoContainer(parentClassLoader, decoratedPico);
        }
    }
View Full Code Here

import java.net.MalformedURLException;

public class DefaultNanoContainerTestCase extends TestCase {

    public void testBasic() throws PicoRegistrationException, PicoInitializationException, ClassNotFoundException {
        NanoContainer nanoContainer = new DefaultNanoContainer();
        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.DefaultWebServerConfig");
        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.WebServer", "org.nanocontainer.testmodel.WebServerImpl");
    }
View Full Code Here

        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.DefaultWebServerConfig");
        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.WebServer", "org.nanocontainer.testmodel.WebServerImpl");
    }

    public void testProvision() throws PicoException, PicoInitializationException, ClassNotFoundException {
        NanoContainer nanoContainer = new DefaultNanoContainer();
        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.DefaultWebServerConfig");
        nanoContainer.registerComponentImplementation("org.nanocontainer.testmodel.WebServerImpl");

        assertNotNull("WebServerImpl should exist", nanoContainer.getPico().getComponentInstance(WebServerImpl.class));
        assertTrue("WebServerImpl should exist", nanoContainer.getPico().getComponentInstance(WebServerImpl.class) instanceof WebServerImpl);
    }
View Full Code Here

        assertNotNull("WebServerImpl should exist", nanoContainer.getPico().getComponentInstance(WebServerImpl.class));
        assertTrue("WebServerImpl should exist", nanoContainer.getPico().getComponentInstance(WebServerImpl.class) instanceof WebServerImpl);
    }

    public void testNoGenerationRegistration() throws PicoRegistrationException, PicoIntrospectionException {
        NanoContainer nanoContainer = new DefaultNanoContainer();
        try {
            nanoContainer.registerComponentImplementation("Ping");
            fail("should have failed");
        } catch (ClassNotFoundException e) {
            // expected
        }
    }
View Full Code Here

            // expected
        }
    }

    public void testParametersCanBePassedInStringForm() throws ClassNotFoundException, PicoException, PicoInitializationException {
        NanoContainer nanoContainer = new DefaultNanoContainer();
        String className = ThingThatTakesParamsInConstructor.class.getName();

        nanoContainer.registerComponentImplementation("thing",
                className,
                new String[]{
                    "java.lang.String",
                    "java.lang.Integer"
                },
                new String[]{
                    "hello",
                    "22"
                });

        ThingThatTakesParamsInConstructor thing =
                (ThingThatTakesParamsInConstructor) nanoContainer.getPico().getComponentInstance("thing");
        assertNotNull("component not present", thing);
        assertEquals("hello22", thing.getValue());
    }
View Full Code Here

    }

    public void testThatTestCompIsNotNaturallyInTheClassPathForTesting() {

        try {
            DefaultNanoContainer dfca = new DefaultNanoContainer();
            dfca.registerComponentImplementation("foo", "TestComp");
            Object o = dfca.getPico().getComponentInstance("foo");
            fail("Should have failed. Class was loaded from " + o.getClass().getProtectionDomain().getCodeSource().getLocation());
        } catch (ClassNotFoundException expected) {
        }

    }
View Full Code Here

        assertNotNull("The testcomp.jar system property should point to java/nanocontainer/src/test-comp/TestComp.jar", testcompJarFileName);
        File testCompJar = new File(testcompJarFileName);

        // Set up parent
        NanoContainer parentContainer = new DefaultNanoContainer();
        parentContainer.addClassLoaderURL(testCompJar.toURL());
        parentContainer.registerComponentImplementation("parentTestComp", "TestComp");
        parentContainer.registerComponentImplementation("java.lang.StringBuffer");

        PicoContainer parentContainerAdapterPico = parentContainer.getPico();
        Object parentTestComp = parentContainerAdapterPico.getComponentInstance("parentTestComp");
        assertEquals("TestComp", parentTestComp.getClass().getName());

        // Set up child
        NanoContainer childContainer = new DefaultNanoContainer(parentContainer);
        File testCompJar2 = new File(testCompJar.getParentFile(), "TestComp2.jar");
        childContainer.addClassLoaderURL(testCompJar2.toURL());
        childContainer.registerComponentImplementation("childTestComp", "TestComp2");

        PicoContainer childContainerAdapterPico = childContainer.getPico();
        Object childTestComp = childContainerAdapterPico.getComponentInstance("childTestComp");

        assertEquals("TestComp2", childTestComp.getClass().getName());

        assertNotSame(parentTestComp, childTestComp);
View Full Code Here

TOP

Related Classes of org.nanocontainer.DefaultNanoContainer

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.