Examples of ObjectCreator


Examples of org.apache.tapestry.ioc.ObjectCreator

    @Test
    public void ensure_only_called_once() throws Exception
    {
        Log log = mockLog();
        ObjectCreatorSource source = mockObjectCreatorSource();
        ObjectCreator delegate = mockObjectCreator();
        Object service = new Object();

        ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", "singleton", false, source);

        train_createObject(delegate, service);

        train_getDescription(source, SOURCE_DESCRIPTION);

        replay();

        ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, log);

        assertSame(wrapper.createObject(), service);

        try
        {
            wrapper.createObject();
            unreachable();
        }
        catch (IllegalStateException ex)
        {
            assertMessageContains(
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

    public void reporting_of_construction_failure() throws Exception
    {
        RuntimeException failure = new RuntimeException("Just cranky.");
        Log log = mockLog();
        ObjectCreatorSource source = mockObjectCreatorSource();
        ObjectCreator delegate = mockObjectCreator();
        Object service = new Object();

        ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", "singleton", false, source);

        expect(delegate.createObject()).andThrow(failure);

        log.error("Construction of service Bar failed: Just cranky.", failure);

        replay();

        ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, log);

        try
        {
            wrapper.createObject();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            assertSame(ex, failure);
        }

        verify();

        // Now test that the locked flag is not set and that the object may still be created.

        train_createObject(delegate, service);

        replay();

        assertSame(service, wrapper.createObject());

        verify();

    }
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        ServiceDef sd = def.getServiceDef("StringHolder");

        assertNotNull(sd);

        ObjectCreator oc = sd.createServiceCreator(resources);

        StringHolder holder = (StringHolder) oc.createObject();

        holder.setValue("foo");
        assertEquals(holder.getValue(), "FOO");

        verify();
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        ServiceDef sd = def.getServiceDef("StringHolder");

        assertNotNull(sd);

        ObjectCreator oc = sd.createServiceCreator(resources);

        StringHolder holder = (StringHolder) oc.createObject();

        holder.setValue("foo");
        assertEquals(holder.getValue(), "FOO");

        verify();
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION,
                findMethod(fixture, "build_noargs"));

        Object actual = sc.createObject();

        assertSame(actual, fixture._fie);

        verify();
    }
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        logger.debug(IOCMessages.invokingMethod(CREATOR_DESCRIPTION));

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION, method);

        Object actual = sc.createObject();

        assertSame(actual, fixture._fie);

        verify();
    }
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        expect(resources.getObject(eq(String.class), isA(AnnotationProvider.class))).andReturn(
                "Injected");

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION, method);

        Object actual = sc.createObject();

        assertSame(actual, fixture._fie);

        verify();
    }
View Full Code Here

Examples of org.apache.tapestry.ioc.ObjectCreator

        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION,
                findMethod(fixture, "build_injected"));

        Object actual = sc.createObject();

        assertSame(actual, fixture._fie);

        verify();
    }
View Full Code Here

Examples of org.apache.tapestry5.ioc.ObjectCreator

        if (constructor == null)
            throw new RuntimeException(String.format(
                    "Service implementation class %s does not have a suitable public constructor.", clazz.getName()));

        ObjectCreator constructorServiceCreator = new ConstructorServiceCreator(resources, String.format(
                "%s (last modified %tc)", constructor, getLastModifiedTimestamp()), constructor);

        return constructorServiceCreator.createObject();
    }
View Full Code Here

Examples of org.apache.tapestry5.ioc.ObjectCreator

                            logger);

                    // Build up a stack of operations that will be needed to realize the service
                    // (by the proxy, at a later date).

                    ObjectCreator creator = def.createServiceCreator(resources);

                    Class serviceInterface = def.getServiceInterface();

                    ServiceLifecycle2 lifecycle = registry.getServiceLifecycle(def.getServiceScope());

                    // For non-proxyable services, we immediately create the service implementation
                    // and return it. There's no interface to proxy, which throws out the possibility of
                    // deferred instantiation, service lifecycles, and decorators.

                    if (!serviceInterface.isInterface())
                    {
                        if (lifecycle.requiresProxy())
                            throw new IllegalArgumentException(
                                    String.format(
                                            "Service scope '%s' requires a proxy, but the service does not have a service interface (necessary to create a proxy). Provide a service interface or select a different service scope.",
                                            def.getServiceScope()));

                        return creator.createObject();
                    }

                    creator = new OperationTrackingObjectCreator(registry, "Invoking " + creator.toString(), creator);

                    creator = new LifecycleWrappedServiceCreator(lifecycle, resources, creator);

                    // Marked services (or services inside marked modules) are not decorated.
                    // TapestryIOCModule prevents decoration of its services. Note that all decorators will decorate
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.