use of org.jboss.as.ee.component.InjectionSource in project wildfly by wildfly.
the class EjbResourceInjectionAnnotationProcessor method process.
private void process(final DeploymentUnit deploymentUnit, final String beanInterface, final String beanName, final String lookup, final ClassInfo classInfo, final InjectionTarget targetDescription, final String localContextName, final EEModuleDescription eeModuleDescription) {
if (!isEmpty(lookup) && !isEmpty(beanName)) {
EjbLogger.DEPLOYMENT_LOGGER.debugf("Both beanName = %s and lookup = %s have been specified in @EJB annotation. Lookup will be given preference. Class: %s", beanName, lookup, classInfo.name());
}
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final InjectionSource valueSource;
EjbInjectionSource ejbInjectionSource = null;
//give preference to lookup
if (!isEmpty(lookup)) {
if (!lookup.startsWith("java:")) {
valueSource = new EjbLookupInjectionSource(lookup, targetDescription == null ? null : targetDescription.getDeclaredValueClassName());
} else {
valueSource = createLookup(lookup, appclient);
}
} else if (!isEmpty(beanName)) {
valueSource = ejbInjectionSource = new EjbInjectionSource(beanName, beanInterface, localContextName, deploymentUnit, appclient);
} else {
valueSource = ejbInjectionSource = new EjbInjectionSource(beanInterface, localContextName, deploymentUnit, appclient);
}
if (ejbInjectionSource != null) {
deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
}
// our injection comes from the local lookup, no matter what.
final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration(targetDescription, createLookup(localContextName, appclient)) : null;
// Create the binding from whence our injection comes.
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
if (injectionConfiguration != null) {
classDescription.addResourceInjection(injectionConfiguration);
}
}
use of org.jboss.as.ee.component.InjectionSource 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;
}
use of org.jboss.as.ee.component.InjectionSource in project wildfly by wildfly.
the class ResourceReferenceProcessor method getResourceEnvRefEntries.
private List<BindingConfiguration> getResourceEnvRefEntries(final DeploymentUnit deploymentUnit, final DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
final ResourceEnvironmentReferencesMetaData resourceEnvRefs = environment.getEnvironment().getResourceEnvironmentReferences();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
if (resourceEnvRefs == null) {
return bindings;
}
for (ResourceEnvironmentReferenceMetaData resourceEnvRef : resourceEnvRefs) {
final String name;
if (resourceEnvRef.getName().startsWith("java:")) {
name = resourceEnvRef.getName();
} else {
name = environment.getDefaultContext() + resourceEnvRef.getName();
}
Class<?> classType = null;
if (resourceEnvRef.getType() != null) {
try {
classType = classLoader.loadClass(resourceEnvRef.getType());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, resourceEnvRef.getType());
}
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
InjectionSource injectionSource = new LookupInjectionSource(name);
classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, resourceEnvRef, classType);
if (!isEmpty(resourceEnvRef.getLookupName())) {
injectionSource = new LookupInjectionSource(resourceEnvRef.getLookupName(), classType != null && JAVAX_NAMING_CONTEXT.equals(classType.getName()));
} 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 {
//TODO: how are we going to handle these? Previously they would have been handled by jboss-*.xml
if (resourceEnvRef.getResourceEnvRefName().startsWith("java:")) {
ROOT_LOGGER.cannotResolve("resource-env-ref", name);
continue;
} else {
injectionSource = new LookupInjectionSource("java:jboss/resources/" + resourceEnvRef.getResourceEnvRefName());
}
}
}
}
bindings.add(new BindingConfiguration(name, injectionSource));
}
return bindings;
}
use of org.jboss.as.ee.component.InjectionSource in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceUnitRefs.
/**
* Resolves persistence-unit-ref
*
* @param environment The environment to resolve the elements for
* @param classLoader The deployment class loader
* @param deploymentReflectionIndex The reflection index
* @return The bindings for the environment entries
*/
private List<BindingConfiguration> getPersistenceUnitRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
if (environment.getEnvironment() == null) {
return bindingConfigurations;
}
PersistenceUnitReferencesMetaData persistenceUnitRefs = environment.getEnvironment().getPersistenceUnitRefs();
if (persistenceUnitRefs != null) {
if (persistenceUnitRefs.size() > 0) {
JPADeploymentMarker.mark(deploymentUnit);
}
for (PersistenceUnitReferenceMetaData puRef : persistenceUnitRefs) {
String name = puRef.getName();
String persistenceUnitName = puRef.getPersistenceUnitName();
String lookup = puRef.getLookupName();
if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
throw JpaLogger.ROOT_LOGGER.cannotSpecifyBoth("<lookup-name>", lookup, "persistence-unit-name", persistenceUnitName, "<persistence-unit-ref/>", resourceInjectionTarget);
}
if (!name.startsWith("java:")) {
name = environment.getDefaultContext() + name;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
//add any injection targets
processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, puRef, EntityManagerFactory.class);
BindingConfiguration bindingConfiguration = null;
if (!isEmpty(lookup)) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
} else {
InjectionSource puBindingSource = this.getPersistenceUnitBindingSource(deploymentUnit, persistenceUnitName);
bindingConfiguration = new BindingConfiguration(name, puBindingSource);
}
bindingConfigurations.add(bindingConfiguration);
}
}
return bindingConfigurations;
}
use of org.jboss.as.ee.component.InjectionSource in project wildfly by wildfly.
the class JPAAnnotationProcessor method processMethod.
private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo));
return;
}
final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
final AnnotationValue declaredNameValue = annotation.value("name");
final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
final String localContextName;
if (declaredName == null || declaredName.isEmpty()) {
localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix;
} else {
localContextName = declaredName;
}
final String injectionType = methodInfo.args()[0].name().toString();
final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
if (bindingSource != null) {
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
// setup the injection configuration
final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
// source is always local ENC jndi name
final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
eeModuleClassDescription.addResourceInjection(injectionConfiguration);
}
}
Aggregations