use of org.jboss.as.ee.component.LookupInjectionSource in project wildfly by wildfly.
the class ResourceReferenceProcessor method getMessageDestinationRefs.
/**
* TODO: should this be part of the messaging subsystem
*/
private List<BindingConfiguration> getMessageDestinationRefs(final DeploymentDescriptorEnvironment environment, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex, final ResourceInjectionTarget resourceInjectionTarget, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
final MessageDestinationReferencesMetaData messageDestinationReferences = environment.getEnvironment().getMessageDestinationReferences();
if (messageDestinationReferences == null) {
return bindings;
}
for (final MessageDestinationReferenceMetaData messageRef : messageDestinationReferences) {
final String name;
if (messageRef.getName().startsWith("java:")) {
name = messageRef.getName();
} else {
name = environment.getDefaultContext() + messageRef.getName();
}
Class<?> classType = null;
if (messageRef.getType() != null) {
try {
classType = classLoader.loadClass(messageRef.getType());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, messageRef.getType());
}
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
final LookupInjectionSource injectionSource = new LookupInjectionSource(name);
classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, messageRef, classType);
final BindingConfiguration bindingConfiguration;
if (!isEmpty(messageRef.getLookupName())) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(messageRef.getLookupName()));
bindings.add(bindingConfiguration);
} else if (!isEmpty(messageRef.getMappedName())) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(messageRef.getMappedName()));
bindings.add(bindingConfiguration);
} else if (!isEmpty(messageRef.getLink())) {
final MessageDestinationInjectionSource messageDestinationInjectionSource = new MessageDestinationInjectionSource(messageRef.getLink(), name);
bindingConfiguration = new BindingConfiguration(name, messageDestinationInjectionSource);
deploymentUnit.addToAttachmentList(Attachments.MESSAGE_DESTINATIONS, messageDestinationInjectionSource);
bindings.add(bindingConfiguration);
} else {
ROOT_LOGGER.cannotResolve("message-destination-ref", name);
}
}
return bindings;
}
use of org.jboss.as.ee.component.LookupInjectionSource 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.LookupInjectionSource 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.LookupInjectionSource in project wildfly by wildfly.
the class DefaultDataSourceBindingProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(EAR, deploymentUnit)) {
return;
}
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
return;
}
final String defaultDataSource = moduleDescription.getDefaultResourceJndiNames().getDataSource();
if (defaultDataSource == null) {
return;
}
final LookupInjectionSource injectionSource = new LookupInjectionSource(defaultDataSource);
if (DeploymentTypeMarker.isType(WAR, deploymentUnit)) {
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(MODULE_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
} else {
if (DeploymentTypeMarker.isType(APPLICATION_CLIENT, deploymentUnit)) {
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
}
for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription.getNamingMode() == ComponentNamingMode.CREATE) {
componentDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
}
}
}
}
use of org.jboss.as.ee.component.LookupInjectionSource 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;
}
Aggregations