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;
}
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();
}
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();
}
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);
}
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";
}
};
}
Aggregations