Search in sources :

Example 1 with ObjectCreator

use of org.apache.tapestry5.commons.ObjectCreator in project tapestry-5 by apache.

the class PlasticProxyFactoryImpl method getMemberLocation.

public Location getMemberLocation(Member member, String methodName, String memberTypeDesc, ObjectCreator<String> textDescriptionCreator) {
    String className = member.getDeclaringClass().getName();
    String key = className + ":" + methodName + ":" + memberTypeDesc;
    Location location = memberToLocation.get(key);
    if (location == null) {
        location = constructMemberLocation(member, methodName, memberTypeDesc, textDescriptionCreator.createObject());
        memberToLocation.put(key, location);
    }
    return location;
}
Also used : StringLocation(org.apache.tapestry5.commons.internal.services.StringLocation) Location(org.apache.tapestry5.commons.Location)

Example 2 with ObjectCreator

use of org.apache.tapestry5.commons.ObjectCreator in project tapestry-5 by apache.

the class RegistryImpl method autobuild.

@Override
public <T> T autobuild(final Class<T> clazz) {
    assert clazz != null;
    final Constructor constructor = InternalUtils.findAutobuildConstructor(clazz);
    if (constructor == null) {
        throw new RuntimeException(IOCMessages.noAutobuildConstructor(clazz));
    }
    Map<Class, Object> resourcesMap = CollectionFactory.newMap();
    resourcesMap.put(OperationTracker.class, RegistryImpl.this);
    InjectionResources resources = new MapInjectionResources(resourcesMap);
    ObjectCreator<T> plan = InternalUtils.createConstructorConstructionPlan(this, this, resources, null, "Invoking " + proxyFactory.getConstructorLocation(constructor).toString(), constructor);
    return plan.createObject();
}
Also used : Constructor(java.lang.reflect.Constructor) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InjectionResources(org.apache.tapestry5.ioc.internal.util.InjectionResources) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources)

Example 3 with ObjectCreator

use of org.apache.tapestry5.commons.ObjectCreator in project tapestry-5 by apache.

the class ReloadableServiceImplementationObjectCreator method createInstance.

@Override
protected Object createInstance(Class clazz) {
    final Constructor constructor = InternalUtils.findAutobuildConstructor(clazz);
    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, constructor.toString(), constructor);
    return constructorServiceCreator.createObject();
}
Also used : Constructor(java.lang.reflect.Constructor) ObjectCreator(org.apache.tapestry5.commons.ObjectCreator)

Example 4 with ObjectCreator

use of org.apache.tapestry5.commons.ObjectCreator in project tapestry-5 by apache.

the class ContributionDefImpl method invokeMethod.

private <T> void invokeMethod(ModuleBuilderSource source, ServiceResources resources, Class<T> parameterType, T parameterValue) {
    Map<Class, Object> resourceMap = CollectionFactory.newMap();
    resourceMap.put(parameterType, parameterValue);
    resourceMap.put(ObjectLocator.class, resources);
    resourceMap.put(Logger.class, resources.getLogger());
    InjectionResources injectionResources = new MapInjectionResources(resourceMap);
    for (Class t : CONFIGURATION_TYPES) {
        if (parameterType != t) {
            injectionResources = new DelegatingInjectionResources(new WrongConfigurationTypeGuard(resources.getServiceId(), t, parameterType), injectionResources);
        }
    }
    Throwable fail = null;
    Object moduleInstance = InternalUtils.isStatic(contributorMethod) ? null : source.getModuleBuilder();
    try {
        ObjectCreator[] parameters = InternalUtils.calculateParametersForMethod(contributorMethod, resources, injectionResources, resources.getTracker());
        contributorMethod.invoke(moduleInstance, InternalUtils.realizeObjects(parameters));
    } catch (InvocationTargetException ex) {
        fail = ex.getTargetException();
    } catch (Exception ex) {
        fail = ex;
    }
    if (fail != null)
        throw new RuntimeException(IOCMessages.contributionMethodError(contributorMethod, fail), fail);
}
Also used : WrongConfigurationTypeGuard(org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InjectionResources(org.apache.tapestry5.ioc.internal.util.InjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ObjectCreator

use of org.apache.tapestry5.commons.ObjectCreator in project tapestry-5 by apache.

the class SpringModuleDef method constructObjectCreatorForApplicationContext.

private ObjectCreator constructObjectCreatorForApplicationContext(final ServiceBuilderResources resources, @Primary ApplicationContextCustomizer customizer) {
    final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
    final Runnable shutdownListener = new Runnable() {

        @Override
        public void run() {
            loader.closeWebApplicationContext(servletContext);
        }
    };
    final RegistryShutdownHub shutdownHub = resources.getService(RegistryShutdownHub.class);
    return new ObjectCreator() {

        @Override
        public Object createObject() {
            return resources.getTracker().invoke("Creating Spring ApplicationContext via ContextLoader", new Invokable<Object>() {

                @Override
                public Object invoke() {
                    resources.getLogger().info(String.format("Starting Spring (version %s)", SpringVersion.getVersion()));
                    WebApplicationContext context = loader.initWebApplicationContext(servletContext);
                    shutdownHub.addRegistryShutdownListener(shutdownListener);
                    applicationContextCreated.set(true);
                    return context;
                }
            });
        }

        @Override
        public String toString() {
            return "ObjectCreator for Spring ApplicationContext";
        }
    };
}
Also used : RegistryShutdownHub(org.apache.tapestry5.ioc.services.RegistryShutdownHub) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)

Aggregations

ObjectCreator (org.apache.tapestry5.commons.ObjectCreator)5 Constructor (java.lang.reflect.Constructor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 InjectionResources (org.apache.tapestry5.ioc.internal.util.InjectionResources)3 MapInjectionResources (org.apache.tapestry5.ioc.internal.util.MapInjectionResources)3 ObjectStreamException (java.io.ObjectStreamException)2 ServiceBuilderResources (org.apache.tapestry5.ioc.ServiceBuilderResources)2 JustInTimeObjectCreator (org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator)2 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)2 EntityManager (javax.persistence.EntityManager)1 PersistenceContext (javax.persistence.PersistenceContext)1 ServletContext (javax.servlet.ServletContext)1 Location (org.apache.tapestry5.commons.Location)1 StringLocation (org.apache.tapestry5.commons.internal.services.StringLocation)1 PlasticProxyFactory (org.apache.tapestry5.commons.services.PlasticProxyFactory)1 Invokable (org.apache.tapestry5.ioc.Invokable)1 ServiceLifecycle2 (org.apache.tapestry5.ioc.ServiceLifecycle2)1 ServiceDef (org.apache.tapestry5.ioc.def.ServiceDef)1 DelegatingInjectionResources (org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources)1 WrongConfigurationTypeGuard (org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard)1