use of org.jboss.as.ee.component.LookupInjectionSource in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceContextRefs.
/**
* 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> getPersistenceContextRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
if (remoteEnvironment == null) {
return bindingConfigurations;
}
if (remoteEnvironment instanceof Environment) {
PersistenceContextReferencesMetaData persistenceUnitRefs = ((Environment) remoteEnvironment).getPersistenceContextRefs();
if (persistenceUnitRefs != null) {
for (PersistenceContextReferenceMetaData 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-context-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, EntityManager.class);
BindingConfiguration bindingConfiguration = null;
if (!isEmpty(lookup)) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
} else {
PropertiesMetaData properties = puRef.getProperties();
Map<String, String> map = new HashMap<>();
if (properties != null) {
for (PropertyMetaData prop : properties) {
map.put(prop.getKey(), prop.getValue());
}
}
PersistenceContextType type = (puRef.getPersistenceContextType() == null || puRef.getPersistenceContextType() == PersistenceContextTypeDescription.TRANSACTION) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
SynchronizationType synchronizationType = (puRef.getPersistenceContextSynchronization() == null || PersistenceContextSynchronizationType.Synchronized.equals(puRef.getPersistenceContextSynchronization())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
InjectionSource pcBindingSource = this.getPersistenceContextBindingSource(deploymentUnit, persistenceUnitName, type, synchronizationType, map);
bindingConfiguration = new BindingConfiguration(name, pcBindingSource);
}
bindingConfigurations.add(bindingConfiguration);
}
}
}
return bindingConfigurations;
}
use of org.jboss.as.ee.component.LookupInjectionSource in project wildfly by wildfly.
the class DefaultJMSConnectionFactoryBindingProcessor 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 defaultJMSConnectionFactory = moduleDescription.getDefaultResourceJndiNames().getJmsConnectionFactory();
if (defaultJMSConnectionFactory == null) {
return;
}
final LookupInjectionSource injectionSource = new LookupInjectionSource(defaultJMSConnectionFactory);
if (DeploymentTypeMarker.isType(WAR, deploymentUnit)) {
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(MODULE_DEFAULT_JMS_CONNECTION_FACTORY, injectionSource));
} else {
if (DeploymentTypeMarker.isType(APPLICATION_CLIENT, deploymentUnit)) {
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_JMS_CONNECTION_FACTORY, injectionSource));
}
for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription.getNamingMode() == ComponentNamingMode.CREATE) {
componentDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_JMS_CONNECTION_FACTORY, injectionSource));
}
}
}
}
use of org.jboss.as.ee.component.LookupInjectionSource 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.LookupInjectionSource in project wildfly by wildfly.
the class ResourceInjectionAnnotationParsingProcessor method process.
protected void process(final DeploymentPhaseContext phaseContext, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final String injectionType, final String localContextName, final InjectionTarget targetDescription, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException {
final EEResourceReferenceProcessorRegistry registry = phaseContext.getDeploymentUnit().getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
final AnnotationValue lookupAnnotation = annotation.value("lookup");
String lookup = (lookupAnnotation == null) ? null : replacer.replaceProperties(lookupAnnotation.asString());
// if "lookup" hasn't been specified then fallback on "mappedName" which we treat the same as "lookup"
if (isEmpty(lookup)) {
final AnnotationValue mappedNameAnnotationValue = annotation.value("mappedName");
lookup = (mappedNameAnnotationValue == null) ? null : replacer.replaceProperties(mappedNameAnnotationValue.asString());
}
if (isEmpty(lookup) && FIXED_LOCATIONS.containsKey(injectionType)) {
lookup = FIXED_LOCATIONS.get(injectionType);
}
InjectionSource valueSource = null;
final boolean isEnvEntryType = this.isEnvEntryType(injectionType, module);
if (!isEmpty(lookup)) {
valueSource = new LookupInjectionSource(lookup, JAVAX_NAMING_CONTEXT.equals(injectionType));
} else if (isEnvEntryType) {
// if it's an env-entry type then we do *not* create a BindingConfiguration to bind to the ENC
// since the binding (value) for env-entry is always driven from a deployment descriptor.
// The deployment descriptor processing and subsequent binding in the ENC is taken care off by a
// different Deployment unit processor. If the value isn't specified in the deployment descriptor,
// then there will be no binding the ENC and that's what is expected by the Java EE 6 spec. Furthermore,
// if the @Resource is an env-entry binding then the injection target will be optional since in the absence of
// an env-entry-value, there won't be a binding and effectively no injection. This again is as expected by spec.
} else {
//otherwise we just try and handle it
//if we don't have a value source we will try and inject from a lookup
//and the user has to configure the value in a deployment descriptor
final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(injectionType);
if (resourceReferenceProcessor != null) {
valueSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
}
}
if (valueSource == null) {
// the ResourceInjectionConfiguration is created by LazyResourceInjection
if (targetDescription != null) {
final LookupInjectionSource optionalInjection = new LookupInjectionSource(localContextName, true);
final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(targetDescription, optionalInjection, true);
classDescription.addResourceInjection(injectionConfiguration);
}
} else {
// our injection comes from the local lookup, no matter what.
final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration(targetDescription, injectionSource) : null;
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
if (injectionConfiguration != null) {
classDescription.addResourceInjection(injectionConfiguration);
}
}
}
use of org.jboss.as.ee.component.LookupInjectionSource in project wildfly by wildfly.
the class ResourceReferenceProcessor method getEnvironmentEntries.
private List<BindingConfiguration> getEnvironmentEntries(final DeploymentDescriptorEnvironment environment, final ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
final List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
final EnvironmentEntriesMetaData envEntries = environment.getEnvironment().getEnvironmentEntries();
if (envEntries == null) {
return bindings;
}
for (final EnvironmentEntryMetaData envEntry : envEntries) {
final String name;
if (envEntry.getName().startsWith("java:")) {
name = envEntry.getName();
} else {
name = environment.getDefaultContext() + envEntry.getEnvEntryName();
}
Class<?> classType = null;
if (envEntry.getType() != null) {
try {
classType = this.loadClass(envEntry.getType(), classLoader);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, envEntry.getType());
}
}
final String value = envEntry.getValue();
final String lookup = envEntry.getLookupName();
if (!isEmpty(value) && !isEmpty(lookup)) {
throw EeLogger.ROOT_LOGGER.cannotSpecifyBoth("<env-entry-value>", "<lookup-name>");
} else if (isEmpty(lookup) && isEmpty(value)) {
// (Java ee platform spec 6.0 fr pg 80)
continue;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, envEntry, classType);
if (classType == null) {
throw EeLogger.ROOT_LOGGER.cannotDetermineType("<env-entry>", name, "<env-entry-type>");
}
final String type = classType.getName();
final BindingConfiguration bindingConfiguration;
if (!isEmpty(lookup)) {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
} else if (type.equals(String.class.getName())) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(value));
} else if (type.equals(Integer.class.getName()) || type.equals("int")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Integer.valueOf(value)));
} else if (type.equals(Short.class.getName()) || type.equals("short")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Short.valueOf(value)));
} else if (type.equals(Long.class.getName()) || type.equals("long")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Long.valueOf(value)));
} else if (type.equals(Byte.class.getName()) || type.equals("byte")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Byte.valueOf(value)));
} else if (type.equals(Double.class.getName()) || type.equals("double")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Double.valueOf(value)));
} else if (type.equals(Float.class.getName()) || type.equals("float")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Float.valueOf(value)));
} else if (type.equals(Boolean.class.getName()) || type.equals("boolean")) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Boolean.valueOf(value)));
} else if (type.equals(Character.class.getName()) || type.equals("char")) {
if (value.length() != 1) {
throw EeLogger.ROOT_LOGGER.invalidCharacterLength("env-entry", value);
}
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(value.charAt(0)));
} else if (type.equals(Class.class.getName())) {
try {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(classLoader.loadClass(value)));
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(value);
}
} else if (classType.isEnum() || (classType.getEnclosingClass() != null && classType.getEnclosingClass().isEnum())) {
bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Enum.valueOf((Class) classType, value)));
} else {
throw EeLogger.ROOT_LOGGER.unknownElementType("env-entry", type);
}
bindings.add(bindingConfiguration);
}
return bindings;
}
Aggregations