use of org.jboss.as.ee.component.FixedInjectionSource in project wildfly by wildfly.
the class WSRefDDProcessor method processDescriptorEntries.
@Override
protected List<BindingConfiguration> processDescriptorEntries(final DeploymentUnit unit, final DeploymentDescriptorEnvironment environment, final ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
final ServiceReferencesMetaData serviceRefsMD = environment.getEnvironment().getServiceReferences();
if (serviceRefsMD == null) {
return Collections.<BindingConfiguration>emptyList();
}
final List<BindingConfiguration> bindingDescriptions = new LinkedList<BindingConfiguration>();
for (final ServiceReferenceMetaData serviceRefMD : serviceRefsMD) {
final UnifiedServiceRefMetaData serviceRefUMDM = getServiceRef(unit, componentDescription, serviceRefMD);
final Module module = unit.getAttachment(Attachments.MODULE);
WebServiceManagedReferenceFactory factory = new WebServiceManagedReferenceFactory(serviceRefUMDM, module.getClassLoader());
final FixedInjectionSource valueSource = new FixedInjectionSource(factory, factory);
final BindingConfiguration bindingConfiguration = new BindingConfiguration(serviceRefUMDM.getServiceRefName(), valueSource);
bindingDescriptions.add(bindingConfiguration);
final String serviceRefTypeName = serviceRefUMDM.getServiceRefType();
final Class<?> serviceRefType = getClass(classLoader, serviceRefTypeName);
processInjectionTargets(resourceInjectionTarget, valueSource, classLoader, deploymentReflectionIndex, serviceRefMD, serviceRefType);
}
return bindingDescriptions;
}
use of org.jboss.as.ee.component.FixedInjectionSource 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.ee.component.FixedInjectionSource in project wildfly by wildfly.
the class ResourceReferenceProcessor method getResourceRefEntries.
private List<BindingConfiguration> getResourceRefEntries(final DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
final ResourceReferencesMetaData resourceRefs = environment.getEnvironment().getResourceReferences();
if (resourceRefs == null) {
return bindings;
}
for (final ResourceReferenceMetaData resourceRef : resourceRefs) {
final String name;
if (resourceRef.getName().startsWith("java:")) {
name = resourceRef.getName();
} else {
name = environment.getDefaultContext() + resourceRef.getName();
}
Class<?> classType = null;
if (resourceRef.getType() != null) {
try {
classType = classLoader.loadClass(resourceRef.getType());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, resourceRef.getType());
}
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
InjectionSource injectionSource = new LookupInjectionSource(name);
classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, resourceRef, classType);
if (!isEmpty(resourceRef.getLookupName())) {
injectionSource = new LookupInjectionSource(resourceRef.getLookupName(), classType != null && JAVAX_NAMING_CONTEXT.equals(classType.getName()));
} else if (!isEmpty(resourceRef.getResUrl())) {
final String url = resourceRef.getResUrl();
if (classType != null && classType.equals(URI.class)) {
try {
//we need a newURI every time
injectionSource = new FixedInjectionSource(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new URI(url));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}, new URI(url));
} catch (URISyntaxException e) {
throw EeLogger.ROOT_LOGGER.cannotParseResourceRefUri(e, resourceRef.getResUrl());
}
} else {
try {
injectionSource = new FixedInjectionSource(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new URL(url));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}, new URL(url));
} catch (MalformedURLException e) {
throw EeLogger.ROOT_LOGGER.cannotParseResourceRefUri(e, resourceRef.getResUrl());
}
}
} else {
if (classType == null) {
throw EeLogger.ROOT_LOGGER.cannotDetermineType(name);
}
//check if it is a well known type
final String lookup = ResourceInjectionAnnotationParsingProcessor.FIXED_LOCATIONS.get(classType.getName());
if (lookup != null) {
injectionSource = new LookupInjectionSource(lookup);
} else {
final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(classType.getName());
if (resourceReferenceProcessor != null) {
injectionSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
} else if (!resourceRef.getResourceRefName().startsWith("java:")) {
injectionSource = new LookupInjectionSource("java:jboss/resources/" + resourceRef.getResourceRefName());
} else {
//if we cannot resolve it just log
ROOT_LOGGER.cannotResolve("resource-env-ref", name);
continue;
}
}
}
bindings.add(new BindingConfiguration(name, injectionSource));
}
return bindings;
}
Aggregations