use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class StatefulTimeoutAnnotationInformationFactory method fromAnnotation.
@Override
protected StatefulTimeoutInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final long value = annotationInstance.value().asLong();
final AnnotationValue unitValue = annotationInstance.value("unit");
final TimeUnit unit;
if (unitValue != null) {
unit = TimeUnit.valueOf(unitValue.asEnum());
} else {
unit = TimeUnit.MINUTES;
}
return new StatefulTimeoutInfo(value, unit);
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class JPAAnnotationProcessor method bindClassSources.
private void bindClassSources(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
// handle PersistenceContext and PersistenceUnit annotations
if (isPersistenceContext(annotation) || isPersistenceUnit(annotation)) {
String injectionTypeName = getClassLevelInjectionType(annotation);
InjectionSource injectionSource = getBindingSource(deploymentUnit, annotation, injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = annotation.value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(annotation.name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
} else if (isPersistenceUnits(annotation)) {
// handle PersistenceUnits (array of PersistenceUnit)
AnnotationValue containedPersistenceUnits = annotation.value("value");
AnnotationInstance[] arrayPersistenceUnits;
if (containedPersistenceUnits != null && (arrayPersistenceUnits = containedPersistenceUnits.asNestedArray()) != null) {
for (int source = 0; source < arrayPersistenceUnits.length; source++) {
String injectionTypeName = getClassLevelInjectionType(arrayPersistenceUnits[source]);
InjectionSource injectionSource = getBindingSource(deploymentUnit, arrayPersistenceUnits[source], injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = arrayPersistenceUnits[source].value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(arrayPersistenceUnits[source].name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
}
}
} else if (isPersistenceContexts(annotation)) {
// handle PersistenceContexts (array of PersistenceContext)
AnnotationValue containedPersistenceContexts = annotation.value("value");
AnnotationInstance[] arrayPersistenceContexts;
if (containedPersistenceContexts != null && (arrayPersistenceContexts = containedPersistenceContexts.asNestedArray()) != null) {
for (int source = 0; source < arrayPersistenceContexts.length; source++) {
String injectionTypeName = getClassLevelInjectionType(arrayPersistenceContexts[source]);
InjectionSource injectionSource = getBindingSource(deploymentUnit, arrayPersistenceContexts[source], injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = arrayPersistenceContexts[source].value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(arrayPersistenceContexts[source].name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
}
}
}
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class JPAAnnotationProcessor method getBindingSource.
private InjectionSource getBindingSource(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, String injectionTypeName, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription);
if (pu == null) {
return null;
}
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
if (isPersistenceContext(annotation)) {
if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.cannotInjectResourceLocalEntityManager());
return null;
}
AnnotationValue pcType = annotation.value("type");
PersistenceContextType type = (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString())) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
AnnotationValue stType = annotation.value("synchronization");
SynchronizationType synchronizationType = (stType == null || SynchronizationType.SYNCHRONIZED.name().equals(stType.asString())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
Map<String, String> properties;
AnnotationValue value = annotation.value("properties");
AnnotationInstance[] props = value != null ? value.asNestedArray() : null;
if (props != null) {
properties = new HashMap<>();
for (int source = 0; source < props.length; source++) {
properties.put(props[source].value("name").asString(), props[source].value("value").asString());
}
} else {
properties = null;
}
// get deployment settings from top level du (jboss-all.xml is only parsed at the top level).
final JPADeploymentSettings jpaDeploymentSettings = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(JpaAttachments.DEPLOYMENT_SETTINGS_KEY);
return new PersistenceContextInjectionSource(type, synchronizationType, properties, puServiceName, deploymentUnit.getServiceRegistry(), scopedPuName, injectionTypeName, pu, jpaDeploymentSettings);
} else {
return new PersistenceUnitInjectionSource(puServiceName, deploymentUnit.getServiceRegistry(), injectionTypeName, pu);
}
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class JPAAnnotationProcessor method getPersistenceUnit.
private PersistenceUnitMetadata getPersistenceUnit(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
final AnnotationValue puName = annotation.value("unitName");
// note: a null searchName will match the first PU definition found
String searchName = null;
if (puName != null && (searchName = puName.asString()) != null) {
searchName = SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit).replaceProperties(searchName);
}
ROOT_LOGGER.debugf("persistence unit search for unitName=%s referenced from class=%s (annotation=%s)", searchName, classDescription.getClassName(), annotation.toString());
PersistenceUnitMetadata pu = PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, searchName);
if (null == pu) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(searchName, deploymentUnit));
return null;
}
return pu;
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class JwtActivationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null) {
return;
}
JBossWebMetaData mergedMetaData = warMetaData.getMergedJBossWebMetaData();
LoginConfigMetaData loginConfig = mergedMetaData != null ? mergedMetaData.getLoginConfig() : null;
if (loginConfig != null && !JWT_AUTH_METHOD.equals(loginConfig.getAuthMethod())) {
// An auth-method has been defined, this is not MP-JWT
return;
}
if (loginConfig == null) {
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
List<AnnotationInstance> annotations = index.getAnnotations(LOGIN_CONFIG_DOT_NAME);
for (AnnotationInstance annotation : annotations) {
// First we must be sure the annotation is on an Application class.
AnnotationTarget target = annotation.target();
if (target.kind() == Kind.CLASS && extendsApplication(target.asClass(), index)) {
loginConfig = new LoginConfigMetaData();
AnnotationValue authMethodValue = annotation.value(AUTH_METHOD);
if (authMethodValue == null) {
throw ROOT_LOGGER.noAuthMethodSpecified();
}
loginConfig.setAuthMethod(authMethodValue.asString());
AnnotationValue realmNameValue = annotation.value(REALM_NAME);
if (realmNameValue != null) {
loginConfig.setRealmName(realmNameValue.asString());
}
mergedMetaData.setLoginConfig(loginConfig);
break;
}
ROOT_LOGGER.loginConfigInvalidTarget(target.toString());
}
}
if (loginConfig != null && JWT_AUTH_METHOD.equals(loginConfig.getAuthMethod())) {
ROOT_LOGGER.tracef("Activating JWT for deployment %s.", deploymentUnit.getName());
JwtDeploymentMarker.mark(deploymentUnit);
VirtualDomainMarkerUtility.virtualDomainRequired(deploymentUnit);
}
}
Aggregations