Package org.picocontainer.defaults

Examples of org.picocontainer.defaults.ConstructorInjectionComponentAdapter


    /**
     * Test fail-fast for components without interface.
     */
    public void testComponentMustImplementInterface() {
        try {
            new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(Object.class, Object.class, null));
            fail("PicoIntrospectionException expected");
        } catch (final PicoIntrospectionException e) {
            assertTrue(e.getMessage().endsWith("It does not implement any interfaces."));
        }
    }
View Full Code Here


            throw new Error("junit");
        }
    }

    public void testExceptionHandling() {
        final ComponentAdapter componentAdapter = new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(
                TargetInvocationExceptionTester.class, ThrowingComponent.class, null));
        final TargetInvocationExceptionTester tester = (TargetInvocationExceptionTester)componentAdapter.getComponentInstance(null);
        try {
            tester.throwsCheckedException();
            fail("ClassNotFoundException expected");
View Full Code Here

    /**
     * Test ComponentAdapter using simple keys.
     */
    public final void testSimpleKeys() {
        final ComponentAdapter componentAdapter = new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(
                "List", ArrayList.class, null));
        final List hello = (List)componentAdapter.getComponentInstance(null);
        assertNotNull(hello);
    }
View Full Code Here

    }

    public void testIHCAFwithCTORandNoCaching() {
        // http://lists.codehaus.org/pipermail/picocontainer-dev/2004-January/001985.html
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponent(new HotSwappingComponentAdapter(new ConstructorInjectionComponentAdapter("l", ArrayList.class)));

        List list1 = (List) pico.getComponentInstance("l");
        List list2 = (List) pico.getComponentInstance("l");

        assertNotSame(list1, list2);
View Full Code Here

        assertFalse(list2.contains("Hello"));
    }

    public void testSwappingViaSwappableInterface() {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponent(new HotSwappingComponentAdapter(new ConstructorInjectionComponentAdapter("l", ArrayList.class)));
        List l = (List) pico.getComponentInstance("l");
        l.add("Hello");
        final ArrayList newList = new ArrayList();
        ArrayList oldSubject = (ArrayList) ((Swappable) l).hotswap(newList);
        assertEquals("Hello", oldSubject.get(0));
View Full Code Here

        }
    }

    public void testInterferingSwapMethodsInComponentMasksHotSwappingFunctionality() {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponent(new HotSwappingComponentAdapter(new ConstructorInjectionComponentAdapter("os", OtherSwappableImpl.class)));
        OtherSwappable os = (OtherSwappable) pico.getComponentInstance("os");
        OtherSwappable os2 = new OtherSwappableImpl();

        assertEquals("TADA", os.hotswap(os2));
        Swappable os_ = (Swappable) os;
View Full Code Here

     *                              container.
     */
    public Object create(Proxy proxy) throws NullPointerException {
        Object mixin = pico.getComponentInstanceOfType(mixinClass);
        if (mixin == null) {
            ComponentAdapter adapter = new ConstructorInjectionComponentAdapter(mixinClass, mixinClass);
            mixin = adapter.getComponentInstance(pico);
        }
        return mixin;
    }
View Full Code Here

            Class classType = loader.loadClass(type);
            if (key == null)
            {
               if (component.isMultiInstance())
               {
                  container.registerComponent(new ConstructorInjectionComponentAdapter(classType, classType));
                  System.out.println("===>>> Thread local component " + classType.getName() + " registered.");
               }
               else
               {
                  container.registerComponentImplementation(classType);
               }
            }
            else
            {
               try
               {
                  Class keyType = loader.loadClass(key);
                  if (component.isMultiInstance())
                  {
                     container.registerComponent(new ConstructorInjectionComponentAdapter(keyType, classType));
                     System.out.println("===>>> Thread local component " + classType.getName() + " registered.");
                  }
                  else
                  {
                     container.registerComponentImplementation(keyType, classType);
View Full Code Here

    private static void registerCoreServices(final MutablePicoContainer container)
    {
        container.registerComponent(new CachingComponentAdapter(
                new PushTaskExecutorFactoryComponentAdapter(
                        new ConstructorInjectionComponentAdapter(PushTaskExecutorFactory.class, ConfigurablePushTaskExecutorFactory.class))));

        // etcl evaluator
        container.registerComponentImplementation(DefaultETCLEvaluator.class);

        // message factory
View Full Code Here

    private static void registerEvaluationContextFactory(final MutablePicoContainer container)
    {
        // PoolingEvaluationContextFactory depends on DefaultEvaluationContextFactory.
        // however both implement the same interface users depend on which causes an ambiguity.
        // therefore DefaultEvaluationContextFactory should be only visible to PoolingEvaluationContextFactory.
        final ConstructorInjectionComponentAdapter _serviceCA =
            new ConstructorInjectionComponentAdapter(DefaultEvaluationContextFactory.class, DefaultEvaluationContextFactory.class);

        final ConstructorInjectionComponentAdapter _poolingServiceCA =
            new ConstructorInjectionComponentAdapter(EvaluationContextFactory.class, PoolingEvaluationContextFactory.class, new Parameter[] {BasicComponentParameter.BASIC_DEFAULT, new BasicComponentParameter(DefaultEvaluationContextFactory.class)});

        final LocalParameterComponentAdapter _localParamCA =
            new LocalParameterComponentAdapter(_poolingServiceCA, new ComponentAdapter[] {_serviceCA});

        final ComponentAdapter _cachingCA =
View Full Code Here

TOP

Related Classes of org.picocontainer.defaults.ConstructorInjectionComponentAdapter

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.