use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class WSRefAnnotationProcessor method processRef.
private static void processRef(final DeploymentUnit unit, final String type, final WSRefAnnotationWrapper annotation, final ClassInfo classInfo, final InjectionTarget injectionTarget, final String bindingName) throws DeploymentUnitProcessingException {
final EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final AnnotatedElement target = createAnnotatedElement(unit, classInfo, injectionTarget);
final String componentClassName = classInfo.name().toString();
final Map<String, String> bindingMap = new HashMap<String, String>();
boolean isEJB = false;
for (final ComponentDescription componentDescription : moduleDescription.getComponentsByClassName(componentClassName)) {
if (componentDescription instanceof SessionBeanComponentDescription) {
isEJB = true;
bindingMap.put(componentDescription.getComponentName() + "/" + bindingName, bindingName);
}
}
if (!isEJB) {
bindingMap.put(bindingName, bindingName);
}
for (String refKey : bindingMap.keySet()) {
String refName = bindingMap.get(refKey);
ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(unit, type, annotation, target, refName, refKey);
final EEModuleClassDescription classDescription = moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
// Create the binding from whence our injection comes.
final InjectionSource serviceRefSource = new FixedInjectionSource(factory, factory);
final BindingConfiguration bindingConfiguration = new BindingConfiguration(refName, serviceRefSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
// our injection comes from the local lookup, no matter what.
final ResourceInjectionConfiguration injectionConfiguration = injectionTarget != null ? new ResourceInjectionConfiguration(injectionTarget, new LookupInjectionSource(refName)) : null;
if (injectionConfiguration != null) {
classDescription.addResourceInjection(injectionConfiguration);
}
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class AbstractResourceInjectionServices method createLazyResourceReferenceFactory.
protected ResourceReferenceFactory<Object> createLazyResourceReferenceFactory(final ContextNames.BindInfo ejbBindInfo) {
return new ResourceReferenceFactory<Object>() {
@Override
public ResourceReference<Object> createResource() {
final ManagedReferenceFactory factory = getManagedReferenceFactory(ejbBindInfo);
if (factory == null) {
return new SimpleResourceReference<>(null);
}
final ManagedReference instance = factory.getReference();
return new ResourceReference<Object>() {
@Override
public Object getInstance() {
return instance.getInstance();
}
@Override
public void release() {
instance.release();
}
};
}
};
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class WeldJaxwsInjectionServices method registerWebServiceRefInjectionPoint.
@Override
public <T> ResourceReferenceFactory<T> registerWebServiceRefInjectionPoint(final InjectionPoint injectionPoint) {
WebServiceRef annotation = getResourceAnnotated(injectionPoint).getAnnotation(WebServiceRef.class);
if (annotation == null) {
throw WeldLogger.ROOT_LOGGER.annotationNotFound(WebServiceRef.class, injectionPoint.getMember());
}
validateWebServiceRefInjectionPoint(injectionPoint, annotation);
try {
ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(deploymentUnit, classNameFromType(injectionPoint.getType()), new WSRefAnnotationWrapper(annotation), (AnnotatedElement) injectionPoint.getMember(), getBindingName(injectionPoint, annotation));
return new ManagedReferenceFactoryToResourceReferenceFactoryAdapter<>(factory);
} catch (DeploymentUnitProcessingException e) {
throw new RuntimeException(e);
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class WeldClassIntrospector method createFactory.
@Override
public ManagedReferenceFactory createFactory(Class<?> clazz) {
final BeanManager beanManager = this.beanManager.getValue();
final InjectionTarget injectionTarget = getInjectionTarget(clazz);
return new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
final CreationalContext context = beanManager.createCreationalContext(null);
final Object instance = injectionTarget.produce(context);
injectionTarget.inject(instance, context);
injectionTarget.postConstruct(instance);
return new WeldManagedReference(injectionTarget, context, instance);
}
};
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class ModuleJndiBindingProcessor method addJndiBinding.
protected void addJndiBinding(final EEModuleConfiguration module, final BindingConfiguration bindingConfiguration, final DeploymentPhaseContext phaseContext, final List<ServiceName> dependencies) throws DeploymentUnitProcessingException {
// Gather information about the dependency
final String bindingName = bindingConfiguration.getName().startsWith("java:") ? bindingConfiguration.getName() : "java:module/env/" + bindingConfiguration.getName();
InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(true, module.getModuleName(), module.getModuleName(), module.getApplicationName());
// Check to see if this entry should actually be bound into JNDI.
if (bindingName != null) {
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(module.getApplicationName(), module.getModuleName(), module.getModuleName(), false, bindingName);
dependencies.add(bindInfo.getBinderServiceName());
if (bindingName.startsWith("java:comp") || bindingName.startsWith("java:module") || bindingName.startsWith("java:app")) {
//this is a binding that does not need to be shared.
try {
final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = phaseContext.getServiceTarget().addService(bindInfo.getBinderServiceName(), service);
bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
serviceBuilder.install();
} catch (DuplicateServiceException e) {
ServiceController<ManagedReferenceFactory> registered = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
if (registered == null)
throw e;
BinderService service = (BinderService) registered.getService();
if (!service.getSource().equals(bindingConfiguration.getSource()))
throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
} catch (CircularDependencyException e) {
throw EeLogger.ROOT_LOGGER.circularDependency(bindingName);
}
} else {
BinderService service;
try {
service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource(), true);
ServiceBuilder<ManagedReferenceFactory> serviceBuilder = CurrentServiceContainer.getServiceContainer().addService(bindInfo.getBinderServiceName(), service);
bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
serviceBuilder.install();
} catch (DuplicateServiceException e) {
final ServiceController<ManagedReferenceFactory> controller = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
if (controller == null)
throw e;
service = (BinderService) controller.getService();
if (!equals(service.getSource(), bindingConfiguration.getSource())) {
throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
}
}
//as these bindings are not child services
//we need to add a listener that released the service when the deployment stops
service.acquire();
ServiceController<?> unitService = CurrentServiceContainer.getServiceContainer().getService(phaseContext.getDeploymentUnit().getServiceName());
unitService.addListener(new BinderReleaseListener(service));
}
} else {
throw EeLogger.ROOT_LOGGER.nullBindingName(bindingConfiguration);
}
}
Aggregations