DeploymentContext deployment)
throws BuilderConfigException {
PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
definition.getImplementation().getComponentType();
PojoConfiguration configuration = new PojoConfiguration();
configuration.setParent(parent);
Scope scope = componentType.getImplementationScope();
if (Scope.MODULE == scope) {
configuration.setScopeContainer(deployment.getModuleScope());
} else {
configuration.setScopeContainer(scopeRegistry.getScopeContainer(scope));
}
if (definition.getInitLevel() != null) {
configuration.setInitLevel(definition.getInitLevel());
} else {
configuration.setInitLevel(componentType.getInitLevel());
}
Method initMethod = componentType.getInitMethod();
if (initMethod != null) {
configuration.setInitInvoker(new MethodEventInvoker(initMethod));
}
Method destroyMethod = componentType.getDestroyMethod();
if (destroyMethod != null) {
configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
}
configuration.setWireService(wireService);
configuration.setWorkContext(workContext);
configuration.setScheduler(workScheduler);
// setup property injection sites
for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
configuration.addPropertySite(property.getName(), property.getMember());
}
// setup reference injection sites
for (JavaMappedReference reference : componentType.getReferences().values()) {
Member member = reference.getMember();
if (member != null) {
// could be null if the reference is mapped to a constructor
configuration.addReferenceSite(reference.getName(), member);
}
}
// setup constructor injection
ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
Constructor<?> constr = ctorDef.getConstructor();
PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
configuration.setInstanceFactory(instanceFactory);
configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
JavaAtomicComponent component =
new JavaAtomicComponent(definition.getName(), configuration, monitor);
// handle properties
for (PropertyValue<?> property : definition.getPropertyValues().values()) {
ObjectFactory<?> factory = property.getValueFactory();
if (factory != null) {
component.addPropertyFactory(property.getName(), factory);
}
}
for (JavaMappedService service : componentType.getServices().values()) {
// setup callback injection sites
if (service.getCallbackReferenceName() != null) {
// Only if there is a callback reference in the service
configuration.addCallbackSite(service.getCallbackReferenceName(), service.getCallbackMember());
}
}
return component;
}