Search in sources :

Example 26 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class AccessTimeoutAnnotationInformationFactory method fromAnnotation.

@Override
protected AccessTimeoutDetails fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
    final long timeout = annotationInstance.value().asLong();
    AnnotationValue unitAnnVal = annotationInstance.value("unit");
    final TimeUnit unit = unitAnnVal != null ? TimeUnit.valueOf(unitAnnVal.asEnum()) : TimeUnit.MILLISECONDS;
    return new AccessTimeoutDetails(timeout, unit);
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) TimeUnit(java.util.concurrent.TimeUnit) AccessTimeoutDetails(org.jboss.as.ejb3.concurrency.AccessTimeoutDetails)

Example 27 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class ApplicationExceptionAnnotationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
        return;
    }
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        return;
    }
    List<AnnotationInstance> applicationExceptionAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ApplicationException.class.getName()));
    if (applicationExceptionAnnotations == null || applicationExceptionAnnotations.isEmpty()) {
        return;
    }
    ApplicationExceptionDescriptions descriptions = new ApplicationExceptionDescriptions();
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS, descriptions);
    for (AnnotationInstance annotationInstance : applicationExceptionAnnotations) {
        AnnotationTarget target = annotationInstance.target();
        if (!(target instanceof ClassInfo)) {
            throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(ApplicationException.class.getName(), target);
        }
        String exceptionClassName = ((ClassInfo) target).name().toString();
        boolean rollback = false;
        AnnotationValue rollBackAnnValue = annotationInstance.value("rollback");
        if (rollBackAnnValue != null) {
            rollback = rollBackAnnValue.asBoolean();
        }
        // default "inherited" is true
        boolean inherited = true;
        AnnotationValue inheritedAnnValue = annotationInstance.value("inherited");
        if (inheritedAnnValue != null) {
            inherited = inheritedAnnValue.asBoolean();
        }
        descriptions.addApplicationException(exceptionClassName, rollback, inherited);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ApplicationException(javax.ejb.ApplicationException) ApplicationExceptionDescriptions(org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions) 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) ClassInfo(org.jboss.jandex.ClassInfo)

Example 28 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class JPAAnnotationProcessor method processMethod.

private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String methodName = methodInfo.name();
    if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
        eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo));
        return;
    }
    final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix;
    } else {
        localContextName = declaredName;
    }
    final String injectionType = methodInfo.args()[0].name().toString();
    final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
    if (bindingSource != null) {
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
        eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
        // setup the injection configuration
        final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
        // source is always local ENC jndi name
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) 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) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 29 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class JPAAnnotationProcessor method processField.

private void processField(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final FieldInfo fieldInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String fieldName = fieldInfo.name();
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = fieldInfo.declaringClass().name().toString() + "/" + fieldName;
    } else {
        localContextName = declaredName;
    }
    // final AnnotationValue declaredTypeValue = annotation.value("type");
    final DotName declaredTypeDotName = fieldInfo.type().name();
    final DotName injectionTypeDotName = declaredTypeDotName == null || declaredTypeDotName.toString().equals(Object.class.getName()) ? fieldInfo.type().name() : declaredTypeDotName;
    final String injectionType = injectionTypeDotName.toString();
    final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
    if (bindingSource != null) {
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
        eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
        // setup the injection target
        final InjectionTarget injectionTarget = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString());
        // source is always local ENC jndi
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
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) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) DotName(org.jboss.jandex.DotName) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 30 with AnnotationValue

use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.

the class WSIntegrationProcessorJAXWS_JMS method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) {
        return;
    }
    final List<AnnotationInstance> webServiceAnnotations = getAnnotations(unit, WEB_SERVICE_ANNOTATION);
    // TODO: how about @WebServiceProvider JMS based endpoints?
    // group @WebService annotations in the deployment by wsdl contract location
    Map<String, List<AnnotationInstance>> map = new HashMap<String, List<AnnotationInstance>>();
    for (AnnotationInstance webServiceAnnotation : webServiceAnnotations) {
        final AnnotationValue wsdlLocation = webServiceAnnotation.value(WSDL_LOCATION);
        final AnnotationValue port = webServiceAnnotation.value(PORT_NAME);
        final AnnotationValue service = webServiceAnnotation.value(SERVICE_NAME);
        // support for contract-first development only: pick-up @WebService annotations referencing a provided wsdl contract only
        if (wsdlLocation != null && port != null && service != null) {
            String key = wsdlLocation.asString();
            List<AnnotationInstance> annotations = map.get(key);
            if (annotations == null) {
                annotations = new LinkedList<AnnotationInstance>();
                map.put(key, annotations);
            }
            annotations.add(webServiceAnnotation);
        }
    }
    // extract SOAP-over-JMS 1.0 bindings
    List<JMSEndpointMetaData> list = new LinkedList<JMSEndpointMetaData>();
    if (!map.isEmpty()) {
        for (String wsdlLocation : map.keySet()) {
            try {
                final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
                if (resourceRoot == null)
                    continue;
                final VirtualFile wsdlLocationFile = resourceRoot.getRoot().getChild(wsdlLocation);
                final URL url = wsdlLocationFile.toURL();
                SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
                for (AnnotationInstance ai : map.get(wsdlLocation)) {
                    String port = ai.value(PORT_NAME).asString();
                    String service = ai.value(SERVICE_NAME).asString();
                    AnnotationValue targetNS = ai.value(TARGET_NAMESPACE);
                    String tns = targetNS != null ? targetNS.asString() : null;
                    QName serviceName = new QName(tns, service);
                    QName portName = new QName(tns, port);
                    String soapAddress = parser.filterSoapAddress(serviceName, portName, SOAPAddressWSDLParser.SOAP_OVER_JMS_NS);
                    if (soapAddress != null) {
                        ClassInfo webServiceClassInfo = (ClassInfo) ai.target();
                        String beanClassName = webServiceClassInfo.name().toString();
                        // service name ?
                        list.add(new JMSEndpointMetaData(beanClassName, port, beanClassName, wsdlLocation, soapAddress));
                    }
                }
            } catch (Exception ignore) {
                WSLogger.ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
            }
        }
    }
    unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, new JMSEndpointsMetaData(list));
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JMSEndpointsMetaData(org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData) LinkedList(java.util.LinkedList) URL(java.net.URL) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JMSEndpointMetaData(org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) LinkedList(java.util.LinkedList) AttachmentList(org.jboss.as.server.deployment.AttachmentList) List(java.util.List) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SOAPAddressWSDLParser(org.jboss.ws.common.deployment.SOAPAddressWSDLParser) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

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