Search in sources :

Example 11 with AnnotationValue

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);
}
Also used : StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) AnnotationValue(org.jboss.jandex.AnnotationValue) TimeUnit(java.util.concurrent.TimeUnit)

Example 12 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 13 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)

Example 14 with AnnotationValue

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

Example 15 with AnnotationValue

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);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) LoginConfigMetaData(org.jboss.metadata.web.spec.LoginConfigMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) AnnotationValue(org.jboss.jandex.AnnotationValue) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) 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