Search in sources :

Example 1 with AnnotationValue

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);
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) TopologyArchive(org.wildfly.swarm.topology.TopologyArchive)

Example 2 with AnnotationValue

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;
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 3 with AnnotationValue

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;
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue)

Example 4 with AnnotationValue

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);
                }
            }
        }
    }
}
Also used : LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) AnnotationValue(org.jboss.jandex.AnnotationValue) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 5 with AnnotationValue

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);
    }
}
Also used : PersistenceContextType(javax.persistence.PersistenceContextType) SynchronizationType(javax.persistence.SynchronizationType) JPADeploymentSettings(org.jboss.as.jpa.config.JPADeploymentSettings) ServiceName(org.jboss.msc.service.ServiceName) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) AnnotationValue(org.jboss.jandex.AnnotationValue) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Aggregations

AnnotationValue (org.jboss.jandex.AnnotationValue)32 AnnotationInstance (org.jboss.jandex.AnnotationInstance)20 ClassInfo (org.jboss.jandex.ClassInfo)12 AnnotationTarget (org.jboss.jandex.AnnotationTarget)10 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)8 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)6 HashSet (java.util.HashSet)5 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)4 InjectionSource (org.jboss.as.ee.component.InjectionSource)4 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)4 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)4 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 MethodInfo (org.jboss.jandex.MethodInfo)4 ServiceName (org.jboss.msc.service.ServiceName)4 ArrayList (java.util.ArrayList)3 TimeUnit (java.util.concurrent.TimeUnit)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)3