use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.
the class AdvertisingMetadataProcessor method advertise.
private void advertise(Archive<?> archive, AnnotationInstance anno) {
String serviceName = anno.value().asString();
List<String> tags = Optional.ofNullable(anno.value(Advertise.TAGS_ATTRIBUTE_NAME)).map(AnnotationValue::asStringArray).map(Arrays::asList).orElse(Collections.emptyList());
TopologyArchive topologyArchive = archive.as(TopologyArchive.class);
topologyArchive.advertise(serviceName, tags);
}
use of org.jboss.jandex.AnnotationValue in project wildfly-camel by wildfly-extras.
the class CamelDeploymentSettingsProcessor method hasCamelActivationAnnotations.
private boolean hasCamelActivationAnnotations(final DeploymentUnit depUnit) {
boolean result = false;
// Search for Camel activation annotations
for (String annotationClassName : ACTIVATION_ANNOTATIONS) {
if (annotationClassName.equals("org.wildfly.extension.camel.CamelAware")) {
AnnotationInstance annotation = getAnnotation(depUnit, annotationClassName);
if (annotation != null) {
LOGGER.debug("@CamelAware annotation found");
AnnotationValue value = annotation.value();
result = value != null ? value.asBoolean() : true;
if (result) {
break;
}
}
} else {
List<AnnotationInstance> annotations = getAnnotations(depUnit, annotationClassName);
if (!annotations.isEmpty()) {
LOGGER.debug("{} annotation found", annotations.get(0).toString(true));
result = true;
break;
}
}
}
return result;
}
use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.
the class JandexUtil method refValue.
/**
* Reads a string property named "ref" value from the given annotation and converts it
* to a value appropriate for setting on a model's "$ref" property.
* @param annotation
* @param refType
*/
public static String refValue(AnnotationInstance annotation, RefType refType) {
AnnotationValue value = annotation.value(OpenApiConstants.PROP_REF);
if (value == null) {
return null;
}
String $ref = value.asString();
if ($ref.startsWith("#/")) {
return $ref;
}
switch(refType) {
case Callback:
$ref = "#/components/callbacks/" + $ref;
break;
case Example:
$ref = "#/components/examples/" + $ref;
break;
case Header:
$ref = "#/components/headers/" + $ref;
break;
case Link:
$ref = "#/components/links/" + $ref;
break;
case Parameter:
$ref = "#/components/parameters/" + $ref;
break;
case RequestBody:
$ref = "#/components/requestBodies/" + $ref;
break;
case Response:
$ref = "#/components/responses/" + $ref;
break;
case Schema:
$ref = "#/components/schemas/" + $ref;
break;
case SecurityScheme:
$ref = "#/components/securitySchemes/" + $ref;
break;
default:
throw new IllegalStateException("Unexpected Jandex RefType " + refType);
}
return $ref;
}
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);
}
}
Aggregations