public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); for (DotName annotationName : PASSIVATION_ANNOTATIONS) { final List<AnnotationInstance> lifecycles = index.getAnnotations(annotationName); for (AnnotationInstance annotation : lifecycles) { processPassivation(eeModuleDescription, annotation.target(), annotationName); } } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); 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; 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(); AnnotationValue inheritedAnnValue = annotationInstance.value("inherited"); if (inheritedAnnValue != null) { inherited = inheritedAnnValue.asBoolean();
public static String asRequiredString(AnnotationInstance annotationInstance, final String attributeName, PropertyReplacer propertyReplacer) { final AnnotationValue nameValue = annotationInstance.value(attributeName); if (nameValue == null) { throw ROOT_LOGGER.annotationAttributeMissing(annotationInstance.name().toString(), attributeName); } final String nameValueAsString = nameValue.asString(); if (nameValueAsString.isEmpty()) { throw ROOT_LOGGER.annotationAttributeMissing(annotationInstance.name().toString(), attributeName); } return propertyReplacer != null ? propertyReplacer.replaceProperties(nameValueAsString) : nameValueAsString; } }
protected List<TargetAnnotation> fromMultiAnnotation(AnnotationInstance multiAnnotationInstance) { List<TargetAnnotation> instances = new ArrayList<TargetAnnotation>(); final AnnotationInstance[] values = multiAnnotationInstance.value().asNestedArray(); for(AnnotationInstance value : values) { instances.add(new TargetAnnotation(value, multiAnnotationInstance.target())); } return instances; }
private List<BindingConfiguration> getAnnotatedClassBindingConfigurations(EEModuleDescription moduleDescription, AnnotationInstance annotationInstance) throws DeploymentUnitProcessingException { final AnnotationTarget target = annotationInstance.target(); if (!(target instanceof ClassInfo)) { throw ROOT_LOGGER.classOnlyAnnotation(annotationInstance.toString(), target); } final ClassInfo classInfo = (ClassInfo) target; return moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString()).getBindingConfigurations(); }
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final EEApplicationClasses eeApplicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); processApplicationAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ProcessApplication.class.getName())); postDeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PostDeploy.class.getName())); preUndeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PreUndeploy.class.getName())); servletProcessApplications = compositeIndex.getAllKnownSubclasses(DotName.createSimple(ServletProcessApplication.class.getName())); } else { ClassInfo paClassInfo = (ClassInfo) annotationInstance.target(); String paClassName = paClassInfo.name().toString(); if(listenerMetaData.getListenerClass().equals(paClassInfo.name().toString())) { isListener = true;
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(RESOURCE_ANNOTATION_NAME); for (AnnotationInstance annotation : resourceAnnotations) { final AnnotationTarget annotationTarget = annotation.target(); final AnnotationValue nameValue = annotation.value("name"); final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null; final AnnotationValue typeValue = annotation.value("type"); final String type = typeValue != null ? typeValue.asClass().name().toString() : null; if (annotationTarget instanceof FieldInfo) { final FieldInfo fieldInfo = (FieldInfo) annotationTarget; final ClassInfo classInfo = fieldInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof MethodInfo) { final MethodInfo methodInfo = (MethodInfo) annotationTarget; ClassInfo classInfo = methodInfo.declaringClass(); EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); } else if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer); final List<AnnotationInstance> resourcesAnnotations = index.getAnnotations(RESOURCES_ANNOTATION_NAME); for (AnnotationInstance outerAnnotation : resourcesAnnotations) { final AnnotationTarget annotationTarget = outerAnnotation.target(); if (annotationTarget instanceof ClassInfo) { final ClassInfo classInfo = (ClassInfo) annotationTarget; final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray(); for (AnnotationInstance annotation : values) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit); if(compositeIndex == null) { return; final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME); if (instances == null || instances.isEmpty()) { return; AnnotationTarget target = instance.target(); if (!(target instanceof ClassInfo)) { throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target); continue; final String beanClassName = classInfo.name().toString(); final AnnotationValue nameValue = instance.value(); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString()); final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
@Override public final void installService(DeploymentPhaseContext ctx, String serviceName, T instance) { CompositeIndex index = ctx.getDeploymentUnit().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); List<AnnotationInstance> annotations = index.getAnnotations(NAMED_FACTORY); if (annotations.isEmpty()) ROOT_LOGGER.noFactoryName(getServiceClass().getName()); else { for (AnnotationInstance annotation : annotations) { AnnotationTarget annotationTarget = annotation.target(); if (annotationTarget instanceof ClassInfo) { ClassInfo classInfo = (ClassInfo) annotationTarget; DotName target = DotName.createSimple(serviceName); if (classInfo.name().equals(target)) { String nameValue = annotation.value("name").asString(); AbstractExtensionManagerService<T> service = createService(nameValue, instance); ServiceName extensionServiceName = Constants.DATAGRID.append(service.getServiceTypeName(), nameValue.replaceAll("\\.", "_")); ServiceBuilder<T> serviceBuilder = ctx.getServiceTarget() .addService(extensionServiceName, service) .setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(extensionManagerServiceName, ExtensionManagerService.class, service.getExtensionManager()); serviceBuilder.install(); } } } } }
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if(JsfVersionMarker.isJsfDisabled(deploymentUnit)) { return; final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); if (compositeIndex == null) { return; // Can not continue without index final Module module = deploymentUnit.getAttachment(Attachments.MODULE); if (module == null) { return; // Can not continue without module final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName); if (annotationInstances == null || annotationInstances.isEmpty()) { continue; instances.put(annotation.annotationClass, discoveredClasses); for (AnnotationInstance annotationInstance : annotationInstances) { final AnnotationTarget target = annotationInstance.target(); if (target instanceof ClassInfo) { final DotName className = ClassInfo.class.cast(target).name(); final Class<?> annotatedClass; try { annotatedClass = classLoader.loadClass(className.toString()); } catch (ClassNotFoundException e) { throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className)); deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME); final AnnotationTarget annotationTarget = annotation.target(); final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer); if (annotationTarget instanceof FieldInfo) { final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME); for (AnnotationInstance annotation : ejbsAnnotations) { final AnnotationTarget annotationTarget = annotation.target(); if (annotationTarget instanceof ClassInfo) { final AnnotationValue annotationValue = annotation.value(); final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray(); for (AnnotationInstance ejbAnnotation : ejbAnnotations) { final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer); throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
final Set<Class<? extends ServerApplicationConfig>> config = new HashSet<>(); final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); final List<AnnotationInstance> serverEndpoints = index.getAnnotations(SERVER_ENDPOINT); if (serverEndpoints != null) { for (AnnotationInstance endpoint : serverEndpoints) { if (endpoint.target() instanceof ClassInfo) { ClassInfo clazz = (ClassInfo) endpoint.target(); try { Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { annotatedEndpoints.add(moduleClass); UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e); final List<AnnotationInstance> clientEndpoints = index.getAnnotations(CLIENT_ENDPOINT); if (clientEndpoints != null) { for (AnnotationInstance endpoint : clientEndpoints) { if (endpoint.target() instanceof ClassInfo) { ClassInfo clazz = (ClassInfo) endpoint.target(); try { Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module); if (!Modifier.isAbstract(moduleClass.getModifiers())) { annotatedEndpoints.add(moduleClass); final Set<ClassInfo> subclasses = index.getAllKnownImplementors(SERVER_APPLICATION_CONFIG);
protected Class<?> getPaClass(AnnotationInstance annotation) throws ClassNotFoundException { String paClassName = ((MethodInfo)annotation.target()).declaringClass().name().toString(); Class<?> paClass = paModule.getClassLoader().loadClass(paClassName); return paClass; }
private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) { final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit); final AnnotationTarget target = sessionBeanAnnotation.target(); if (!(target instanceof ClassInfo)) { EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage()); continue; continue; final String ejbName = sessionBeanClassInfo.name().local(); final AnnotationValue nameValue = sessionBeanAnnotation.value("name"); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString()); final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class); final SessionBeanComponentDescription.SessionBeanType sessionBeanType; final String beanClassName; if (beanMetaData != null) { beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass()); sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType())); } else { beanClassName = sessionBeanClassInfo.name().toString(); sessionBeanType = annotatedSessionBeanType; final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean(); final Boolean passivationCapableDeploymentDescriptorValue; if ((beanMetaData instanceof SessionBean32MetaData)) {
final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); DeploymentDescriptorEnvironment deploymentDescriptorEnvironment = null; final AnnotationTarget target = messageBeanAnnotation.target(); final ClassInfo beanClassInfo = (ClassInfo) target; if (! EjbValidationsUtil.assertEjbClassValidity(beanClassInfo).isEmpty() ) { continue; final String ejbName = beanClassInfo.name().local(); final AnnotationValue nameValue = messageBeanAnnotation.value("name"); final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString()); final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class); final String beanClassName; final String messagingType; if (beanMetaData != null) { beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass()); deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData); beanClassName = beanClassInfo.name().toString(); messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation); final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry()); final MessageDrivenComponentDescription beanDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, messageListenerInterfaceName, activationConfigProperties, defaultResourceAdapterName, beanMetaData, defaultMdbPoolAvailable); beanDescription.setDeploymentDescriptorEnvironment(deploymentDescriptorEnvironment);
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); } }
@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass .getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
protected void process(final DeploymentPhaseContext phaseContext, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final String injectionType, final String localContextName, final InjectionTarget targetDescription, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException { final EEResourceReferenceProcessorRegistry registry = phaseContext.getDeploymentUnit().getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY); final AnnotationValue lookupAnnotation = annotation.value("lookup"); String lookup = (lookupAnnotation == null) ? null : replacer.replaceProperties(lookupAnnotation.asString()); final AnnotationValue mappedNameAnnotationValue = annotation.value("mappedName"); lookup = (mappedNameAnnotationValue == null) ? null : replacer.replaceProperties(mappedNameAnnotationValue.asString());
private boolean hasInjectConstructor() { List<AnnotationInstance> annotationInstances = classInfo.annotations().get(DOT_NAME_INJECT); if (annotationInstances != null) { for (AnnotationInstance instance : annotationInstances) { AnnotationTarget target = instance.target(); if (target instanceof MethodInfo) { MethodInfo methodInfo = (MethodInfo) target; if (methodInfo.name().equals(CONSTRUCTOR_METHOD_NAME)) { return true; } } } } return false; }
private void handleAnnotations(final CompositeIndex index, final Set<String> managedBeanClasses) throws DeploymentUnitProcessingException { final List<AnnotationInstance> annotations = index.getAnnotations(MANAGED_BEAN_ANNOTATION); if (annotations != null) { for (final AnnotationInstance annotation : annotations) { final AnnotationTarget target = annotation.target(); if (target instanceof ClassInfo) { final String className = ((ClassInfo) target).name().toString(); managedBeanClasses.add(className); } else { throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidManagedBeanAnnotation(target)); } } } }